From f1925d9429f8674b25fff8010e04f2fc132ea38a Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 16 Oct 2018 05:22:03 +0000 Subject: Use more unique_ptrs in cfx_psrenderer.cpp for FaxCompressData(). Change-Id: I2a1f03b7336f2b03ef1d4bbbd396e7a2c5bdea50 Reviewed-on: https://pdfium-review.googlesource.com/c/43999 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- core/fxge/win32/cfx_psrenderer.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index 11acfc8b3d..921005dd70 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fxcodec/codec/ccodec_basicmodule.h" @@ -28,19 +29,20 @@ namespace { -void FaxCompressData(uint8_t* src_buf, +bool FaxCompressData(std::unique_ptr src_buf, int width, int height, std::unique_ptr* dest_buf, uint32_t* dest_size) { - if (width * height > 128) { - CCodec_FaxModule::FaxEncode(src_buf, width, height, (width + 7) / 8, - dest_buf, dest_size); - FX_Free(src_buf); - } else { - dest_buf->reset(src_buf); + if (width * height <= 128) { + *dest_buf = std::move(src_buf); *dest_size = (width + 7) / 8 * height; + return false; } + + CCodec_FaxModule::FaxEncode(src_buf.get(), width, height, (width + 7) / 8, + dest_buf, dest_size); + return true; } void PSCompressData(int PSLevel, @@ -391,15 +393,17 @@ bool CFX_PSRenderer::DrawDIBits(const RetainPtr& pSource, if (pSource->GetBPP() == 1 && !pSource->GetPalette()) { int pitch = (width + 7) / 8; uint32_t src_size = height * pitch; - uint8_t* src_buf = FX_Alloc(uint8_t, src_size); + std::unique_ptr src_buf( + FX_Alloc(uint8_t, src_size)); for (int row = 0; row < height; row++) { const uint8_t* src_scan = pSource->GetScanline(row); - memcpy(src_buf + row * pitch, src_scan, pitch); + memcpy(src_buf.get() + row * pitch, src_scan, pitch); } std::unique_ptr output_buf; uint32_t output_size; - FaxCompressData(src_buf, width, height, &output_buf, &output_size); + bool compressed = FaxCompressData(std::move(src_buf), width, height, + &output_buf, &output_size); if (pSource->IsAlphaMask()) { SetColor(color); m_bColorSet = false; @@ -410,7 +414,7 @@ bool CFX_PSRenderer::DrawDIBits(const RetainPtr& pSource, buf << width << " 0 0 -" << height << " 0 " << height << "]currentfile/ASCII85Decode filter "; - if (output_buf.get() != src_buf) { + if (compressed) { buf << "<>/CCITTFaxDecode filter "; } @@ -421,7 +425,6 @@ bool CFX_PSRenderer::DrawDIBits(const RetainPtr& pSource, WriteToStream(&buf); WritePSBinary(output_buf.get(), output_size); - output_buf.release(); } else { CFX_DIBExtractor source_extractor(pSource); RetainPtr pConverted = source_extractor.GetBitmap(); -- cgit v1.2.3