Remove most GetBppFromFormat() calls from CFX_DIBBase and subclasses

Call CFX_DIBBase::GetBPP() instead, as it does the same thing as
GetBppFromFormat(m_Format), but is much shorter.

Change-Id: Ia3f19525c73d37bd78a6ec2bd21cec6b4b3f7451
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/121554
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 b46cac6..b2f7e73 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -274,8 +274,7 @@
     m_Format = MakeRGBFormat(CalculateBitsPerPixel(m_bpc, m_nComponents));
   }
 
-  std::optional<uint32_t> pitch =
-      fxge::CalculatePitch32(GetBppFromFormat(m_Format), m_Width);
+  std::optional<uint32_t> pitch = fxge::CalculatePitch32(GetBPP(), m_Width);
   if (!pitch.has_value())
     return false;
 
@@ -283,7 +282,7 @@
   LoadPalette();
   if (m_bColorKey) {
     m_Format = FXDIB_Format::kArgb;
-    pitch = fxge::CalculatePitch32(GetBppFromFormat(m_Format), m_Width);
+    pitch = fxge::CalculatePitch32(GetBPP(), m_Width);
     if (!pitch.has_value())
       return false;
     m_MaskBuf = DataVector<uint8_t>(pitch.value());
diff --git a/core/fpdfapi/page/cpdf_transferfuncdib.cpp b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
index 7e53a10..6c396b3 100644
--- a/core/fpdfapi/page/cpdf_transferfuncdib.cpp
+++ b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
@@ -32,7 +32,7 @@
   m_Width = m_pSrc->GetWidth();
   m_Height = m_pSrc->GetHeight();
   m_Format = GetDestFormat();
-  m_Pitch = fxge::CalculatePitch32OrDie(GetBppFromFormat(m_Format), m_Width);
+  m_Pitch = fxge::CalculatePitch32OrDie(GetBPP(), m_Width);
   m_Scanline.resize(m_Pitch);
   DCHECK(m_palette.empty());
 }
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp
index 7bd6c2d..d35bc90 100644
--- a/core/fxge/dib/cfx_dibbase.cpp
+++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -711,7 +711,7 @@
     copy_len = std::min<uint32_t>(m_Pitch, copy_len.value());
 
     FX_SAFE_UINT32 offset = rect.left;
-    offset *= GetBppFromFormat(m_Format);
+    offset *= GetBPP();
     offset /= 8;
     if (!offset.IsValid())
       return nullptr;
@@ -744,7 +744,7 @@
   if (IsMaskFormat())
     return 0;
 
-  switch (GetBppFromFormat(m_Format)) {
+  switch (GetBPP()) {
     case 1:
       return 2;
     case 8:
@@ -923,7 +923,7 @@
     return nullptr;
 
   pFlipped->SetPalette(GetPaletteSpan());
-  int Bpp = GetBppFromFormat(m_Format) / 8;
+  const int Bpp = GetBPP() / 8;
   UNSAFE_TODO({
     for (int row = 0; row < m_Height; ++row) {
       const uint8_t* src_scan = GetScanline(row).data();
@@ -934,7 +934,7 @@
         FXSYS_memcpy(dest_scan, src_scan, m_Pitch);
         continue;
       }
-      if (GetBppFromFormat(m_Format) == 1) {
+      if (GetBPP() == 1) {
         FXSYS_memset(dest_scan, 0, m_Pitch);
         for (int col = 0; col < m_Width; ++col) {
           if (src_scan[col / 8] & (1 << (7 - col % 8))) {
@@ -1128,8 +1128,7 @@
     const RetainPtr<const CFX_DIBBase>& pSrcBitmap,
     int src_left,
     int src_top) {
-  FXDIB_Format src_format = pSrcBitmap->GetFormat();
-  const int src_bpp = GetBppFromFormat(src_format);
+  const int src_bpp = pSrcBitmap->GetBPP();
   switch (dest_format) {
     case FXDIB_Format::kInvalid:
     case FXDIB_Format::k1bppRgb:
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index 563bb36..2d8f5e4 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -224,8 +224,9 @@
   if (HasPalette())
     return false;
 
-  if (GetBppFromFormat(m_Format) == 8)
+  if (GetBPP() == 8) {
     dest_format = FXDIB_Format::k8bppMask;
+  }
 
   FX_SAFE_UINT32 offset = dest_left;
   offset *= GetBPP();
@@ -425,12 +426,12 @@
   int br = FXSYS_GetRValue(backcolor);
   int bg = FXSYS_GetGValue(backcolor);
   int bb = FXSYS_GetBValue(backcolor);
-  if (GetBppFromFormat(m_Format) <= 8) {
+  if (GetBPP() <= 8) {
     if (forecolor == 0 && backcolor == 0xffffff && !HasPalette())
       return;
 
     BuildPalette();
-    int size = 1 << GetBppFromFormat(m_Format);
+    int size = 1 << GetBPP();
     for (int i = 0; i < size; ++i) {
       int gray = FXRGB2GRAY(FXARGB_R(m_palette[i]), FXARGB_G(m_palette[i]),
                             FXARGB_B(m_palette[i]));
@@ -444,7 +445,7 @@
     if (forecolor == 0 && backcolor == 0xffffff) {
       for (int row = 0; row < m_Height; ++row) {
         uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch;
-        int gap = GetBppFromFormat(m_Format) / 8 - 2;
+        int gap = GetBPP() / 8 - 2;
         for (int col = 0; col < m_Width; ++col) {
           int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
           *scanline++ = gray;
@@ -457,7 +458,7 @@
     }
     for (int row = 0; row < m_Height; ++row) {
       uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch;
-      int gap = GetBppFromFormat(m_Format) / 8 - 2;
+      int gap = GetBPP() / 8 - 2;
       for (int col = 0; col < m_Width; ++col) {
         int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
         *scanline++ = bb + (fb - bb) * gray / 255;
@@ -527,8 +528,9 @@
   if (!m_pBuffer)
     return false;
 
-  if (GetBppFromFormat(m_Format) < 8)
+  if (GetBPP() < 8) {
     return false;
+  }
 
   if (!GetOverlapRect(dest_left, dest_top, width, height, source->GetWidth(),
                       source->GetHeight(), src_left, src_top, pClipRgn)) {
@@ -547,7 +549,7 @@
                        pClipMask != nullptr, bRgbByteOrder)) {
     return false;
   }
-  const int dest_Bpp = GetBppFromFormat(m_Format) / 8;
+  const int dest_Bpp = GetBPP() / 8;
   const int src_Bpp = source->GetBPP() / 8;
   const bool bRgb = src_Bpp > 1;
   if (!bRgb && !source->HasPalette()) {
@@ -591,8 +593,9 @@
   if (!m_pBuffer)
     return false;
 
-  if (GetBppFromFormat(m_Format) < 8)
+  if (GetBPP() < 8) {
     return false;
+  }
 
   if (!GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(),
                       pMask->GetHeight(), src_left, src_top, pClipRgn)) {
@@ -686,7 +689,7 @@
   uint32_t dst_color = color;
   uint8_t* color_p = reinterpret_cast<uint8_t*>(&dst_color);
   UNSAFE_TODO({
-    if (GetBppFromFormat(m_Format) == 8) {
+    if (GetBPP() == 8) {
       uint8_t gray =
           IsMaskFormat()
               ? 255
@@ -704,7 +707,7 @@
       }
       return true;
     }
-    if (GetBppFromFormat(m_Format) == 1) {
+    if (GetBPP() == 1) {
       int left_shift = rect.left % 8;
       int right_shift = rect.right % 8;
       int new_width = rect.right / 8 - rect.left / 8;
@@ -745,9 +748,9 @@
       return true;
     }
 
-    CHECK_GE(GetBppFromFormat(m_Format), 24);
+    CHECK_GE(GetBPP(), 24);
     color_p[3] = static_cast<uint8_t>(src_alpha);
-    int Bpp = GetBppFromFormat(m_Format) / 8;
+    int Bpp = GetBPP() / 8;
     const bool bAlpha = IsAlphaFormat();
     if (bAlpha) {
       // Other formats with alpha have already been handled above.