Change CFX_DIBBase::SetPalette() to take a span. Change ScanlineComposerIface::SetInfo() to take a span as well. Change-Id: Iea761f1767d67487fee5d10ef07bce6e211c9dcf Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75235 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/dib/cfx_bitmapcomposer.cpp b/core/fxge/dib/cfx_bitmapcomposer.cpp index beb02b7..d754fb8 100644 --- a/core/fxge/dib/cfx_bitmapcomposer.cpp +++ b/core/fxge/dib/cfx_bitmapcomposer.cpp
@@ -44,10 +44,10 @@ bool CFX_BitmapComposer::SetInfo(int width, int height, FXDIB_Format src_format, - uint32_t* pSrcPalette) { + pdfium::span<const uint32_t> src_palette) { m_SrcFormat = src_format; - if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, pSrcPalette, - m_MaskColor, BlendMode::kNormal, + if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, + src_palette.data(), m_MaskColor, BlendMode::kNormal, m_pClipMask != nullptr || (m_BitmapAlpha < 255), m_bRgbByteOrder)) { return false;
diff --git a/core/fxge/dib/cfx_bitmapcomposer.h b/core/fxge/dib/cfx_bitmapcomposer.h index 69c0e63..1c6bde9 100644 --- a/core/fxge/dib/cfx_bitmapcomposer.h +++ b/core/fxge/dib/cfx_bitmapcomposer.h
@@ -36,11 +36,11 @@ bool bRgbByteOrder, BlendMode blend_type); - // ScanlineComposerIface + // ScanlineComposerIface: bool SetInfo(int width, int height, FXDIB_Format src_format, - uint32_t* pSrcPalette) override; + pdfium::span<const uint32_t> src_palette) override; void ComposeScanline(int line, const uint8_t* scanline,
diff --git a/core/fxge/dib/cfx_bitmapstorer.cpp b/core/fxge/dib/cfx_bitmapstorer.cpp index 72f3093..0871995 100644 --- a/core/fxge/dib/cfx_bitmapstorer.cpp +++ b/core/fxge/dib/cfx_bitmapstorer.cpp
@@ -42,13 +42,13 @@ bool CFX_BitmapStorer::SetInfo(int width, int height, FXDIB_Format src_format, - uint32_t* pSrcPalette) { + pdfium::span<const uint32_t> src_palette) { auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); if (!pBitmap->Create(width, height, src_format)) return false; - if (pSrcPalette) - pBitmap->SetPalette(pSrcPalette); + if (!src_palette.empty()) + pBitmap->SetPalette(src_palette); m_pBitmap = std::move(pBitmap); return true;
diff --git a/core/fxge/dib/cfx_bitmapstorer.h b/core/fxge/dib/cfx_bitmapstorer.h index c8158a3..8775273 100644 --- a/core/fxge/dib/cfx_bitmapstorer.h +++ b/core/fxge/dib/cfx_bitmapstorer.h
@@ -18,14 +18,14 @@ CFX_BitmapStorer(); ~CFX_BitmapStorer() override; - // ScanlineComposerIface + // ScanlineComposerIface: void ComposeScanline(int line, const uint8_t* scanline, const uint8_t* scan_extra_alpha) override; bool SetInfo(int width, int height, FXDIB_Format src_format, - uint32_t* pSrcPalette) override; + pdfium::span<const uint32_t> src_palette) override; RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; } RetainPtr<CFX_DIBitmap> Detach();
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp index bb31b80..d40de46 100644 --- a/core/fxge/dib/cfx_dibbase.cpp +++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -723,7 +723,7 @@ if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat())) return nullptr; - pNewBitmap->SetPalette(GetPaletteData()); + pNewBitmap->SetPalette(GetPaletteSpan()); pNewBitmap->SetAlphaMask(m_pAlphaMask, pClip); if (GetBPP() == 1 && rect.left % 8 != 0) { int left_shift = rect.left % 32; @@ -899,9 +899,9 @@ return width != 0 && height != 0; } -void CFX_DIBBase::SetPalette(const uint32_t* pSrc) { +void CFX_DIBBase::SetPalette(pdfium::span<const uint32_t> src_palette) { static const uint32_t kPaletteSize = 256; - if (!pSrc || GetBPP() > 8) { + if (src_palette.empty() || GetBPP() > 8) { m_palette.clear(); return; } @@ -909,7 +909,8 @@ if (m_palette.empty()) m_palette.resize(pal_size); pal_size = std::min(pal_size, kPaletteSize); - std::copy(pSrc, pSrc + pal_size, m_palette.begin()); + for (size_t i = 0; i < pal_size; ++i) + m_palette[i] = src_palette[i]; } void CFX_DIBBase::GetPalette(uint32_t* pal, int alpha) const { @@ -984,7 +985,7 @@ if (!pFlipped->Create(m_Width, m_Height, GetFormat())) return nullptr; - pFlipped->SetPalette(GetPaletteData()); + pFlipped->SetPalette(GetPaletteSpan()); uint8_t* pDestBuffer = pFlipped->GetBuffer(); int Bpp = m_bpp / 8; for (int row = 0; row < m_Height; ++row) { @@ -1085,7 +1086,7 @@ return nullptr; } if (!pal_8bpp.empty()) - pClone->SetPalette(pal_8bpp.data()); + pClone->SetPalette(pal_8bpp); return pClone; } @@ -1101,7 +1102,7 @@ if (!pTransBitmap->Create(result_width, result_height, GetFormat())) return nullptr; - pTransBitmap->SetPalette(GetPaletteData()); + pTransBitmap->SetPalette(GetPaletteSpan()); int dest_pitch = pTransBitmap->GetPitch(); uint8_t* dest_buf = pTransBitmap->GetBuffer(); int row_start = bXFlip ? m_Height - dest_clip.right : dest_clip.left;
diff --git a/core/fxge/dib/cfx_dibbase.h b/core/fxge/dib/cfx_dibbase.h index 763f3d1..80f9ef3 100644 --- a/core/fxge/dib/cfx_dibbase.h +++ b/core/fxge/dib/cfx_dibbase.h
@@ -72,7 +72,7 @@ void SetPaletteArgb(int index, uint32_t color); // Copies into internally-owned palette. - void SetPalette(const uint32_t* pSrcPal); + void SetPalette(pdfium::span<const uint32_t> src_palette); RetainPtr<CFX_DIBitmap> Clone(const FX_RECT* pClip) const; RetainPtr<CFX_DIBitmap> CloneConvert(FXDIB_Format format);
diff --git a/core/fxge/dib/cfx_dibextractor.cpp b/core/fxge/dib/cfx_dibextractor.cpp index fe0c48f..679ac09 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->GetPaletteData()); + m_pBitmap->SetPalette(pOldSrc->GetPaletteSpan()); m_pBitmap->SetAlphaMask(pOldSrc->m_pAlphaMask, nullptr); }
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index 7d70927..6569700 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->GetPaletteData()); + SetPalette(pSrc->GetPaletteSpan()); 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);
diff --git a/core/fxge/dib/cfx_imagestretcher.cpp b/core/fxge/dib/cfx_imagestretcher.cpp index 2546c70..73cfc13 100644 --- a/core/fxge/dib/cfx_imagestretcher.cpp +++ b/core/fxge/dib/cfx_imagestretcher.cpp
@@ -114,7 +114,7 @@ return false; } } else if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(), - m_DestFormat, nullptr)) { + m_DestFormat, {})) { return false; } return StartStretch();
diff --git a/core/fxge/dib/scanlinecomposer_iface.h b/core/fxge/dib/scanlinecomposer_iface.h index 316736f..79fac95 100644 --- a/core/fxge/dib/scanlinecomposer_iface.h +++ b/core/fxge/dib/scanlinecomposer_iface.h
@@ -8,6 +8,7 @@ #define CORE_FXGE_DIB_SCANLINECOMPOSER_IFACE_H_ #include "core/fxge/fx_dib.h" +#include "third_party/base/span.h" class ScanlineComposerIface { public: @@ -20,7 +21,7 @@ virtual bool SetInfo(int width, int height, FXDIB_Format src_format, - uint32_t* pSrcPalette) = 0; + pdfium::span<const uint32_t> src_palette) = 0; }; #endif // CORE_FXGE_DIB_SCANLINECOMPOSER_IFACE_H_
diff --git a/core/fxge/win32/cfx_windowsdib.cpp b/core/fxge/win32/cfx_windowsdib.cpp index 4a6fd54..2d531a4 100644 --- a/core/fxge/win32/cfx_windowsdib.cpp +++ b/core/fxge/win32/cfx_windowsdib.cpp
@@ -61,8 +61,8 @@ if (pBitmap->GetBPP() == 1) { uint32_t* pPalette = (uint32_t*)(pbmih + 1); if (pBitmap->HasPalette()) { - pPalette[0] = pBitmap->GetPaletteData()[0]; - pPalette[1] = pBitmap->GetPaletteData()[1]; + pPalette[0] = pBitmap->GetPaletteSpan()[0]; + pPalette[1] = pBitmap->GetPaletteSpan()[1]; } else { pPalette[0] = 0; pPalette[1] = 0xffffff;