Home | History | Annotate | Download | only in parser
      1 // Copyright 2016 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef CORE_FPDFAPI_PARSER_FPDF_PARSER_DECODE_H_
      8 #define CORE_FPDFAPI_PARSER_FPDF_PARSER_DECODE_H_
      9 
     10 #include <memory>
     11 
     12 #include "core/fxcrt/fx_basic.h"
     13 
     14 class CCodec_ScanlineDecoder;
     15 class CPDF_Dictionary;
     16 
     17 // Indexed by 8-bit char code, contains unicode code points.
     18 extern const uint16_t PDFDocEncoding[256];
     19 
     20 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& orig);
     21 CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig);
     22 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig);
     23 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, bool bHex = false);
     24 CFX_WideString PDF_DecodeText(const uint8_t* pData, uint32_t size);
     25 CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr);
     26 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len = -1);
     27 CFX_ByteString PDF_EncodeText(const CFX_WideString& str);
     28 
     29 bool FlateEncode(const uint8_t* src_buf,
     30                  uint32_t src_size,
     31                  uint8_t** dest_buf,
     32                  uint32_t* dest_size);
     33 
     34 // This used to have more parameters like the predictor and bpc, but there was
     35 // only one caller, so the interface has been simplified, the values are hard
     36 // coded, and dead code has been removed.
     37 bool PngEncode(const uint8_t* src_buf,
     38                uint32_t src_size,
     39                uint8_t** dest_buf,
     40                uint32_t* dest_size);
     41 
     42 uint32_t FlateDecode(const uint8_t* src_buf,
     43                      uint32_t src_size,
     44                      uint8_t*& dest_buf,
     45                      uint32_t& dest_size);
     46 uint32_t RunLengthDecode(const uint8_t* src_buf,
     47                          uint32_t src_size,
     48                          uint8_t*& dest_buf,
     49                          uint32_t& dest_size);
     50 
     51 std::unique_ptr<CCodec_ScanlineDecoder> FPDFAPI_CreateFaxDecoder(
     52     const uint8_t* src_buf,
     53     uint32_t src_size,
     54     int width,
     55     int height,
     56     const CPDF_Dictionary* pParams);
     57 
     58 std::unique_ptr<CCodec_ScanlineDecoder> FPDFAPI_CreateFlateDecoder(
     59     const uint8_t* src_buf,
     60     uint32_t src_size,
     61     int width,
     62     int height,
     63     int nComps,
     64     int bpc,
     65     const CPDF_Dictionary* pParams);
     66 
     67 // Public for testing.
     68 uint32_t A85Decode(const uint8_t* src_buf,
     69                    uint32_t src_size,
     70                    uint8_t*& dest_buf,
     71                    uint32_t& dest_size);
     72 // Public for testing.
     73 uint32_t HexDecode(const uint8_t* src_buf,
     74                    uint32_t src_size,
     75                    uint8_t*& dest_buf,
     76                    uint32_t& dest_size);
     77 // Public for testing.
     78 uint32_t FPDFAPI_FlateOrLZWDecode(bool bLZW,
     79                                   const uint8_t* src_buf,
     80                                   uint32_t src_size,
     81                                   CPDF_Dictionary* pParams,
     82                                   uint32_t estimated_size,
     83                                   uint8_t*& dest_buf,
     84                                   uint32_t& dest_size);
     85 bool PDF_DataDecode(const uint8_t* src_buf,
     86                     uint32_t src_size,
     87                     const CPDF_Dictionary* pDict,
     88                     uint8_t*& dest_buf,
     89                     uint32_t& dest_size,
     90                     CFX_ByteString& ImageEncoding,
     91                     CPDF_Dictionary*& pImageParms,
     92                     uint32_t estimated_size,
     93                     bool bImageAcc);
     94 
     95 #endif  // CORE_FPDFAPI_PARSER_FPDF_PARSER_DECODE_H_
     96