7#include "core/fxge/dib/cfx_imagestretcher.h"
11#include "core/fxcrt/check.h"
12#include "core/fxcrt/check_op.h"
13#include "core/fxcrt/data_vector.h"
14#include "core/fxcrt/fx_safe_types.h"
15#include "core/fxcrt/span.h"
16#include "core/fxge/dib/cfx_dibbase.h"
17#include "core/fxge/dib/cfx_dibitmap.h"
18#include "core/fxge/dib/cstretchengine.h"
19#include "core/fxge/dib/fx_dib.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());
48 ArgbToBGRAStruct(source->GetPaletteArgb(0));
50 ArgbToBGRAStruct(source->GetPaletteArgb(1));
54 DataVector<uint32_t> palette(CFX_DIBBase::kPaletteSize);
56 int r = bgra0.red + (bgra1.red - bgra0.red) * i / 255;
57 int g = bgra0.green + (bgra1.green - bgra0.green) * i / 255;
58 int b = bgra0.blue + (bgra1.blue - bgra0.blue) * i / 255;
59 palette[i] = ArgbEncode(255, r, g, b);
74 m_ResampleOptions(options),
75 m_DestWidth(dest_width),
76 m_DestHeight(dest_height),
77 m_ClipRect
(bitmap_rect
),
79 DCHECK(m_ClipRect.Valid());
85 if (m_DestWidth == 0 || m_DestHeight == 0)
88 if (m_pSource->GetFormat() == FXDIB_Format::k1bppRgb &&
89 m_pSource->HasPalette()) {
90 if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(), m_DestFormat,
91 BuildPaletteFrom1BppSource(m_pSource))) {
94 }
else if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(),
98 return StartStretch();
102 return ContinueStretch(pPause);
110 m_pStretchEngine = std::make_unique<CStretchEngine>(
111 m_pDest, m_DestFormat, m_DestWidth, m_DestHeight, m_ClipRect, m_pSource,
113 m_pStretchEngine->StartStretchHorz();
114 if (SourceSizeWithinLimit(m_pSource->GetWidth(), m_pSource->GetHeight())) {
115 m_pStretchEngine->Continue(
nullptr);
122 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