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/ccodec_jpxmodule.h | 8 +++---- core/fxcodec/codec/cjpx_decoder.h | 36 ++++++++++++++++++++++++++++++++ core/fxcodec/codec/fx_codec_flate.cpp | 4 ++-- core/fxcodec/codec/fx_codec_jpx_opj.cpp | 37 +++++++++------------------------ 4 files changed, 52 insertions(+), 33 deletions(-) create mode 100644 core/fxcodec/codec/cjpx_decoder.h (limited to 'core/fxcodec/codec') 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 #include #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 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& 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 + +#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& 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 decoder(new CLZWDecoder); + auto decoder = pdfium::MakeUnique(); dest_size = 0xFFFFFFFF; offset = src_size; int err = @@ -832,7 +832,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, } } { - std::unique_ptr decoder(new CLZWDecoder); + auto decoder = pdfium::MakeUnique(); 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 #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