blob: 8c607e242632e5dcb00618ce18e1a3d11de463f0 [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#include <vector>
12
Ryan Harrison808b52a2017-09-08 10:10:26 -040013#include "core/fxcodec/codec/codec_int.h"
Dan Sinclairaee0db02017-09-21 16:53:58 -040014#include "core/fxcrt/unowned_ptr.h"
Tom Sepez00ba8bb2018-06-27 18:02:30 +000015#include "third_party/base/span.h"
Felix Kauselmann8d72a472019-02-13 23:44:56 +000016
17#ifdef USE_SYSTEM_LIBOPENJPEG2
18#include <openjpeg.h>
19#else
Dan Sinclair0bb13332017-03-30 16:12:02 -040020#include "third_party/libopenjpeg20/openjpeg.h"
Felix Kauselmann8d72a472019-02-13 23:44:56 +000021#endif
Dan Sinclair0bb13332017-03-30 16:12:02 -040022
Dan Sinclair0bb13332017-03-30 16:12:02 -040023class CJPX_Decoder {
24 public:
Tom Sepez7ade67c2019-05-31 21:34:51 +000025 enum ColorSpaceOption {
26 kNoColorSpace,
27 kNormalColorSpace,
28 kIndexedColorSpace
29 };
30
31 explicit CJPX_Decoder(ColorSpaceOption option);
Dan Sinclair0bb13332017-03-30 16:12:02 -040032 ~CJPX_Decoder();
33
Tom Sepez00ba8bb2018-06-27 18:02:30 +000034 bool Init(pdfium::span<const uint8_t> src_data);
Dan Sinclair0bb13332017-03-30 16:12:02 -040035 void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components);
Nicolas Penafa7983e2018-11-16 21:54:51 +000036 bool StartDecode();
Dan Sinclair0bb13332017-03-30 16:12:02 -040037 bool Decode(uint8_t* dest_buf,
Ryan Harrisonb6e01172018-06-20 13:43:04 +000038 uint32_t pitch,
Dan Sinclair0bb13332017-03-30 16:12:02 -040039 const std::vector<uint8_t>& offsets);
40
41 private:
Tom Sepez7ade67c2019-05-31 21:34:51 +000042 const ColorSpaceOption m_ColorSpaceOption;
Tom Sepez00ba8bb2018-06-27 18:02:30 +000043 pdfium::span<const uint8_t> m_SrcData;
44 UnownedPtr<opj_image_t> m_Image;
45 UnownedPtr<opj_codec_t> m_Codec;
Ryan Harrison808b52a2017-09-08 10:10:26 -040046 std::unique_ptr<DecodeData> m_DecodeData;
Tom Sepez00ba8bb2018-06-27 18:02:30 +000047 UnownedPtr<opj_stream_t> m_Stream;
Ryan Harrison808b52a2017-09-08 10:10:26 -040048 opj_dparameters_t m_Parameters;
Dan Sinclair0bb13332017-03-30 16:12:02 -040049};
50
Lei Zhangffa67dd2019-06-17 20:27:52 +000051#endif // CORE_FXCODEC_JPX_CJPX_DECODER_H_