diff options
author | tsepez <tsepez@chromium.org> | 2016-12-13 12:48:13 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-13 12:48:13 -0800 |
commit | 974b4a6c4bceb50bbe5bf316e9e273b62eaeceac (patch) | |
tree | e243d34a04905b88a11e9146e698daaa0cee2416 /core/fxcodec/codec | |
parent | 988599c5d81bbb568f949454580ec6001258f806 (diff) | |
download | pdfium-974b4a6c4bceb50bbe5bf316e9e273b62eaeceac.tar.xz |
Return unique_ptr<>s from fxcodec/chromium/2951
Review-Url: https://codereview.chromium.org/2572843002
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r-- | core/fxcodec/codec/ccodec_basicmodule.h | 15 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_faxmodule.h | 22 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_flatemodule.h | 22 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_jpegmodule.h | 14 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec.cpp | 24 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_fax.cpp | 28 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_flate.cpp | 9 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jpeg.cpp | 19 |
8 files changed, 85 insertions, 68 deletions
diff --git a/core/fxcodec/codec/ccodec_basicmodule.h b/core/fxcodec/codec/ccodec_basicmodule.h index 1c3f4d1cfb..425b5d7229 100644 --- a/core/fxcodec/codec/ccodec_basicmodule.h +++ b/core/fxcodec/codec/ccodec_basicmodule.h @@ -7,18 +7,21 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_BASICMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_BASICMODULE_H_ +#include <memory> + #include "core/fxcrt/fx_system.h" class CCodec_ScanlineDecoder; class CCodec_BasicModule { public: - CCodec_ScanlineDecoder* CreateRunLengthDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int nComps, - int bpc); + std::unique_ptr<CCodec_ScanlineDecoder> CreateRunLengthDecoder( + const uint8_t* src_buf, + uint32_t src_size, + int width, + int height, + int nComps, + int bpc); }; #endif // CORE_FXCODEC_CODEC_CCODEC_BASICMODULE_H_ diff --git a/core/fxcodec/codec/ccodec_faxmodule.h b/core/fxcodec/codec/ccodec_faxmodule.h index 18b9bb6b8c..ce9e97bbe9 100644 --- a/core/fxcodec/codec/ccodec_faxmodule.h +++ b/core/fxcodec/codec/ccodec_faxmodule.h @@ -7,22 +7,24 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_FAXMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_FAXMODULE_H_ +#include <memory> + #include "core/fxcrt/fx_system.h" class CCodec_ScanlineDecoder; class CCodec_FaxModule { public: - CCodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int K, - bool EndOfLine, - bool EncodedByteAlign, - bool BlackIs1, - int Columns, - int Rows); + std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(const uint8_t* src_buf, + uint32_t src_size, + int width, + int height, + int K, + bool EndOfLine, + bool EncodedByteAlign, + bool BlackIs1, + int Columns, + int Rows); }; #endif // CORE_FXCODEC_CODEC_CCODEC_FAXMODULE_H_ diff --git a/core/fxcodec/codec/ccodec_flatemodule.h b/core/fxcodec/codec/ccodec_flatemodule.h index ee8fd8defd..5178943ca0 100644 --- a/core/fxcodec/codec/ccodec_flatemodule.h +++ b/core/fxcodec/codec/ccodec_flatemodule.h @@ -7,22 +7,24 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_FLATEMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_FLATEMODULE_H_ +#include <memory> + #include "core/fxcrt/fx_system.h" class CCodec_ScanlineDecoder; class CCodec_FlateModule { public: - CCodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int nComps, - int bpc, - int predictor, - int Colors, - int BitsPerComponent, - int Columns); + std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(const uint8_t* src_buf, + uint32_t src_size, + int width, + int height, + int nComps, + int bpc, + int predictor, + int Colors, + int BitsPerComponent, + int Columns); uint32_t FlateOrLZWDecode(bool bLZW, const uint8_t* src_buf, uint32_t src_size, diff --git a/core/fxcodec/codec/ccodec_jpegmodule.h b/core/fxcodec/codec/ccodec_jpegmodule.h index db7f3dfb77..b2ae731bb4 100644 --- a/core/fxcodec/codec/ccodec_jpegmodule.h +++ b/core/fxcodec/codec/ccodec_jpegmodule.h @@ -7,6 +7,8 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_JPEGMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_JPEGMODULE_H_ +#include <memory> + #include "core/fxcrt/fx_system.h" class CCodec_ScanlineDecoder; @@ -21,12 +23,12 @@ class CCodec_JpegModule { public: CCodec_JpegModule() {} - CCodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int nComps, - bool ColorTransform); + std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(const uint8_t* src_buf, + uint32_t src_size, + int width, + int height, + int nComps, + bool ColorTransform); bool LoadInfo(const uint8_t* src_buf, uint32_t src_size, int* width, diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp index 2f4a81155c..aa2ecef345 100644 --- a/core/fxcodec/codec/fx_codec.cpp +++ b/core/fxcodec/codec/fx_codec.cpp @@ -14,6 +14,7 @@ #include "core/fxcrt/fx_ext.h" #include "core/fxcrt/fx_safe_types.h" #include "third_party/base/logging.h" +#include "third_party/base/ptr_util.h" CCodec_ModuleMgr::CCodec_ModuleMgr() : m_pBasicModule(new CCodec_BasicModule), @@ -302,19 +303,16 @@ void CCodec_RLScanlineDecoder::UpdateOperator(uint8_t used_bytes) { m_Operator = 257 - count; } -CCodec_ScanlineDecoder* CCodec_BasicModule::CreateRunLengthDecoder( - const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int nComps, - int bpc) { - std::unique_ptr<CCodec_RLScanlineDecoder> pRLScanlineDecoder( - new CCodec_RLScanlineDecoder); - if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, - bpc)) { +std::unique_ptr<CCodec_ScanlineDecoder> +CCodec_BasicModule::CreateRunLengthDecoder(const uint8_t* src_buf, + uint32_t src_size, + int width, + int height, + int nComps, + int bpc) { + auto pDecoder = pdfium::MakeUnique<CCodec_RLScanlineDecoder>(); + if (!pDecoder->Create(src_buf, src_size, width, height, nComps, bpc)) return nullptr; - } - return pRLScanlineDecoder.release(); + return std::move(pDecoder); } diff --git a/core/fxcodec/codec/fx_codec_fax.cpp b/core/fxcodec/codec/fx_codec_fax.cpp index 5102c778a4..62ad38e19f 100644 --- a/core/fxcodec/codec/fx_codec_fax.cpp +++ b/core/fxcodec/codec/fx_codec_fax.cpp @@ -5,10 +5,12 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include <algorithm> +#include <memory> #include <vector> #include "core/fxcodec/codec/codec_int.h" #include "core/fxcodec/fx_codec.h" +#include "third_party/base/ptr_util.h" namespace { @@ -580,16 +582,17 @@ void FaxG4Decode(const uint8_t* src_buf, *pbitpos = bitpos; } -CCodec_ScanlineDecoder* CCodec_FaxModule::CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int K, - bool EndOfLine, - bool EncodedByteAlign, - bool BlackIs1, - int Columns, - int Rows) { +std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FaxModule::CreateDecoder( + const uint8_t* src_buf, + uint32_t src_size, + int width, + int height, + int K, + bool EndOfLine, + bool EncodedByteAlign, + bool BlackIs1, + int Columns, + int Rows) { int actual_width = Columns ? Columns : width; int actual_height = Rows ? Rows : height; @@ -602,6 +605,7 @@ CCodec_ScanlineDecoder* CCodec_FaxModule::CreateDecoder(const uint8_t* src_buf, return nullptr; uint32_t pitch = (static_cast<uint32_t>(actual_width) + 31) / 32 * 4; - return new CCodec_FaxDecoder(src_buf, src_size, actual_width, actual_height, - pitch, K, EndOfLine, EncodedByteAlign, BlackIs1); + return pdfium::MakeUnique<CCodec_FaxDecoder>( + src_buf, src_size, actual_width, actual_height, pitch, K, EndOfLine, + EncodedByteAlign, BlackIs1); } diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp index c5611cc27a..d01b40f318 100644 --- a/core/fxcodec/codec/fx_codec_flate.cpp +++ b/core/fxcodec/codec/fx_codec_flate.cpp @@ -8,9 +8,11 @@ #include <algorithm> #include <memory> +#include <utility> #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/fx_ext.h" +#include "third_party/base/ptr_util.h" #include "third_party/zlib_v128/zlib.h" extern "C" { @@ -771,7 +773,7 @@ uint32_t CCodec_FlateScanlineDecoder::GetSrcOffset() { return FPDFAPI_FlateGetTotalIn(m_pFlate); } -CCodec_ScanlineDecoder* CCodec_FlateModule::CreateDecoder( +std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FlateModule::CreateDecoder( const uint8_t* src_buf, uint32_t src_size, int width, @@ -782,11 +784,12 @@ CCodec_ScanlineDecoder* CCodec_FlateModule::CreateDecoder( int Colors, int BitsPerComponent, int Columns) { - CCodec_FlateScanlineDecoder* pDecoder = new CCodec_FlateScanlineDecoder; + auto pDecoder = pdfium::MakeUnique<CCodec_FlateScanlineDecoder>(); pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, Colors, BitsPerComponent, Columns); - return pDecoder; + return std::move(pDecoder); } + uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, const uint8_t* src_buf, uint32_t src_size, diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp index 873b52a81c..fdfdd4faeb 100644 --- a/core/fxcodec/codec/fx_codec_jpeg.cpp +++ b/core/fxcodec/codec/fx_codec_jpeg.cpp @@ -7,11 +7,13 @@ #include <setjmp.h> #include <memory> +#include <utility> #include "core/fxcodec/codec/codec_int.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/fx_dib.h" +#include "third_party/base/ptr_util.h" extern "C" { #undef FAR @@ -313,21 +315,22 @@ uint32_t CCodec_JpegDecoder::GetSrcOffset() { return (uint32_t)(m_SrcSize - src.bytes_in_buffer); } -CCodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int nComps, - bool ColorTransform) { +std::unique_ptr<CCodec_ScanlineDecoder> CCodec_JpegModule::CreateDecoder( + const uint8_t* src_buf, + uint32_t src_size, + int width, + int height, + int nComps, + bool ColorTransform) { if (!src_buf || src_size == 0) return nullptr; - std::unique_ptr<CCodec_JpegDecoder> pDecoder(new CCodec_JpegDecoder); + auto pDecoder = pdfium::MakeUnique<CCodec_JpegDecoder>(); if (!pDecoder->Create(src_buf, src_size, width, height, nComps, ColorTransform)) { return nullptr; } - return pDecoder.release(); + return std::move(pDecoder); } bool CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, |