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