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 #include <utility> 12 #include <vector> 13 14 #include "core/fxcrt/fx_memory_wrappers.h" 15 #include "core/fxcrt/fx_string.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 #include "third_party/base/optional.h" 18 #include "third_party/base/span.h" 19 20 class CPDF_Array; 21 class CPDF_Dictionary; 22 class CPDF_Object; 23 24 namespace fxcodec { 25 class ScanlineDecoder; 26 } 27 28 // Indexed by 8-bit char code, contains unicode code points. 29 extern const uint16_t PDFDocEncoding[256]; 30 31 bool ValidateDecoderPipeline(const CPDF_Array* pDecoders); 32 33 ByteString PDF_EncodeString(const ByteString& src, bool bHex); 34 WideString PDF_DecodeText(pdfium::span<const uint8_t> span); 35 ByteString PDF_EncodeText(const WideString& str); 36 37 std::unique_ptr<fxcodec::ScanlineDecoder> CreateFaxDecoder( 38 pdfium::span<const uint8_t> src_span, 39 int width, 40 int height, 41 const CPDF_Dictionary* pParams); 42 43 std::unique_ptr<fxcodec::ScanlineDecoder> CreateFlateDecoder( 44 pdfium::span<const uint8_t> src_span, 45 int width, 46 int height, 47 int nComps, 48 int bpc, 49 const CPDF_Dictionary* pParams); 50 51 bool FlateEncode(pdfium::span<const uint8_t> src_span, 52 std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, 53 uint32_t* dest_size); 54 55 uint32_t FlateDecode(pdfium::span<const uint8_t> src_span, 56 std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, 57 uint32_t* dest_size); 58 59 uint32_t RunLengthDecode(pdfium::span<const uint8_t> src_span, 60 std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, 61 uint32_t* dest_size); 62 63 uint32_t A85Decode(pdfium::span<const uint8_t> src_span, 64 std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, 65 uint32_t* dest_size); 66 67 uint32_t HexDecode(pdfium::span<const uint8_t> src_span, 68 std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, 69 uint32_t* dest_size); 70 71 uint32_t FlateOrLZWDecode(bool bLZW, 72 pdfium::span<const uint8_t> src_span, 73 const CPDF_Dictionary* pParams, 74 uint32_t estimated_size, 75 std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, 76 uint32_t* dest_size); 77 78 Optional<std::vector<std::pair<ByteString, const CPDF_Object*>>> 79 GetDecoderArray(const CPDF_Dictionary* pDict); 80 81 bool PDF_DataDecode( 82 pdfium::span<const uint8_t> src_span, 83 uint32_t estimated_size, 84 bool bImageAcc, 85 const std::vector<std::pair<ByteString, const CPDF_Object*>>& decoder_array, 86 std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, 87 uint32_t* dest_size, 88 ByteString* ImageEncoding, 89 RetainPtr<const CPDF_Dictionary>* pImageParams); 90 91 #endif // CORE_FPDFAPI_PARSER_FPDF_PARSER_DECODE_H_ 92