7#include "core/fxge/dib/cfx_imagestretcher.h"
11#include "core/fxcrt/data_vector.h"
12#include "core/fxcrt/fx_safe_types.h"
13#include "core/fxge/dib/cfx_dibbase.h"
14#include "core/fxge/dib/cfx_dibitmap.h"
15#include "core/fxge/dib/cstretchengine.h"
16#include "core/fxge/dib/fx_dib.h"
17#include "third_party/base/check.h"
18#include "third_party/base/check_op.h"
19#include "third_party/base/containers/span.h"
23const int kMaxProgressiveStretchPixels = 1000000;
25bool SourceSizeWithinLimit(
int width,
int height) {
26 return !height || width < kMaxProgressiveStretchPixels / height;
42DataVector<uint32_t> BuildPaletteFrom1BppSource(
44 DCHECK_EQ(FXDIB_Format::k1bppRgb, source->GetFormat());
45 DCHECK(source->HasPalette());
51 std::tie(a0, r0, g0, b0) = ArgbDecode(source->GetPaletteArgb(0));
56 std::tie(a1, r1, g1, b1) = ArgbDecode(source->GetPaletteArgb(1));
60 DataVector<uint32_t> palette(CFX_DIBBase::kPaletteSize);
62 int r = r0 + (r1 - r0) * i / 255;
63 int g = g0 + (g1 - g0) * i / 255;
64 int b = b0 + (b1 - b0) * i / 255;
65 palette[i] = ArgbEncode(255, r, g, b);
80 m_ResampleOptions(options),
81 m_DestWidth(dest_width),
82 m_DestHeight(dest_height),
83 m_ClipRect
(bitmap_rect
),
85 DCHECK(m_ClipRect.Valid());
91 if (m_DestWidth == 0 || m_DestHeight == 0)
94 if (m_pSource->GetFormat() == FXDIB_Format::k1bppRgb &&
95 m_pSource->HasPalette()) {
96 if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(), m_DestFormat,
97 BuildPaletteFrom1BppSource(m_pSource))) {
100 }
else if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(),
104 return StartStretch();
108 return ContinueStretch(pPause);
116 m_pStretchEngine = std::make_unique<CStretchEngine>(
117 m_pDest, m_DestFormat, m_DestWidth, m_DestHeight, m_ClipRect, m_pSource,
119 m_pStretchEngine->StartStretchHorz();
120 if (SourceSizeWithinLimit(m_pSource->GetWidth(), m_pSource->GetHeight())) {
121 m_pStretchEngine->Continue(
nullptr);
128 return m_pStretchEngine && m_pStretchEngine->Continue(pPause);
FXDIB_Format GetFormat() const
static constexpr uint32_t kPaletteSize
CFX_ImageStretcher(ScanlineComposerIface *pDest, RetainPtr< const CFX_DIBBase > source, int dest_width, int dest_height, const FX_RECT &bitmap_rect, const FXDIB_ResampleOptions &options)
RetainPtr< const CFX_DIBBase > source()
bool Continue(PauseIndicatorIface *pPause)
FX_RECT(const FX_RECT &that)=default