Make FXDIB_Channel an enum class and nest in CFX_DIBitmap.

Change-Id: Icc60f181e8a0763e6cd5455b7c04aa3dbd81c5e1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75490
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index b8d4dea..a3cdcdd 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -947,9 +947,10 @@
     }
   }
   if (bAlphaMode)
-    pBitmap->LoadChannelFromAlpha(FXDIB_Red, pBitmap);
+    pBitmap->LoadChannelFromAlpha(CFX_DIBitmap::Channel::kRed, pBitmap);
 
   if (options.ColorModeIs(CPDF_RenderOptions::kGray))
     pBitmap->ConvertColorScale(0, 0xffffff);
+
   buffer.OutputToDevice();
 }
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp
index 0a973ad..f73e6c3 100644
--- a/core/fxge/dib/cfx_dibbase.cpp
+++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -982,8 +982,10 @@
   if (GetIsAlphaFromFormat(dest_format)) {
     bool ret;
     if (dest_format == FXDIB_Format::kArgb) {
-      ret = pSrcAlpha ? pClone->LoadChannelFromAlpha(FXDIB_Alpha, pSrcAlpha)
-                      : pClone->LoadChannel(FXDIB_Alpha, 0xff);
+      ret = pSrcAlpha
+                ? pClone->LoadChannelFromAlpha(CFX_DIBitmap::Channel::kAlpha,
+                                               pSrcAlpha)
+                : pClone->LoadChannel(CFX_DIBitmap::Channel::kAlpha, 0xff);
     } else {
       ret = pClone->SetAlphaMask(pSrcAlpha, nullptr);
     }
diff --git a/core/fxge/dib/cfx_dibbase.h b/core/fxge/dib/cfx_dibbase.h
index 3e99a45..d609c45 100644
--- a/core/fxge/dib/cfx_dibbase.h
+++ b/core/fxge/dib/cfx_dibbase.h
@@ -15,17 +15,6 @@
 #include "core/fxge/dib/fx_dib.h"
 #include "third_party/base/span.h"
 
-enum FXDIB_Channel {
-  FXDIB_Red = 1,
-  FXDIB_Green,
-  FXDIB_Blue,
-  FXDIB_Cyan,
-  FXDIB_Magenta,
-  FXDIB_Yellow,
-  FXDIB_Black,
-  FXDIB_Alpha
-};
-
 class CFX_ClipRgn;
 class CFX_DIBitmap;
 class PauseIndicatorIface;
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index e625b8e..d22ee2e 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -270,7 +270,7 @@
 }
 
 bool CFX_DIBitmap::LoadChannelFromAlpha(
-    FXDIB_Channel destChannel,
+    Channel destChannel,
     const RetainPtr<CFX_DIBBase>& pSrcBitmap) {
   if (!m_pBuffer)
     return false;
@@ -286,7 +286,7 @@
   }
   int srcOffset = pSrcBitmap->GetFormat() == FXDIB_Format::kArgb ? 3 : 0;
   int destOffset = 0;
-  if (destChannel == FXDIB_Alpha) {
+  if (destChannel == CFX_DIBitmap::Channel::kAlpha) {
     if (IsMask()) {
       if (!ConvertFormat(FXDIB_Format::k8bppMask))
         return false;
@@ -315,7 +315,7 @@
           return false;
       }
     }
-    destOffset = kChannelOffset[destChannel];
+    destOffset = kChannelOffset[static_cast<size_t>(destChannel)];
   }
   if (pSrcClone->m_pAlphaMask) {
     RetainPtr<CFX_DIBBase> pAlphaMask = pSrcClone->m_pAlphaMask;
@@ -340,7 +340,7 @@
     pSrcClone = pSrcMatched;
   }
   RetainPtr<CFX_DIBitmap> pDst(this);
-  if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
+  if (destChannel == CFX_DIBitmap::Channel::kAlpha && m_pAlphaMask) {
     pDst = m_pAlphaMask;
     destOffset = 0;
   }
@@ -358,12 +358,12 @@
   return true;
 }
 
-bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
+bool CFX_DIBitmap::LoadChannel(Channel destChannel, int value) {
   if (!m_pBuffer)
     return false;
 
   int destOffset;
-  if (destChannel == FXDIB_Alpha) {
+  if (destChannel == CFX_DIBitmap::Channel::kAlpha) {
     if (IsMask()) {
       if (!ConvertFormat(FXDIB_Format::k8bppMask)) {
         return false;
@@ -395,14 +395,14 @@
           return false;
       }
     }
-    destOffset = kChannelOffset[destChannel];
+    destOffset = kChannelOffset[static_cast<size_t>(destChannel)];
   }
   int Bpp = GetBPP() / 8;
   if (Bpp == 1) {
     memset(m_pBuffer.Get(), value, m_Height * m_Pitch);
     return true;
   }
-  if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
+  if (destChannel == CFX_DIBitmap::Channel::kAlpha && m_pAlphaMask) {
     memset(m_pAlphaMask->GetBuffer(), value,
            m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
     return true;
@@ -427,7 +427,7 @@
   }
 
   if (IsOpaqueImage())
-    return LoadChannelFromAlpha(FXDIB_Alpha, pSrcBitmap);
+    return LoadChannelFromAlpha(CFX_DIBitmap::Channel::kAlpha, pSrcBitmap);
 
   RetainPtr<CFX_DIBitmap> pSrcClone = pSrcBitmap.As<CFX_DIBitmap>();
   if (pSrcBitmap->GetWidth() != m_Width ||
diff --git a/core/fxge/dib/cfx_dibitmap.h b/core/fxge/dib/cfx_dibitmap.h
index 97c5148..57da0b4 100644
--- a/core/fxge/dib/cfx_dibitmap.h
+++ b/core/fxge/dib/cfx_dibitmap.h
@@ -17,6 +17,17 @@
 
 class CFX_DIBitmap : public CFX_DIBBase {
  public:
+  enum class Channel : uint8_t {
+    kRed = 1,
+    kGreen,
+    kBlue,
+    kCyan,
+    kMagenta,
+    kYellow,
+    kBlack,
+    kAlpha
+  };
+
   struct PitchAndSize {
     uint32_t pitch;
     uint32_t size;
@@ -25,7 +36,6 @@
   CONSTRUCT_VIA_MAKE_RETAIN;
 
   bool Create(int width, int height, FXDIB_Format format);
-
   bool Create(int width,
               int height,
               FXDIB_Format format,
@@ -56,9 +66,9 @@
   void SetPixel(int x, int y, uint32_t color);
 #endif
 
-  bool LoadChannelFromAlpha(FXDIB_Channel destChannel,
+  bool LoadChannelFromAlpha(Channel destChannel,
                             const RetainPtr<CFX_DIBBase>& pSrcBitmap);
-  bool LoadChannel(FXDIB_Channel destChannel, int value);
+  bool LoadChannel(Channel destChannel, int value);
 
   bool MultiplyAlpha(int alpha);
   bool MultiplyAlpha(const RetainPtr<CFX_DIBBase>& pSrcBitmap);
diff --git a/core/fxge/win32/cgdi_display_driver.cpp b/core/fxge/win32/cgdi_display_driver.cpp
index 7e9ec91..f1e48aa 100644
--- a/core/fxge/win32/cgdi_display_driver.cpp
+++ b/core/fxge/win32/cgdi_display_driver.cpp
@@ -63,7 +63,7 @@
     }
   }
   if (pBitmap->HasAlpha() && ret)
-    pBitmap->LoadChannel(FXDIB_Alpha, 0xff);
+    pBitmap->LoadChannel(CFX_DIBitmap::Channel::kAlpha, 0xff);
 
   DeleteObject(hbmp);
   DeleteObject(hDCMemory);