Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1262)

Unified Diff: core/fpdfapi/page/cpdf_streamparser.cpp

Issue 2572843002: Return unique_ptr<>s from fxcodec/ (Closed)
Patch Set: std::move it Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfapi/page/cpdf_streamparser.cpp
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index cabf3d3cb3cb7d804934ef749f3767e71c679fd0..fd5267b111446e21ad8188c0cb7b1edf25790757 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -27,20 +27,13 @@
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_ext.h"
-CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(
Tom Sepez 2016/12/13 19:21:19 Note: moved to .h, sheesh.
- const uint8_t* src_buf,
- uint32_t src_size,
- int width,
- int height,
- const CPDF_Dictionary* pParams);
-
namespace {
const uint32_t kMaxNestedArrayLevel = 512;
const uint32_t kMaxWordBuffer = 256;
const FX_STRSIZE kMaxStringLength = 32767;
-uint32_t DecodeAllScanlines(CCodec_ScanlineDecoder* pDecoder,
+uint32_t DecodeAllScanlines(std::unique_ptr<CCodec_ScanlineDecoder> pDecoder,
uint8_t*& dest_buf,
uint32_t& dest_size) {
if (!pDecoder)
@@ -50,10 +43,9 @@ uint32_t DecodeAllScanlines(CCodec_ScanlineDecoder* pDecoder,
int width = pDecoder->GetWidth();
int height = pDecoder->GetHeight();
int pitch = (width * ncomps * bpc + 7) / 8;
- if (height == 0 || pitch > (1 << 30) / height) {
- delete pDecoder;
+ if (height == 0 || pitch > (1 << 30) / height)
return FX_INVALID_OFFSET;
- }
+
dest_buf = FX_Alloc2D(uint8_t, pitch, height);
dest_size = pitch * height; // Safe since checked alloc returned.
for (int row = 0; row < height; row++) {
@@ -63,9 +55,7 @@ uint32_t DecodeAllScanlines(CCodec_ScanlineDecoder* pDecoder,
FXSYS_memcpy(dest_buf + row * pitch, pLine, pitch);
}
- uint32_t srcoff = pDecoder->GetSrcOffset();
- delete pDecoder;
- return srcoff;
+ return pDecoder->GetSrcOffset();
}
uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf,
@@ -77,9 +67,9 @@ uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf,
uint8_t*& dest_buf,
uint32_t& dest_size) {
if (decoder == "CCITTFaxDecode" || decoder == "CCF") {
- CCodec_ScanlineDecoder* pDecoder =
+ std::unique_ptr<CCodec_ScanlineDecoder> pDecoder =
FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam);
- return DecodeAllScanlines(pDecoder, dest_buf, dest_size);
+ return DecodeAllScanlines(std::move(pDecoder), dest_buf, dest_size);
}
if (decoder == "ASCII85Decode" || decoder == "A85")
return A85Decode(src_buf, limit, dest_buf, dest_size);
@@ -94,11 +84,11 @@ uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf,
dest_size);
}
if (decoder == "DCTDecode" || decoder == "DCT") {
- CCodec_ScanlineDecoder* pDecoder =
+ std::unique_ptr<CCodec_ScanlineDecoder> pDecoder =
CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(
src_buf, limit, width, height, 0,
!pParam || pParam->GetIntegerFor("ColorTransform", 1));
- return DecodeAllScanlines(pDecoder, dest_buf, dest_size);
+ return DecodeAllScanlines(std::move(pDecoder), dest_buf, dest_size);
}
if (decoder == "RunLengthDecode" || decoder == "RL")
return RunLengthDecode(src_buf, limit, dest_buf, dest_size);
« no previous file with comments | « no previous file | core/fpdfapi/parser/fpdf_parser_decode.h » ('j') | core/fpdfapi/render/fpdf_render_loadimage.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698