From 0bb1333a9eff1190ddd68f34c71d6a779c69dfef Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 30 Mar 2017 16:12:02 -0400 Subject: Add some calls to MakeUnique This CL replaces some new's with pdfium::MakeUnique. Change-Id: I50faf3ed55e7730b094c14a7989a9dd51cf33cbb Reviewed-on: https://pdfium-review.googlesource.com/3430 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- core/fxcodec/codec/fx_codec_jpx_opj.cpp | 37 +++++++++------------------------ 1 file changed, 10 insertions(+), 27 deletions(-) (limited to 'core/fxcodec/codec/fx_codec_jpx_opj.cpp') 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 #include #include +#include #include #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& 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 decoder(new CJPX_Decoder(cs)); - return decoder->Init(src_buf, src_size) ? decoder.release() : nullptr; +std::unique_ptr CCodec_JpxModule::CreateDecoder( + const uint8_t* src_buf, + uint32_t src_size, + CPDF_ColorSpace* cs) { + auto decoder = pdfium::MakeUnique(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& offsets) { return pDecoder->Decode(dest_data, pitch, offsets); } - -void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { - delete pDecoder; -} -- cgit v1.2.3