Split CFX_DIBBase::GetPalette() into HasPalette() and GetPaletteData().

Change existing calls, and many direct users of `m_pPalette`, to use
these methods(). GetPaletteData() is just GetPalette() renamed.

Change-Id: Idb10f2eca337d55e6592a63fd9ca5ada68c2c1e7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75232
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 b744004..bc421c6 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -1091,8 +1091,8 @@
       return m_pLineBuf.get();
     }
 
-    uint32_t reset_argb = m_pPalette ? m_pPalette.get()[0] : 0xFF000000;
-    uint32_t set_argb = m_pPalette ? m_pPalette.get()[1] : 0xFFFFFFFF;
+    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)
@@ -1126,10 +1126,10 @@
     const uint8_t* pSrcPixel = m_pLineBuf.get();
     for (int col = 0; col < m_Width; col++) {
       uint8_t index = *pSrcPixel++;
-      if (m_pPalette) {
-        *pDestPixel++ = FXARGB_B(m_pPalette.get()[index]);
-        *pDestPixel++ = FXARGB_G(m_pPalette.get()[index]);
-        *pDestPixel++ = FXARGB_R(m_pPalette.get()[index]);
+      if (HasPalette()) {
+        *pDestPixel++ = FXARGB_B(GetPaletteData()[index]);
+        *pDestPixel++ = FXARGB_G(GetPaletteData()[index]);
+        *pDestPixel++ = FXARGB_R(GetPaletteData()[index]);
       } else {
         *pDestPixel++ = index;
         *pDestPixel++ = index;
@@ -1244,8 +1244,8 @@
                                       int clip_left,
                                       int clip_width) const {
   if (m_bColorKey && !m_bImageMask) {
-    uint32_t reset_argb = m_pPalette ? m_pPalette.get()[0] : 0xFF000000;
-    uint32_t set_argb = m_pPalette ? m_pPalette.get()[1] : 0xFFFFFFFF;
+    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)
@@ -1268,9 +1268,9 @@
       set_argb = 0;
       reset_argb = 0xFFFFFFFF;
     }
-  } else if (m_pPalette && dest_Bpp != 1) {
-    reset_argb = m_pPalette.get()[0];
-    set_argb = m_pPalette.get()[1];
+  } else if (HasPalette() && dest_Bpp != 1) {
+    reset_argb = GetPaletteData()[0];
+    set_argb = GetPaletteData()[1];
   }
   for (int i = 0; i < clip_width; i++) {
     uint32_t src_x = (clip_left + i) * src_width / dest_width;
@@ -1322,10 +1322,10 @@
       src_x %= src_width;
       uint8_t* pDestPixel = dest_scan + i * 4;
       uint8_t index = pSrcLine[src_x];
-      if (m_pPalette) {
-        *pDestPixel++ = FXARGB_B(m_pPalette.get()[index]);
-        *pDestPixel++ = FXARGB_G(m_pPalette.get()[index]);
-        *pDestPixel++ = FXARGB_R(m_pPalette.get()[index]);
+      if (HasPalette()) {
+        *pDestPixel++ = FXARGB_B(GetPaletteData()[index]);
+        *pDestPixel++ = FXARGB_G(GetPaletteData()[index]);
+        *pDestPixel++ = FXARGB_R(GetPaletteData()[index]);
       } else {
         *pDestPixel++ = index;
         *pDestPixel++ = index;
@@ -1348,7 +1348,7 @@
       dest_scan[i] = index;
     } else {
       int dest_pos = i * dest_Bpp;
-      FX_ARGB argb = m_pPalette.get()[index];
+      FX_ARGB argb = GetPaletteData()[index];
       dest_scan[dest_pos] = FXARGB_B(argb);
       dest_scan[dest_pos + 1] = FXARGB_G(argb);
       dest_scan[dest_pos + 2] = FXARGB_R(argb);
diff --git a/core/fpdfapi/page/cpdf_transferfuncdib.cpp b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
index bfe0153..dc51a86 100644
--- a/core/fpdfapi/page/cpdf_transferfuncdib.cpp
+++ b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
@@ -86,7 +86,7 @@
       break;
     }
     case FXDIB_8bppRgb: {
-      const FX_ARGB* pPal = m_pSrc->GetPalette();
+      const FX_ARGB* pPal = m_pSrc->GetPaletteData();
       int index = 0;
       for (int i = 0; i < m_Width; i++) {
         if (pPal) {
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp
index 13a328a..df6ab72 100644
--- a/core/fxcodec/progressive_decoder.cpp
+++ b/core/fxcodec/progressive_decoder.cpp
@@ -337,9 +337,9 @@
           return false;
         case FXDIB_8bppMask:
         case FXDIB_8bppRgb: {
-          if (pDIBitmap->GetPalette()) {
+          if (pDIBitmap->HasPalette())
             return false;
-          }
+
           uint32_t dest_g = 0;
           dest_g += pPixelWeights->m_Weights[0] * src_scan[src_col];
           dest_scan[pPixelWeights->m_SrcStart] = (uint8_t)(dest_g >> 16);
@@ -647,9 +647,9 @@
           return;
         case FXDIB_8bppMask:
         case FXDIB_8bppRgb: {
-          if (pDeviceBitmap->GetPalette()) {
+          if (pDeviceBitmap->HasPalette())
             return;
-          }
+
           int dest_g = 0;
           dest_g += pWeight->m_Weights[0] * (*scan_src1++);
           dest_g += pWeight->m_Weights[1] * (*scan_src2++);
@@ -922,9 +922,9 @@
           return;
         case FXDIB_8bppMask:
         case FXDIB_8bppRgb: {
-          if (pDeviceBitmap->GetPalette()) {
+          if (pDeviceBitmap->HasPalette())
             return;
-          }
+
           int dest_g = 0;
           dest_g += pWeight->m_Weights[0] * (*scan_src1++);
           dest_g += pWeight->m_Weights[1] * (*scan_src2++);
@@ -1132,9 +1132,9 @@
         return;
       case FXDIB_8bppMask:
       case FXDIB_8bppRgb: {
-        if (pDeviceBitmap->GetPalette()) {
+        if (pDeviceBitmap->HasPalette())
           return;
-        }
+
         uint32_t dest_g = 0;
         dest_g +=
             pPixelWeights->m_Weights[0] * src_scan[pPixelWeights->m_SrcStart];
@@ -2008,9 +2008,9 @@
           return;
         case FXDIB_8bppMask:
         case FXDIB_8bppRgb: {
-          if (pDeviceBitmap->GetPalette()) {
+          if (pDeviceBitmap->HasPalette())
             return;
-          }
+
           int dest_g = 0;
           dest_g += pWeight->m_Weights[0] * (*scan_src1++);
           dest_g += pWeight->m_Weights[1] * (*scan_src2++);
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index d39e0a4..d4db32f 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -978,9 +978,9 @@
                                            const uint8_t* clip_scan,
                                            int span_left) {
   int index = 0;
-  if (m_pDevice->GetPalette()) {
+  if (m_pDevice->HasPalette()) {
     for (int i = 0; i < 2; i++) {
-      if (m_pDevice->GetPalette()[i] == m_Color)
+      if (m_pDevice->GetPaletteData()[i] == m_Color)
         index = i;
     }
   } else {
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp
index 40e262c..29ee7be 100644
--- a/core/fxge/dib/cfx_dibbase.cpp
+++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -142,7 +142,7 @@
                                 const RetainPtr<CFX_DIBBase>& pSrcBitmap,
                                 int src_left,
                                 int src_top) {
-  const uint32_t* src_plt = pSrcBitmap->GetPalette();
+  const uint32_t* src_plt = pSrcBitmap->GetPaletteData();
   uint8_t gray[2];
   uint8_t reset_r;
   uint8_t reset_g;
@@ -187,7 +187,7 @@
                                 const RetainPtr<CFX_DIBBase>& pSrcBitmap,
                                 int src_left,
                                 int src_top) {
-  const uint32_t* src_plt = pSrcBitmap->GetPalette();
+  const uint32_t* src_plt = pSrcBitmap->GetPaletteData();
   uint8_t gray[256];
   if (pSrcBitmap->IsCmykImage()) {
     uint8_t r;
@@ -294,7 +294,7 @@
                                uint32_t* dst_plt) {
   ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap,
                           src_left, src_top);
-  const uint32_t* src_plt = pSrcBitmap->GetPalette();
+  const uint32_t* src_plt = pSrcBitmap->GetPaletteData();
   size_t plt_size = pSrcBitmap->GetPaletteSize();
   if (pSrcBitmap->IsCmykImage()) {
     for (size_t i = 0; i < plt_size; ++i) {
@@ -421,7 +421,7 @@
                                int src_left,
                                int src_top) {
   int comps = GetCompsFromFormat(dest_format);
-  const uint32_t* src_plt = pSrcBitmap->GetPalette();
+  const uint32_t* src_plt = pSrcBitmap->GetPaletteData();
   uint32_t plt[2];
   uint8_t* bgr_ptr = reinterpret_cast<uint8_t*>(plt);
   if (pSrcBitmap->IsCmykImage()) {
@@ -465,7 +465,7 @@
                                int src_left,
                                int src_top) {
   int comps = GetCompsFromFormat(dest_format);
-  const uint32_t* src_plt = pSrcBitmap->GetPalette();
+  const uint32_t* src_plt = pSrcBitmap->GetPaletteData();
   uint32_t plt[256];
   uint8_t* bgr_ptr = reinterpret_cast<uint8_t*>(plt);
   if (!pSrcBitmap->IsCmykImage()) {
@@ -582,7 +582,7 @@
                             int src_top) {
   switch (bpp) {
     case 1:
-      if (pSrcBitmap->GetPalette()) {
+      if (pSrcBitmap->HasPalette()) {
         ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height,
                                    pSrcBitmap, src_left, src_top);
       } else {
@@ -591,7 +591,7 @@
       }
       return true;
     case 8:
-      if (pSrcBitmap->GetPalette()) {
+      if (pSrcBitmap->HasPalette()) {
         ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height,
                                    pSrcBitmap, src_left, src_top);
       } else {
@@ -620,7 +620,7 @@
                        int src_top) {
   switch (bpp) {
     case 1:
-      if (pSrcBitmap->GetPalette()) {
+      if (pSrcBitmap->HasPalette()) {
         ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
                                   height, pSrcBitmap, src_left, src_top);
       } else {
@@ -629,7 +629,7 @@
       }
       return true;
     case 8:
-      if (pSrcBitmap->GetPalette()) {
+      if (pSrcBitmap->HasPalette()) {
         ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
                                   height, pSrcBitmap, src_left, src_top);
       } else {
@@ -662,7 +662,7 @@
                         int src_top) {
   switch (bpp) {
     case 1:
-      if (pSrcBitmap->GetPalette()) {
+      if (pSrcBitmap->HasPalette()) {
         ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
                                   height, pSrcBitmap, src_left, src_top);
       } else {
@@ -671,7 +671,7 @@
       }
       return true;
     case 8:
-      if (pSrcBitmap->GetPalette()) {
+      if (pSrcBitmap->HasPalette()) {
         ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
                                   height, pSrcBitmap, src_left, src_top);
       } else {
@@ -720,7 +720,7 @@
   if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
     return nullptr;
 
-  pNewBitmap->SetPalette(m_pPalette.get());
+  pNewBitmap->SetPalette(GetPaletteData());
   pNewBitmap->SetAlphaMask(m_pAlphaMask, pClip);
   if (GetBPP() == 1 && rect.left % 8 != 0) {
     int left_shift = rect.left % 32;
@@ -751,7 +751,7 @@
 }
 
 void CFX_DIBBase::BuildPalette() {
-  if (m_pPalette)
+  if (HasPalette())
     return;
 
   if (GetBPP() == 1) {
@@ -805,8 +805,8 @@
 
 uint32_t CFX_DIBBase::GetPaletteArgb(int index) const {
   ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
-  if (m_pPalette)
-    return m_pPalette.get()[index];
+  if (HasPalette())
+    return GetPaletteData()[index];
 
   if (IsCmykImage()) {
     if (GetBPP() == 1)
@@ -822,32 +822,30 @@
 
 void CFX_DIBBase::SetPaletteArgb(int index, uint32_t color) {
   ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
-  if (!m_pPalette) {
-    BuildPalette();
-  }
+  BuildPalette();
   m_pPalette.get()[index] = color;
 }
 
 int CFX_DIBBase::FindPalette(uint32_t color) const {
   ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
-  if (!m_pPalette) {
-    if (IsCmykImage()) {
-      if (GetBPP() == 1)
-        return (static_cast<uint8_t>(color) == 0xff) ? 0 : 1;
-
-      return 0xff - static_cast<uint8_t>(color);
+  if (HasPalette()) {
+    int palsize = (1 << GetBPP());
+    for (int i = 0; i < palsize; ++i) {
+      if (GetPaletteData()[i] == color)
+        return i;
     }
-    if (GetBPP() == 1)
-      return (static_cast<uint8_t>(color) == 0xff) ? 1 : 0;
+    return -1;
+  }
 
-    return static_cast<uint8_t>(color);
+  if (IsCmykImage()) {
+    if (GetBPP() == 1)
+      return (static_cast<uint8_t>(color) == 0xff) ? 0 : 1;
+    return 0xff - static_cast<uint8_t>(color);
   }
-  int palsize = (1 << GetBPP());
-  for (int i = 0; i < palsize; ++i) {
-    if (m_pPalette.get()[i] == color)
-      return i;
-  }
-  return -1;
+
+  if (GetBPP() == 1)
+    return (static_cast<uint8_t>(color) == 0xff) ? 1 : 0;
+  return static_cast<uint8_t>(color);
 }
 
 bool CFX_DIBBase::GetOverlapRect(int& dest_left,
@@ -919,15 +917,15 @@
   ASSERT(!IsCmykImage());
 
   if (GetBPP() == 1) {
-    pal[0] = ((m_pPalette ? m_pPalette.get()[0] : 0xff000000) & 0xffffff) |
+    pal[0] = ((HasPalette() ? GetPaletteData()[0] : 0xff000000) & 0xffffff) |
              (alpha << 24);
-    pal[1] = ((m_pPalette ? m_pPalette.get()[1] : 0xffffffff) & 0xffffff) |
+    pal[1] = ((HasPalette() ? GetPaletteData()[1] : 0xffffffff) & 0xffffff) |
              (alpha << 24);
     return;
   }
-  if (m_pPalette) {
+  if (HasPalette()) {
     for (int i = 0; i < 256; ++i)
-      pal[i] = (m_pPalette.get()[i] & 0x00ffffff) | (alpha << 24);
+      pal[i] = (GetPaletteData()[i] & 0x00ffffff) | (alpha << 24);
   } else {
     for (int i = 0; i < 256; ++i)
       pal[i] = (i * 0x10101) | (alpha << 24);
@@ -985,7 +983,7 @@
   if (!pFlipped->Create(m_Width, m_Height, GetFormat()))
     return nullptr;
 
-  pFlipped->SetPalette(m_pPalette.get());
+  pFlipped->SetPalette(GetPaletteData());
   uint8_t* pDestBuffer = pFlipped->GetBuffer();
   int Bpp = m_bpp / 8;
   for (int row = 0; row < m_Height; ++row) {
@@ -1102,7 +1100,7 @@
   if (!pTransBitmap->Create(result_width, result_height, GetFormat()))
     return nullptr;
 
-  pTransBitmap->SetPalette(m_pPalette.get());
+  pTransBitmap->SetPalette(GetPaletteData());
   int dest_pitch = pTransBitmap->GetPitch();
   uint8_t* dest_buf = pTransBitmap->GetBuffer();
   int row_start = bXFlip ? m_Height - dest_clip.right : dest_clip.left;
@@ -1239,12 +1237,12 @@
     case FXDIB_8bppRgb:
     case FXDIB_8bppRgba: {
       const bool bpp_1_or_8 = (bpp == 1 || bpp == 8);
-      if (bpp_1_or_8 && !pSrcBitmap->GetPalette()) {
+      if (bpp_1_or_8 && !pSrcBitmap->HasPalette()) {
         return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width,
                              height, pSrcBitmap, src_left, src_top, p_pal);
       }
       p_pal->reset(FX_Alloc(uint32_t, 256));
-      if (bpp_1_or_8 && pSrcBitmap->GetPalette()) {
+      if (bpp_1_or_8 && pSrcBitmap->HasPalette()) {
         ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height,
                                   pSrcBitmap, src_left, src_top, p_pal->get());
         return true;
diff --git a/core/fxge/dib/cfx_dibbase.h b/core/fxge/dib/cfx_dibbase.h
index 84d423e..90eada6 100644
--- a/core/fxge/dib/cfx_dibbase.h
+++ b/core/fxge/dib/cfx_dibbase.h
@@ -55,7 +55,8 @@
     return static_cast<FXDIB_Format>(m_AlphaFlag * 0x100 + m_bpp);
   }
   uint32_t GetPitch() const { return m_Pitch; }
-  const uint32_t* GetPalette() const { return m_pPalette.get(); }
+  bool HasPalette() const { return !!m_pPalette; }
+  const uint32_t* GetPaletteData() const { return m_pPalette.get(); }
   int GetBPP() const { return m_bpp; }
 
   bool IsAlphaMask() const { return !!(m_AlphaFlag & 1); }
diff --git a/core/fxge/dib/cfx_dibextractor.cpp b/core/fxge/dib/cfx_dibextractor.cpp
index 21e73b9..fe0c48f 100644
--- a/core/fxge/dib/cfx_dibextractor.cpp
+++ b/core/fxge/dib/cfx_dibextractor.cpp
@@ -21,7 +21,7 @@
     m_pBitmap.Reset();
     return;
   }
-  m_pBitmap->SetPalette(pOldSrc->GetPalette());
+  m_pBitmap->SetPalette(pOldSrc->GetPaletteData());
   m_pBitmap->SetAlphaMask(pOldSrc->m_pAlphaMask, nullptr);
 }
 
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index 72c003b..a8aa1bc 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -85,7 +85,7 @@
   if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat()))
     return false;
 
-  SetPalette(pSrc->GetPalette());
+  SetPalette(pSrc->GetPaletteData());
   SetAlphaMask(pSrc->m_pAlphaMask, nullptr);
   for (int row = 0; row < pSrc->GetHeight(); row++)
     memcpy(m_pBuffer.Get() + row * m_Pitch, pSrc->GetScanline(row), m_Pitch);
@@ -220,7 +220,7 @@
     const RetainPtr<CFX_DIBBase>& pSrcBitmap,
     int src_left,
     int src_top) {
-  if (m_pPalette)
+  if (HasPalette())
     return false;
 
   if (m_bpp == 8)
@@ -550,15 +550,15 @@
     }
     case FXDIB_1bppRgb: {
       if ((*pos) & (1 << (7 - x % 8))) {
-        return m_pPalette ? m_pPalette.get()[1] : 0xffffffff;
+        return HasPalette() ? GetPaletteData()[1] : 0xffffffff;
       }
-      return m_pPalette ? m_pPalette.get()[0] : 0xff000000;
+      return HasPalette() ? GetPaletteData()[0] : 0xff000000;
     }
     case FXDIB_8bppMask:
       return (*pos) << 24;
     case FXDIB_8bppRgb:
-      return m_pPalette ? m_pPalette.get()[*pos]
-                        : (0xff000000 | ((*pos) * 0x10101));
+      return HasPalette() ? GetPaletteData()[*pos]
+                          : (0xff000000 | ((*pos) * 0x10101));
     case FXDIB_Rgb:
     case FXDIB_Rgba:
     case FXDIB_Rgb32:
@@ -590,8 +590,8 @@
       }
       break;
     case FXDIB_1bppRgb:
-      if (m_pPalette) {
-        if (color == m_pPalette.get()[1]) {
+      if (HasPalette()) {
+        if (color == GetPaletteData()[1]) {
           *pos |= 1 << (7 - x % 8);
         } else {
           *pos &= ~(1 << (7 - x % 8));
@@ -608,9 +608,9 @@
       *pos = (uint8_t)(color >> 24);
       break;
     case FXDIB_8bppRgb: {
-      if (m_pPalette) {
+      if (HasPalette()) {
         for (int i = 0; i < 256; i++) {
-          if (m_pPalette.get()[i] == color) {
+          if (GetPaletteData()[i] == color) {
             *pos = (uint8_t)i;
             return;
           }
@@ -675,16 +675,16 @@
       }
       src_x %= m_Width;
       int dest_pos = i;
-      if (m_pPalette) {
+      if (HasPalette()) {
         if (!IsCmykImage()) {
           dest_pos *= 3;
-          FX_ARGB argb = m_pPalette.get()[scanline[src_x]];
+          FX_ARGB argb = GetPaletteData()[scanline[src_x]];
           dest_scan[dest_pos] = FXARGB_B(argb);
           dest_scan[dest_pos + 1] = FXARGB_G(argb);
           dest_scan[dest_pos + 2] = FXARGB_R(argb);
         } else {
           dest_pos *= 4;
-          FX_CMYK cmyk = m_pPalette.get()[scanline[src_x]];
+          FX_CMYK cmyk = GetPaletteData()[scanline[src_x]];
           dest_scan[dest_pos] = FXSYS_GetCValue(cmyk);
           dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk);
           dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk);
@@ -718,10 +718,10 @@
   int bg = FXSYS_GetGValue(backcolor);
   int bb = FXSYS_GetBValue(backcolor);
   if (m_bpp <= 8) {
-    if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette)
+    if (forecolor == 0 && backcolor == 0xffffff && !HasPalette())
       return;
-    if (!m_pPalette)
-      BuildPalette();
+
+    BuildPalette();
     int size = 1 << m_bpp;
     for (int i = 0; i < size; ++i) {
       int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]),
@@ -771,10 +771,10 @@
   int by = FXSYS_GetYValue(backcolor);
   int bk = FXSYS_GetKValue(backcolor);
   if (m_bpp <= 8) {
-    if (forecolor == 0xff && backcolor == 0 && !m_pPalette)
+    if (forecolor == 0xff && backcolor == 0 && !HasPalette())
       return;
-    if (!m_pPalette)
-      BuildPalette();
+
+    BuildPalette();
     int size = 1 << m_bpp;
     for (int i = 0; i < size; ++i) {
       uint8_t r;
@@ -905,7 +905,7 @@
   }
   CFX_ScanlineCompositor compositor;
   if (!compositor.Init(GetFormat(), pSrcBitmap->GetFormat(), width,
-                       pSrcBitmap->GetPalette(), 0, blend_type,
+                       pSrcBitmap->GetPaletteData(), 0, blend_type,
                        pClipMask != nullptr, bRgbByteOrder)) {
     return false;
   }
@@ -1074,9 +1074,9 @@
     int right_shift = rect.right % 8;
     int new_width = rect.right / 8 - rect.left / 8;
     int index = 0;
-    if (m_pPalette) {
+    if (HasPalette()) {
       for (int i = 0; i < 2; i++) {
-        if (m_pPalette.get()[i] == color)
+        if (GetPaletteData()[i] == color)
           index = i;
       }
     } else {
@@ -1215,7 +1215,7 @@
     return true;
 
   if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb &&
-      !m_pPalette) {
+      !HasPalette()) {
     m_AlphaFlag = 1;
     return true;
   }
diff --git a/core/fxge/dib/cfx_imagestretcher.cpp b/core/fxge/dib/cfx_imagestretcher.cpp
index 414e3b5..2546c70 100644
--- a/core/fxge/dib/cfx_imagestretcher.cpp
+++ b/core/fxge/dib/cfx_imagestretcher.cpp
@@ -30,7 +30,7 @@
     return FXDIB_8bppMask;
   if (format == FXDIB_1bppRgb)
     return FXDIB_8bppRgb;
-  if (format == FXDIB_8bppRgb && src.GetPalette())
+  if (format == FXDIB_8bppRgb && src.HasPalette())
     return FXDIB_Rgb;
   return format;
 }
@@ -66,7 +66,7 @@
   if (m_DestWidth == 0 || m_DestHeight == 0)
     return false;
 
-  if (m_pSource->GetFormat() == FXDIB_1bppRgb && m_pSource->GetPalette()) {
+  if (m_pSource->GetFormat() == FXDIB_1bppRgb && m_pSource->HasPalette()) {
     FX_ARGB pal[256];
     int a0;
     int r0;
@@ -90,7 +90,7 @@
       return false;
     }
   } else if (m_pSource->GetFormat() == FXDIB_1bppCmyk &&
-             m_pSource->GetPalette()) {
+             m_pSource->HasPalette()) {
     FX_CMYK pal[256];
     int c0;
     int m0;
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp
index 03b201c..bb0b683 100644
--- a/core/fxge/dib/cfx_imagetransformer.cpp
+++ b/core/fxge/dib/cfx_imagetransformer.cpp
@@ -513,7 +513,7 @@
 void CFX_ImageTransformer::CalcMono(const CalcData& cdata,
                                     FXDIB_Format format) {
   uint32_t argb[256];
-  const FX_ARGB* pPal = m_Storer.GetBitmap()->GetPalette();
+  const FX_ARGB* pPal = m_Storer.GetBitmap()->GetPaletteData();
   if (pPal) {
     for (size_t i = 0; i < pdfium::size(argb); i++)
       argb[i] = pPal[i];
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index e36c418..86622ae 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -236,7 +236,7 @@
       m_SrcBpp(GetBppFromFormat(pSrcBitmap->GetFormat())),
       m_bHasAlpha(GetIsAlphaFromFormat(pSrcBitmap->GetFormat())),
       m_pSource(pSrcBitmap),
-      m_pSrcPalette(pSrcBitmap->GetPalette()),
+      m_pSrcPalette(pSrcBitmap->GetPaletteData()),
       m_SrcWidth(pSrcBitmap->GetWidth()),
       m_SrcHeight(pSrcBitmap->GetHeight()),
       m_pDestBitmap(pDestBitmap),
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index f2d2487..868360c 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -664,10 +664,10 @@
     }
     case 8:
       // we upscale ctables to 32bit.
-      if (pSource->GetPalette()) {
+      if (pSource->HasPalette()) {
         dst32Storage.reset(FX_Alloc2D(uint32_t, width, height));
         SkPMColor* dst32Pixels = dst32Storage.get();
-        const SkPMColor* ctable = pSource->GetPalette();
+        const SkPMColor* ctable = pSource->GetPaletteData();
         const unsigned ctableSize = pSource->GetPaletteSize();
         for (int y = 0; y < height; ++y) {
           const uint8_t* srcRow =
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 5c80646..a27e8bc 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -327,7 +327,7 @@
   int height = pSource->GetHeight();
   buf << width << " " << height;
 
-  if (pSource->GetBPP() == 1 && !pSource->GetPalette()) {
+  if (pSource->GetBPP() == 1 && !pSource->HasPalette()) {
     int pitch = (width + 7) / 8;
     uint32_t src_size = height * pitch;
     std::unique_ptr<uint8_t, FxFreeDeleter> src_buf(
@@ -373,17 +373,15 @@
         pConverted = pConverted->CloneConvert(FXDIB_Rgb);
         break;
       case FXDIB_8bppRgb:
-        if (pSource->GetPalette()) {
+        if (pSource->HasPalette())
           pConverted = pConverted->CloneConvert(FXDIB_Rgb);
-        }
         break;
       case FXDIB_1bppCmyk:
         pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
         break;
       case FXDIB_8bppCmyk:
-        if (pSource->GetPalette()) {
+        if (pSource->HasPalette())
           pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
-        }
         break;
       default:
         break;
diff --git a/core/fxge/win32/cfx_windowsdib.cpp b/core/fxge/win32/cfx_windowsdib.cpp
index fad6e2c..08e8d81 100644
--- a/core/fxge/win32/cfx_windowsdib.cpp
+++ b/core/fxge/win32/cfx_windowsdib.cpp
@@ -47,9 +47,9 @@
     pbmih->biWidth = pBitmap->GetWidth();
     if (pBitmap->GetBPP() == 8) {
       uint32_t* pPalette = (uint32_t*)(pbmih + 1);
-      if (pBitmap->GetPalette()) {
+      if (pBitmap->HasPalette()) {
         for (int i = 0; i < 256; i++) {
-          pPalette[i] = pBitmap->GetPalette()[i];
+          pPalette[i] = pBitmap->GetPaletteData()[i];
         }
       } else {
         for (int i = 0; i < 256; i++) {
@@ -59,9 +59,9 @@
     }
     if (pBitmap->GetBPP() == 1) {
       uint32_t* pPalette = (uint32_t*)(pbmih + 1);
-      if (pBitmap->GetPalette()) {
-        pPalette[0] = pBitmap->GetPalette()[0];
-        pPalette[1] = pBitmap->GetPalette()[1];
+      if (pBitmap->HasPalette()) {
+        pPalette[0] = pBitmap->GetPaletteData()[0];
+        pPalette[1] = pBitmap->GetPaletteData()[1];
       } else {
         pPalette[0] = 0;
         pPalette[1] = 0xffffff;