summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/font/cpdf_type3char.cpp2
-rw-r--r--core/fpdfapi/render/cpdf_imagecacheentry.cpp2
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.cpp6
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp15
-rw-r--r--core/fpdfapi/render/cpdf_type3cache.cpp6
-rw-r--r--core/fpdfapi/render/fpdf_render_loadimage.cpp10
-rw-r--r--core/fpdfapi/render/render_int.h2
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp9
-rw-r--r--core/fxge/agg/fx_agg_driver.cpp13
-rw-r--r--core/fxge/dib/fx_dib_convert.cpp9
-rw-r--r--core/fxge/dib/fx_dib_main.cpp172
-rw-r--r--core/fxge/dib/fx_dib_transform.cpp25
-rw-r--r--core/fxge/fx_dib.h29
-rw-r--r--core/fxge/win32/fx_win32_device.cpp11
-rw-r--r--core/fxge/win32/fx_win32_gdipext.cpp43
-rw-r--r--xfa/fxbarcode/BC_TwoDimWriter.cpp5
-rw-r--r--xfa/fxbarcode/oned/BC_OneDimWriter.cpp5
-rw-r--r--xfa/fxfa/app/xfa_ffwidget.cpp40
18 files changed, 169 insertions, 235 deletions
diff --git a/core/fpdfapi/font/cpdf_type3char.cpp b/core/fpdfapi/font/cpdf_type3char.cpp
index e5b7450a0a..41ab824717 100644
--- a/core/fpdfapi/font/cpdf_type3char.cpp
+++ b/core/fpdfapi/font/cpdf_type3char.cpp
@@ -32,7 +32,7 @@ bool CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) {
std::unique_ptr<CFX_DIBSource> pSource(
pPageObj->AsImage()->GetImage()->LoadDIBSource());
if (pSource)
- m_pBitmap.reset(pSource->Clone());
+ m_pBitmap = pSource->Clone();
m_pForm.reset();
return true;
}
diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.cpp b/core/fpdfapi/render/cpdf_imagecacheentry.cpp
index 93ec162a7c..932d281f98 100644
--- a/core/fpdfapi/render/cpdf_imagecacheentry.cpp
+++ b/core/fpdfapi/render/cpdf_imagecacheentry.cpp
@@ -34,7 +34,7 @@ CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() {}
void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) {
m_pCachedBitmap.reset();
if (pBitmap)
- m_pCachedBitmap = pdfium::WrapUnique<CFX_DIBSource>(pBitmap->Clone());
+ m_pCachedBitmap = pBitmap->Clone();
CalcSize();
}
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index bdcd2b3c65..eae32443d8 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -94,7 +94,7 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
m_pImageObject->m_GeneralState.GetTransferFunc()->TranslateImage(
m_Loader.m_pBitmap, !m_Loader.m_bCached);
if (m_Loader.m_bCached && m_Loader.m_pMask)
- m_Loader.m_pMask = m_Loader.m_pMask->Clone();
+ m_Loader.m_pMask = m_Loader.m_pMask->Clone().release();
m_Loader.m_bCached = false;
}
}
@@ -110,7 +110,7 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
}
m_FillArgb = m_pRenderStatus->GetFillArgb(m_pImageObject);
} else if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_GRAY) {
- m_pClone.reset(m_pDIBSource->Clone());
+ m_pClone = m_pDIBSource->Clone();
m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor,
m_pRenderStatus->m_Options.m_ForeColor);
m_pDIBSource = m_pClone.get();
@@ -400,7 +400,7 @@ bool CPDF_ImageRenderer::StartDIBSource() {
}
}
#ifdef _SKIA_SUPPORT_
- CFX_DIBitmap* premultiplied = m_pDIBSource->Clone();
+ CFX_DIBitmap* premultiplied = m_pDIBSource->Clone().release();
if (m_pDIBSource->HasAlpha())
CFX_SkiaDeviceDriver::PreMultiply(premultiplied);
if (m_pRenderStatus->m_pDevice->StartDIBitsWithBlend(
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 126e04662e..88dbb030ce 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -46,6 +46,7 @@
#include "core/fpdfapi/render/render_int.h"
#include "core/fpdfdoc/cpdf_occontext.h"
#include "core/fxcodec/fx_codec.h"
+#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_graphstatedata.h"
@@ -2265,7 +2266,7 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
std::unique_ptr<CFX_DIBitmap> pEnlargedBitmap =
DrawPatternBitmap(m_pContext->GetDocument(), m_pContext->GetPageCache(),
pPattern, pObj2Device, 8, 8, m_Options.m_Flags);
- pPatternBitmap.reset(pEnlargedBitmap->StretchTo(width, height));
+ pPatternBitmap = pEnlargedBitmap->StretchTo(width, height);
} else {
pPatternBitmap = DrawPatternBitmap(
m_pContext->GetDocument(), m_pContext->GetPageCache(), pPattern,
@@ -2439,10 +2440,8 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
rect.Intersect(m_pDevice->GetClipBox());
- CFX_DIBitmap* pClone = nullptr;
- bool bClone = false;
+ CFX_MaybeOwned<CFX_DIBitmap> pClone;
if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) {
- bClone = true;
pClone = m_pDevice->GetBackDrop()->Clone(&rect);
CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap();
pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
@@ -2459,17 +2458,13 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
pClone = pDIBitmap;
}
if (m_pDevice->GetBackDrop()) {
- m_pDevice->SetDIBits(pClone, rect.left, rect.top);
+ m_pDevice->SetDIBits(pClone.Get(), rect.left, rect.top);
} else {
- if (pDIBitmap->IsAlphaMask()) {
+ if (pDIBitmap->IsAlphaMask())
return;
- }
m_pDevice->SetDIBitsWithBlend(pDIBitmap, rect.left, rect.top,
blend_mode);
}
- if (bClone) {
- delete pClone;
- }
}
return;
}
diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp
index ba92142dbf..b27fdf507e 100644
--- a/core/fpdfapi/render/cpdf_type3cache.cpp
+++ b/core/fpdfapi/render/cpdf_type3cache.cpp
@@ -143,10 +143,10 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize,
bottom_y = temp;
}
pSize->AdjustBlue(top_y, bottom_y, top_line, bottom_line);
- pResBitmap.reset(pBitmap->StretchTo(
+ pResBitmap = pBitmap->StretchTo(
(int)(FXSYS_round(image_matrix.a) * retinaScaleX),
(int)((bFlipped ? top_line - bottom_line : bottom_line - top_line) *
- retinaScaleY)));
+ retinaScaleY));
top = top_line;
if (image_matrix.a < 0) {
image_matrix.Scale(retinaScaleX, retinaScaleY);
@@ -158,7 +158,7 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize,
}
if (!pResBitmap) {
image_matrix.Scale(retinaScaleX, retinaScaleY);
- pResBitmap.reset(pBitmap->TransformTo(&image_matrix, left, top));
+ pResBitmap = pBitmap->TransformTo(&image_matrix, left, top);
}
if (!pResBitmap)
return nullptr;
diff --git a/core/fpdfapi/render/fpdf_render_loadimage.cpp b/core/fpdfapi/render/fpdf_render_loadimage.cpp
index d797b06135..f690f688b1 100644
--- a/core/fpdfapi/render/fpdf_render_loadimage.cpp
+++ b/core/fpdfapi/render/fpdf_render_loadimage.cpp
@@ -132,16 +132,6 @@ CPDF_DIBSource::~CPDF_DIBSource() {
}
}
-CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const {
- return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone();
-}
-
-void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const {
- if (pBitmap && pBitmap != m_pCachedBitmap.get()) {
- delete pBitmap;
- }
-}
-
bool CPDF_DIBSource::Load(CPDF_Document* pDoc,
const CPDF_Stream* pStream,
CPDF_DIBSource** ppMask,
diff --git a/core/fpdfapi/render/render_int.h b/core/fpdfapi/render/render_int.h
index 5d04fa77bb..276370d386 100644
--- a/core/fpdfapi/render/render_int.h
+++ b/core/fpdfapi/render/render_int.h
@@ -85,8 +85,6 @@ class CPDF_DIBSource : public CFX_DIBSource {
int clip_left,
int clip_width) const override;
- CFX_DIBitmap* GetBitmap() const;
- void ReleaseBitmap(CFX_DIBitmap* pBitmap) const;
uint32_t GetMatteColor() const { return m_MatteColor; }
int StartLoadDIBSource(CPDF_Document* pDoc,
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index 7d8a3203e9..8d29a7b3f3 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -7,6 +7,7 @@
#include "core/fxcodec/codec/ccodec_progressivedecoder.h"
#include <algorithm>
+#include <memory>
#include "core/fxcodec/fx_codec.h"
#include "core/fxge/fx_dib.h"
@@ -2261,7 +2262,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
(m_clipBox.left == 0 && m_clipBox.top == 0 &&
m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight)
? pDIBitmap
- : pDIBitmap->Clone(&m_clipBox);
+ : pDIBitmap->Clone(&m_clipBox).release();
if (pDIBitmap != pClipBitmap) {
delete pDIBitmap;
}
@@ -2346,7 +2347,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
m_status = FXCODEC_STATUS_ERR_MEMORY;
return m_status;
}
- CFX_DIBitmap* pStrechBitmap = pFormatBitmap->StretchTo(
+ std::unique_ptr<CFX_DIBitmap> pStrechBitmap = pFormatBitmap->StretchTo(
m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
delete pFormatBitmap;
pFormatBitmap = nullptr;
@@ -2357,9 +2358,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
return m_status;
}
m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
- pStrechBitmap, 0, 0);
- delete pStrechBitmap;
- pStrechBitmap = nullptr;
+ pStrechBitmap.get(), 0, 0);
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
m_status = FXCODEC_STATUS_DECODE_FINISH;
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index e341e8c045..2258a257f1 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1602,7 +1602,7 @@ bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
FX_RECT rect(left, top, left + pBitmap->GetWidth(),
top + pBitmap->GetHeight());
- CFX_DIBitmap* pBack = nullptr;
+ std::unique_ptr<CFX_DIBitmap> pBack;
if (m_pOriDevice) {
pBack = m_pOriDevice->Clone(&rect);
if (!pBack)
@@ -1616,18 +1616,15 @@ bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
return true;
}
- bool bRet = true;
left = std::min(left, 0);
top = std::min(top, 0);
if (m_bRgbByteOrder) {
RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(),
- pBack, left, top);
- } else {
- bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack,
- left, top);
+ pBack.get(), left, top);
+ return true;
}
- delete pBack;
- return bRet;
+ return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack.get(),
+ left, top);
}
CFX_DIBitmap* CFX_AggDeviceDriver::GetBackDrop() {
diff --git a/core/fxge/dib/fx_dib_convert.cpp b/core/fxge/dib/fx_dib_convert.cpp
index f5ae563d57..b1362462c3 100644
--- a/core/fxge/dib/fx_dib_convert.cpp
+++ b/core/fxge/dib/fx_dib_convert.cpp
@@ -9,6 +9,7 @@
#include "core/fxcodec/fx_codec.h"
#include "core/fxge/fx_dib.h"
+#include "third_party/base/ptr_util.h"
class CFX_Palette {
public:
@@ -781,11 +782,12 @@ bool ConvertBuffer(FXDIB_Format dest_format,
}
}
-CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format) const {
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
+ FXDIB_Format dest_format) const {
if (dest_format == GetFormat())
return Clone(nullptr);
- std::unique_ptr<CFX_DIBitmap> pClone(new CFX_DIBitmap);
+ std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pClone->Create(m_Width, m_Height, dest_format))
return nullptr;
@@ -819,7 +821,8 @@ CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format) const {
}
if (pal_8bpp)
pClone->CopyPalette(pal_8bpp.get());
- return pClone.release();
+
+ return pClone;
}
bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index 83899553a2..310c62fcc5 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -13,6 +13,7 @@
#include <utility>
#include "core/fxcodec/fx_codec.h"
+#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxge/cfx_gemodule.h"
#include "core/fxge/dib/dib_int.h"
#include "core/fxge/ge/cfx_cliprgn.h"
@@ -174,15 +175,14 @@ void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
m_Pitch = pSrcBitmap->m_Pitch;
}
-CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const {
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
FX_RECT rect(0, 0, m_Width, m_Height);
if (pClip) {
rect.Intersect(*pClip);
- if (rect.IsEmpty()) {
+ if (rect.IsEmpty())
return nullptr;
- }
}
- std::unique_ptr<CFX_DIBitmap> pNewBitmap(new CFX_DIBitmap);
+ auto pNewBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
return nullptr;
@@ -202,22 +202,22 @@ CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const {
}
} else {
int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8;
- if (m_Pitch < (uint32_t)copy_len) {
+ if (m_Pitch < (uint32_t)copy_len)
copy_len = m_Pitch;
- }
+
for (int row = rect.top; row < rect.bottom; row++) {
const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8;
uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top);
FXSYS_memcpy(dest_scan, src_scan, copy_len);
}
}
- return pNewBitmap.release();
+ return pNewBitmap;
}
void CFX_DIBSource::BuildPalette() {
- if (m_pPalette) {
+ if (m_pPalette)
return;
- }
+
if (GetBPP() == 1) {
m_pPalette.reset(FX_Alloc(uint32_t, 2));
if (IsCmykImage()) {
@@ -230,13 +230,11 @@ void CFX_DIBSource::BuildPalette() {
} else if (GetBPP() == 8) {
m_pPalette.reset(FX_Alloc(uint32_t, 256));
if (IsCmykImage()) {
- for (int i = 0; i < 256; i++) {
+ for (int i = 0; i < 256; i++)
m_pPalette.get()[i] = 0xff - i;
- }
} else {
- for (int i = 0; i < 256; i++) {
+ for (int i = 0; i < 256; i++)
m_pPalette.get()[i] = 0xff000000 | (i * 0x10101);
- }
}
}
}
@@ -663,127 +661,92 @@ bool CFX_DIBSource::CopyAlphaMask(const CFX_DIBSource* pAlphaMask,
const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
- const CFX_DIBSource* pSrcBitmap,
+ CFX_DIBSource* pSrcBitmap,
FXDIB_Channel srcChannel) {
- if (!m_pBuffer) {
+ if (!m_pBuffer)
return false;
- }
- CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap;
- CFX_DIBitmap* pDst = this;
- int destOffset, srcOffset;
+
+ CFX_MaybeOwned<CFX_DIBSource> pSrcClone(pSrcBitmap);
+ int srcOffset;
if (srcChannel == FXDIB_Alpha) {
- if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) {
+ if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask())
return false;
- }
+
if (pSrcBitmap->GetBPP() == 1) {
pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask);
- if (!pSrcClone) {
+ if (!pSrcClone)
return false;
- }
- }
- if (pSrcBitmap->GetFormat() == FXDIB_Argb) {
- srcOffset = 3;
- } else {
- srcOffset = 0;
}
+ srcOffset = pSrcBitmap->GetFormat() == FXDIB_Argb ? 3 : 0;
} else {
- if (pSrcBitmap->IsAlphaMask()) {
+ if (pSrcBitmap->IsAlphaMask())
return false;
- }
+
if (pSrcBitmap->GetBPP() < 24) {
if (pSrcBitmap->IsCmykImage()) {
- pSrcClone = pSrcBitmap->CloneConvert(
- (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20));
+ pSrcClone = pSrcBitmap->CloneConvert(static_cast<FXDIB_Format>(
+ (pSrcBitmap->GetFormat() & 0xff00) | 0x20));
} else {
- pSrcClone = pSrcBitmap->CloneConvert(
- (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18));
+ pSrcClone = pSrcBitmap->CloneConvert(static_cast<FXDIB_Format>(
+ (pSrcBitmap->GetFormat() & 0xff00) | 0x18));
}
- if (!pSrcClone) {
+ if (!pSrcClone)
return false;
- }
}
srcOffset = g_ChannelOffset[srcChannel];
}
+ int destOffset = 0;
if (destChannel == FXDIB_Alpha) {
if (IsAlphaMask()) {
- if (!ConvertFormat(FXDIB_8bppMask)) {
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
+ if (!ConvertFormat(FXDIB_8bppMask))
return false;
- }
- destOffset = 0;
} else {
- destOffset = 0;
- if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb))
return false;
- }
- if (GetFormat() == FXDIB_Argb) {
+
+ if (GetFormat() == FXDIB_Argb)
destOffset = 3;
- }
}
} else {
- if (IsAlphaMask()) {
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
+ if (IsAlphaMask())
return false;
- }
+
if (GetBPP() < 24) {
if (HasAlpha()) {
- if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb))
return false;
- }
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
} else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
#else
} else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
#endif
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
return false;
}
}
destOffset = g_ChannelOffset[destChannel];
}
if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
- CFX_DIBitmap* pAlphaMask = pSrcClone->m_pAlphaMask;
+ CFX_MaybeOwned<CFX_DIBSource> pAlphaMask(pSrcClone->m_pAlphaMask);
if (pSrcClone->GetWidth() != m_Width ||
pSrcClone->GetHeight() != m_Height) {
if (pAlphaMask) {
pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height);
- if (!pAlphaMask) {
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
+ if (!pAlphaMask)
return false;
- }
}
}
- if (pSrcClone != pSrcBitmap) {
- pSrcClone->m_pAlphaMask = nullptr;
- delete pSrcClone;
- }
- pSrcClone = pAlphaMask;
+ pSrcClone = std::move(pAlphaMask);
srcOffset = 0;
} else if (pSrcClone->GetWidth() != m_Width ||
pSrcClone->GetHeight() != m_Height) {
- CFX_DIBitmap* pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height);
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
- if (!pSrcMatched) {
+ std::unique_ptr<CFX_DIBitmap> pSrcMatched =
+ pSrcClone->StretchTo(m_Width, m_Height);
+ if (!pSrcMatched)
return false;
- }
- pSrcClone = pSrcMatched;
+
+ pSrcClone = std::move(pSrcMatched);
}
+ CFX_DIBitmap* pDst = this;
if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
pDst = m_pAlphaMask;
destOffset = 0;
@@ -799,9 +762,6 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
src_pos += srcBytes;
}
}
- if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) {
- delete pSrcClone;
- }
return true;
}
@@ -864,40 +824,36 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
return true;
}
-bool CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) {
- if (!m_pBuffer) {
+bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) {
+ if (!m_pBuffer)
return false;
- }
+
ASSERT(pSrcBitmap->IsAlphaMask());
- if (!pSrcBitmap->IsAlphaMask()) {
+ if (!pSrcBitmap->IsAlphaMask())
return false;
- }
- if (!IsAlphaMask() && !HasAlpha()) {
+
+ if (!IsAlphaMask() && !HasAlpha())
return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
- }
- CFX_DIBitmap* pSrcClone = (CFX_DIBitmap*)pSrcBitmap;
+
+ CFX_MaybeOwned<CFX_DIBitmap> pSrcClone(
+ static_cast<CFX_DIBitmap*>(pSrcBitmap));
if (pSrcBitmap->GetWidth() != m_Width ||
pSrcBitmap->GetHeight() != m_Height) {
pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
- if (!pSrcClone) {
+ if (!pSrcClone)
return false;
- }
}
if (IsAlphaMask()) {
- if (!ConvertFormat(FXDIB_8bppMask)) {
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
+ if (!ConvertFormat(FXDIB_8bppMask))
return false;
- }
+
for (int row = 0; row < m_Height; row++) {
uint8_t* dest_scan = m_pBuffer + m_Pitch * row;
uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
if (pSrcClone->GetBPP() == 1) {
for (int col = 0; col < m_Width; col++) {
- if (!((1 << (7 - col % 8)) & src_scan[col / 8])) {
+ if (!((1 << (7 - col % 8)) & src_scan[col / 8]))
dest_scan[col] = 0;
- }
}
} else {
for (int col = 0; col < m_Width; col++) {
@@ -908,12 +864,9 @@ bool CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) {
}
} else {
if (GetFormat() == FXDIB_Argb) {
- if (pSrcClone->GetBPP() == 1) {
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
+ if (pSrcClone->GetBPP() == 1)
return false;
- }
+
for (int row = 0; row < m_Height; row++) {
uint8_t* dest_scan = m_pBuffer + m_Pitch * row + 3;
uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
@@ -923,12 +876,9 @@ bool CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) {
}
}
} else {
- m_pAlphaMask->MultiplyAlpha(pSrcClone);
+ m_pAlphaMask->MultiplyAlpha(pSrcClone.Get());
}
}
- if (pSrcClone != pSrcBitmap) {
- delete pSrcClone;
- }
return true;
}
@@ -1476,7 +1426,7 @@ CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
m_pBitmap->CopyPalette(pSrc->GetPalette());
m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask);
} else {
- m_pBitmap.reset(pSrc->Clone());
+ m_pBitmap = pSrc->Clone();
}
}
diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp
index b938d648a8..dacc0aa393 100644
--- a/core/fxge/dib/fx_dib_transform.cpp
+++ b/core/fxge/dib/fx_dib_transform.cpp
@@ -301,23 +301,25 @@ FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
return rect;
}
-CFX_DIBitmap* CFX_DIBSource::TransformTo(const CFX_Matrix* pDestMatrix,
- int& result_left,
- int& result_top,
- uint32_t flags,
- const FX_RECT* pDestClip) const {
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
+ const CFX_Matrix* pDestMatrix,
+ int& result_left,
+ int& result_top,
+ uint32_t flags,
+ const FX_RECT* pDestClip) const {
CFX_ImageTransformer transformer(this, pDestMatrix, flags, pDestClip);
transformer.Start();
transformer.Continue(nullptr);
result_left = transformer.result().left;
result_top = transformer.result().top;
- return transformer.DetachBitmap().release();
+ return transformer.DetachBitmap();
}
-CFX_DIBitmap* CFX_DIBSource::StretchTo(int dest_width,
- int dest_height,
- uint32_t flags,
- const FX_RECT* pClip) const {
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::StretchTo(
+ int dest_width,
+ int dest_height,
+ uint32_t flags,
+ const FX_RECT* pClip) const {
FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height));
if (pClip)
clip_rect.Intersect(*pClip);
@@ -333,7 +335,8 @@ CFX_DIBitmap* CFX_DIBSource::StretchTo(int dest_width,
clip_rect, flags);
if (stretcher.Start())
stretcher.Continue(nullptr);
- return storer.Detach().release();
+
+ return storer.Detach();
}
CFX_ImageTransformer::CFX_ImageTransformer(const CFX_DIBSource* pSrc,
diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h
index 1719ae13e5..ed2b47f9c1 100644
--- a/core/fxge/fx_dib.h
+++ b/core/fxge/fx_dib.h
@@ -215,18 +215,19 @@ class CFX_DIBSource {
void CopyPalette(const uint32_t* pSrcPal);
- CFX_DIBitmap* Clone(const FX_RECT* pClip = nullptr) const;
- CFX_DIBitmap* CloneConvert(FXDIB_Format format) const;
-
- CFX_DIBitmap* StretchTo(int dest_width,
- int dest_height,
- uint32_t flags = 0,
- const FX_RECT* pClip = nullptr) const;
- CFX_DIBitmap* TransformTo(const CFX_Matrix* pMatrix,
- int& left,
- int& top,
- uint32_t flags = 0,
- const FX_RECT* pClip = nullptr) const;
+ std::unique_ptr<CFX_DIBitmap> Clone(const FX_RECT* pClip = nullptr) const;
+ std::unique_ptr<CFX_DIBitmap> CloneConvert(FXDIB_Format format) const;
+
+ std::unique_ptr<CFX_DIBitmap> StretchTo(int dest_width,
+ int dest_height,
+ uint32_t flags = 0,
+ const FX_RECT* pClip = nullptr) const;
+ std::unique_ptr<CFX_DIBitmap> TransformTo(
+ const CFX_Matrix* pMatrix,
+ int& left,
+ int& top,
+ uint32_t flags = 0,
+ const FX_RECT* pClip = nullptr) const;
CFX_DIBitmap* GetAlphaMask(const FX_RECT* pClip = nullptr) const;
bool CopyAlphaMask(const CFX_DIBSource* pAlphaMask,
@@ -307,14 +308,14 @@ class CFX_DIBitmap : public CFX_DIBSource {
void SetPixel(int x, int y, uint32_t color);
bool LoadChannel(FXDIB_Channel destChannel,
- const CFX_DIBSource* pSrcBitmap,
+ CFX_DIBSource* pSrcBitmap,
FXDIB_Channel srcChannel);
bool LoadChannel(FXDIB_Channel destChannel, int value);
bool MultiplyAlpha(int alpha);
- bool MultiplyAlpha(const CFX_DIBSource* pAlphaMask);
+ bool MultiplyAlpha(CFX_DIBSource* pAlphaMask);
bool TransferBitmap(int dest_left,
int dest_top,
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 004f344d67..e0d2e60a15 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -11,6 +11,7 @@
#include <vector>
#include "core/fxcodec/fx_codec.h"
+#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_fontmapper.h"
@@ -813,7 +814,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
} else {
CFX_DIBitmap* pBitmap = pBitmap1;
if (pBitmap->IsCmykImage()) {
- pBitmap = pBitmap->CloneConvert(FXDIB_Rgb);
+ pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release();
if (!pBitmap)
return false;
}
@@ -852,23 +853,19 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
} else {
SetStretchBltMode(m_hDC, COLORONCOLOR);
}
- CFX_DIBitmap* pToStrechBitmap = pBitmap;
- bool del = false;
+ CFX_MaybeOwned<CFX_DIBitmap> pToStrechBitmap(pBitmap);
if (m_DeviceClass == FXDC_PRINTER &&
((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() >
(int64_t)abs(dest_width) * abs(dest_height))) {
pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height);
- del = true;
}
CFX_ByteString toStrechBitmapInfo =
- CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap);
+ CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap.Get());
::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0,
pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(),
pToStrechBitmap->GetBuffer(),
(BITMAPINFO*)toStrechBitmapInfo.c_str(), DIB_RGB_COLORS,
SRCCOPY);
- if (del)
- delete pToStrechBitmap;
return true;
}
diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp
index f3bf2deae2..cd18525b00 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -7,6 +7,7 @@
#include <windows.h>
#include <algorithm>
+#include <memory>
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_gemodule.h"
@@ -14,6 +15,7 @@
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/win32/cfx_windowsdib.h"
#include "core/fxge/win32/win32_int.h"
+#include "third_party/base/ptr_util.h"
// Has to come before gdiplus.h
namespace Gdiplus {
@@ -458,26 +460,27 @@ static GpBrush* _GdipCreateBrush(DWORD argb) {
CallFunc(GdipCreateSolidFill)((ARGB)argb, &solidBrush);
return solidBrush;
}
-static CFX_DIBitmap* _StretchMonoToGray(int dest_width,
- int dest_height,
- const CFX_DIBitmap* pSource,
- FX_RECT* pClipRect) {
+
+static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
+ int dest_width,
+ int dest_height,
+ const CFX_DIBitmap* pSource,
+ FX_RECT* pClipRect) {
bool bFlipX = dest_width < 0;
- if (bFlipX) {
+ if (bFlipX)
dest_width = -dest_width;
- }
+
bool bFlipY = dest_height < 0;
- if (bFlipY) {
+ if (bFlipY)
dest_height = -dest_height;
- }
+
int result_width = pClipRect->Width();
int result_height = pClipRect->Height();
int result_pitch = (result_width + 3) / 4 * 4;
- CFX_DIBitmap* pStretched = new CFX_DIBitmap;
- if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb)) {
- delete pStretched;
+ auto pStretched = pdfium::MakeUnique<CFX_DIBitmap>();
+ if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb))
return nullptr;
- }
+
LPBYTE dest_buf = pStretched->GetBuffer();
int src_width = pSource->GetWidth();
int src_height = pSource->GetHeight();
@@ -512,6 +515,7 @@ static CFX_DIBitmap* _StretchMonoToGray(int dest_width,
}
return pStretched;
}
+
static void OutputImageMask(GpGraphics* pGraphics,
BOOL bMonoDevice,
const CFX_DIBitmap* pBitmap,
@@ -558,10 +562,10 @@ static void OutputImageMask(GpGraphics* pGraphics,
return;
}
image_clip.Offset(-image_rect.left, -image_rect.top);
- CFX_DIBitmap* pStretched = nullptr;
+ std::unique_ptr<CFX_DIBitmap> pStretched;
if (src_width * src_height > 10000) {
pStretched =
- _StretchMonoToGray(dest_width, dest_height, pBitmap, &image_clip);
+ StretchMonoToGray(dest_width, dest_height, pBitmap, &image_clip);
} else {
pStretched =
pBitmap->StretchTo(dest_width, dest_height, false, &image_clip);
@@ -584,7 +588,6 @@ static void OutputImageMask(GpGraphics* pGraphics,
image_rect.left + image_clip.left,
image_rect.top + image_clip.top);
CallFunc(GdipDisposeImage)(bitmap);
- delete pStretched;
return;
}
GpBitmap* bitmap;
@@ -610,13 +613,11 @@ static void OutputImage(GpGraphics* pGraphics,
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
if (pBitmap->GetBPP() == 1 && (pSrcRect->left % 8)) {
FX_RECT new_rect(0, 0, src_width, src_height);
- CFX_DIBitmap* pCloned = pBitmap->Clone(pSrcRect);
- if (!pCloned) {
+ std::unique_ptr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
+ if (!pCloned)
return;
- }
- OutputImage(pGraphics, pCloned, &new_rect, dest_left, dest_top, dest_width,
- dest_height);
- delete pCloned;
+ OutputImage(pGraphics, pCloned.get(), &new_rect, dest_left, dest_top,
+ dest_width, dest_height);
return;
}
int src_pitch = pBitmap->GetPitch();
diff --git a/xfa/fxbarcode/BC_TwoDimWriter.cpp b/xfa/fxbarcode/BC_TwoDimWriter.cpp
index 83b7b3c081..ec6c3626b2 100644
--- a/xfa/fxbarcode/BC_TwoDimWriter.cpp
+++ b/xfa/fxbarcode/BC_TwoDimWriter.cpp
@@ -82,9 +82,10 @@ void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
}
}
if (!m_bFixedSize) {
- CFX_DIBitmap* pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
+ std::unique_ptr<CFX_DIBitmap> pStretchBitmap =
+ pOutBitmap->StretchTo(m_Width, m_Height);
delete pOutBitmap;
- pOutBitmap = pStretchBitmap;
+ pOutBitmap = pStretchBitmap.release();
}
}
diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp b/xfa/fxbarcode/oned/BC_OneDimWriter.cpp
index 0555ba65fd..09f7aea9db 100644
--- a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/xfa/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -343,9 +343,10 @@ void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
e);
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
- CFX_DIBitmap* pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
+ std::unique_ptr<CFX_DIBitmap> pStretchBitmap =
+ pOutBitmap->StretchTo(m_Width, m_Height);
delete pOutBitmap;
- pOutBitmap = pStretchBitmap;
+ pOutBitmap = pStretchBitmap.release();
}
void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device,
diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp
index bc1854eb42..dfe418b76b 100644
--- a/xfa/fxfa/app/xfa_ffwidget.cpp
+++ b/xfa/fxfa/app/xfa_ffwidget.cpp
@@ -13,6 +13,7 @@
#include "core/fpdfapi/page/cpdf_pageobjectholder.h"
#include "core/fxcodec/codec/ccodec_progressivedecoder.h"
#include "core/fxcodec/fx_codec.h"
+#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxge/cfx_gemodule.h"
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
@@ -647,7 +648,7 @@ bool CXFA_ImageRenderer::StartDIBSource() {
if (m_pDIBSource->HasAlpha() &&
!(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE) &&
!(m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
- m_pCloneConvert.reset(m_pDIBSource->CloneConvert(FXDIB_Rgb));
+ m_pCloneConvert = m_pDIBSource->CloneConvert(FXDIB_Rgb);
if (!m_pCloneConvert) {
m_Result = false;
return false;
@@ -783,10 +784,8 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
rect.Intersect(m_pDevice->GetClipBox());
- CFX_DIBitmap* pClone = nullptr;
- bool bClone = false;
+ CFX_MaybeOwned<CFX_DIBitmap> pClone;
if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) {
- bClone = true;
pClone = m_pDevice->GetBackDrop()->Clone(&rect);
CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap();
pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
@@ -803,35 +802,34 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
pClone = pDIBitmap;
}
if (m_pDevice->GetBackDrop()) {
- m_pDevice->SetDIBits(pClone, rect.left, rect.top);
+ m_pDevice->SetDIBits(pClone.Get(), rect.left, rect.top);
} else {
if (pDIBitmap->IsAlphaMask())
return;
m_pDevice->SetDIBitsWithBlend(pDIBitmap, rect.left, rect.top,
blend_mode);
}
- if (bClone) {
- delete pClone;
- }
}
return;
}
- if (pDIBitmap->HasAlpha() &&
- !(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE)) {
- CFX_DIBitmap* pCloneConvert = pDIBitmap->CloneConvert(FXDIB_Rgb);
- if (!pCloneConvert) {
- return;
- }
- CXFA_ImageRenderer imageRender;
- bool bRet = imageRender.Start(m_pDevice, pCloneConvert, m_FillArgb,
- m_BitmapAlpha, &m_ImageMatrix, m_Flags);
- while (bRet) {
- bRet = imageRender.Continue(nullptr);
- }
- delete pCloneConvert;
+ if (!pDIBitmap->HasAlpha() ||
+ (m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE)) {
+ return;
+ }
+ std::unique_ptr<CFX_DIBitmap> pCloneConvert =
+ pDIBitmap->CloneConvert(FXDIB_Rgb);
+ if (!pCloneConvert)
+ return;
+
+ CXFA_ImageRenderer imageRender;
+ if (!imageRender.Start(m_pDevice, pCloneConvert.get(), m_FillArgb,
+ m_BitmapAlpha, &m_ImageMatrix, m_Flags)) {
return;
}
+ while (imageRender.Continue(nullptr))
+ continue;
}
+
void XFA_DrawImage(CFX_Graphics* pGS,
const CFX_RectF& rtImage,
CFX_Matrix* pMatrix,