Make class CFX_DIBitmap::Channel private.
Split the one routine that uses it in two. Then remove its
unused values.
Change-Id: Ic446e8be119bd2c45cf4e9f49811b69411fceb4e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75551
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index a3cdcdd..3886312 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -947,7 +947,7 @@
}
}
if (bAlphaMode)
- pBitmap->LoadChannelFromAlpha(CFX_DIBitmap::Channel::kRed, pBitmap);
+ pBitmap->SetRedFromBitmap(pBitmap);
if (options.ColorModeIs(CPDF_RenderOptions::kGray))
pBitmap->ConvertColorScale(0, 0xffffff);
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp
index e63f67e..0b53c47 100644
--- a/core/fxge/dib/cfx_dibbase.cpp
+++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -982,8 +982,7 @@
if (GetIsAlphaFromFormat(dest_format)) {
bool ret;
if (dest_format == FXDIB_Format::kArgb) {
- ret = pSrcAlpha ? pClone->LoadChannelFromAlpha(
- CFX_DIBitmap::Channel::kAlpha, pSrcAlpha)
+ ret = pSrcAlpha ? pClone->SetAlphaFromBitmap(pSrcAlpha)
: pClone->SetUniformOpaqueAlpha();
} else {
ret = pClone->SetAlphaMask(pSrcAlpha, nullptr);
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index e2d49bf..37b4887 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -15,14 +15,9 @@
#include "core/fxge/cfx_cliprgn.h"
#include "core/fxge/dib/cfx_cmyk_to_srgb.h"
#include "core/fxge/dib/cfx_scanlinecompositor.h"
+#include "third_party/base/check_op.h"
#include "third_party/base/notreached.h"
-namespace {
-
-constexpr int8_t kChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
-
-} // namespace
-
CFX_DIBitmap::CFX_DIBitmap() = default;
bool CFX_DIBitmap::Create(int width, int height, FXDIB_Format format) {
@@ -269,7 +264,7 @@
}
}
-bool CFX_DIBitmap::LoadChannelFromAlpha(
+bool CFX_DIBitmap::SetChannelFromBitmap(
Channel destChannel,
const RetainPtr<CFX_DIBBase>& pSrcBitmap) {
if (!m_pBuffer)
@@ -286,7 +281,7 @@
}
int srcOffset = pSrcBitmap->GetFormat() == FXDIB_Format::kArgb ? 3 : 0;
int destOffset = 0;
- if (destChannel == CFX_DIBitmap::Channel::kAlpha) {
+ if (destChannel == Channel::kAlpha) {
if (IsMask()) {
if (!ConvertFormat(FXDIB_Format::k8bppMask))
return false;
@@ -294,10 +289,10 @@
if (!ConvertFormat(FXDIB_Format::kArgb))
return false;
- if (GetFormat() == FXDIB_Format::kArgb)
- destOffset = 3;
+ destOffset = 3;
}
} else {
+ DCHECK_EQ(destChannel, Channel::kRed);
if (IsMask())
return false;
@@ -315,7 +310,7 @@
return false;
}
}
- destOffset = kChannelOffset[static_cast<size_t>(destChannel)];
+ destOffset = 2;
}
if (pSrcClone->m_pAlphaMask) {
RetainPtr<CFX_DIBBase> pAlphaMask = pSrcClone->m_pAlphaMask;
@@ -340,7 +335,7 @@
pSrcClone = pSrcMatched;
}
RetainPtr<CFX_DIBitmap> pDst(this);
- if (destChannel == CFX_DIBitmap::Channel::kAlpha && m_pAlphaMask) {
+ if (destChannel == Channel::kAlpha && m_pAlphaMask) {
pDst = m_pAlphaMask;
destOffset = 0;
}
@@ -358,6 +353,15 @@
return true;
}
+bool CFX_DIBitmap::SetAlphaFromBitmap(
+ const RetainPtr<CFX_DIBBase>& pSrcBitmap) {
+ return SetChannelFromBitmap(Channel::kAlpha, pSrcBitmap);
+}
+
+bool CFX_DIBitmap::SetRedFromBitmap(const RetainPtr<CFX_DIBBase>& pSrcBitmap) {
+ return SetChannelFromBitmap(Channel::kRed, pSrcBitmap);
+}
+
bool CFX_DIBitmap::SetUniformOpaqueAlpha() {
if (!m_pBuffer)
return false;
@@ -400,7 +404,7 @@
}
if (IsOpaqueImage())
- return LoadChannelFromAlpha(CFX_DIBitmap::Channel::kAlpha, pSrcBitmap);
+ return SetAlphaFromBitmap(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 0397a8b..15f2c78 100644
--- a/core/fxge/dib/cfx_dibitmap.h
+++ b/core/fxge/dib/cfx_dibitmap.h
@@ -17,17 +17,6 @@
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;
@@ -66,8 +55,8 @@
void SetPixel(int x, int y, uint32_t color);
#endif
- bool LoadChannelFromAlpha(Channel destChannel,
- const RetainPtr<CFX_DIBBase>& pSrcBitmap);
+ bool SetRedFromBitmap(const RetainPtr<CFX_DIBBase>& pSrcBitmap);
+ bool SetAlphaFromBitmap(const RetainPtr<CFX_DIBBase>& pSrcBitmap);
bool SetUniformOpaqueAlpha();
bool MultiplyAlpha(int alpha);
@@ -146,6 +135,10 @@
#endif
private:
+ enum class Channel : uint8_t { kRed, kAlpha };
+
+ bool SetChannelFromBitmap(Channel destChannel,
+ const RetainPtr<CFX_DIBBase>& pSrcBitmap);
void ConvertBGRColorScale(uint32_t forecolor, uint32_t backcolor);
bool TransferWithUnequalFormats(FXDIB_Format dest_format,
int dest_left,