summaryrefslogtreecommitdiff
path: root/core/fxge/dib
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/dib')
-rw-r--r--core/fxge/dib/dib_int.h4
-rw-r--r--core/fxge/dib/fx_dib_composite.cpp42
-rw-r--r--core/fxge/dib/fx_dib_convert.cpp122
-rw-r--r--core/fxge/dib/fx_dib_engine.cpp15
-rw-r--r--core/fxge/dib/fx_dib_engine_unittest.cpp8
-rw-r--r--core/fxge/dib/fx_dib_main.cpp170
-rw-r--r--core/fxge/dib/fx_dib_transform.cpp38
7 files changed, 208 insertions, 191 deletions
diff --git a/core/fxge/dib/dib_int.h b/core/fxge/dib/dib_int.h
index a898a479a2..000003a9c6 100644
--- a/core/fxge/dib/dib_int.h
+++ b/core/fxge/dib/dib_int.h
@@ -71,7 +71,7 @@ class CStretchEngine {
int dest_width,
int dest_height,
const FX_RECT& clip_rect,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int flags);
~CStretchEngine();
@@ -91,7 +91,7 @@ class CStretchEngine {
uint8_t* m_pDestScanline;
uint8_t* m_pDestMaskScanline;
FX_RECT m_SrcClip;
- CFX_RetainPtr<CFX_DIBSource> m_pSource;
+ const CFX_DIBSource* m_pSource;
uint32_t* m_pSrcPalette;
int m_SrcWidth;
int m_SrcHeight;
diff --git a/core/fxge/dib/fx_dib_composite.cpp b/core/fxge/dib/fx_dib_composite.cpp
index fb00cb855b..435a1ad9b6 100644
--- a/core/fxge/dib/fx_dib_composite.cpp
+++ b/core/fxge/dib/fx_dib_composite.cpp
@@ -3914,18 +3914,17 @@ void CFX_ScanlineCompositor::CompositeBitMaskLine(uint8_t* dest_scan,
}
}
-bool CFX_DIBitmap::CompositeBitmap(
- int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top,
- int blend_type,
- const CFX_ClipRgn* pClipRgn,
- bool bRgbByteOrder,
- void* pIccTransform) {
+bool CFX_DIBitmap::CompositeBitmap(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top,
+ int blend_type,
+ const CFX_ClipRgn* pClipRgn,
+ bool bRgbByteOrder,
+ void* pIccTransform) {
if (!m_pBuffer) {
return false;
}
@@ -3939,11 +3938,11 @@ bool CFX_DIBitmap::CompositeBitmap(
if (width == 0 || height == 0) {
return true;
}
- CFX_RetainPtr<CFX_DIBitmap> pClipMask;
+ const CFX_DIBitmap* pClipMask = nullptr;
FX_RECT clip_box;
if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
- pClipMask = pClipRgn->GetMask();
+ pClipMask = pClipRgn->GetMask().GetObject();
clip_box = pClipRgn->GetBox();
}
CFX_ScanlineCompositor compositor;
@@ -3955,7 +3954,7 @@ bool CFX_DIBitmap::CompositeBitmap(
int dest_Bpp = m_bpp / 8;
int src_Bpp = pSrcBitmap->GetBPP() / 8;
bool bRgb = src_Bpp > 1 && !pSrcBitmap->IsCmykImage();
- CFX_RetainPtr<CFX_DIBitmap> pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
+ CFX_DIBitmap* pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
for (int row = 0; row < height; row++) {
uint8_t* dest_scan =
m_pBuffer + (dest_top + row) * m_Pitch + dest_left * dest_Bpp;
@@ -3991,7 +3990,7 @@ bool CFX_DIBitmap::CompositeMask(int dest_left,
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ const CFX_DIBSource* pMask,
uint32_t color,
int src_left,
int src_top,
@@ -4018,11 +4017,11 @@ bool CFX_DIBitmap::CompositeMask(int dest_left,
if (src_alpha == 0) {
return true;
}
- CFX_RetainPtr<CFX_DIBitmap> pClipMask;
+ const CFX_DIBitmap* pClipMask = nullptr;
FX_RECT clip_box;
if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
- pClipMask = pClipRgn->GetMask();
+ pClipMask = pClipRgn->GetMask().GetObject();
clip_box = pClipRgn->GetBox();
}
int src_bpp = pMask->GetBPP();
@@ -4283,7 +4282,7 @@ CFX_BitmapComposer::~CFX_BitmapComposer() {
FX_Free(m_pAddClipScan);
}
-void CFX_BitmapComposer::Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
+void CFX_BitmapComposer::Compose(CFX_DIBitmap* pDest,
const CFX_ClipRgn* pClipRgn,
int bitmap_alpha,
uint32_t mask_color,
@@ -4304,8 +4303,9 @@ void CFX_BitmapComposer::Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
m_BitmapAlpha = bitmap_alpha;
m_MaskColor = mask_color;
m_pClipMask = nullptr;
- if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI)
- m_pClipMask = pClipRgn->GetMask();
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
+ m_pClipMask = pClipRgn->GetMask().GetObject();
+ }
m_bVertical = bVertical;
m_bFlipX = bFlipX;
m_bFlipY = bFlipY;
diff --git a/core/fxge/dib/fx_dib_convert.cpp b/core/fxge/dib/fx_dib_convert.cpp
index 624e1437e9..aad3f343e2 100644
--- a/core/fxge/dib/fx_dib_convert.cpp
+++ b/core/fxge/dib/fx_dib_convert.cpp
@@ -17,7 +17,7 @@ class CFX_Palette {
CFX_Palette();
~CFX_Palette();
- bool BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap);
+ bool BuildPalette(const CFX_DIBSource* pBitmap);
uint32_t* GetPalette() const { return m_pPalette; }
uint32_t* GetColorLut() const { return m_cLut; }
uint32_t* GetAmountLut() const { return m_aLut; }
@@ -101,7 +101,7 @@ CFX_Palette::~CFX_Palette() {
m_lut = 0;
}
-bool CFX_Palette::BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap) {
+bool CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) {
if (!pBitmap) {
return false;
}
@@ -145,7 +145,7 @@ bool ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
uint8_t set_gray, reset_gray;
@@ -169,7 +169,7 @@ bool ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
for (int row = 0; row < height; row++) {
@@ -184,7 +184,7 @@ bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
uint32_t* src_plt = pSrcBitmap->GetPalette();
@@ -231,7 +231,7 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
uint32_t* src_plt = pSrcBitmap->GetPalette();
@@ -263,14 +263,13 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
return true;
}
-bool ConvertBuffer_RgbOrCmyk2Gray(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
int Bpp = pSrcBitmap->GetBPP() / 8;
if (pSrcBitmap->IsCmykImage()) {
for (int row = 0; row < height; row++) {
@@ -305,7 +304,7 @@ void ConvertBuffer_IndexCopy(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
if (pSrcBitmap->GetBPP() == 1) {
@@ -334,7 +333,7 @@ bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top,
uint32_t* dst_plt) {
@@ -362,7 +361,7 @@ bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top,
uint32_t* dst_plt) {
@@ -425,7 +424,7 @@ bool ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -456,7 +455,7 @@ bool ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -480,7 +479,7 @@ bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -532,7 +531,7 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -573,14 +572,13 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
return true;
}
-bool ConvertBuffer_24bppRgb2Rgb24(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
@@ -590,14 +588,13 @@ bool ConvertBuffer_24bppRgb2Rgb24(
return true;
}
-bool ConvertBuffer_32bppRgb2Rgb24(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool ConvertBuffer_32bppRgb2Rgb24(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
@@ -616,7 +613,7 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = pSrcBitmap->GetBPP() / 8;
@@ -635,14 +632,13 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
return true;
}
-bool ConvertBuffer_32bppCmyk2Rgb32(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
@@ -662,7 +658,7 @@ bool ConvertBuffer(FXDIB_Format dest_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top,
std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
@@ -787,16 +783,16 @@ bool ConvertBuffer(FXDIB_Format dest_format,
}
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
- FXDIB_Format dest_format) {
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
+ FXDIB_Format dest_format) const {
if (dest_format == GetFormat())
return Clone(nullptr);
- auto pClone = pdfium::MakeRetain<CFX_DIBitmap>();
+ std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pClone->Create(m_Width, m_Height, dest_format))
return nullptr;
- CFX_RetainPtr<CFX_DIBitmap> pSrcAlpha;
+ CFX_MaybeOwned<CFX_DIBitmap> pSrcAlpha;
if (HasAlpha()) {
if (GetFormat() == FXDIB_Argb)
pSrcAlpha = CloneAlphaMask();
@@ -809,19 +805,19 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
bool ret = true;
if (dest_format & 0x0200) {
if (dest_format == FXDIB_Argb) {
- ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha)
- : pClone->LoadChannel(FXDIB_Alpha, 0xff);
+ ret = pSrcAlpha
+ ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha.Get(), FXDIB_Alpha)
+ : pClone->LoadChannel(FXDIB_Alpha, 0xff);
} else {
- ret = pClone->SetAlphaMask(pSrcAlpha);
+ ret = pClone->SetAlphaMask(pSrcAlpha.Get());
}
}
if (!ret)
return nullptr;
- CFX_RetainPtr<CFX_DIBSource> holder(this);
std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(),
- m_Width, m_Height, holder, 0, 0, &pal_8bpp)) {
+ m_Width, m_Height, this, 0, 0, &pal_8bpp)) {
return nullptr;
}
if (pal_8bpp)
@@ -857,7 +853,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
if (!dest_buf) {
return false;
}
- CFX_RetainPtr<CFX_DIBitmap> pAlphaMask;
+ CFX_DIBitmap* pAlphaMask = nullptr;
if (dest_format == FXDIB_Argb) {
FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4);
if (m_pAlphaMask) {
@@ -872,7 +868,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
}
} else if (dest_format & 0x0200) {
if (src_format == FXDIB_Argb) {
- pAlphaMask = CloneAlphaMask();
+ pAlphaMask = CloneAlphaMask().release();
if (!pAlphaMask) {
FX_Free(dest_buf);
return false;
@@ -883,21 +879,25 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
FX_Free(dest_buf);
return false;
}
- pAlphaMask = std::move(m_pAlphaMask);
+ pAlphaMask = m_pAlphaMask;
+ m_pAlphaMask = nullptr;
} else {
pAlphaMask = m_pAlphaMask;
}
}
}
bool ret = false;
- CFX_RetainPtr<CFX_DIBSource> holder(this);
std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height,
- holder, 0, 0, &pal_8bpp);
+ this, 0, 0, &pal_8bpp);
if (!ret) {
+ if (pAlphaMask != m_pAlphaMask)
+ delete pAlphaMask;
FX_Free(dest_buf);
return false;
}
+ if (m_pAlphaMask && pAlphaMask != m_pAlphaMask)
+ delete m_pAlphaMask;
m_pAlphaMask = pAlphaMask;
m_pPalette = std::move(pal_8bpp);
if (!m_bExtBuf)
diff --git a/core/fxge/dib/fx_dib_engine.cpp b/core/fxge/dib/fx_dib_engine.cpp
index 7aa710b795..5975a5e975 100644
--- a/core/fxge/dib/fx_dib_engine.cpp
+++ b/core/fxge/dib/fx_dib_engine.cpp
@@ -265,7 +265,7 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
int dest_width,
int dest_height,
const FX_RECT& clip_rect,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int flags) {
m_State = 0;
m_DestFormat = dest_format;
@@ -852,13 +852,12 @@ void CStretchEngine::StretchVert() {
}
}
-CFX_ImageStretcher::CFX_ImageStretcher(
- IFX_ScanlineComposer* pDest,
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- int dest_width,
- int dest_height,
- const FX_RECT& bitmap_rect,
- uint32_t flags)
+CFX_ImageStretcher::CFX_ImageStretcher(IFX_ScanlineComposer* pDest,
+ const CFX_DIBSource* pSource,
+ int dest_width,
+ int dest_height,
+ const FX_RECT& bitmap_rect,
+ uint32_t flags)
: m_pDest(pDest),
m_pSource(pSource),
m_Flags(flags),
diff --git a/core/fxge/dib/fx_dib_engine_unittest.cpp b/core/fxge/dib/fx_dib_engine_unittest.cpp
index 86df82442f..705d761ca8 100644
--- a/core/fxge/dib/fx_dib_engine_unittest.cpp
+++ b/core/fxge/dib/fx_dib_engine_unittest.cpp
@@ -23,9 +23,9 @@ TEST(CStretchEngine, OverflowInCtor) {
dict_obj->SetNewFor<CPDF_Number>("Height", 12500);
std::unique_ptr<CPDF_Stream> stream =
pdfium::MakeUnique<CPDF_Stream>(nullptr, 0, std::move(dict_obj));
- auto dib_source = pdfium::MakeRetain<CPDF_DIBSource>();
- dib_source->Load(nullptr, stream.get());
- CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect, dib_source,
- 0);
+ CPDF_DIBSource dib_source;
+ dib_source.Load(nullptr, stream.get());
+ CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect,
+ &dib_source, 0);
EXPECT_EQ(FXDIB_INTERPOL, engine.m_Flags);
}
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index 8a97d342b5..96cae9d4e7 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -44,9 +44,16 @@ uint32_t ArgbEncode(int a, FX_COLORREF rgb) {
}
CFX_DIBSource::CFX_DIBSource()
- : m_Width(0), m_Height(0), m_bpp(0), m_AlphaFlag(0), m_Pitch(0) {}
-
-CFX_DIBSource::~CFX_DIBSource() {}
+ : m_pAlphaMask(nullptr),
+ m_Width(0),
+ m_Height(0),
+ m_bpp(0),
+ m_AlphaFlag(0),
+ m_Pitch(0) {}
+
+CFX_DIBSource::~CFX_DIBSource() {
+ delete m_pAlphaMask;
+}
uint8_t* CFX_DIBSource::GetBuffer() const {
return nullptr;
@@ -120,7 +127,7 @@ bool CFX_DIBitmap::Create(int width,
return true;
}
-bool CFX_DIBitmap::Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+bool CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) {
if (m_pBuffer)
return false;
@@ -150,10 +157,11 @@ const uint8_t* CFX_DIBitmap::GetScanline(int line) const {
return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr;
}
-void CFX_DIBitmap::TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap) {
+void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
if (!m_bExtBuf)
FX_Free(m_pBuffer);
+ delete m_pAlphaMask;
m_pBuffer = pSrcBitmap->m_pBuffer;
m_pPalette = std::move(pSrcBitmap->m_pPalette);
m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
@@ -167,14 +175,14 @@ void CFX_DIBitmap::TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap) {
m_Pitch = pSrcBitmap->m_Pitch;
}
-CFX_RetainPtr<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())
return nullptr;
}
- auto pNewBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pNewBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
return nullptr;
@@ -232,11 +240,12 @@ void CFX_DIBSource::BuildPalette() {
}
bool CFX_DIBSource::BuildAlphaMask() {
- if (m_pAlphaMask)
+ if (m_pAlphaMask) {
return true;
-
- m_pAlphaMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ }
+ m_pAlphaMask = new CFX_DIBitmap;
if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete m_pAlphaMask;
m_pAlphaMask = nullptr;
return false;
}
@@ -392,14 +401,13 @@ void CFX_DIBSource::GetOverlapRect(int& dest_left,
height = dest_rect.bottom - dest_rect.top;
}
-bool CFX_DIBitmap::TransferBitmap(
- int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool CFX_DIBitmap::TransferBitmap(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
if (!m_pBuffer)
return false;
@@ -458,7 +466,7 @@ bool CFX_DIBitmap::TransferMask(int dest_left,
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ const CFX_DIBSource* pMask,
uint32_t color,
int src_left,
int src_top,
@@ -597,7 +605,7 @@ void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const {
}
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
const FX_RECT* pClip) const {
ASSERT(GetFormat() == FXDIB_Argb);
FX_RECT rect(0, 0, m_Width, m_Height);
@@ -606,7 +614,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
if (rect.IsEmpty())
return nullptr;
}
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pMask = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask))
return nullptr;
@@ -622,7 +630,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
return pMask;
}
-bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask,
+bool CFX_DIBSource::SetAlphaMask(const CFX_DIBSource* pAlphaMask,
const FX_RECT* pClip) {
if (!HasAlpha() || GetFormat() == FXDIB_Argb)
return false;
@@ -652,12 +660,12 @@ bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr<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_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ CFX_DIBSource* pSrcBitmap,
FXDIB_Channel srcChannel) {
if (!m_pBuffer)
return false;
- CFX_RetainPtr<CFX_DIBSource> pSrcClone = pSrcBitmap;
+ CFX_MaybeOwned<CFX_DIBSource> pSrcClone(pSrcBitmap);
int srcOffset;
if (srcChannel == FXDIB_Alpha) {
if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask())
@@ -717,7 +725,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
destOffset = g_ChannelOffset[destChannel];
}
if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
- CFX_RetainPtr<CFX_DIBSource> pAlphaMask = pSrcClone->m_pAlphaMask;
+ CFX_MaybeOwned<CFX_DIBSource> pAlphaMask(pSrcClone->m_pAlphaMask);
if (pSrcClone->GetWidth() != m_Width ||
pSrcClone->GetHeight() != m_Height) {
if (pAlphaMask) {
@@ -730,14 +738,14 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
srcOffset = 0;
} else if (pSrcClone->GetWidth() != m_Width ||
pSrcClone->GetHeight() != m_Height) {
- CFX_RetainPtr<CFX_DIBitmap> pSrcMatched =
+ std::unique_ptr<CFX_DIBitmap> pSrcMatched =
pSrcClone->StretchTo(m_Width, m_Height);
if (!pSrcMatched)
return false;
pSrcClone = std::move(pSrcMatched);
}
- CFX_RetainPtr<CFX_DIBitmap> pDst(this);
+ CFX_DIBitmap* pDst = this;
if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
pDst = m_pAlphaMask;
destOffset = 0;
@@ -815,8 +823,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
return true;
}
-bool CFX_DIBitmap::MultiplyAlpha(
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap) {
+bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) {
if (!m_pBuffer)
return false;
@@ -827,7 +834,8 @@ bool CFX_DIBitmap::MultiplyAlpha(
if (!IsAlphaMask() && !HasAlpha())
return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
- CFX_RetainPtr<CFX_DIBitmap> pSrcClone = pSrcBitmap.As<CFX_DIBitmap>();
+ 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);
@@ -867,7 +875,7 @@ bool CFX_DIBitmap::MultiplyAlpha(
}
}
} else {
- m_pAlphaMask->MultiplyAlpha(pSrcClone);
+ m_pAlphaMask->MultiplyAlpha(pSrcClone.Get());
}
}
return true;
@@ -879,9 +887,9 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
}
switch (GetFormat()) {
case FXDIB_1bppRgb: {
- if (!m_pPalette)
+ if (!m_pPalette) {
return false;
-
+ }
uint8_t gray[2];
for (int i = 0; i < 2; i++) {
int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
@@ -889,10 +897,11 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
int b = static_cast<uint8_t>(m_pPalette.get()[i]);
gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
}
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
+ CFX_DIBitmap* pMask = new CFX_DIBitmap;
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
return false;
-
+ }
FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height);
for (int row = 0; row < m_Height; row++) {
uint8_t* src_pos = m_pBuffer + row * m_Pitch;
@@ -904,13 +913,14 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
dest_pos++;
}
}
- TakeOver(std::move(pMask));
+ TakeOver(pMask);
+ delete pMask;
break;
}
case FXDIB_8bppRgb: {
- if (!m_pPalette)
+ if (!m_pPalette) {
return false;
-
+ }
uint8_t gray[256];
for (int i = 0; i < 256; i++) {
int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
@@ -918,10 +928,11 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
int b = static_cast<uint8_t>(m_pPalette.get()[i]);
gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
}
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
+ CFX_DIBitmap* pMask = new CFX_DIBitmap;
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
return false;
-
+ }
for (int row = 0; row < m_Height; row++) {
uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
uint8_t* src_pos = m_pBuffer + row * m_Pitch;
@@ -929,14 +940,16 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
*dest_pos++ = gray[*src_pos++];
}
}
- TakeOver(std::move(pMask));
+ TakeOver(pMask);
+ delete pMask;
break;
}
case FXDIB_Rgb: {
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
+ CFX_DIBitmap* pMask = new CFX_DIBitmap;
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
return false;
-
+ }
for (int row = 0; row < m_Height; row++) {
uint8_t* src_pos = m_pBuffer + row * m_Pitch;
uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
@@ -945,14 +958,16 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
src_pos += 3;
}
}
- TakeOver(std::move(pMask));
+ TakeOver(pMask);
+ delete pMask;
break;
}
case FXDIB_Rgb32: {
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
+ CFX_DIBitmap* pMask = new CFX_DIBitmap;
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
return false;
-
+ }
for (int row = 0; row < m_Height; row++) {
uint8_t* src_pos = m_pBuffer + row * m_Pitch;
uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
@@ -961,7 +976,8 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
src_pos += 4;
}
}
- TakeOver(std::move(pMask));
+ TakeOver(pMask);
+ delete pMask;
break;
}
default:
@@ -1326,9 +1342,9 @@ bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) {
return true;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
- bool bYFlip) const {
- auto pFlipped = pdfium::MakeRetain<CFX_DIBitmap>();
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
+ bool bYFlip) const {
+ auto pFlipped = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pFlipped->Create(m_Width, m_Height, GetFormat()))
return nullptr;
@@ -1398,12 +1414,12 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
return pFlipped;
}
-CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
if (pSrc->GetBuffer()) {
- m_pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(),
pSrc->GetFormat(), pSrc->GetBuffer())) {
- m_pBitmap.Reset();
+ m_pBitmap.reset();
return;
}
m_pBitmap->SetPalette(pSrc->GetPalette());
@@ -1415,12 +1431,17 @@ CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
CFX_DIBExtractor::~CFX_DIBExtractor() {}
-CFX_FilteredDIB::CFX_FilteredDIB() {}
+CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {}
-CFX_FilteredDIB::~CFX_FilteredDIB() {}
+CFX_FilteredDIB::~CFX_FilteredDIB() {
+ if (m_bAutoDropSrc) {
+ delete m_pSrc;
+ }
+}
-void CFX_FilteredDIB::LoadSrc(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc) {
m_pSrc = pSrc;
+ m_bAutoDropSrc = bAutoDropSrc;
m_Width = pSrc->GetWidth();
m_Height = pSrc->GetHeight();
FXDIB_Format format = GetDestFormat();
@@ -1457,9 +1478,9 @@ CFX_ImageRenderer::CFX_ImageRenderer() {
CFX_ImageRenderer::~CFX_ImageRenderer() {}
-bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+bool CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice,
const CFX_ClipRgn* pClipRgn,
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ const CFX_DIBSource* pSource,
int bitmap_alpha,
uint32_t mask_color,
const CFX_Matrix* pMatrix,
@@ -1548,7 +1569,7 @@ bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_pTransformer->Continue(pPause))
return true;
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
+ std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
if (!pBitmap || !pBitmap->GetBuffer())
return false;
@@ -1564,16 +1585,16 @@ bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
}
m_pDevice->CompositeMask(
m_pTransformer->result().left, m_pTransformer->result().top,
- pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0,
- m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag,
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), m_MaskColor,
+ 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag,
m_pIccTransform);
} else {
if (m_BitmapAlpha != 255)
pBitmap->MultiplyAlpha(m_BitmapAlpha);
m_pDevice->CompositeBitmap(
m_pTransformer->result().left, m_pTransformer->result().top,
- pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType,
- m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), 0, 0,
+ m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
}
return false;
}
@@ -1586,11 +1607,11 @@ CFX_BitmapStorer::CFX_BitmapStorer() {
CFX_BitmapStorer::~CFX_BitmapStorer() {
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
+std::unique_ptr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
return std::move(m_pBitmap);
}
-void CFX_BitmapStorer::Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap) {
+void CFX_BitmapStorer::Replace(std::unique_ptr<CFX_DIBitmap> pBitmap) {
m_pBitmap = std::move(pBitmap);
}
@@ -1615,13 +1636,12 @@ bool CFX_BitmapStorer::SetInfo(int width,
int height,
FXDIB_Format src_format,
uint32_t* pSrcPalette) {
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pBitmap->Create(width, height, src_format))
+ m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ if (!m_pBitmap->Create(width, height, src_format)) {
+ m_pBitmap.reset();
return false;
-
+ }
if (pSrcPalette)
- pBitmap->SetPalette(pSrcPalette);
-
- m_pBitmap = std::move(pBitmap);
+ m_pBitmap->SetPalette(pSrcPalette);
return true;
}
diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp
index 3d8ddf8783..4a1c3ee050 100644
--- a/core/fxge/dib/fx_dib_transform.cpp
+++ b/core/fxge/dib/fx_dib_transform.cpp
@@ -100,7 +100,7 @@ void bicubic_get_pos_weight(int pos_pixel[],
v_w[3] = SDP_Table[512 - res_y];
}
-FXDIB_Format GetTransformedFormat(const CFX_RetainPtr<CFX_DIBSource>& pDrc) {
+FXDIB_Format GetTransformedFormat(const CFX_DIBSource* pDrc) {
FXDIB_Format format = pDrc->GetFormat();
if (pDrc->IsAlphaMask()) {
format = FXDIB_8bppMask;
@@ -179,7 +179,7 @@ class CFX_BilinearMatrix : public CPDF_FixedMatrix {
}
};
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
bool bXFlip,
bool bYFlip,
const FX_RECT* pDestClip) const {
@@ -189,7 +189,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
if (dest_clip.IsEmpty())
return nullptr;
- auto pTransBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pTransBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
int result_height = dest_clip.Height();
int result_width = dest_clip.Width();
if (!pTransBitmap->Create(result_width, result_height, GetFormat()))
@@ -303,14 +303,13 @@ FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
return rect;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
+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) {
- CFX_RetainPtr<CFX_DIBSource> holder(this);
- CFX_ImageTransformer transformer(holder, pDestMatrix, flags, pDestClip);
+ const FX_RECT* pDestClip) const {
+ CFX_ImageTransformer transformer(this, pDestMatrix, flags, pDestClip);
transformer.Start();
transformer.Continue(nullptr);
result_left = transformer.result().left;
@@ -318,11 +317,11 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
return transformer.DetachBitmap();
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width,
- int dest_height,
- uint32_t flags,
- const FX_RECT* pClip) {
- CFX_RetainPtr<CFX_DIBSource> holder(this);
+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);
@@ -334,7 +333,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width,
return Clone(&clip_rect);
CFX_BitmapStorer storer;
- CFX_ImageStretcher stretcher(&storer, holder, dest_width, dest_height,
+ CFX_ImageStretcher stretcher(&storer, this, dest_width, dest_height,
clip_rect, flags);
if (stretcher.Start())
stretcher.Continue(nullptr);
@@ -342,11 +341,10 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width,
return storer.Detach();
}
-CFX_ImageTransformer::CFX_ImageTransformer(
- const CFX_RetainPtr<CFX_DIBSource>& pSrc,
- const CFX_Matrix* pMatrix,
- int flags,
- const FX_RECT* pClip)
+CFX_ImageTransformer::CFX_ImageTransformer(const CFX_DIBSource* pSrc,
+ const CFX_Matrix* pMatrix,
+ int flags,
+ const FX_RECT* pClip)
: m_pSrc(pSrc),
m_pMatrix(pMatrix),
m_pClip(pClip),
@@ -446,7 +444,7 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer();
int stretch_pitch = m_Storer.GetBitmap()->GetPitch();
- auto pTransformed = pdfium::MakeRetain<CFX_DIBitmap>();
+ std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap);
FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source());
if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF))
return false;
@@ -960,6 +958,6 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
return false;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
+std::unique_ptr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
return m_Storer.Detach();
}