Make CFX_DIBBase dimension variables private
Make `m_Width`, `m_Height` and `m_Pitch` private. Switch all users to
getters or the newly added protected setters.
Change-Id: I941e3fc2032aa0ce8cc4f1039fa9afabdd3955f9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/121556
Reviewed-by: dan sinclair <dsinclair@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index 05fd50c..0e11d9b 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -274,7 +274,7 @@
SetFormat(MakeRGBFormat(CalculateBitsPerPixel(m_bpc, m_nComponents)));
}
- std::optional<uint32_t> pitch = fxge::CalculatePitch32(GetBPP(), m_Width);
+ std::optional<uint32_t> pitch = fxge::CalculatePitch32(GetBPP(), GetWidth());
if (!pitch.has_value())
return false;
@@ -282,12 +282,12 @@
LoadPalette();
if (m_bColorKey) {
SetFormat(FXDIB_Format::kArgb);
- pitch = fxge::CalculatePitch32(GetBPP(), m_Width);
+ pitch = fxge::CalculatePitch32(GetBPP(), GetWidth());
if (!pitch.has_value())
return false;
m_MaskBuf = DataVector<uint8_t>(pitch.value());
}
- m_Pitch = pitch.value();
+ SetPitch(pitch.value());
return true;
}
@@ -312,9 +312,9 @@
uint8_t resolution_levels_to_skip = 0;
if (max_size_required.width != 0 && max_size_required.height != 0) {
- resolution_levels_to_skip = static_cast<uint8_t>(
- std::log2(std::max(1, std::min(m_Width / max_size_required.width,
- m_Height / max_size_required.height))));
+ resolution_levels_to_skip = static_cast<uint8_t>(std::log2(
+ std::max(1, std::min(GetWidth() / max_size_required.width,
+ GetHeight() / max_size_required.height))));
}
LoadState iCreatedDecoder = CreateDecoder(resolution_levels_to_skip);
@@ -375,8 +375,8 @@
nGlobalKey = m_pGlobalAcc->KeyForCache();
}
iDecodeStatus = Jbig2Decoder::StartDecode(
- m_pJbig2Context.get(), m_pDocument->GetOrCreateCodecContext(), m_Width,
- m_Height, pSrcSpan, nSrcKey, pGlobalSpan, nGlobalKey,
+ m_pJbig2Context.get(), m_pDocument->GetOrCreateCodecContext(),
+ GetWidth(), GetHeight(), pSrcSpan, nSrcKey, pGlobalSpan, nGlobalKey,
m_pCachedBitmap->GetWritableBuffer(), m_pCachedBitmap->GetPitch(),
pPause);
} else {
@@ -542,7 +542,7 @@
if (decoder == "JBIG2Decode") {
m_pCachedBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!m_pCachedBitmap->Create(
- m_Width, m_Height,
+ GetWidth(), GetHeight(),
m_bImageMask ? FXDIB_Format::k1bppMask : FXDIB_Format::k1bppRgb)) {
m_pCachedBitmap.Reset();
return LoadState::kFail;
@@ -554,13 +554,13 @@
pdfium::span<const uint8_t> src_span = m_pStreamAcc->GetSpan();
RetainPtr<const CPDF_Dictionary> pParams = m_pStreamAcc->GetImageParam();
if (decoder == "CCITTFaxDecode") {
- m_pDecoder = CreateFaxDecoder(src_span, m_Width, m_Height, pParams);
+ m_pDecoder = CreateFaxDecoder(src_span, GetWidth(), GetHeight(), pParams);
} else if (decoder == "FlateDecode") {
- m_pDecoder = CreateFlateDecoder(src_span, m_Width, m_Height, m_nComponents,
- m_bpc, pParams);
+ m_pDecoder = CreateFlateDecoder(src_span, GetWidth(), GetHeight(),
+ m_nComponents, m_bpc, pParams);
} else if (decoder == "RunLengthDecode") {
m_pDecoder = BasicModule::CreateRunLengthDecoder(
- src_span, m_Width, m_Height, m_nComponents, m_bpc);
+ src_span, GetWidth(), GetHeight(), m_nComponents, m_bpc);
} else if (decoder == "DCTDecode") {
if (!CreateDCTDecoder(src_span, pParams))
return LoadState::kFail;
@@ -569,7 +569,7 @@
return LoadState::kFail;
const std::optional<uint32_t> requested_pitch =
- fxge::CalculatePitch8(m_bpc, m_nComponents, m_Width);
+ fxge::CalculatePitch8(m_bpc, m_nComponents, GetWidth());
if (!requested_pitch.has_value())
return LoadState::kFail;
const std::optional<uint32_t> provided_pitch = fxge::CalculatePitch8(
@@ -584,7 +584,7 @@
bool CPDF_DIB::CreateDCTDecoder(pdfium::span<const uint8_t> src_span,
const CPDF_Dictionary* pParams) {
m_pDecoder = JpegModule::CreateDecoder(
- src_span, m_Width, m_Height, m_nComponents,
+ src_span, GetWidth(), GetHeight(), m_nComponents,
!pParams || pParams->GetIntegerFor("ColorTransform", 1));
if (m_pDecoder)
return true;
@@ -595,8 +595,8 @@
return false;
const JpegModule::ImageInfo& info = info_opt.value();
- m_Width = info.width;
- m_Height = info.height;
+ SetWidth(info.width);
+ SetHeight(info.height);
if (!CPDF_Image::IsValidJpegComponent(info.num_components) ||
!CPDF_Image::IsValidJpegBitsPerComponent(info.bits_per_components)) {
@@ -605,7 +605,7 @@
if (m_nComponents == static_cast<uint32_t>(info.num_components)) {
m_bpc = info.bits_per_components;
- m_pDecoder = JpegModule::CreateDecoder(src_span, m_Width, m_Height,
+ m_pDecoder = JpegModule::CreateDecoder(src_span, GetWidth(), GetHeight(),
m_nComponents, info.color_transform);
return true;
}
@@ -650,7 +650,7 @@
return false;
m_bpc = info.bits_per_components;
- m_pDecoder = JpegModule::CreateDecoder(src_span, m_Width, m_Height,
+ m_pDecoder = JpegModule::CreateDecoder(src_span, GetWidth(), GetHeight(),
m_nComponents, info.color_transform);
return true;
}
@@ -664,15 +664,15 @@
if (!decoder)
return nullptr;
- m_Height >>= resolution_levels_to_skip;
- m_Width >>= resolution_levels_to_skip;
+ SetWidth(GetWidth() >> resolution_levels_to_skip);
+ SetHeight(GetHeight() >> resolution_levels_to_skip);
if (!decoder->StartDecode())
return nullptr;
CJPX_Decoder::JpxImageInfo image_info = decoder->GetInfo();
- if (static_cast<int>(image_info.width) < m_Width ||
- static_cast<int>(image_info.height) < m_Height) {
+ if (static_cast<int>(image_info.width) < GetWidth() ||
+ static_cast<int>(image_info.height) < GetHeight()) {
return nullptr;
}
@@ -816,10 +816,11 @@
return false;
m_pDict = m_pStream->GetDict();
- m_Width = m_pDict->GetIntegerFor("Width");
- m_Height = m_pDict->GetIntegerFor("Height");
- if (!IsValidDimension(m_Width) || !IsValidDimension(m_Height))
+ SetWidth(m_pDict->GetIntegerFor("Width"));
+ SetHeight(m_pDict->GetIntegerFor("Height"));
+ if (!IsValidDimension(GetWidth()) || !IsValidDimension(GetHeight())) {
return false;
+ }
if (!LoadColorInfo(pFormResources, pPageResources))
return false;
@@ -828,12 +829,12 @@
return false;
const std::optional<uint32_t> maybe_size =
- fxge::CalculatePitch8(m_bpc, m_nComponents, m_Width);
+ fxge::CalculatePitch8(m_bpc, m_nComponents, GetWidth());
if (!maybe_size.has_value())
return false;
FX_SAFE_UINT32 src_size = maybe_size.value();
- src_size *= m_Height;
+ src_size *= GetHeight();
if (!src_size.IsValid())
return false;
@@ -1049,7 +1050,7 @@
uint64_t src_byte_pos = 0;
size_t dest_byte_pos = 0;
const bool bpp8 = m_bpc == 8;
- for (int column = 0; column < m_Width; column++) {
+ for (int column = 0; column < GetWidth(); column++) {
for (uint32_t color = 0; color < m_nComponents; color++) {
if (bpp8) {
uint8_t data = src_scan[src_byte_pos++];
@@ -1092,8 +1093,8 @@
return false;
if (m_nComponents == m_pColorSpace->ComponentCount()) {
- m_pColorSpace->TranslateImageLine(dest_scan, src_scan, m_Width, m_Width,
- m_Height, TransMask());
+ m_pColorSpace->TranslateImageLine(dest_scan, src_scan, GetWidth(),
+ GetWidth(), GetHeight(), TransMask());
}
return true;
}
@@ -1106,7 +1107,7 @@
switch (m_bpc) {
case 8:
UNSAFE_TODO({
- for (int column = 0; column < m_Width; column++) {
+ for (int column = 0; column < GetWidth(); column++) {
*dest_pos++ = src_pos[2];
*dest_pos++ = src_pos[1];
*dest_pos++ = *src_pos;
@@ -1116,7 +1117,7 @@
break;
case 16:
UNSAFE_TODO({
- for (int col = 0; col < m_Width; col++) {
+ for (int col = 0; col < GetWidth(); col++) {
*dest_pos++ = src_pos[4];
*dest_pos++ = src_pos[2];
*dest_pos++ = *src_pos;
@@ -1129,7 +1130,7 @@
uint64_t src_bit_pos = 0;
size_t dest_byte_pos = 0;
UNSAFE_TODO({
- for (int column = 0; column < m_Width; column++) {
+ for (int column = 0; column < GetWidth(); column++) {
unsigned int R = GetBits8(src_scan.data(), src_bit_pos, m_bpc);
src_bit_pos += m_bpc;
unsigned int G = GetBits8(src_scan.data(), src_bit_pos, m_bpc);
@@ -1155,7 +1156,7 @@
return pdfium::span<const uint8_t>();
const std::optional<uint32_t> src_pitch =
- fxge::CalculatePitch8(m_bpc, m_nComponents, m_Width);
+ fxge::CalculatePitch8(m_bpc, m_nComponents, GetWidth());
if (!src_pitch.has_value())
return pdfium::span<const uint8_t>();
@@ -1204,11 +1205,11 @@
uint32_t set_argb = Get1BitSetValue();
uint32_t* dest_scan = reinterpret_cast<uint32_t*>(m_MaskBuf.data());
UNSAFE_TODO({
- for (int col = 0; col < m_Width; col++, dest_scan++) {
+ for (int col = 0; col < GetWidth(); col++, dest_scan++) {
*dest_scan = GetBitValue(pSrcLine.data(), col) ? set_argb : reset_argb;
}
});
- return pdfium::make_span(m_MaskBuf).first(m_Width * sizeof(uint32_t));
+ return pdfium::make_span(m_MaskBuf).first(GetWidth() * sizeof(uint32_t));
}
if (m_bpc * m_nComponents <= 8) {
pdfium::span<uint8_t> result = m_LineBuf;
@@ -1217,7 +1218,7 @@
result = result.first(src_pitch_value);
} else {
uint64_t src_bit_pos = 0;
- for (int col = 0; col < m_Width; col++) {
+ for (int col = 0; col < GetWidth(); col++) {
unsigned int color_index = 0;
for (uint32_t color = 0; color < m_nComponents; color++) {
unsigned int data = GetBits8(pSrcLine.data(), src_bit_pos, m_bpc);
@@ -1226,7 +1227,7 @@
}
m_LineBuf[col] = color_index;
}
- result = result.first(m_Width);
+ result = result.first(GetWidth());
}
if (!m_bColorKey)
return result;
@@ -1236,7 +1237,7 @@
pdfium::span<const uint32_t> palette = GetPaletteSpan();
UNSAFE_TODO({
if (HasPalette()) {
- for (int col = 0; col < m_Width; col++) {
+ for (int col = 0; col < GetWidth(); col++) {
uint8_t index = *pSrcPixel++;
*pDestPixel++ = FXARGB_B(palette[index]);
*pDestPixel++ = FXARGB_G(palette[index]);
@@ -1245,7 +1246,7 @@
IsColorIndexOutOfBounds(index, m_CompData[0]) ? 0xFF : 0;
}
} else {
- for (int col = 0; col < m_Width; col++) {
+ for (int col = 0; col < GetWidth(); col++) {
uint8_t index = *pSrcPixel++;
*pDestPixel++ = index;
*pDestPixel++ = index;
@@ -1255,13 +1256,13 @@
}
}
});
- return pdfium::make_span(m_MaskBuf).first(4 * m_Width);
+ return pdfium::make_span(m_MaskBuf).first(4 * GetWidth());
}
if (m_bColorKey) {
if (m_nComponents == 3 && m_bpc == 8) {
UNSAFE_TODO({
uint8_t* alpha_channel = m_MaskBuf.data() + 3;
- for (int col = 0; col < m_Width; col++) {
+ for (int col = 0; col < GetWidth(); col++) {
const uint8_t* pPixel = pSrcLine.data() + col * 3;
alpha_channel[col * 4] =
AreColorIndicesOutOfBounds(pPixel, m_CompData.data(), 3) ? 0xFF
@@ -1274,7 +1275,7 @@
}
if (m_pColorSpace) {
TranslateScanline24bpp(m_LineBuf, pSrcLine);
- src_pitch_value = 3 * m_Width;
+ src_pitch_value = 3 * GetWidth();
pSrcLine = pdfium::make_span(m_LineBuf).first(src_pitch_value);
}
if (!m_bColorKey)
@@ -1284,14 +1285,14 @@
const uint8_t* pSrcPixel = pSrcLine.data();
uint8_t* pDestPixel = m_MaskBuf.data();
UNSAFE_TODO({
- for (int col = 0; col < m_Width; col++) {
+ for (int col = 0; col < GetWidth(); col++) {
*pDestPixel++ = *pSrcPixel++;
*pDestPixel++ = *pSrcPixel++;
*pDestPixel++ = *pSrcPixel++;
pDestPixel++;
}
});
- return pdfium::make_span(m_MaskBuf).first(4 * m_Width);
+ return pdfium::make_span(m_MaskBuf).first(4 * GetWidth());
}
bool CPDF_DIB::SkipToScanline(int line, PauseIndicatorIface* pPause) const {
diff --git a/core/fpdfapi/page/cpdf_pageimagecache.cpp b/core/fpdfapi/page/cpdf_pageimagecache.cpp
index 5cf2570..d1ac782 100644
--- a/core/fpdfapi/page/cpdf_pageimagecache.cpp
+++ b/core/fpdfapi/page/cpdf_pageimagecache.cpp
@@ -52,9 +52,9 @@
explicit CachedImage(RetainPtr<CFX_DIBBase> image)
: image_(std::move(image)) {
SetFormat(image_->GetFormat());
- m_Width = image_->GetWidth();
- m_Height = image_->GetHeight();
- m_Pitch = image_->GetPitch();
+ SetWidth(image_->GetWidth());
+ SetHeight(image_->GetHeight());
+ SetPitch(image_->GetPitch());
if (image_->HasPalette()) {
pdfium::span<const uint32_t> palette = image_->GetPaletteSpan();
diff --git a/core/fpdfapi/page/cpdf_transferfuncdib.cpp b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
index d7fdfb4..503e8bf 100644
--- a/core/fpdfapi/page/cpdf_transferfuncdib.cpp
+++ b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
@@ -29,11 +29,11 @@
m_RampR(m_pTransferFunc->GetSamplesR()),
m_RampG(m_pTransferFunc->GetSamplesG()),
m_RampB(m_pTransferFunc->GetSamplesB()) {
- m_Width = m_pSrc->GetWidth();
- m_Height = m_pSrc->GetHeight();
+ SetWidth(m_pSrc->GetWidth());
+ SetHeight(m_pSrc->GetHeight());
SetFormat(GetDestFormat());
- m_Pitch = fxge::CalculatePitch32OrDie(GetBPP(), m_Width);
- m_Scanline.resize(m_Pitch);
+ SetPitch(fxge::CalculatePitch32OrDie(GetBPP(), GetWidth()));
+ m_Scanline.resize(GetPitch());
DCHECK(m_palette.empty());
}
@@ -66,7 +66,7 @@
int b1 = m_RampB[255];
int index = 0;
UNSAFE_TODO({
- for (int i = 0; i < m_Width; i++) {
+ for (int i = 0; i < GetWidth(); i++) {
if (src_buf[i / 8] & (1 << (7 - i % 8))) {
m_Scanline[index++] = b1;
m_Scanline[index++] = g1;
@@ -86,7 +86,7 @@
int m1 = m_RampR[255];
int index = 0;
UNSAFE_TODO({
- for (int i = 0; i < m_Width; i++) {
+ for (int i = 0; i < GetWidth(); i++) {
if (src_buf[i / 8] & (1 << (7 - i % 8))) {
m_Scanline[index++] = m1;
} else {
@@ -100,7 +100,7 @@
pdfium::span<const uint32_t> src_palette = m_pSrc->GetPaletteSpan();
int index = 0;
UNSAFE_TODO({
- for (int i = 0; i < m_Width; i++) {
+ for (int i = 0; i < GetWidth(); i++) {
if (m_pSrc->HasPalette()) {
FX_ARGB src_argb = src_palette[*src_buf];
m_Scanline[index++] = m_RampB[FXARGB_R(src_argb)];
@@ -121,7 +121,7 @@
case FXDIB_Format::k8bppMask: {
int index = 0;
UNSAFE_TODO({
- for (int i = 0; i < m_Width; i++) {
+ for (int i = 0; i < GetWidth(); i++) {
m_Scanline[index++] = m_RampR[*(src_buf++)];
}
});
@@ -130,7 +130,7 @@
case FXDIB_Format::kRgb: {
int index = 0;
UNSAFE_TODO({
- for (int i = 0; i < m_Width; i++) {
+ for (int i = 0; i < GetWidth(); i++) {
m_Scanline[index++] = m_RampB[*(src_buf++)];
m_Scanline[index++] = m_RampG[*(src_buf++)];
m_Scanline[index++] = m_RampR[*(src_buf++)];
@@ -145,7 +145,7 @@
case FXDIB_Format::kArgb: {
int index = 0;
UNSAFE_TODO({
- for (int i = 0; i < m_Width; i++) {
+ for (int i = 0; i < GetWidth(); i++) {
m_Scanline[index++] = m_RampB[*(src_buf++)];
m_Scanline[index++] = m_RampG[*(src_buf++)];
m_Scanline[index++] = m_RampR[*(src_buf++)];
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp
index d35bc90..4df13bf 100644
--- a/core/fxge/dib/cfx_dibbase.cpp
+++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -671,7 +671,7 @@
RetainPtr<CFX_DIBitmap> CFX_DIBBase::ClipToInternal(
const FX_RECT* pClip) const {
- FX_RECT rect(0, 0, m_Width, m_Height);
+ FX_RECT rect(0, 0, GetWidth(), GetHeight());
if (pClip) {
rect.Intersect(*pClip);
if (rect.IsEmpty())
@@ -685,7 +685,7 @@
if (GetBPP() == 1 && rect.left % 8 != 0) {
int left_shift = rect.left % 32;
int right_shift = 32 - left_shift;
- int dword_count = pNewBitmap->m_Pitch / 4;
+ int dword_count = pNewBitmap->GetPitch() / 4;
for (int row = rect.top; row < rect.bottom; ++row) {
auto src_span = GetScanlineAs<const uint32_t>(row);
auto dst_span =
@@ -708,7 +708,7 @@
return nullptr;
}
- copy_len = std::min<uint32_t>(m_Pitch, copy_len.value());
+ copy_len = std::min<uint32_t>(GetPitch(), copy_len.value());
FX_SAFE_UINT32 offset = rect.left;
offset *= GetBPP();
@@ -803,8 +803,9 @@
DCHECK_GT(width, 0);
DCHECK_GT(height, 0);
- if (dest_left > m_Width || dest_top > m_Height)
+ if (dest_left > GetWidth() || dest_top > GetHeight()) {
return false;
+ }
FX_SAFE_INT32 safe_src_width = src_left;
safe_src_width += width;
@@ -854,7 +855,7 @@
FX_RECT dest_rect(safe_dest_left.ValueOrDie(), safe_dest_top.ValueOrDie(),
safe_dest_right.ValueOrDie(),
safe_dest_bottom.ValueOrDie());
- FX_RECT dest_bound(0, 0, m_Width, m_Height);
+ FX_RECT dest_bound(0, 0, GetWidth(), GetHeight());
dest_rect.Intersect(dest_bound);
if (pClipRgn)
@@ -901,14 +902,15 @@
RetainPtr<CFX_DIBitmap> CFX_DIBBase::CloneAlphaMask() const {
DCHECK_EQ(GetFormat(), FXDIB_Format::kArgb);
auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_Format::k8bppMask))
+ if (!pMask->Create(GetWidth(), GetHeight(), FXDIB_Format::k8bppMask)) {
return nullptr;
+ }
- for (int row = 0; row < m_Height; ++row) {
+ for (int row = 0; row < GetHeight(); ++row) {
const uint8_t* src_scan = GetScanline(row).subspan(3).data();
uint8_t* dest_scan = pMask->GetWritableScanline(row).data();
UNSAFE_TODO({
- for (int col = 0; col < m_Width; ++col) {
+ for (int col = 0; col < GetWidth(); ++col) {
*dest_scan++ = *src_scan;
src_scan += 4;
}
@@ -919,48 +921,49 @@
RetainPtr<CFX_DIBitmap> CFX_DIBBase::FlipImage(bool bXFlip, bool bYFlip) const {
auto pFlipped = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pFlipped->Create(m_Width, m_Height, GetFormat()))
+ if (!pFlipped->Create(GetWidth(), GetHeight(), GetFormat())) {
return nullptr;
+ }
pFlipped->SetPalette(GetPaletteSpan());
const int Bpp = GetBPP() / 8;
UNSAFE_TODO({
- for (int row = 0; row < m_Height; ++row) {
+ for (int row = 0; row < GetHeight(); ++row) {
const uint8_t* src_scan = GetScanline(row).data();
uint8_t* dest_scan =
- pFlipped->GetWritableScanline(bYFlip ? m_Height - row - 1 : row)
+ pFlipped->GetWritableScanline(bYFlip ? GetHeight() - row - 1 : row)
.data();
if (!bXFlip) {
- FXSYS_memcpy(dest_scan, src_scan, m_Pitch);
+ FXSYS_memcpy(dest_scan, src_scan, GetPitch());
continue;
}
if (GetBPP() == 1) {
- FXSYS_memset(dest_scan, 0, m_Pitch);
- for (int col = 0; col < m_Width; ++col) {
+ FXSYS_memset(dest_scan, 0, GetPitch());
+ for (int col = 0; col < GetWidth(); ++col) {
if (src_scan[col / 8] & (1 << (7 - col % 8))) {
- int dest_col = m_Width - col - 1;
+ int dest_col = GetWidth() - col - 1;
dest_scan[dest_col / 8] |= (1 << (7 - dest_col % 8));
}
}
continue;
}
- dest_scan += (m_Width - 1) * Bpp;
+ dest_scan += (GetWidth() - 1) * Bpp;
if (Bpp == 1) {
- for (int col = 0; col < m_Width; ++col) {
+ for (int col = 0; col < GetWidth(); ++col) {
*dest_scan = *src_scan;
--dest_scan;
++src_scan;
}
} else if (Bpp == 3) {
- for (int col = 0; col < m_Width; ++col) {
+ for (int col = 0; col < GetWidth(); ++col) {
FXSYS_memcpy(dest_scan, src_scan, 3);
dest_scan -= 3;
src_scan += 3;
}
} else {
DCHECK_EQ(Bpp, 4);
- for (int col = 0; col < m_Width; ++col) {
+ for (int col = 0; col < GetWidth(); ++col) {
const auto* src_scan32 = reinterpret_cast<const uint32_t*>(src_scan);
uint32_t* dest_scan32 = reinterpret_cast<uint32_t*>(dest_scan);
*dest_scan32 = *src_scan32;
@@ -978,8 +981,9 @@
return Realize();
auto pClone = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pClone->Create(m_Width, m_Height, dest_format))
+ if (!pClone->Create(GetWidth(), GetHeight(), dest_format)) {
return nullptr;
+ }
if (dest_format == FXDIB_Format::kArgb) {
pClone->SetUniformOpaqueAlpha();
@@ -988,7 +992,7 @@
RetainPtr<const CFX_DIBBase> holder(this);
DataVector<uint32_t> pal_8bpp =
ConvertBuffer(dest_format, pClone->GetWritableBuffer(),
- pClone->GetPitch(), m_Width, m_Height, holder, 0, 0);
+ pClone->GetPitch(), GetWidth(), GetHeight(), holder, 0, 0);
if (!pal_8bpp.empty()) {
pClone->TakePalette(std::move(pal_8bpp));
}
@@ -996,7 +1000,7 @@
}
RetainPtr<CFX_DIBitmap> CFX_DIBBase::SwapXY(bool bXFlip, bool bYFlip) const {
- FX_RECT dest_clip(0, 0, m_Height, m_Width);
+ FX_RECT dest_clip(0, 0, GetHeight(), GetWidth());
if (dest_clip.IsEmpty())
return nullptr;
@@ -1012,10 +1016,10 @@
Fx2DSizeOrDie(dest_pitch, result_height));
const size_t dest_last_row_offset =
Fx2DSizeOrDie(dest_pitch, result_height - 1);
- const int row_start = bXFlip ? m_Height - dest_clip.right : dest_clip.left;
- const int row_end = bXFlip ? m_Height - dest_clip.left : dest_clip.right;
- const int col_start = bYFlip ? m_Width - dest_clip.bottom : dest_clip.top;
- const int col_end = bYFlip ? m_Width - dest_clip.top : dest_clip.bottom;
+ const int row_start = bXFlip ? GetHeight() - dest_clip.right : dest_clip.left;
+ const int row_end = bXFlip ? GetHeight() - dest_clip.left : dest_clip.right;
+ const int col_start = bYFlip ? GetWidth() - dest_clip.bottom : dest_clip.top;
+ const int col_end = bYFlip ? GetWidth() - dest_clip.top : dest_clip.bottom;
UNSAFE_TODO({
if (GetBPP() == 1) {
fxcrt::Fill(dest_span, 0xff);
@@ -1106,8 +1110,9 @@
if (clip_rect.IsEmpty())
return nullptr;
- if (dest_width == m_Width && dest_height == m_Height)
+ if (dest_width == GetWidth() && dest_height == GetHeight()) {
return ClipTo(clip_rect);
+ }
CFX_BitmapStorer storer;
CFX_ImageStretcher stretcher(&storer, holder, dest_width, dest_height,
diff --git a/core/fxge/dib/cfx_dibbase.h b/core/fxge/dib/cfx_dibbase.h
index 7c8eb75..1eb780b 100644
--- a/core/fxge/dib/cfx_dibbase.h
+++ b/core/fxge/dib/cfx_dibbase.h
@@ -134,14 +134,17 @@
int FindPalette(uint32_t color) const;
void SetFormat(FXDIB_Format format) { m_Format = format; }
+ void SetWidth(int width) { m_Width = width; }
+ void SetHeight(int height) { m_Height = height; }
+ void SetPitch(uint32_t pitch) { m_Pitch = pitch; }
- int m_Width = 0;
- int m_Height = 0;
- uint32_t m_Pitch = 0;
DataVector<uint32_t> m_palette;
private:
FXDIB_Format m_Format = FXDIB_Format::kInvalid;
+ int m_Width = 0;
+ int m_Height = 0;
+ uint32_t m_Pitch = 0;
};
#endif // CORE_FXGE_DIB_CFX_DIBBASE_H_
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index 22ff631..ae81e14 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -41,9 +41,9 @@
uint32_t pitch) {
m_pBuffer = nullptr;
SetFormat(format);
- m_Width = 0;
- m_Height = 0;
- m_Pitch = 0;
+ SetWidth(0);
+ SetHeight(0);
+ SetPitch(0);
std::optional<PitchAndSize> pitch_size =
CalculatePitchAndSize(width, height, format, pitch);
@@ -63,9 +63,9 @@
if (!m_pBuffer)
return false;
}
- m_Width = width;
- m_Height = height;
- m_Pitch = pitch_size.value().pitch;
+ SetWidth(width);
+ SetHeight(height);
+ SetPitch(pitch_size.value().pitch);
return true;
}
@@ -79,8 +79,8 @@
SetPalette(source->GetPaletteSpan());
for (int row = 0; row < source->GetHeight(); row++) {
- UNSAFE_TODO(FXSYS_memcpy(m_pBuffer.Get() + row * m_Pitch,
- source->GetScanline(row).data(), m_Pitch));
+ UNSAFE_TODO(FXSYS_memcpy(m_pBuffer.Get() + row * GetPitch(),
+ source->GetScanline(row).data(), GetPitch()));
}
return true;
}
@@ -91,7 +91,8 @@
if (!m_pBuffer)
return pdfium::span<const uint8_t>();
- return UNSAFE_TODO(pdfium::make_span(m_pBuffer.Get(), m_Height * m_Pitch));
+ return UNSAFE_TODO(
+ pdfium::make_span(m_pBuffer.Get(), GetHeight() * GetPitch()));
}
pdfium::span<const uint8_t> CFX_DIBitmap::GetScanline(int line) const {
@@ -99,7 +100,7 @@
if (buffer_span.empty())
return pdfium::span<const uint8_t>();
- return buffer_span.subspan(line * m_Pitch, m_Pitch);
+ return buffer_span.subspan(line * GetPitch(), GetPitch());
}
size_t CFX_DIBitmap::GetEstimatedImageMemoryBurden() const {
@@ -126,9 +127,9 @@
m_palette = std::move(pSrcBitmap->m_palette);
pSrcBitmap->m_pBuffer = nullptr;
SetFormat(pSrcBitmap->GetFormat());
- m_Width = pSrcBitmap->m_Width;
- m_Height = pSrcBitmap->m_Height;
- m_Pitch = pSrcBitmap->m_Pitch;
+ SetWidth(pSrcBitmap->GetWidth());
+ SetHeight(pSrcBitmap->GetHeight());
+ SetPitch(pSrcBitmap->GetPitch());
}
void CFX_DIBitmap::Clear(uint32_t color) {
@@ -157,7 +158,7 @@
if (bgr.red == bgr.green && bgr.green == bgr.blue) {
fxcrt::Fill(buffer, bgr.red);
} else {
- for (int row = 0; row < m_Height; row++) {
+ for (int row = 0; row < GetHeight(); row++) {
fxcrt::Fill(GetWritableScanlineAs<FX_BGR_STRUCT<uint8_t>>(row), bgr);
}
}
@@ -171,7 +172,7 @@
}
[[fallthrough]];
case FXDIB_Format::kArgb:
- for (int row = 0; row < m_Height; row++) {
+ for (int row = 0; row < GetHeight(); row++) {
fxcrt::Fill(GetWritableScanlineAs<uint32_t>(row), color);
}
break;
@@ -235,9 +236,10 @@
return false;
pdfium::span<uint8_t> dest_buf = GetWritableBuffer().subspan(
- dest_top * m_Pitch + static_cast<uint32_t>(offset.ValueOrDie()));
- DataVector<uint32_t> dest_palette = ConvertBuffer(
- dest_format, dest_buf, m_Pitch, width, height, source, src_left, src_top);
+ dest_top * GetPitch() + static_cast<uint32_t>(offset.ValueOrDie()));
+ DataVector<uint32_t> dest_palette =
+ ConvertBuffer(dest_format, dest_buf, GetPitch(), width, height, source,
+ src_left, src_top);
CHECK(dest_palette.empty());
return true;
}
@@ -253,7 +255,7 @@
UNSAFE_TODO({
for (int row = 0; row < height; ++row) {
uint8_t* dest_scan =
- m_pBuffer.Get() + (dest_top + row) * m_Pitch + dest_left * Bpp;
+ m_pBuffer.Get() + (dest_top + row) * GetPitch() + dest_left * Bpp;
const uint8_t* src_scan =
source->GetScanline(src_top + row).subspan(src_left * Bpp).data();
FXSYS_memcpy(dest_scan, src_scan, width * Bpp);
@@ -271,7 +273,7 @@
int src_top) {
UNSAFE_TODO({
for (int row = 0; row < height; ++row) {
- uint8_t* dest_scan = m_pBuffer.Get() + (dest_top + row) * m_Pitch;
+ uint8_t* dest_scan = m_pBuffer.Get() + (dest_top + row) * GetPitch();
const uint8_t* src_scan = source->GetScanline(src_top + row).data();
for (int col = 0; col < width; ++col) {
int src_idx = src_left + col;
@@ -290,9 +292,9 @@
CHECK_EQ(FXDIB_Format::kArgb, GetFormat());
CHECK(m_pBuffer);
- for (int row = 0; row < m_Height; row++) {
+ for (int row = 0; row < GetHeight(); row++) {
auto scanline =
- GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(m_Width);
+ GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(GetWidth());
for (auto& pixel : scanline) {
pixel.red = pixel.alpha;
}
@@ -303,9 +305,9 @@
CHECK_EQ(FXDIB_Format::kArgb, GetFormat());
CHECK(m_pBuffer);
- for (int row = 0; row < m_Height; row++) {
+ for (int row = 0; row < GetHeight(); row++) {
auto scanline =
- GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(m_Width);
+ GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(GetWidth());
for (auto& pixel : scanline) {
pixel.alpha = 0xff;
}
@@ -313,8 +315,8 @@
}
bool CFX_DIBitmap::MultiplyAlphaMask(RetainPtr<const CFX_DIBitmap> mask) {
- CHECK_EQ(m_Width, mask->GetWidth());
- CHECK_EQ(m_Height, mask->GetHeight());
+ CHECK_EQ(GetWidth(), mask->GetWidth());
+ CHECK_EQ(GetHeight(), mask->GetHeight());
CHECK_EQ(FXDIB_Format::k8bppMask, mask->GetFormat());
CHECK(m_pBuffer);
@@ -323,11 +325,11 @@
return false;
}
- for (int row = 0; row < m_Height; row++) {
+ for (int row = 0; row < GetHeight(); row++) {
auto dest_scan =
- GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(m_Width);
- auto mask_scan = mask->GetScanline(row).first(m_Width);
- for (int col = 0; col < m_Width; col++) {
+ GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(GetWidth());
+ auto mask_scan = mask->GetScanline(row).first(GetWidth());
+ for (int col = 0; col < GetWidth(); col++) {
// Since the `dest_scan` value always starts out as 255 in this case,
// simplify 255 * x / 255.
dest_scan[col].alpha = mask_scan[col];
@@ -337,11 +339,11 @@
}
CHECK_EQ(GetFormat(), FXDIB_Format::kArgb);
- for (int row = 0; row < m_Height; row++) {
+ for (int row = 0; row < GetHeight(); row++) {
auto dest_scan =
- GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(m_Width);
- auto mask_scan = mask->GetScanline(row).first(m_Width);
- for (int col = 0; col < m_Width; col++) {
+ GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(GetWidth());
+ auto mask_scan = mask->GetScanline(row).first(GetWidth());
+ for (int col = 0; col < GetWidth(); col++) {
dest_scan[col].alpha = dest_scan[col].alpha * mask_scan[col] / 255;
}
}
@@ -366,9 +368,9 @@
}
const int bitmap_alpha = static_cast<int>(alpha * 255.0f);
- for (int row = 0; row < m_Height; row++) {
+ for (int row = 0; row < GetHeight(); row++) {
auto dest_scan =
- GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(m_Width);
+ GetWritableScanlineAs<FX_BGRA_STRUCT<uint8_t>>(row).first(GetWidth());
for (auto& pixel : dest_scan) {
pixel.alpha = pixel.alpha * bitmap_alpha / 255;
}
@@ -388,7 +390,7 @@
return 0;
uint8_t* pos =
- UNSAFE_TODO(m_pBuffer.Get() + y * m_Pitch + offset.ValueOrDie());
+ UNSAFE_TODO(m_pBuffer.Get() + y * GetPitch() + offset.ValueOrDie());
switch (GetFormat()) {
case FXDIB_Format::kInvalid:
return 0;
@@ -443,10 +445,10 @@
}
UNSAFE_TODO({
if (forecolor == 0 && backcolor == 0xffffff) {
- for (int row = 0; row < m_Height; ++row) {
- uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch;
+ for (int row = 0; row < GetHeight(); ++row) {
+ uint8_t* scanline = m_pBuffer.Get() + row * GetPitch();
int gap = GetBPP() / 8 - 2;
- for (int col = 0; col < m_Width; ++col) {
+ for (int col = 0; col < GetWidth(); ++col) {
int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
*scanline++ = gray;
*scanline++ = gray;
@@ -456,10 +458,10 @@
}
return;
}
- for (int row = 0; row < m_Height; ++row) {
- uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch;
+ for (int row = 0; row < GetHeight(); ++row) {
+ uint8_t* scanline = m_pBuffer.Get() + row * GetPitch();
int gap = GetBPP() / 8 - 2;
- for (int col = 0; col < m_Width; ++col) {
+ for (int col = 0; col < GetWidth(); ++col) {
int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
*scanline++ = bb + (fb - bb) * gray / 255;
*scanline++ = bg + (fg - bg) * gray / 255;
@@ -655,7 +657,7 @@
}
UNSAFE_TODO({
for (int row = 0; row < height; ++row) {
- uint8_t* dest_scan = m_pBuffer.Get() + (dest_top + row) * m_Pitch;
+ uint8_t* dest_scan = m_pBuffer.Get() + (dest_top + row) * GetPitch();
const uint8_t* src_scan = source->GetScanline(src_top + row).data();
for (int col = 0; col < width; ++col) {
int src_idx = src_left + col;
@@ -681,7 +683,7 @@
return true;
FX_RECT rect(left, top, left + width, top + height);
- rect.Intersect(0, 0, m_Width, m_Height);
+ rect.Intersect(0, 0, GetWidth(), GetHeight());
if (rect.IsEmpty())
return true;
@@ -695,7 +697,7 @@
? 255
: (uint8_t)FXRGB2GRAY((int)color_p[2], color_p[1], color_p[0]);
for (int row = rect.top; row < rect.bottom; row++) {
- uint8_t* dest_scan = m_pBuffer.Get() + row * m_Pitch + rect.left;
+ uint8_t* dest_scan = m_pBuffer.Get() + row * GetPitch() + rect.left;
if (src_alpha == 255) {
FXSYS_memset(dest_scan, gray, width);
} else {
@@ -758,7 +760,8 @@
}
if (src_alpha == 255) {
for (int row = rect.top; row < rect.bottom; row++) {
- uint8_t* dest_scan = m_pBuffer.Get() + row * m_Pitch + rect.left * Bpp;
+ uint8_t* dest_scan =
+ m_pBuffer.Get() + row * GetPitch() + rect.left * Bpp;
if (Bpp == 4) {
uint32_t* scan = reinterpret_cast<uint32_t*>(dest_scan);
for (int col = 0; col < width; col++) {
@@ -775,7 +778,7 @@
return true;
}
for (int row = rect.top; row < rect.bottom; row++) {
- uint8_t* dest_scan = m_pBuffer.Get() + row * m_Pitch + rect.left * Bpp;
+ uint8_t* dest_scan = m_pBuffer.Get() + row * GetPitch() + rect.left * Bpp;
if (bAlpha) {
for (int col = 0; col < width; col++) {
uint8_t back_alpha = dest_scan[3];
@@ -833,9 +836,9 @@
GetFormat() == FXDIB_Format::kRgb32) {
SetFormat(FXDIB_Format::kArgb);
UNSAFE_TODO({
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch + 3;
- for (int col = 0; col < m_Width; col++) {
+ for (int row = 0; row < GetHeight(); row++) {
+ uint8_t* scanline = m_pBuffer.Get() + row * GetPitch() + 3;
+ for (int col = 0; col < GetWidth(); col++) {
*scanline = 0xff;
scanline += 4;
}
@@ -844,8 +847,8 @@
return true;
}
int dest_bpp = GetBppFromFormat(dest_format);
- int dest_pitch = fxge::CalculatePitch32OrDie(dest_bpp, m_Width);
- const size_t dest_buf_size = dest_pitch * m_Height + 4;
+ int dest_pitch = fxge::CalculatePitch32OrDie(dest_bpp, GetWidth());
+ const size_t dest_buf_size = dest_pitch * GetHeight() + 4;
std::unique_ptr<uint8_t, FxFreeDeleter> dest_buf(
FX_TryAlloc(uint8_t, dest_buf_size));
if (!dest_buf)
@@ -859,9 +862,10 @@
m_palette = ConvertBuffer(
dest_format,
UNSAFE_BUFFERS(pdfium::make_span(dest_buf.get(), dest_buf_size)),
- dest_pitch, m_Width, m_Height, holder, /*src_left=*/0, /*src_top=*/0);
+ dest_pitch, GetWidth(), GetHeight(), holder, /*src_left=*/0,
+ /*src_top=*/0);
m_pBuffer = std::move(dest_buf);
SetFormat(dest_format);
- m_Pitch = dest_pitch;
+ SetPitch(dest_pitch);
return true;
}