summaryrefslogtreecommitdiff
path: root/core/fxge/dib
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-14 14:15:14 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-14 14:15:14 -0800
commit72c1bda4efaf0121e13b794cb886acd9806b6c89 (patch)
tree42930bca08650730ef2aba728799c9428edab79e /core/fxge/dib
parent5e4388ef805b1666a1064e4dc73f4f1e792aa041 (diff)
downloadpdfium-72c1bda4efaf0121e13b794cb886acd9806b6c89.tar.xz
Return unique_ptr from GetAlphaMask.
Rename GetAlphaMask => CloneAlphaMask since it does more than get. Rename CopyAlphaMask => SetAlphaMask, as it copies IN, not OUT. ditto for CopyPalette => SetPalette. BUG= Review-Url: https://codereview.chromium.org/2572243002
Diffstat (limited to 'core/fxge/dib')
-rw-r--r--core/fxge/dib/fx_dib_convert.cpp25
-rw-r--r--core/fxge/dib/fx_dib_main.cpp99
-rw-r--r--core/fxge/dib/fx_dib_transform.cpp2
3 files changed, 63 insertions, 63 deletions
diff --git a/core/fxge/dib/fx_dib_convert.cpp b/core/fxge/dib/fx_dib_convert.cpp
index b1362462c3..aad3f343e2 100644
--- a/core/fxge/dib/fx_dib_convert.cpp
+++ b/core/fxge/dib/fx_dib_convert.cpp
@@ -8,6 +8,7 @@
#include <utility>
#include "core/fxcodec/fx_codec.h"
+#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
@@ -791,26 +792,26 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
if (!pClone->Create(m_Width, m_Height, dest_format))
return nullptr;
- CFX_DIBitmap* pSrcAlpha = nullptr;
+ CFX_MaybeOwned<CFX_DIBitmap> pSrcAlpha;
if (HasAlpha()) {
- pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask;
+ if (GetFormat() == FXDIB_Argb)
+ pSrcAlpha = CloneAlphaMask();
+ else
+ pSrcAlpha = m_pAlphaMask;
+
if (!pSrcAlpha)
return nullptr;
}
-
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->CopyAlphaMask(pSrcAlpha);
+ ret = pClone->SetAlphaMask(pSrcAlpha.Get());
}
}
- if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) {
- delete pSrcAlpha;
- pSrcAlpha = nullptr;
- }
if (!ret)
return nullptr;
@@ -820,7 +821,7 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
return nullptr;
}
if (pal_8bpp)
- pClone->CopyPalette(pal_8bpp.get());
+ pClone->SetPalette(pal_8bpp.get());
return pClone;
}
@@ -867,7 +868,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
}
} else if (dest_format & 0x0200) {
if (src_format == FXDIB_Argb) {
- pAlphaMask = GetAlphaMask();
+ pAlphaMask = CloneAlphaMask().release();
if (!pAlphaMask) {
FX_Free(dest_buf);
return false;
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index 310c62fcc5..f90cbc1a91 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -128,17 +128,17 @@ bool CFX_DIBitmap::Create(int width,
}
bool CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) {
- if (m_pBuffer) {
+ if (m_pBuffer)
return false;
- }
- if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat())) {
+
+ if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat()))
return false;
- }
- CopyPalette(pSrc->GetPalette());
- CopyAlphaMask(pSrc->m_pAlphaMask);
- for (int row = 0; row < pSrc->GetHeight(); row++) {
+
+ SetPalette(pSrc->GetPalette());
+ SetAlphaMask(pSrc->m_pAlphaMask);
+ for (int row = 0; row < pSrc->GetHeight(); row++)
FXSYS_memcpy(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch);
- }
+
return true;
}
@@ -186,8 +186,8 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
return nullptr;
- pNewBitmap->CopyPalette(m_pPalette.get());
- pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip);
+ pNewBitmap->SetPalette(m_pPalette.get());
+ pNewBitmap->SetAlphaMask(m_pAlphaMask, pClip);
if (GetBPP() == 1 && rect.left % 8 != 0) {
int left_shift = rect.left % 32;
int right_shift = 32 - left_shift;
@@ -572,18 +572,17 @@ bool CFX_DIBitmap::TransferMask(int dest_left,
return true;
}
-void CFX_DIBSource::CopyPalette(const uint32_t* pSrc) {
+void CFX_DIBSource::SetPalette(const uint32_t* pSrc) {
static const uint32_t kPaletteSize = 256;
-
if (!pSrc || GetBPP() > 8) {
m_pPalette.reset();
- } else {
- uint32_t pal_size = 1 << GetBPP();
- if (!m_pPalette)
- m_pPalette.reset(FX_Alloc(uint32_t, pal_size));
- pal_size = std::min(pal_size, kPaletteSize);
- FXSYS_memcpy(m_pPalette.get(), pSrc, pal_size * sizeof(uint32_t));
+ return;
}
+ uint32_t pal_size = 1 << GetBPP();
+ if (!m_pPalette)
+ m_pPalette.reset(FX_Alloc(uint32_t, pal_size));
+ pal_size = std::min(pal_size, kPaletteSize);
+ FXSYS_memcpy(m_pPalette.get(), pSrc, pal_size * sizeof(uint32_t));
}
void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const {
@@ -606,23 +605,23 @@ void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const {
}
}
-CFX_DIBitmap* CFX_DIBSource::GetAlphaMask(const FX_RECT* pClip) const {
+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);
if (pClip) {
rect.Intersect(*pClip);
- if (rect.IsEmpty()) {
+ if (rect.IsEmpty())
return nullptr;
- }
}
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask)) {
- delete pMask;
+ auto pMask = pdfium::MakeUnique<CFX_DIBitmap>();
+ if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask))
return nullptr;
- }
+
for (int row = rect.top; row < rect.bottom; row++) {
const uint8_t* src_scan = GetScanline(row) + rect.left * 4 + 3;
- uint8_t* dest_scan = (uint8_t*)pMask->GetScanline(row - rect.top);
+ uint8_t* dest_scan =
+ const_cast<uint8_t*>(pMask->GetScanline(row - rect.top));
for (int col = rect.left; col < rect.right; col++) {
*dest_scan++ = *src_scan;
src_scan += 4;
@@ -631,30 +630,30 @@ CFX_DIBitmap* CFX_DIBSource::GetAlphaMask(const FX_RECT* pClip) const {
return pMask;
}
-bool CFX_DIBSource::CopyAlphaMask(const CFX_DIBSource* pAlphaMask,
- const FX_RECT* pClip) {
- if (!HasAlpha() || GetFormat() == FXDIB_Argb) {
+bool CFX_DIBSource::SetAlphaMask(const CFX_DIBSource* pAlphaMask,
+ const FX_RECT* pClip) {
+ if (!HasAlpha() || GetFormat() == FXDIB_Argb)
return false;
+
+ if (!pAlphaMask) {
+ m_pAlphaMask->Clear(0xff000000);
+ return true;
}
- if (pAlphaMask) {
- FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height);
- if (pClip) {
- rect.Intersect(*pClip);
- if (rect.IsEmpty() || rect.Width() != m_Width ||
- rect.Height() != m_Height) {
- return false;
- }
- } else {
- if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height) {
- return false;
- }
+ FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height);
+ if (pClip) {
+ rect.Intersect(*pClip);
+ if (rect.IsEmpty() || rect.Width() != m_Width ||
+ rect.Height() != m_Height) {
+ return false;
}
- for (int row = 0; row < m_Height; row++)
- FXSYS_memcpy((void*)m_pAlphaMask->GetScanline(row),
- pAlphaMask->GetScanline(row + rect.top) + rect.left,
- m_pAlphaMask->m_Pitch);
} else {
- m_pAlphaMask->Clear(0xff000000);
+ if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height)
+ return false;
+ }
+ for (int row = 0; row < m_Height; row++) {
+ FXSYS_memcpy(const_cast<uint8_t*>(m_pAlphaMask->GetScanline(row)),
+ pAlphaMask->GetScanline(row + rect.top) + rect.left,
+ m_pAlphaMask->m_Pitch);
}
return true;
}
@@ -1349,7 +1348,7 @@ CFX_DIBitmap* CFX_DIBSource::FlipImage(bool bXFlip, bool bYFlip) const {
delete pFlipped;
return nullptr;
}
- pFlipped->CopyPalette(m_pPalette.get());
+ pFlipped->SetPalette(m_pPalette.get());
uint8_t* pDestBuffer = pFlipped->GetBuffer();
int Bpp = m_bpp / 8;
for (int row = 0; row < m_Height; row++) {
@@ -1423,8 +1422,8 @@ CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
m_pBitmap.reset();
return;
}
- m_pBitmap->CopyPalette(pSrc->GetPalette());
- m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask);
+ m_pBitmap->SetPalette(pSrc->GetPalette());
+ m_pBitmap->SetAlphaMask(pSrc->m_pAlphaMask);
} else {
m_pBitmap = pSrc->Clone();
}
@@ -1642,6 +1641,6 @@ bool CFX_BitmapStorer::SetInfo(int width,
return false;
}
if (pSrcPalette)
- m_pBitmap->CopyPalette(pSrcPalette);
+ 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 dacc0aa393..e56e7fccbb 100644
--- a/core/fxge/dib/fx_dib_transform.cpp
+++ b/core/fxge/dib/fx_dib_transform.cpp
@@ -194,7 +194,7 @@ CFX_DIBitmap* CFX_DIBSource::SwapXY(bool bXFlip,
delete pTransBitmap;
return nullptr;
}
- pTransBitmap->CopyPalette(m_pPalette.get());
+ pTransBitmap->SetPalette(m_pPalette.get());
int dest_pitch = pTransBitmap->GetPitch();
uint8_t* dest_buf = pTransBitmap->GetBuffer();
int row_start = bXFlip ? m_Height - dest_clip.right : dest_clip.left;