diff options
Diffstat (limited to 'core/fxcodec')
-rw-r--r-- | core/fxcodec/codec/ccodec_jpxmodule.h | 8 | ||||
-rw-r--r-- | core/fxcodec/codec/cjpx_decoder.h | 36 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_flate.cpp | 4 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jpx_opj.cpp | 37 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Context.cpp | 38 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GrdProc.cpp | 17 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GrrdProc.cpp | 9 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GsidProc.cpp | 5 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_HtrdProc.cpp | 8 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_PddProc.cpp | 9 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_TrdProc.cpp | 14 |
11 files changed, 102 insertions, 83 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; -} diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 109013204e..9261d16bfc 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -122,7 +122,7 @@ int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { int32_t nRet; while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { - std::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); + auto pSegment = pdfium::MakeUnique<CJBig2_Segment>(); nRet = parseSegmentHeader(pSegment.get()); if (nRet != JBIG2_SUCCESS) { return nRet; @@ -364,7 +364,7 @@ int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, return parseGenericRefinementRegion(pSegment); case 48: { uint16_t wTemp; - std::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); + auto pPageInfo = pdfium::MakeUnique<JBig2PageInfo>(); if (m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0 || m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0 || m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0 || @@ -424,7 +424,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, if (m_pStream->readShortInteger(&wFlags) != 0) return JBIG2_ERROR_TOO_SHORT; - std::unique_ptr<CJBig2_SDDProc> pSymbolDictDecoder(new CJBig2_SDDProc); + auto pSymbolDictDecoder = pdfium::MakeUnique<CJBig2_SDDProc>(); pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; @@ -600,8 +600,8 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, } if (!cache_hit) { if (bUseGbContext) { - std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = + pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_Result.sd = pSymbolDictDecoder->decode_Arith( pArithDecoder.get(), &gbContext, &grContext); if (!pSegment->m_Result.sd) @@ -644,7 +644,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { return JBIG2_ERROR_TOO_SHORT; } - std::unique_ptr<CJBig2_TRDProc> pTRD(new CJBig2_TRDProc); + auto pTRD = pdfium::MakeUnique<CJBig2_TRDProc>(); pTRD->SBW = ri.width; pTRD->SBH = ri.height; pTRD->SBHUFF = wFlags & 0x0001; @@ -902,8 +902,8 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); } if (pTRD->SBHUFF == 0) { - std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = + pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_nResultType = JBIG2_IMAGE_POINTER; pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder.get(), grContext.get(), nullptr); @@ -938,7 +938,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, IFX_Pause* pPause) { uint8_t cFlags; - std::unique_ptr<CJBig2_PDDProc> pPDD(new CJBig2_PDDProc); + auto pPDD = pdfium::MakeUnique<CJBig2_PDDProc>(); if (m_pStream->read1Byte(&cFlags) != 0 || m_pStream->read1Byte(&pPDD->HDPW) != 0 || m_pStream->read1Byte(&pPDD->HDPH) != 0 || @@ -956,8 +956,8 @@ int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( FX_Alloc(JBig2ArithCtx, size)); JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); - std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = + pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_Result.pd = pPDD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); if (!pSegment->m_Result.pd) @@ -978,7 +978,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause) { uint8_t cFlags; JBig2RegionInfo ri; - std::unique_ptr<CJBig2_HTRDProc> pHRD(new CJBig2_HTRDProc); + auto pHRD = pdfium::MakeUnique<CJBig2_HTRDProc>(); if (parseRegionInfo(&ri) != JBIG2_SUCCESS || m_pStream->read1Byte(&cFlags) != 0 || m_pStream->readInteger(&pHRD->HGW) != 0 || @@ -1022,8 +1022,8 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( FX_Alloc(JBig2ArithCtx, size)); JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); - std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = + pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_Result.im = pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); if (!pSegment->m_Result.im) @@ -1056,7 +1056,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause) { if (!m_pGRD) { - std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc); + auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); uint8_t cFlags; if (parseRegionInfo(&m_ri) != JBIG2_SUCCESS || m_pStream->read1Byte(&cFlags) != 0) { @@ -1165,7 +1165,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { m_pStream->read1Byte(&cFlags) != 0) { return JBIG2_ERROR_TOO_SHORT; } - std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc); + auto pGRRD = pdfium::MakeUnique<CJBig2_GRRDProc>(); pGRRD->GRW = ri.width; pGRRD->GRH = ri.height; pGRRD->GRTEMPLATE = !!(cFlags & 0x01); @@ -1202,8 +1202,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext( FX_Alloc(JBig2ArithCtx, size)); JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); - std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_nResultType = JBIG2_IMAGE_POINTER; pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get()); if (!pSegment->m_Result.im) @@ -1230,8 +1229,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; pSegment->m_Result.ht = nullptr; - std::unique_ptr<CJBig2_HuffmanTable> pHuff( - new CJBig2_HuffmanTable(m_pStream.get())); + auto pHuff = pdfium::MakeUnique<CJBig2_HuffmanTable>(m_pStream.get()); if (!pHuff->IsOK()) return JBIG2_ERROR_FATAL; diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp index d5d4c6d0dc..675de9bcdd 100644 --- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp @@ -12,6 +12,7 @@ #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" #include "core/fxcodec/jbig2/JBig2_BitStream.h" #include "core/fxcodec/jbig2/JBig2_Image.h" +#include "third_party/base/ptr_util.h" CJBig2_GRDProc::CJBig2_GRDProc() : m_loopIndex(0), @@ -65,7 +66,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); if (!GBREG->m_pData) return nullptr; @@ -164,7 +165,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; - std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { if (TPGDON) { @@ -214,7 +215,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); if (!GBREG->m_pData) return nullptr; @@ -312,7 +313,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; - std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { if (TPGDON) { @@ -360,7 +361,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); if (!GBREG->m_pData) return nullptr; @@ -458,7 +459,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; - std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { if (TPGDON) { @@ -504,7 +505,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); if (!GBREG->m_pData) return nullptr; @@ -590,7 +591,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; - std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { if (TPGDON) { diff --git a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp index 669fed68e9..936b851d37 100644 --- a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp @@ -11,6 +11,7 @@ #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" #include "core/fxcodec/jbig2/JBig2_BitStream.h" #include "core/fxcodec/jbig2/JBig2_Image.h" +#include "third_party/base/ptr_util.h" CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { @@ -35,7 +36,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { int LTP = 0; - std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); + auto GRREG = pdfium::MakeUnique<CJBig2_Image>(GRW, GRH); GRREG->fill(0); for (uint32_t h = 0; h < GRH; h++) { if (TPGRON) @@ -155,7 +156,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( int32_t iGRW = static_cast<int32_t>(GRW); int32_t iGRH = static_cast<int32_t>(GRH); - std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); + auto GRREG = pdfium::MakeUnique<CJBig2_Image>(iGRW, iGRH); if (!GRREG->m_pData) return nullptr; @@ -283,7 +284,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { int LTP = 0; - std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); + auto GRREG = pdfium::MakeUnique<CJBig2_Image>(GRW, GRH); GRREG->fill(0); for (uint32_t h = 0; h < GRH; h++) { if (TPGRON) @@ -389,7 +390,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( int32_t iGRW = static_cast<int32_t>(GRW); int32_t iGRH = static_cast<int32_t>(GRH); - std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); + auto GRREG = pdfium::MakeUnique<CJBig2_Image>(iGRW, iGRH); if (!GRREG->m_pData) return nullptr; diff --git a/core/fxcodec/jbig2/JBig2_GsidProc.cpp b/core/fxcodec/jbig2/JBig2_GsidProc.cpp index 387f8ee511..e65b47de62 100644 --- a/core/fxcodec/jbig2/JBig2_GsidProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GsidProc.cpp @@ -13,11 +13,12 @@ #include "core/fxcodec/jbig2/JBig2_GrdProc.h" #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/fx_basic.h" +#include "third_party/base/ptr_util.h" uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); + auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); pGRD->MMR = GSMMR; pGRD->GBW = GSW; pGRD->GBH = GSH; @@ -69,7 +70,7 @@ uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, uint32_t* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream, IFX_Pause* pPause) { - std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); + auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); pGRD->MMR = GSMMR; pGRD->GBW = GSW; pGRD->GBH = GSH; diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp index 121bf1d6df..8899fb1350 100644 --- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp @@ -20,7 +20,7 @@ CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, uint32_t HBPP; uint32_t* GI; std::unique_ptr<CJBig2_Image> HSKIP; - std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH)); + auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH); HTREG->fill(HDEFPIXEL); if (HENABLESKIP == 1) { HSKIP = pdfium::MakeUnique<CJBig2_Image>(HGW, HGH); @@ -41,7 +41,7 @@ CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, while ((uint32_t)(1 << HBPP) < HNUMPATS) { HBPP++; } - std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc()); + auto pGID = pdfium::MakeUnique<CJBig2_GSIDProc>(); pGID->GSMMR = HMMR; pGID->GSW = HGW; pGID->GSH = HGH; @@ -73,13 +73,13 @@ CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream, uint32_t ng, mg; int32_t x, y; uint32_t* GI; - std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH)); + auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH); HTREG->fill(HDEFPIXEL); uint32_t HBPP = 1; while ((uint32_t)(1 << HBPP) < HNUMPATS) { HBPP++; } - std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc()); + auto pGID = pdfium::MakeUnique<CJBig2_GSIDProc>(); pGID->GSMMR = HMMR; pGID->GSW = HGW; pGID->GSH = HGH; diff --git a/core/fxcodec/jbig2/JBig2_PddProc.cpp b/core/fxcodec/jbig2/JBig2_PddProc.cpp index 679a87a036..3eef302baf 100644 --- a/core/fxcodec/jbig2/JBig2_PddProc.cpp +++ b/core/fxcodec/jbig2/JBig2_PddProc.cpp @@ -11,6 +11,7 @@ #include "core/fxcodec/jbig2/JBig2_GrdProc.h" #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcodec/jbig2/JBig2_PatternDict.h" +#include "third_party/base/ptr_util.h" CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( CJBig2_ArithDecoder* pArithDecoder, @@ -18,12 +19,12 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( IFX_Pause* pPause) { uint32_t GRAY; CJBig2_Image* BHDC = nullptr; - std::unique_ptr<CJBig2_PatternDict> pDict(new CJBig2_PatternDict()); + auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>(); pDict->NUMPATS = GRAYMAX + 1; pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); - std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); + auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); pGRD->MMR = HDMMR; pGRD->GBW = (GRAYMAX + 1) * HDPW; pGRD->GBH = HDPH; @@ -60,12 +61,12 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream, IFX_Pause* pPause) { uint32_t GRAY; CJBig2_Image* BHDC = nullptr; - std::unique_ptr<CJBig2_PatternDict> pDict(new CJBig2_PatternDict()); + auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>(); pDict->NUMPATS = GRAYMAX + 1; pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); - std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); + auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); pGRD->MMR = HDMMR; pGRD->GBW = (GRAYMAX + 1) * HDPW; pGRD->GBH = HDPH; diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp index 84042dbd8c..cf58d9c3c6 100644 --- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp @@ -16,9 +16,8 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, JBig2ArithCtx* grContext) { - std::unique_ptr<CJBig2_HuffmanDecoder> pHuffmanDecoder( - new CJBig2_HuffmanDecoder(pStream)); - std::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); + auto pHuffmanDecoder = pdfium::MakeUnique<CJBig2_HuffmanDecoder>(pStream); + auto SBREG = pdfium::MakeUnique<CJBig2_Image>(SBW, SBH); SBREG->fill(SBDEFPIXEL); int32_t STRIPT; if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) @@ -120,7 +119,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) return nullptr; - std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); + auto pGRRD = pdfium::MakeUnique<CJBig2_GRRDProc>(); pGRRD->GRW = WOI + RDWI; pGRRD->GRH = HOI + RDHI; pGRRD->GRTEMPLATE = SBRTEMPLATE; @@ -134,8 +133,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, pGRRD->GRAT[3] = SBRAT[3]; { - std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( - new CJBig2_ArithDecoder(pStream)); + auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(pStream); IBI = pGRRD->decode(pArithDecoder.get(), grContext); if (!IBI) return nullptr; @@ -264,7 +262,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, pIARDY = IARDY.get(); pIAID = IAID.get(); } - std::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); + auto SBREG = pdfium::MakeUnique<CJBig2_Image>(SBW, SBH); SBREG->fill(SBDEFPIXEL); int32_t STRIPT; if (!pIADT->decode(pArithDecoder, &STRIPT)) @@ -335,7 +333,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) return nullptr; - std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); + auto pGRRD = pdfium::MakeUnique<CJBig2_GRRDProc>(); pGRRD->GRW = WOI + RDWI; pGRRD->GRH = HOI + RDHI; pGRRD->GRTEMPLATE = SBRTEMPLATE; |