summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-16 05:22:03 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-16 05:22:03 +0000
commitf1925d9429f8674b25fff8010e04f2fc132ea38a (patch)
tree01a86ec545137478bb0bcb90ee0a8bd7eac5fa9b /core
parent2e2acbdc523735fdbbf69b1f9fee9a24e4303045 (diff)
downloadpdfium-f1925d9429f8674b25fff8010e04f2fc132ea38a.tar.xz
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 <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fxge/win32/cfx_psrenderer.cpp27
1 files 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 <algorithm>
#include <memory>
#include <sstream>
+#include <utility>
#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<uint8_t, FxFreeDeleter> src_buf,
int width,
int height,
std::unique_ptr<uint8_t, FxFreeDeleter>* 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<CFX_DIBBase>& 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<uint8_t, FxFreeDeleter> 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<uint8_t, FxFreeDeleter> 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<CFX_DIBBase>& pSource,
buf << width << " 0 0 -" << height << " 0 " << height
<< "]currentfile/ASCII85Decode filter ";
- if (output_buf.get() != src_buf) {
+ if (compressed) {
buf << "<</K -1/EndOfBlock false/Columns " << width << "/Rows " << height
<< ">>/CCITTFaxDecode filter ";
}
@@ -421,7 +425,6 @@ bool CFX_PSRenderer::DrawDIBits(const RetainPtr<CFX_DIBBase>& pSource,
WriteToStream(&buf);
WritePSBinary(output_buf.get(), output_size);
- output_buf.release();
} else {
CFX_DIBExtractor source_extractor(pSource);
RetainPtr<CFX_DIBBase> pConverted = source_extractor.GetBitmap();