Add GetIsAlphaFromFormat() and use where appropriate. Fix nits in CFX_ScanlineCompositor along the way. Change-Id: I2aa922c1a3e6b770ee0f5060b1956632889ef3e8 Reviewed-on: https://pdfium-review.googlesource.com/c/50994 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp index 6f490c6..f91d946 100644 --- a/core/fxge/dib/cfx_dibbase.cpp +++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -1069,7 +1069,7 @@ if (!pSrcAlpha) return nullptr; } - if (dest_format & 0x0200) { + if (GetIsAlphaFromFormat(dest_format)) { bool ret; if (dest_format == FXDIB_Argb) { ret = pSrcAlpha ? pClone->LoadChannelFromAlpha(FXDIB_Alpha, pSrcAlpha)
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index a710330..3622c65 100644 --- a/core/fxge/dib/cfx_dibitmap.cpp +++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -1230,7 +1230,7 @@ } } } - } else if (dest_format & 0x0200) { + } else if (GetIsAlphaFromFormat(dest_format)) { if (src_format == FXDIB_Argb) { pAlphaMask = CloneAlphaMask(); if (!pAlphaMask)
diff --git a/core/fxge/dib/cfx_scanlinecompositor.cpp b/core/fxge/dib/cfx_scanlinecompositor.cpp index 7ed27a5..5bc3912 100644 --- a/core/fxge/dib/cfx_scanlinecompositor.cpp +++ b/core/fxge/dib/cfx_scanlinecompositor.cpp
@@ -2860,15 +2860,16 @@ InitSourcePalette(src_format, dest_format, pSrcPalette); m_iTransparency = (dest_format == FXDIB_Argb ? 1 : 0) + - (dest_format & 0x0200 ? 2 : 0) + + (GetIsAlphaFromFormat(dest_format) ? 2 : 0) + (dest_format & 0x0400 ? 4 : 0) + (GetBppFromFormat(src_format) == 1 ? 8 : 0); return true; } - m_iTransparency = - (src_format & 0x0200 ? 0 : 1) + (dest_format & 0x0200 ? 0 : 2) + - (blend_type == BlendMode::kNormal ? 4 : 0) + (bClip ? 8 : 0) + - (src_format & 0x0400 ? 16 : 0) + (dest_format & 0x0400 ? 32 : 0); + m_iTransparency = (GetIsAlphaFromFormat(src_format) ? 0 : 1) + + (GetIsAlphaFromFormat(dest_format) ? 0 : 2) + + (blend_type == BlendMode::kNormal ? 4 : 0) + + (bClip ? 8 : 0) + (src_format & 0x0400 ? 16 : 0) + + (dest_format & 0x0400 ? 32 : 0); return true; } @@ -3037,7 +3038,7 @@ return; } if (m_DestFormat == FXDIB_8bppMask) { - if (m_SrcFormat & 0x0200) { + if (GetIsAlphaFromFormat(m_SrcFormat)) { if (m_SrcFormat == FXDIB_Argb) { CompositeRow_AlphaToMask(dest_scan, src_scan, width, clip_scan, 4); } else { @@ -3054,8 +3055,8 @@ dest_scan++; } } - if (m_SrcFormat & 0x0200) { - if (m_DestFormat & 0x0200) { + if (GetIsAlphaFromFormat(m_SrcFormat)) { + if (GetIsAlphaFromFormat(m_DestFormat)) { CompositeRow_Argb2Graya(dest_scan, src_scan, width, m_BlendType, clip_scan, src_extra_alpha, dst_extra_alpha); } else { @@ -3063,7 +3064,7 @@ clip_scan, src_extra_alpha); } } else { - if (m_DestFormat & 0x0200) { + if (GetIsAlphaFromFormat(m_DestFormat)) { CompositeRow_Rgb2Graya(dest_scan, src_scan, src_Bpp, width, m_BlendType, clip_scan, dst_extra_alpha); } else { @@ -3176,7 +3177,7 @@ } if ((m_DestFormat & 0xff) == 8) { if (m_iTransparency & 8) { - if (m_DestFormat & 0x0200) { + if (GetIsAlphaFromFormat(m_DestFormat)) { CompositeRow_1bppPal2Graya( dest_scan, src_scan, src_left, reinterpret_cast<const uint8_t*>(m_pSrcPalette.get()), width, @@ -3188,16 +3189,17 @@ m_BlendType, clip_scan); } } else { - if (m_DestFormat & 0x0200) + if (GetIsAlphaFromFormat(m_DestFormat)) { CompositeRow_8bppPal2Graya( dest_scan, src_scan, reinterpret_cast<const uint8_t*>(m_pSrcPalette.get()), width, m_BlendType, clip_scan, dst_extra_alpha, src_extra_alpha); - else + } else { CompositeRow_8bppPal2Gray( dest_scan, src_scan, reinterpret_cast<const uint8_t*>(m_pSrcPalette.get()), width, m_BlendType, clip_scan, src_extra_alpha); + } } } else { switch (m_iTransparency) { @@ -3230,7 +3232,6 @@ m_pSrcPalette.get(), clip_scan, dst_extra_alpha); break; - break; } } } @@ -3244,7 +3245,7 @@ CompositeRow_ByteMask2Mask(dest_scan, src_scan, m_MaskAlpha, width, clip_scan); } else if ((m_DestFormat & 0xff) == 8) { - if (m_DestFormat & 0x0200) { + if (GetIsAlphaFromFormat(m_DestFormat)) { CompositeRow_ByteMask2Graya(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, width, clip_scan, dst_extra_alpha); } else { @@ -3261,7 +3262,6 @@ dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan); } - return; } else if (m_DestFormat == FXDIB_Argb) { CompositeRow_ByteMask2Argb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, width, m_BlendType, @@ -3287,7 +3287,7 @@ CompositeRow_BitMask2Mask(dest_scan, src_scan, m_MaskAlpha, src_left, width, clip_scan); } else if ((m_DestFormat & 0xff) == 8) { - if (m_DestFormat & 0x0200) { + if (GetIsAlphaFromFormat(m_DestFormat)) { CompositeRow_BitMask2Graya(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, src_left, width, clip_scan, dst_extra_alpha); } else { @@ -3304,7 +3304,6 @@ dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, src_left, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan); } - return; } else if (m_DestFormat == FXDIB_Argb) { CompositeRow_BitMask2Argb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, src_left, width,
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp index 7a582b5..35275dd 100644 --- a/core/fxge/dib/cstretchengine.cpp +++ b/core/fxge/dib/cstretchengine.cpp
@@ -233,7 +233,7 @@ : m_DestFormat(dest_format), m_DestBpp(GetBppFromFormat(dest_format)), m_SrcBpp(GetBppFromFormat(pSrcBitmap->GetFormat())), - m_bHasAlpha(pSrcBitmap->GetFormat() & 0x200), + m_bHasAlpha(GetIsAlphaFromFormat(pSrcBitmap->GetFormat())), m_pSource(pSrcBitmap), m_pSrcPalette(pSrcBitmap->GetPalette()), m_SrcWidth(pSrcBitmap->GetWidth()),
diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h index 86173e2..23dd468 100644 --- a/core/fxge/fx_dib.h +++ b/core/fxge/fx_dib.h
@@ -119,6 +119,10 @@ return (format & 0xff) / 8; } +inline bool GetIsAlphaFromFormat(FXDIB_Format format) { + return format & 0x200; +} + inline FX_CMYK CmykEncode(int c, int m, int y, int k) { return (c << 24) | (m << 16) | (y << 8) | k; }