blob: 1fe50437da85e3ba75cb567efa611008cfb906e5 [file] [log] [blame]
Dan Sinclair0bb13332017-03-30 16:12:02 -04001// 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 Zhangffa67dd2019-06-17 20:27:52 +00007#ifndef CORE_FXCODEC_JPX_CJPX_DECODER_H_
8#define CORE_FXCODEC_JPX_CJPX_DECODER_H_
Dan Sinclair0bb13332017-03-30 16:12:02 -04009
Ryan Harrison808b52a2017-09-08 10:10:26 -040010#include <memory>
Dan Sinclair0bb13332017-03-30 16:12:02 -040011
Dan Sinclairaee0db02017-09-21 16:53:58 -040012#include "core/fxcrt/unowned_ptr.h"
Tom Sepez00ba8bb2018-06-27 18:02:30 +000013#include "third_party/base/span.h"
Felix Kauselmann8d72a472019-02-13 23:44:56 +000014
Lei Zhang20707712019-06-17 20:29:12 +000015#if defined(USE_SYSTEM_LIBOPENJPEG2)
Felix Kauselmann8d72a472019-02-13 23:44:56 +000016#include <openjpeg.h>
17#else
Dan Sinclair0bb13332017-03-30 16:12:02 -040018#include "third_party/libopenjpeg20/openjpeg.h"
Felix Kauselmann8d72a472019-02-13 23:44:56 +000019#endif
Dan Sinclair0bb13332017-03-30 16:12:02 -040020
Lei Zhang20707712019-06-17 20:29:12 +000021namespace fxcodec {
22
23struct DecodeData;
24
Dan Sinclair0bb13332017-03-30 16:12:02 -040025class CJPX_Decoder {
26 public:
Tom Sepez7ade67c2019-05-31 21:34:51 +000027 enum ColorSpaceOption {
28 kNoColorSpace,
29 kNormalColorSpace,
30 kIndexedColorSpace
31 };
32
Lei Zhang20707712019-06-17 20:29:12 +000033 static void Sycc420ToRgbForTesting(opj_image_t* img);
34
Tom Sepez7ade67c2019-05-31 21:34:51 +000035 explicit CJPX_Decoder(ColorSpaceOption option);
Dan Sinclair0bb13332017-03-30 16:12:02 -040036 ~CJPX_Decoder();
37
Tom Sepez00ba8bb2018-06-27 18:02:30 +000038 bool Init(pdfium::span<const uint8_t> src_data);
Dan Sinclair0bb13332017-03-30 16:12:02 -040039 void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components);
Nicolas Penafa7983e2018-11-16 21:54:51 +000040 bool StartDecode();
Dan Sinclair0bb13332017-03-30 16:12:02 -040041 bool Decode(uint8_t* dest_buf,
Ryan Harrisonb6e01172018-06-20 13:43:04 +000042 uint32_t pitch,
Tom Sepez237c4dd2019-11-20 23:52:03 +000043 pdfium::span<const uint8_t> offsets);
Dan Sinclair0bb13332017-03-30 16:12:02 -040044
45 private:
Tom Sepez7ade67c2019-05-31 21:34:51 +000046 const ColorSpaceOption m_ColorSpaceOption;
Tom Sepez00ba8bb2018-06-27 18:02:30 +000047 pdfium::span<const uint8_t> m_SrcData;
48 UnownedPtr<opj_image_t> m_Image;
49 UnownedPtr<opj_codec_t> m_Codec;
Ryan Harrison808b52a2017-09-08 10:10:26 -040050 std::unique_ptr<DecodeData> m_DecodeData;
Tom Sepez00ba8bb2018-06-27 18:02:30 +000051 UnownedPtr<opj_stream_t> m_Stream;
Ryan Harrison808b52a2017-09-08 10:10:26 -040052 opj_dparameters_t m_Parameters;
Dan Sinclair0bb13332017-03-30 16:12:02 -040053};
54
Lei Zhang20707712019-06-17 20:29:12 +000055} // namespace fxcodec
56
57using fxcodec::CJPX_Decoder;
58
Lei Zhangffa67dd2019-06-17 20:27:52 +000059#endif // CORE_FXCODEC_JPX_CJPX_DECODER_H_