1 // Copyright 2017 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_FXCODEC_JPX_CJPX_DECODER_H_ 8 #define CORE_FXCODEC_JPX_CJPX_DECODER_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxcrt/unowned_ptr.h" 14 #include "third_party/base/span.h" 15 16 #if defined(USE_SYSTEM_LIBOPENJPEG2) 17 #include <openjpeg.h> 18 #else 19 #include "third_party/libopenjpeg20/openjpeg.h" 20 #endif 21 22 namespace fxcodec { 23 24 struct DecodeData; 25 26 class CJPX_Decoder { 27 public: 28 enum ColorSpaceOption { 29 kNoColorSpace, 30 kNormalColorSpace, 31 kIndexedColorSpace 32 }; 33 34 struct JpxImageInfo { 35 uint32_t width; 36 uint32_t height; 37 uint32_t components; 38 }; 39 40 static void Sycc420ToRgbForTesting(opj_image_t* img); 41 42 explicit CJPX_Decoder(ColorSpaceOption option); 43 ~CJPX_Decoder(); 44 45 bool Init(pdfium::span<const uint8_t> src_data); 46 JpxImageInfo GetInfo() const; 47 bool StartDecode(); 48 49 // |swap_rgb| can only be set for images with 3 or more components. 50 bool Decode(uint8_t* dest_buf, uint32_t pitch, bool swap_rgb); 51 52 private: 53 const ColorSpaceOption m_ColorSpaceOption; 54 pdfium::span<const uint8_t> m_SrcData; 55 UnownedPtr<opj_image_t> m_Image; 56 UnownedPtr<opj_codec_t> m_Codec; 57 std::unique_ptr<DecodeData> m_DecodeData; 58 UnownedPtr<opj_stream_t> m_Stream; 59 opj_dparameters_t m_Parameters; 60 }; 61 62 } // namespace fxcodec 63 64 using fxcodec::CJPX_Decoder; 65 66 #endif // CORE_FXCODEC_JPX_CJPX_DECODER_H_ 67