Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 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 | |
Lei Zhang | ffa67dd | 2019-06-17 20:27:52 +0000 | [diff] [blame^] | 7 | #ifndef CORE_FXCODEC_JPX_CJPX_DECODER_H_ |
| 8 | #define CORE_FXCODEC_JPX_CJPX_DECODER_H_ |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 9 | |
Ryan Harrison | 808b52a | 2017-09-08 10:10:26 -0400 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
Ryan Harrison | 808b52a | 2017-09-08 10:10:26 -0400 | [diff] [blame] | 13 | #include "core/fxcodec/codec/codec_int.h" |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 14 | #include "core/fxcrt/unowned_ptr.h" |
Tom Sepez | 00ba8bb | 2018-06-27 18:02:30 +0000 | [diff] [blame] | 15 | #include "third_party/base/span.h" |
Felix Kauselmann | 8d72a47 | 2019-02-13 23:44:56 +0000 | [diff] [blame] | 16 | |
| 17 | #ifdef USE_SYSTEM_LIBOPENJPEG2 |
| 18 | #include <openjpeg.h> |
| 19 | #else |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 20 | #include "third_party/libopenjpeg20/openjpeg.h" |
Felix Kauselmann | 8d72a47 | 2019-02-13 23:44:56 +0000 | [diff] [blame] | 21 | #endif |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 22 | |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 23 | class CJPX_Decoder { |
| 24 | public: |
Tom Sepez | 7ade67c | 2019-05-31 21:34:51 +0000 | [diff] [blame] | 25 | enum ColorSpaceOption { |
| 26 | kNoColorSpace, |
| 27 | kNormalColorSpace, |
| 28 | kIndexedColorSpace |
| 29 | }; |
| 30 | |
| 31 | explicit CJPX_Decoder(ColorSpaceOption option); |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 32 | ~CJPX_Decoder(); |
| 33 | |
Tom Sepez | 00ba8bb | 2018-06-27 18:02:30 +0000 | [diff] [blame] | 34 | bool Init(pdfium::span<const uint8_t> src_data); |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 35 | void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components); |
Nicolas Pena | fa7983e | 2018-11-16 21:54:51 +0000 | [diff] [blame] | 36 | bool StartDecode(); |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 37 | bool Decode(uint8_t* dest_buf, |
Ryan Harrison | b6e0117 | 2018-06-20 13:43:04 +0000 | [diff] [blame] | 38 | uint32_t pitch, |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 39 | const std::vector<uint8_t>& offsets); |
| 40 | |
| 41 | private: |
Tom Sepez | 7ade67c | 2019-05-31 21:34:51 +0000 | [diff] [blame] | 42 | const ColorSpaceOption m_ColorSpaceOption; |
Tom Sepez | 00ba8bb | 2018-06-27 18:02:30 +0000 | [diff] [blame] | 43 | pdfium::span<const uint8_t> m_SrcData; |
| 44 | UnownedPtr<opj_image_t> m_Image; |
| 45 | UnownedPtr<opj_codec_t> m_Codec; |
Ryan Harrison | 808b52a | 2017-09-08 10:10:26 -0400 | [diff] [blame] | 46 | std::unique_ptr<DecodeData> m_DecodeData; |
Tom Sepez | 00ba8bb | 2018-06-27 18:02:30 +0000 | [diff] [blame] | 47 | UnownedPtr<opj_stream_t> m_Stream; |
Ryan Harrison | 808b52a | 2017-09-08 10:10:26 -0400 | [diff] [blame] | 48 | opj_dparameters_t m_Parameters; |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
Lei Zhang | ffa67dd | 2019-06-17 20:27:52 +0000 | [diff] [blame^] | 51 | #endif // CORE_FXCODEC_JPX_CJPX_DECODER_H_ |