Rename/Re-order some CFX_DIBBase methods. Do some tidying before attempting to encapsuate m_pAlphaMask. Straight rename/shuffle, no funny business. Encapsulation will require a new HasAlphaMask() method, which sounds too much like the existing HasAlpha() method, so rename that to IsAlphaFormat(). Then rename IsMask() to IsMaskFormat() for consistency. Then separate out the palette functions into their own section. In doing so, notice that GetPaletteSize() is returning a size based on format, not what was actually allocated for the palette, so rename to GetRequiredPaletteSize(). Then flag places where we are using this size rather than the actual size with which a palette span was previously allocated. Will address those in a follow-up to avoid the possibility of ever getting a mismatch. Change-Id: I98c7fb1669a72c8d9dfd5e550b1c1bbbb9c22cb6 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79931 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index 16d76b8..f389d5c 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -182,7 +182,7 @@ int32_t set_r = 0; int32_t set_g = 0; int32_t set_b = 0; - if (!pBitmap->IsMask()) { + if (!pBitmap->IsMaskFormat()) { std::tie(reset_a, reset_r, reset_g, reset_b) = ArgbDecode(pBitmap->GetPaletteArgb(0)); std::tie(set_a, set_r, set_g, set_b) = @@ -217,7 +217,7 @@ pDict->SetNewFor<CPDF_Number>("BitsPerComponent", 1); dest_pitch = (BitmapWidth + 7) / 8; } else if (bpp == 8) { - size_t palette_size = pBitmap->GetPaletteSize(); + size_t palette_size = pBitmap->GetRequiredPaletteSize(); if (palette_size > 0) { DCHECK(palette_size <= 256); CPDF_Array* pCS = m_pDocument->NewIndirect<CPDF_Array>(); @@ -253,7 +253,7 @@ } RetainPtr<CFX_DIBitmap> pMaskBitmap; - if (pBitmap->HasAlpha()) + if (pBitmap->IsAlphaFormat()) pMaskBitmap = pBitmap->CloneAlphaMask(); if (pMaskBitmap) { @@ -318,7 +318,7 @@ m_pStream = pdfium::MakeRetain<CPDF_Stream>(); m_pStream->InitStream(dest_span, std::move(pDict)); - m_bIsMask = pBitmap->IsMask(); + m_bIsMask = pBitmap->IsMaskFormat(); m_Width = BitmapWidth; m_Height = BitmapHeight; }
diff --git a/core/fpdfapi/page/cpdf_transferfuncdib.cpp b/core/fpdfapi/page/cpdf_transferfuncdib.cpp index 5d4e4ac..0353016 100644 --- a/core/fpdfapi/page/cpdf_transferfuncdib.cpp +++ b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
@@ -33,10 +33,10 @@ CPDF_TransferFuncDIB::~CPDF_TransferFuncDIB() = default; FXDIB_Format CPDF_TransferFuncDIB::GetDestFormat() const { - if (m_pSrc->IsMask()) + if (m_pSrc->IsMaskFormat()) return FXDIB_Format::k8bppMask; - if (m_pSrc->HasAlpha()) + if (m_pSrc->IsAlphaFormat()) return FXDIB_Format::kArgb; return CFX_DIBBase::kPlatformRGBFormat; @@ -163,7 +163,7 @@ } } else { #if defined(OS_APPLE) - if (!m_pSrc->HasAlpha()) { + if (!m_pSrc->IsAlphaFormat()) { for (int i = 0; i < pixels; i++) { *dest_buf++ = m_RampB[*(src_buf++)]; *dest_buf++ = m_RampG[*(src_buf++)];
diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.cpp b/core/fpdfapi/render/cpdf_imagecacheentry.cpp index 6148878..08a992e 100644 --- a/core/fpdfapi/render/cpdf_imagecacheentry.cpp +++ b/core/fpdfapi/render/cpdf_imagecacheentry.cpp
@@ -31,7 +31,7 @@ int height = pDIB->GetHeight(); DCHECK(pdfium::base::IsValueInRangeForNumericType<uint32_t>(height)); return static_cast<uint32_t>(height) * pDIB->GetPitch() + - pDIB->GetPaletteSize() * 4; + pDIB->GetRequiredPaletteSize() * 4; } } // namespace
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp index 8b29b26..3d1c947 100644 --- a/core/fpdfapi/render/cpdf_imagerenderer.cpp +++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -92,7 +92,7 @@ m_FillArgb = 0; m_bPatternColor = false; m_pPattern = nullptr; - if (m_pDIBBase->IsMask()) { + if (m_pDIBBase->IsMaskFormat()) { const CPDF_Color* pColor = m_pImageObject->m_ColorState.GetFillColor(); if (pColor && pColor->IsPattern()) { m_pPattern.Reset(pColor->GetPattern()); @@ -388,7 +388,7 @@ } #if defined(_SKIA_SUPPORT_) RetainPtr<CFX_DIBitmap> premultiplied = m_pDIBBase->Clone(nullptr); - if (m_pDIBBase->HasAlpha()) + if (m_pDIBBase->IsAlphaFormat()) CFX_SkiaDeviceDriver::PreMultiply(premultiplied); if (m_pRenderStatus->GetRenderDevice()->StartDIBitsWithBlend( premultiplied, m_BitmapAlpha, m_FillArgb, m_ImageMatrix, @@ -450,7 +450,7 @@ return false; } } - if (m_pDIBBase->IsMask()) { + if (m_pDIBBase->IsMaskFormat()) { if (m_BitmapAlpha != 255) m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); if (m_pRenderStatus->GetRenderDevice()->StretchBitMaskWithFlags( @@ -493,7 +493,7 @@ return false; } RetainPtr<CFX_DIBBase> pAlphaMask; - if (m_pDIBBase->IsMask()) + if (m_pDIBBase->IsMaskFormat()) pAlphaMask = m_pDIBBase; else pAlphaMask = m_pDIBBase->CloneAlphaMask(); @@ -572,7 +572,7 @@ if (!pBitmap) return false; - if (pBitmap->IsMask()) { + if (pBitmap->IsMaskFormat()) { if (m_BitmapAlpha != 255) m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); m_Result = m_pRenderStatus->GetRenderDevice()->SetBitMask(
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 7173baa..206994e 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -750,7 +750,7 @@ return nullptr; bool bNeedDraw; - if (pBackdrop->HasAlpha()) + if (pBackdrop->IsAlphaFormat()) bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT); else bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS); @@ -761,7 +761,7 @@ } CFX_Matrix FinalMatrix = m_DeviceMatrix; FinalMatrix.Translate(-*left, -*top); - pBackdrop->Clear(pBackdrop->HasAlpha() ? 0 : 0xffffffff); + pBackdrop->Clear(pBackdrop->IsAlphaFormat() ? 0 : 0xffffffff); CFX_DefaultRenderDevice device; device.Attach(pBackdrop, false, nullptr, false); @@ -1255,7 +1255,7 @@ return; if (blend_mode == BlendMode::kNormal) { - if (!pDIBitmap->IsMask()) { + if (!pDIBitmap->IsMaskFormat()) { if (bitmap_alpha < 255) { #if defined(_SKIA_SUPPORT_) std::unique_ptr<CFX_ImageRenderer> dummy; @@ -1294,7 +1294,7 @@ (m_pDevice->GetRenderCaps() & FXRC_GET_BITS) && !bBackAlphaRequired); if (bGetBackGround) { if (bIsolated || !transparency.IsGroup()) { - if (!pDIBitmap->IsMask()) + if (!pDIBitmap->IsMaskFormat()) m_pDevice->SetDIBitsWithBlend(pDIBitmap, left, top, blend_mode); return; } @@ -1314,7 +1314,7 @@ BlendMode::kNormal, nullptr, false); left = std::min(left, 0); top = std::min(top, 0); - if (pDIBitmap->IsMask()) { + if (pDIBitmap->IsMaskFormat()) { pClone->CompositeMask(0, 0, pClone->GetWidth(), pClone->GetHeight(), pDIBitmap, mask_argb, left, top, blend_mode, nullptr, false); @@ -1329,7 +1329,7 @@ if (m_pDevice->GetBackDrop()) { m_pDevice->SetDIBits(pClone, rect.left, rect.top); } else { - if (!pDIBitmap->IsMask()) { + if (!pDIBitmap->IsMaskFormat()) { m_pDevice->SetDIBitsWithBlend(pDIBitmap, rect.left, rect.top, blend_mode); } @@ -1346,7 +1346,7 @@ if (!pBackdrop) return; - if (pDIBitmap->IsMask()) { + if (pDIBitmap->IsMaskFormat()) { pBackdrop->CompositeMask(left - back_left, top - back_top, pDIBitmap->GetWidth(), pDIBitmap->GetHeight(), pDIBitmap, mask_argb, 0, 0, blend_mode, nullptr,
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp index 1fa2107..14a9569 100644 --- a/core/fxcodec/progressive_decoder.cpp +++ b/core/fxcodec/progressive_decoder.cpp
@@ -462,7 +462,7 @@ trans_index = -1; if (trans_index != -1) { m_pSrcPalette.get()[trans_index] &= 0x00ffffff; - if (pDevice->HasAlpha()) + if (pDevice->IsAlphaFormat()) pal_index = trans_index; } if (pal_index >= pal_num) @@ -509,7 +509,7 @@ RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap; DCHECK(pDIBitmap); int32_t img_width = m_GifFrameRect.Width(); - if (!pDIBitmap->HasAlpha()) { + if (!pDIBitmap->IsAlphaFormat()) { uint8_t* byte_ptr = row_buf; for (int i = 0; i < img_width; i++) { if (*byte_ptr == m_GifTransIndex) { @@ -519,7 +519,7 @@ } } int32_t pal_index = m_GifBgIndex; - if (m_GifTransIndex != -1 && m_pDeviceBitmap->HasAlpha()) { + if (m_GifTransIndex != -1 && m_pDeviceBitmap->IsAlphaFormat()) { pal_index = m_GifTransIndex; } memset(m_pDecodeBuf.get(), pal_index, m_SrcWidth);
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index 7335541..f56bcb6 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -86,7 +86,7 @@ } return; } - bool bAlpha = pBitmap->HasAlpha(); + bool bAlpha = pBitmap->IsAlphaFormat(); for (int row = rect.top; row < rect.bottom; row++) { uint8_t* dest_scan = pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp; if (bAlpha) { @@ -826,7 +826,7 @@ m_CompositeSpanFunc(GetCompositeSpanFunc(m_pDevice)) { if (m_pDevice->GetBPP() == 8) { DCHECK(!m_bRgbByteOrder); - if (m_pDevice->IsMask()) + if (m_pDevice->IsMaskFormat()) m_Gray = 255; else m_Gray = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color)); @@ -855,7 +855,7 @@ m_pBackdropDevice->GetBuffer() + m_pBackdropDevice->GetPitch() * y; } int Bpp = m_pDevice->GetBPP() / 8; - bool bDestAlpha = m_pDevice->HasAlpha() || m_pDevice->IsMask(); + bool bDestAlpha = m_pDevice->IsAlphaFormat() || m_pDevice->IsMaskFormat(); unsigned num_spans = sl.num_spans(); typename Scanline::const_iterator span = sl.begin(); while (1) { @@ -1062,9 +1062,9 @@ case FXDC_RENDER_CAPS: { int flags = FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | FXRC_BLEND_MODE | FXRC_SOFT_CLIP; - if (m_pBitmap->HasAlpha()) { + if (m_pBitmap->IsAlphaFormat()) { flags |= FXRC_ALPHA_OUTPUT; - } else if (m_pBitmap->IsMask()) { + } else if (m_pBitmap->IsMaskFormat()) { if (m_pBitmap->GetBPP() == 1) flags |= FXRC_BITMASK_OUTPUT; else @@ -1358,7 +1358,7 @@ if (!m_pBitmap->GetBuffer()) return true; - if (pBitmap->IsMask()) { + if (pBitmap->IsMaskFormat()) { return m_pBitmap->CompositeMask(left, top, src_rect.Width(), src_rect.Height(), pBitmap, argb, src_rect.left, src_rect.top, blend_type,
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp index 87c64aa..5016306 100644 --- a/core/fxge/cfx_renderdevice.cpp +++ b/core/fxge/cfx_renderdevice.cpp
@@ -772,7 +772,7 @@ if (!CreateCompatibleBitmap(bitmap, rect.Width(), rect.Height())) return false; - if (bitmap->HasAlpha()) { + if (bitmap->IsAlphaFormat()) { bitmap->Clear(0); backdrop->Copy(bitmap); } else { @@ -895,7 +895,7 @@ int left, int top, BlendMode blend_mode) { - DCHECK(!pBitmap->IsMask()); + DCHECK(!pBitmap->IsMaskFormat()); FX_RECT dest_rect(left, top, left + pBitmap->GetWidth(), top + pBitmap->GetHeight()); dest_rect.Intersect(m_ClipBox); @@ -906,7 +906,7 @@ dest_rect.left - left + dest_rect.Width(), dest_rect.top - top + dest_rect.Height()); if ((blend_mode == BlendMode::kNormal || (m_RenderCaps & FXRC_BLEND_MODE)) && - (!pBitmap->HasAlpha() || (m_RenderCaps & FXRC_ALPHA_IMAGE))) { + (!pBitmap->IsAlphaFormat() || (m_RenderCaps & FXRC_ALPHA_IMAGE))) { return m_pDeviceDriver->SetDIBits(pBitmap, 0, src_rect, dest_rect.left, dest_rect.top, blend_mode); } @@ -1164,7 +1164,7 @@ if (!CreateCompatibleBitmap(bitmap, pixel_width, pixel_height)) return false; } - if (!bitmap->HasAlpha() && !bitmap->IsMask()) { + if (!bitmap->IsAlphaFormat() && !bitmap->IsMaskFormat()) { bitmap->Clear(0xFFFFFFFF); if (!GetDIBits(bitmap, bmp_rect.left, bmp_rect.top)) return false; @@ -1215,7 +1215,7 @@ DrawNormalTextHelper(bitmap, pGlyph, nrows, point->x, point->y, start_col, end_col, normalize, x_subpixel, a, r, g, b); } - if (bitmap->IsMask()) + if (bitmap->IsMaskFormat()) SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color); else SetDIBits(bitmap, bmp_rect.left, bmp_rect.top);
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp index 493e449..9d0c71d 100644 --- a/core/fxge/dib/cfx_dibbase.cpp +++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -250,7 +250,9 @@ ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top); const uint32_t* src_plt = pSrcBitmap->GetPaletteData(); - size_t plt_size = pSrcBitmap->GetPaletteSize(); + + // TODO(tsepez): check against actual allocated span size. + size_t plt_size = pSrcBitmap->GetRequiredPaletteSize(); for (size_t i = 0; i < plt_size; ++i) dst_plt[i] = src_plt[i]; } @@ -670,8 +672,8 @@ return true; } -size_t CFX_DIBBase::GetPaletteSize() const { - if (IsMask()) +size_t CFX_DIBBase::GetRequiredPaletteSize() const { + if (IsMaskFormat()) return 0; switch (GetBppFromFormat(m_Format)) { @@ -685,7 +687,7 @@ } uint32_t CFX_DIBBase::GetPaletteArgb(int index) const { - DCHECK((GetBPP() == 1 || GetBPP() == 8) && !IsMask()); + DCHECK((GetBPP() == 1 || GetBPP() == 8) && !IsMaskFormat()); if (HasPalette()) return GetPaletteSpan()[index]; @@ -696,13 +698,13 @@ } void CFX_DIBBase::SetPaletteArgb(int index, uint32_t color) { - DCHECK((GetBPP() == 1 || GetBPP() == 8) && !IsMask()); + DCHECK((GetBPP() == 1 || GetBPP() == 8) && !IsMaskFormat()); BuildPalette(); m_palette[index] = color; } int CFX_DIBBase::FindPalette(uint32_t color) const { - DCHECK((GetBPP() == 1 || GetBPP() == 8) && !IsMask()); + DCHECK((GetBPP() == 1 || GetBPP() == 8) && !IsMaskFormat()); if (HasPalette()) { int palsize = (1 << GetBPP()); pdfium::span<const uint32_t> palette = GetPaletteSpan(); @@ -866,7 +868,7 @@ bool CFX_DIBBase::SetAlphaMask(const RetainPtr<CFX_DIBBase>& pAlphaMask, const FX_RECT* pClip) { - if (!HasAlpha() || GetFormat() == FXDIB_Format::kArgb) + if (!IsAlphaFormat() || GetFormat() == FXDIB_Format::kArgb) return false; if (!pAlphaMask) { @@ -974,7 +976,7 @@ return nullptr; RetainPtr<CFX_DIBitmap> pSrcAlpha; - if (HasAlpha()) { + if (IsAlphaFormat()) { pSrcAlpha = (GetFormat() == FXDIB_Format::kArgb) ? CloneAlphaMask() : m_pAlphaMask; if (!pSrcAlpha)
diff --git a/core/fxge/dib/cfx_dibbase.h b/core/fxge/dib/cfx_dibbase.h index 0e89f98..529f296 100644 --- a/core/fxge/dib/cfx_dibbase.h +++ b/core/fxge/dib/cfx_dibbase.h
@@ -47,20 +47,18 @@ } int GetWidth() const { return m_Width; } int GetHeight() const { return m_Height; } + uint32_t GetPitch() const { return m_Pitch; } FXDIB_Format GetFormat() const { return m_Format; } - uint32_t GetPitch() const { return m_Pitch; } + int GetBPP() const { return GetBppFromFormat(m_Format); } + bool IsMaskFormat() const { return GetIsMaskFromFormat(m_Format); } + bool IsAlphaFormat() const { return GetIsAlphaFromFormat(m_Format); } + bool IsOpaqueImage() const { return !IsMaskFormat() && !IsAlphaFormat(); } + bool HasPalette() const { return !m_palette.empty(); } pdfium::span<const uint32_t> GetPaletteSpan() const { return m_palette; } const uint32_t* GetPaletteData() const { return m_palette.data(); } - int GetBPP() const { return GetBppFromFormat(m_Format); } - - bool IsMask() const { return GetIsMaskFromFormat(m_Format); } - bool HasAlpha() const { return GetIsAlphaFromFormat(m_Format); } - bool IsOpaqueImage() const { return !IsMask() && !HasAlpha(); } - - size_t GetPaletteSize() const; - + size_t GetRequiredPaletteSize() const; uint32_t GetPaletteArgb(int index) const; void SetPaletteArgb(int index, uint32_t color);
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index d5716b8..9b77e86 100644 --- a/core/fxge/dib/cfx_dibitmap.cpp +++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -55,7 +55,7 @@ m_Width = width; m_Height = height; m_Pitch = pitch_size.value().pitch; - if (!HasAlpha() || format == FXDIB_Format::kArgb) + if (!IsAlphaFormat() || format == FXDIB_Format::kArgb) return true; if (BuildAlphaMask()) @@ -270,7 +270,7 @@ return false; RetainPtr<CFX_DIBBase> pSrcClone = pSrcBitmap; - if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsMask()) + if (!pSrcBitmap->IsAlphaFormat() && !pSrcBitmap->IsMaskFormat()) return false; if (pSrcBitmap->GetBPP() == 1) { @@ -281,7 +281,7 @@ int srcOffset = pSrcBitmap->GetFormat() == FXDIB_Format::kArgb ? 3 : 0; int destOffset = 0; if (destChannel == Channel::kAlpha) { - if (IsMask()) { + if (IsMaskFormat()) { if (!ConvertFormat(FXDIB_Format::k8bppMask)) return false; } else { @@ -292,11 +292,11 @@ } } else { DCHECK_EQ(destChannel, Channel::kRed); - if (IsMask()) + if (IsMaskFormat()) return false; if (GetBPP() < 24) { - if (HasAlpha()) { + if (IsAlphaFormat()) { if (!ConvertFormat(FXDIB_Format::kArgb)) return false; } else { @@ -360,7 +360,7 @@ if (!m_pBuffer) return false; - if (IsMask()) { + if (IsMaskFormat()) { if (!ConvertFormat(FXDIB_Format::k8bppMask)) return false; } else { @@ -392,7 +392,7 @@ if (!m_pBuffer) return false; - if (!pSrcBitmap->IsMask()) { + if (!pSrcBitmap->IsMaskFormat()) { NOTREACHED(); return false; } @@ -408,7 +408,7 @@ if (!pSrcClone) return false; } - if (IsMask()) { + if (IsMaskFormat()) { if (!ConvertFormat(FXDIB_Format::k8bppMask)) return false; @@ -479,7 +479,7 @@ break; } default: - if (HasAlpha()) { + if (IsAlphaFormat()) { m_pAlphaMask->MultiplyAlpha(alpha); } else { if (!ConvertFormat(FXDIB_Format::kArgb)) { @@ -703,7 +703,7 @@ } bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) { - if (!m_pBuffer || IsMask()) + if (!m_pBuffer || IsMaskFormat()) return false; ConvertBGRColorScale(forecolor, backcolor); @@ -755,7 +755,7 @@ BlendMode blend_type, const CFX_ClipRgn* pClipRgn, bool bRgbByteOrder) { - if (pSrcBitmap->IsMask()) { + if (pSrcBitmap->IsMaskFormat()) { // Should have called CompositeMask(). NOTREACHED(); return false; @@ -835,7 +835,7 @@ BlendMode blend_type, const CFX_ClipRgn* pClipRgn, bool bRgbByteOrder) { - if (!pMask->IsMask()) { + if (!pMask->IsMaskFormat()) { // Should have called CompositeBitmap(). NOTREACHED(); return false; @@ -916,9 +916,9 @@ uint32_t dst_color = color; uint8_t* color_p = reinterpret_cast<uint8_t*>(&dst_color); if (GetBppFromFormat(m_Format) == 8) { - uint8_t gray = - IsMask() ? 255 - : (uint8_t)FXRGB2GRAY((int)color_p[2], color_p[1], color_p[0]); + uint8_t gray = IsMaskFormat() ? 255 + : (uint8_t)FXRGB2GRAY((int)color_p[2], + color_p[1], color_p[0]); for (int row = rect.top; row < rect.bottom; row++) { uint8_t* dest_scan = m_pBuffer.Get() + row * m_Pitch + rect.left; if (src_alpha == 255) { @@ -977,7 +977,7 @@ color_p[3] = static_cast<uint8_t>(src_alpha); int Bpp = GetBppFromFormat(m_Format) / 8; - bool bAlpha = HasAlpha(); + bool bAlpha = IsAlphaFormat(); bool bArgb = GetFormat() == FXDIB_Format::kArgb; if (src_alpha == 255) { for (int row = rect.top; row < rect.bottom; row++) {
diff --git a/core/fxge/dib/cfx_imagerenderer.cpp b/core/fxge/dib/cfx_imagerenderer.cpp index 0db7fd1..1be59e7 100644 --- a/core/fxge/dib/cfx_imagerenderer.cpp +++ b/core/fxge/dib/cfx_imagerenderer.cpp
@@ -96,7 +96,7 @@ if (!pBitmap || !pBitmap->GetBuffer()) return false; - if (pBitmap->IsMask()) { + if (pBitmap->IsMaskFormat()) { if (m_BitmapAlpha != 255) m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); m_pDevice->CompositeMask(
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp index c5e1576..191c9c1 100644 --- a/core/fxge/dib/cfx_imagetransformer.cpp +++ b/core/fxge/dib/cfx_imagetransformer.cpp
@@ -237,7 +237,7 @@ return; auto pTransformed = pdfium::MakeRetain<CFX_DIBitmap>(); - FXDIB_Format format = m_Stretcher->source()->IsMask() + FXDIB_Format format = m_Stretcher->source()->IsMaskFormat() ? FXDIB_Format::k8bppMask : FXDIB_Format::kArgb; if (!pTransformed->Create(m_result.Width(), m_result.Height(), format)) @@ -270,7 +270,7 @@ CalcData calc_data = {pTransformed.Get(), result2stretch, m_Storer.GetBitmap()->GetBuffer(), m_Storer.GetBitmap()->GetPitch()}; - if (m_Storer.GetBitmap()->IsMask()) { + if (m_Storer.GetBitmap()->IsMaskFormat()) { CalcAlpha(calc_data); } else { int Bpp = m_Storer.GetBitmap()->GetBPP() / 8; @@ -324,7 +324,7 @@ int Bpp) { DCHECK(format == FXDIB_Format::k8bppMask || format == FXDIB_Format::kArgb); const int destBpp = calc_data.bitmap->GetBPP() / 8; - if (!m_Storer.GetBitmap()->HasAlpha()) { + if (!m_Storer.GetBitmap()->IsAlphaFormat()) { auto func = [&calc_data, Bpp](const BilinearData& data, uint8_t* dest) { uint8_t b = BilinearInterpolate(calc_data.buf, data, Bpp, 0); uint8_t g = BilinearInterpolate(calc_data.buf, data, Bpp, 1);
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index d2ba799..371ac1e 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp
@@ -645,11 +645,11 @@ void* buffer = pSource->GetBuffer(); if (!buffer) return false; - SkColorType colorType = forceAlpha || pSource->IsMask() + SkColorType colorType = forceAlpha || pSource->IsMaskFormat() ? SkColorType::kAlpha_8_SkColorType : SkColorType::kGray_8_SkColorType; SkAlphaType alphaType = - pSource->IsMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; + pSource->IsMaskFormat() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; int width = pSource->GetWidth(); int height = pSource->GetHeight(); int rowBytes = pSource->GetPitch(); @@ -674,7 +674,8 @@ dst32Storage.reset(FX_Alloc2D(uint32_t, width, height)); SkPMColor* dst32Pixels = dst32Storage.get(); pdfium::span<const uint32_t> src_palette = pSource->GetPaletteSpan(); - const unsigned src_palette_size = pSource->GetPaletteSize(); + // TODO(tsepez): check against actual allocated span size. + const unsigned src_palette_size = pSource->GetRequiredPaletteSize(); for (int y = 0; y < height; ++y) { const uint8_t* srcRow = static_cast<const uint8_t*>(buffer) + y * rowBytes; @@ -1884,9 +1885,9 @@ case FXDC_RENDER_CAPS: { int flags = FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_SHADING; - if (m_pBitmap->HasAlpha()) { + if (m_pBitmap->IsAlphaFormat()) { flags |= FXRC_ALPHA_OUTPUT; - } else if (m_pBitmap->IsMask()) { + } else if (m_pBitmap->IsMaskFormat()) { if (m_pBitmap->GetBPP() == 1) { flags |= FXRC_BITMASK_OUTPUT; } else { @@ -2453,7 +2454,7 @@ #if defined(_SKIA_SUPPORT_PATHS_) Flush(); - if (pBitmap->IsMask()) { + if (pBitmap->IsMaskFormat()) { return m_pBitmap->CompositeMask(left, top, src_rect.Width(), src_rect.Height(), pBitmap, argb, src_rect.left, src_rect.top, blend_type, @@ -2539,7 +2540,7 @@ SetBitmapMatrix(matrix, width, height, &skMatrix); m_pCanvas->concat(skMatrix); SkPaint paint; - SetBitmapPaint(pSource->IsMask(), !m_FillOptions.aliased_path, argb, + SetBitmapPaint(pSource->IsMaskFormat(), !m_FillOptions.aliased_path, argb, bitmap_alpha, blend_type, &paint); // TODO(caryclark) Once Skia supports 8 bit src to 8 bit dst remove this if (m_pBitmap && m_pBitmap->GetBPP() == 8 && pSource->GetBPP() == 8) { @@ -2675,8 +2676,8 @@ SetBitmapMatrix(matrix, srcWidth, srcHeight, &skMatrix); m_pCanvas->concat(skMatrix); SkPaint paint; - SetBitmapPaint(pSource->IsMask(), !m_FillOptions.aliased_path, 0xFFFFFFFF, - bitmap_alpha, blend_type, &paint); + SetBitmapPaint(pSource->IsMaskFormat(), !m_FillOptions.aliased_path, + 0xFFFFFFFF, bitmap_alpha, blend_type, &paint); sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap); sk_sp<SkShader> skSrcShader = skSrc->makeShader( SkTileMode::kClamp, SkTileMode::kClamp, SkSamplingOptions());
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index a80181d..f0dd85c 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -308,11 +308,11 @@ if ((matrix.a == 0 && matrix.b == 0) || (matrix.c == 0 && matrix.d == 0)) return true; - if (pSource->HasAlpha()) + if (pSource->IsAlphaFormat()) return false; int alpha = FXARGB_A(color); - if (pSource->IsMask() && (alpha < 255 || pSource->GetBPP() != 1)) + if (pSource->IsMaskFormat() && (alpha < 255 || pSource->GetBPP() != 1)) return false; m_pStream->WriteString("q\n"); @@ -339,7 +339,7 @@ uint32_t output_size; bool compressed = FaxCompressData(std::move(src_buf), width, height, &output_buf, &output_size); - if (pSource->IsMask()) { + if (pSource->IsMaskFormat()) { SetColor(color); m_bColorSet = false; buf << " true["; @@ -353,7 +353,7 @@ buf << "<</K -1/EndOfBlock false/Columns " << width << "/Rows " << height << ">>/CCITTFaxDecode filter "; } - if (pSource->IsMask()) + if (pSource->IsMaskFormat()) buf << "iM\n"; else buf << "false 1 colorimage\n";
diff --git a/core/fxge/win32/cgdi_display_driver.cpp b/core/fxge/win32/cgdi_display_driver.cpp index d51ad63..90b93e9 100644 --- a/core/fxge/win32/cgdi_display_driver.cpp +++ b/core/fxge/win32/cgdi_display_driver.cpp
@@ -64,7 +64,7 @@ ret = false; } } - if (ret && pBitmap->HasAlpha()) + if (ret && pBitmap->IsAlphaFormat()) pBitmap->SetUniformOpaqueAlpha(); DeleteObject(hbmp); @@ -79,7 +79,7 @@ int top, BlendMode blend_type) { DCHECK_EQ(blend_type, BlendMode::kNormal); - if (pSource->IsMask()) { + if (pSource->IsMaskFormat()) { int width = pSource->GetWidth(), height = pSource->GetHeight(); int alpha = FXARGB_A(color); if (pSource->GetBPP() != 1 || alpha != 255) { @@ -102,7 +102,7 @@ } int width = src_rect.Width(); int height = src_rect.Height(); - if (pSource->HasAlpha()) { + if (pSource->IsAlphaFormat()) { auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>(); if (!bitmap->Create(width, height, FXDIB_Format::kRgb) || !GetDIBits(bitmap, left, top) || @@ -165,7 +165,7 @@ return UseFoxitStretchEngine(pSource, color, dest_left, dest_top, dest_width, dest_height, pClipRect, options); } - if (pSource->IsMask()) { + if (pSource->IsMaskFormat()) { FX_RECT image_rect; image_rect.left = dest_width > 0 ? dest_left : dest_left + dest_width; image_rect.right = dest_width > 0 ? dest_left + dest_width : dest_left; @@ -194,7 +194,7 @@ return SetDIBits(background, 0, src_rect, image_rect.left + clip_rect.left, image_rect.top + clip_rect.top, BlendMode::kNormal); } - if (pSource->HasAlpha()) { + if (pSource->IsAlphaFormat()) { auto* pPlatform = static_cast<CWin32Platform*>(CFX_GEModule::Get()->GetPlatform()); if (pPlatform->m_GdiplusExt.IsAvailable()) {
diff --git a/core/fxge/win32/cgdi_printer_driver.cpp b/core/fxge/win32/cgdi_printer_driver.cpp index ea75455..d7f4981 100644 --- a/core/fxge/win32/cgdi_printer_driver.cpp +++ b/core/fxge/win32/cgdi_printer_driver.cpp
@@ -77,7 +77,7 @@ int left, int top, BlendMode blend_type) { - if (pSource->IsMask()) { + if (pSource->IsMaskFormat()) { FX_RECT clip_rect(left, top, left + src_rect.Width(), top + src_rect.Height()); return StretchDIBits(pSource, color, left - src_rect.left, @@ -86,9 +86,9 @@ FXDIB_ResampleOptions(), BlendMode::kNormal); } DCHECK(pSource); - DCHECK(!pSource->IsMask()); + DCHECK(!pSource->IsMaskFormat()); DCHECK_EQ(blend_type, BlendMode::kNormal); - if (pSource->HasAlpha()) + if (pSource->IsAlphaFormat()) return false; CFX_DIBExtractor temp(pSource); @@ -108,7 +108,7 @@ const FX_RECT* pClipRect, const FXDIB_ResampleOptions& options, BlendMode blend_type) { - if (pSource->IsMask()) { + if (pSource->IsMaskFormat()) { int alpha = FXARGB_A(color); if (pSource->GetBPP() != 1 || alpha != 255) return false; @@ -136,7 +136,7 @@ dest_height, color); } - if (pSource->HasAlpha()) + if (pSource->IsAlphaFormat()) return false; if (dest_width < 0 || dest_height < 0) { @@ -169,8 +169,8 @@ const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) { - if (bitmap_alpha < 255 || pSource->HasAlpha() || - (pSource->IsMask() && (pSource->GetBPP() != 1))) { + if (bitmap_alpha < 255 || pSource->IsAlphaFormat() || + (pSource->IsMaskFormat() && (pSource->GetBPP() != 1))) { return false; } CFX_FloatRect unit_rect = matrix.GetUnitRect();
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index 2883eca..5f8bf5c 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp
@@ -860,7 +860,7 @@ CFX_DefaultRenderDevice device; RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap)); device.Attach(pBitmap, false, nullptr, false); - if (!pBitmap->HasAlpha()) + if (!pBitmap->IsAlphaFormat()) color |= 0xFF000000; device.FillRect(FX_RECT(left, top, left + width, top + height), color); }
diff --git a/testing/fuzzers/pdf_scanlinecompositor_fuzzer.cc b/testing/fuzzers/pdf_scanlinecompositor_fuzzer.cc index b0109a1..0a698f1 100644 --- a/testing/fuzzers/pdf_scanlinecompositor_fuzzer.cc +++ b/testing/fuzzers/pdf_scanlinecompositor_fuzzer.cc
@@ -77,7 +77,7 @@ std::unique_ptr<CFX_ClipRgn> clip_rgn; if (is_clip) clip_rgn = std::make_unique<CFX_ClipRgn>(width, height); - if (src_bitmap->IsMask()) { + if (src_bitmap->IsMaskFormat()) { dest_bitmap->CompositeMask(dest_left, dest_top, width, height, src_bitmap, argb, src_left, src_top, blend_mode, clip_rgn.get(), is_rgb_byte_order);
diff --git a/xfa/fxfa/cxfa_imagerenderer.cpp b/xfa/fxfa/cxfa_imagerenderer.cpp index 4407ca3..bc3abe8 100644 --- a/xfa/fxfa/cxfa_imagerenderer.cpp +++ b/xfa/fxfa/cxfa_imagerenderer.cpp
@@ -37,7 +37,7 @@ if ((fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || (fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { RetainPtr<CFX_DIBBase> pDib = m_pDIBBase; - if (m_pDIBBase->HasAlpha() && + if (m_pDIBBase->IsAlphaFormat() && !(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE) && !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) { m_pCloneConvert = m_pDIBBase->CloneConvert(FXDIB_Format::kRgb); @@ -67,7 +67,7 @@ return false; } } - if (m_pDIBBase->IsMask()) { + if (m_pDIBBase->IsMaskFormat()) { if (m_pDevice->StretchBitMaskWithFlags(m_pDIBBase, dest_left, dest_top, dest_width, dest_height, 0, options)) { @@ -98,7 +98,7 @@ if (!pBitmap) return false; - if (pBitmap->IsMask()) { + if (pBitmap->IsMaskFormat()) { m_pDevice->SetBitMask(pBitmap, m_pTransformer->result().left, m_pTransformer->result().top, 0); } else { @@ -121,7 +121,7 @@ if (!pDIBitmap) return; - if (!pDIBitmap->IsMask()) { + if (!pDIBitmap->IsMaskFormat()) { if (m_pDevice->SetDIBits(pDIBitmap, left, top)) return; } else if (m_pDevice->SetBitMask(pDIBitmap, left, top, 0)) { @@ -132,13 +132,13 @@ (!(m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT) && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)); if (bGetBackGround) { - if (pDIBitmap->IsMask()) + if (pDIBitmap->IsMaskFormat()) return; m_pDevice->SetDIBitsWithBlend(pDIBitmap, left, top, BlendMode::kNormal); return; } - if (!pDIBitmap->HasAlpha() || + if (!pDIBitmap->IsAlphaFormat() || (m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE)) { return; }