summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r--core/fxcodec/codec/ccodec_jpxmodule.h8
-rw-r--r--core/fxcodec/codec/cjpx_decoder.h36
-rw-r--r--core/fxcodec/codec/fx_codec_flate.cpp4
-rw-r--r--core/fxcodec/codec/fx_codec_jpx_opj.cpp37
4 files changed, 52 insertions, 33 deletions
diff --git a/core/fxcodec/codec/ccodec_jpxmodule.h b/core/fxcodec/codec/ccodec_jpxmodule.h
index fd919d91b0..c57002722e 100644
--- a/core/fxcodec/codec/ccodec_jpxmodule.h
+++ b/core/fxcodec/codec/ccodec_jpxmodule.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_
#define CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_
+#include <memory>
#include <vector>
#include "core/fxcrt/fx_system.h"
@@ -19,9 +20,9 @@ class CCodec_JpxModule {
CCodec_JpxModule();
~CCodec_JpxModule();
- CJPX_Decoder* CreateDecoder(const uint8_t* src_buf,
- uint32_t src_size,
- CPDF_ColorSpace* cs);
+ std::unique_ptr<CJPX_Decoder> CreateDecoder(const uint8_t* src_buf,
+ uint32_t src_size,
+ CPDF_ColorSpace* cs);
void GetImageInfo(CJPX_Decoder* pDecoder,
uint32_t* width,
uint32_t* height,
@@ -30,7 +31,6 @@ class CCodec_JpxModule {
uint8_t* dest_data,
int pitch,
const std::vector<uint8_t>& offsets);
- void DestroyDecoder(CJPX_Decoder* pDecoder);
};
#endif // CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_
diff --git a/core/fxcodec/codec/cjpx_decoder.h b/core/fxcodec/codec/cjpx_decoder.h
new file mode 100644
index 0000000000..2e63caac73
--- /dev/null
+++ b/core/fxcodec/codec/cjpx_decoder.h
@@ -0,0 +1,36 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FXCODEC_CODEC_CJPX_DECODER_H_
+#define CORE_FXCODEC_CODEC_CJPX_DECODER_H_
+
+#include <vector>
+
+#include "third_party/libopenjpeg20/openjpeg.h"
+
+class CPDF_ColorSpace;
+
+class CJPX_Decoder {
+ public:
+ explicit CJPX_Decoder(CPDF_ColorSpace* cs);
+ ~CJPX_Decoder();
+
+ bool Init(const unsigned char* src_data, uint32_t src_size);
+ void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components);
+ bool Decode(uint8_t* dest_buf,
+ int pitch,
+ const std::vector<uint8_t>& offsets);
+
+ private:
+ const uint8_t* m_SrcData;
+ uint32_t m_SrcSize;
+ opj_image_t* image;
+ opj_codec_t* l_codec;
+ opj_stream_t* l_stream;
+ const CPDF_ColorSpace* const m_ColorSpace;
+};
+
+#endif // CORE_FXCODEC_CODEC_CJPX_DECODER_H_
diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp
index 7c19d335bb..269bf58813 100644
--- a/core/fxcodec/codec/fx_codec_flate.cpp
+++ b/core/fxcodec/codec/fx_codec_flate.cpp
@@ -822,7 +822,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW,
}
if (bLZW) {
{
- std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder);
+ auto decoder = pdfium::MakeUnique<CLZWDecoder>();
dest_size = 0xFFFFFFFF;
offset = src_size;
int err =
@@ -832,7 +832,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW,
}
}
{
- std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder);
+ auto decoder = pdfium::MakeUnique<CLZWDecoder>();
dest_buf = FX_Alloc(uint8_t, dest_size + 1);
dest_buf[dest_size] = '\0';
decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange);
diff --git a/core/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/fxcodec/codec/fx_codec_jpx_opj.cpp
index eccf876218..4fc3d689f1 100644
--- a/core/fxcodec/codec/fx_codec_jpx_opj.cpp
+++ b/core/fxcodec/codec/fx_codec_jpx_opj.cpp
@@ -7,12 +7,15 @@
#include <algorithm>
#include <limits>
#include <memory>
+#include <utility>
#include <vector>
#include "core/fpdfapi/page/cpdf_colorspace.h"
+#include "core/fxcodec/codec/cjpx_decoder.h"
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_safe_types.h"
+#include "third_party/base/ptr_util.h"
#include "third_party/lcms2-2.6/include/lcms2.h"
#include "third_party/libopenjpeg20/openjpeg.h"
@@ -669,24 +672,6 @@ void color_apply_conversion(opj_image_t* image) {
return;
}
}
-class CJPX_Decoder {
- public:
- explicit CJPX_Decoder(CPDF_ColorSpace* cs);
- ~CJPX_Decoder();
- bool Init(const unsigned char* src_data, uint32_t src_size);
- void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components);
- bool Decode(uint8_t* dest_buf,
- int pitch,
- const std::vector<uint8_t>& offsets);
-
- private:
- const uint8_t* m_SrcData;
- uint32_t m_SrcSize;
- opj_image_t* image;
- opj_codec_t* l_codec;
- opj_stream_t* l_stream;
- const CPDF_ColorSpace* const m_ColorSpace;
-};
CJPX_Decoder::CJPX_Decoder(CPDF_ColorSpace* cs)
: image(nullptr), l_codec(nullptr), l_stream(nullptr), m_ColorSpace(cs) {}
@@ -872,13 +857,15 @@ bool CJPX_Decoder::Decode(uint8_t* dest_buf,
}
CCodec_JpxModule::CCodec_JpxModule() {}
+
CCodec_JpxModule::~CCodec_JpxModule() {}
-CJPX_Decoder* CCodec_JpxModule::CreateDecoder(const uint8_t* src_buf,
- uint32_t src_size,
- CPDF_ColorSpace* cs) {
- std::unique_ptr<CJPX_Decoder> decoder(new CJPX_Decoder(cs));
- return decoder->Init(src_buf, src_size) ? decoder.release() : nullptr;
+std::unique_ptr<CJPX_Decoder> CCodec_JpxModule::CreateDecoder(
+ const uint8_t* src_buf,
+ uint32_t src_size,
+ CPDF_ColorSpace* cs) {
+ auto decoder = pdfium::MakeUnique<CJPX_Decoder>(cs);
+ return decoder->Init(src_buf, src_size) ? std::move(decoder) : nullptr;
}
void CCodec_JpxModule::GetImageInfo(CJPX_Decoder* pDecoder,
@@ -894,7 +881,3 @@ bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder,
const std::vector<uint8_t>& offsets) {
return pDecoder->Decode(dest_data, pitch, offsets);
}
-
-void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) {
- delete pDecoder;
-}