Move some repeated code in CPDF_DIB into helper methods.

Add Get1BitSetValue() and Get1BitResetValue().

Change-Id: Ic884fcb02112714874d7c7bf1cbef1e71b3f2da9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75233
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index bc421c6..65c7eeb 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -1091,12 +1091,8 @@
       return m_pLineBuf.get();
     }
 
-    uint32_t reset_argb = HasPalette() ? GetPaletteData()[0] : 0xFF000000;
-    uint32_t set_argb = HasPalette() ? GetPaletteData()[1] : 0xFFFFFFFF;
-    if (m_CompData[0].m_ColorKeyMin == 0)
-      reset_argb = 0;
-    if (m_CompData[0].m_ColorKeyMax == 1)
-      set_argb = 0;
+    uint32_t reset_argb = Get1BitResetValue();
+    uint32_t set_argb = Get1BitSetValue();
     uint32_t* dest_scan = reinterpret_cast<uint32_t*>(m_pMaskedLine.get());
     for (int col = 0; col < m_Width; col++) {
       *dest_scan = GetBitValue(pSrcLine, col) ? set_argb : reset_argb;
@@ -1244,12 +1240,8 @@
                                       int clip_left,
                                       int clip_width) const {
   if (m_bColorKey && !m_bImageMask) {
-    uint32_t reset_argb = HasPalette() ? GetPaletteData()[0] : 0xFF000000;
-    uint32_t set_argb = HasPalette() ? GetPaletteData()[1] : 0xFFFFFFFF;
-    if (m_CompData[0].m_ColorKeyMin == 0)
-      reset_argb = 0;
-    if (m_CompData[0].m_ColorKeyMax == 1)
-      set_argb = 0;
+    uint32_t reset_argb = Get1BitResetValue();
+    uint32_t set_argb = Get1BitSetValue();
     uint32_t* dest_scan_dword = reinterpret_cast<uint32_t*>(dest_scan);
     for (int i = 0; i < clip_width; i++) {
       uint32_t src_x = (clip_left + i) * src_width / dest_width;
@@ -1465,3 +1457,15 @@
   m_nComponents = 1;
   m_AlphaFlag = 1;
 }
+
+uint32_t CPDF_DIB::Get1BitSetValue() const {
+  if (m_CompData[0].m_ColorKeyMax == 1)
+    return 0x00000000;
+  return HasPalette() ? GetPaletteData()[1] : 0xFFFFFFFF;
+}
+
+uint32_t CPDF_DIB::Get1BitResetValue() const {
+  if (m_CompData[0].m_ColorKeyMin == 0)
+    return 0x00000000;
+  return HasPalette() ? GetPaletteData()[0] : 0xFF000000;
+}
diff --git a/core/fpdfapi/page/cpdf_dib.h b/core/fpdfapi/page/cpdf_dib.h
index 94db0e7..4d9f91d 100644
--- a/core/fpdfapi/page/cpdf_dib.h
+++ b/core/fpdfapi/page/cpdf_dib.h
@@ -132,6 +132,9 @@
   bool TransMask() const;
   void SetMaskProperties();
 
+  uint32_t Get1BitSetValue() const;
+  uint32_t Get1BitResetValue() const;
+
   UnownedPtr<CPDF_Document> m_pDocument;
   RetainPtr<const CPDF_Stream> m_pStream;
   RetainPtr<const CPDF_Dictionary> m_pDict;