Make `CFX_DIBBase::m_Format` private
Add a protected setter. Then change all users to switch to the getter or
the setter.
Change-Id: Ic3f40b01fc362213f494ccd847ae16bc5690c769
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/121555
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: dan sinclair <dsinclair@google.com>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index b2f7e73..05fd50c 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -271,7 +271,7 @@
if (!m_bpc || !m_nComponents)
return false;
- m_Format = MakeRGBFormat(CalculateBitsPerPixel(m_bpc, m_nComponents));
+ SetFormat(MakeRGBFormat(CalculateBitsPerPixel(m_bpc, m_nComponents)));
}
std::optional<uint32_t> pitch = fxge::CalculatePitch32(GetBPP(), m_Width);
@@ -281,7 +281,7 @@
m_LineBuf = DataVector<uint8_t>(pitch.value());
LoadPalette();
if (m_bColorKey) {
- m_Format = FXDIB_Format::kArgb;
+ SetFormat(FXDIB_Format::kArgb);
pitch = fxge::CalculatePitch32(GetBPP(), m_Width);
if (!pitch.has_value())
return false;
@@ -1310,7 +1310,7 @@
void CPDF_DIB::SetMaskProperties() {
m_bpc = 1;
m_nComponents = 1;
- m_Format = FXDIB_Format::k1bppMask;
+ SetFormat(FXDIB_Format::k1bppMask);
}
uint32_t CPDF_DIB::Get1BitSetValue() const {
diff --git a/core/fpdfapi/page/cpdf_pageimagecache.cpp b/core/fpdfapi/page/cpdf_pageimagecache.cpp
index c47b4b5..5cf2570 100644
--- a/core/fpdfapi/page/cpdf_pageimagecache.cpp
+++ b/core/fpdfapi/page/cpdf_pageimagecache.cpp
@@ -51,7 +51,7 @@
public:
explicit CachedImage(RetainPtr<CFX_DIBBase> image)
: image_(std::move(image)) {
- m_Format = image_->GetFormat();
+ SetFormat(image_->GetFormat());
m_Width = image_->GetWidth();
m_Height = image_->GetHeight();
m_Pitch = image_->GetPitch();
diff --git a/core/fpdfapi/page/cpdf_transferfuncdib.cpp b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
index 6c396b3..d7fdfb4 100644
--- a/core/fpdfapi/page/cpdf_transferfuncdib.cpp
+++ b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
@@ -31,7 +31,7 @@
m_RampB(m_pTransferFunc->GetSamplesB()) {
m_Width = m_pSrc->GetWidth();
m_Height = m_pSrc->GetHeight();
- m_Format = GetDestFormat();
+ SetFormat(GetDestFormat());
m_Pitch = fxge::CalculatePitch32OrDie(GetBPP(), m_Width);
m_Scanline.resize(m_Pitch);
DCHECK(m_palette.empty());
diff --git a/core/fxge/dib/cfx_dibbase.h b/core/fxge/dib/cfx_dibbase.h
index 5a3b7c1..7c8eb75 100644
--- a/core/fxge/dib/cfx_dibbase.h
+++ b/core/fxge/dib/cfx_dibbase.h
@@ -61,9 +61,9 @@
uint32_t GetPitch() const { return m_Pitch; }
FXDIB_Format GetFormat() const { return m_Format; }
- int GetBPP() const { return GetBppFromFormat(m_Format); }
- bool IsMaskFormat() const { return GetIsMaskFromFormat(m_Format); }
- bool IsAlphaFormat() const { return m_Format == FXDIB_Format::kArgb; }
+ int GetBPP() const { return GetBppFromFormat(GetFormat()); }
+ bool IsMaskFormat() const { return GetIsMaskFromFormat(GetFormat()); }
+ bool IsAlphaFormat() const { return GetFormat() == FXDIB_Format::kArgb; }
bool IsOpaqueImage() const { return !IsMaskFormat() && !IsAlphaFormat(); }
bool HasPalette() const { return !m_palette.empty(); }
@@ -133,11 +133,15 @@
void BuildPalette();
int FindPalette(uint32_t color) const;
- FXDIB_Format m_Format = FXDIB_Format::kInvalid;
+ void SetFormat(FXDIB_Format format) { m_Format = format; }
+
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;
};
#endif // CORE_FXGE_DIB_CFX_DIBBASE_H_
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index 2d8f5e4..22ff631 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -40,7 +40,7 @@
uint8_t* pBuffer,
uint32_t pitch) {
m_pBuffer = nullptr;
- m_Format = format;
+ SetFormat(format);
m_Width = 0;
m_Height = 0;
m_Pitch = 0;
@@ -125,7 +125,7 @@
m_pBuffer = std::move(pSrcBitmap->m_pBuffer);
m_palette = std::move(pSrcBitmap->m_palette);
pSrcBitmap->m_pBuffer = nullptr;
- m_Format = pSrcBitmap->m_Format;
+ SetFormat(pSrcBitmap->GetFormat());
m_Width = pSrcBitmap->m_Width;
m_Height = pSrcBitmap->m_Height;
m_Pitch = pSrcBitmap->m_Pitch;
@@ -820,16 +820,18 @@
dest_format == FXDIB_Format::kRgb32 ||
dest_format == FXDIB_Format::kRgb);
- if (dest_format == m_Format)
- return true;
-
- if (dest_format == FXDIB_Format::k8bppMask &&
- m_Format == FXDIB_Format::k8bppRgb && !HasPalette()) {
- m_Format = FXDIB_Format::k8bppMask;
+ if (dest_format == GetFormat()) {
return true;
}
- if (dest_format == FXDIB_Format::kArgb && m_Format == FXDIB_Format::kRgb32) {
- m_Format = FXDIB_Format::kArgb;
+
+ if (dest_format == FXDIB_Format::k8bppMask &&
+ GetFormat() == FXDIB_Format::k8bppRgb && !HasPalette()) {
+ SetFormat(FXDIB_Format::k8bppMask);
+ return true;
+ }
+ if (dest_format == FXDIB_Format::kArgb &&
+ 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;
@@ -859,7 +861,7 @@
UNSAFE_BUFFERS(pdfium::make_span(dest_buf.get(), dest_buf_size)),
dest_pitch, m_Width, m_Height, holder, /*src_left=*/0, /*src_top=*/0);
m_pBuffer = std::move(dest_buf);
- m_Format = dest_format;
+ SetFormat(dest_format);
m_Pitch = dest_pitch;
return true;
}