7#include "core/fxge/dib/cfx_bitmapcomposer.h"
11#include "core/fxcrt/fx_2d_size.h"
12#include "core/fxcrt/fx_coordinates.h"
13#include "core/fxcrt/fx_safe_types.h"
14#include "core/fxcrt/fx_system.h"
15#include "core/fxcrt/span_util.h"
16#include "core/fxge/cfx_cliprgn.h"
17#include "core/fxge/dib/cfx_dibitmap.h"
18#include "third_party/base/check_op.h"
35 m_pClipRgn = pClipRgn;
36 m_DestLeft = dest_rect
.left;
37 m_DestTop = dest_rect
.top;
41 m_MaskColor = mask_color;
42 m_pClipMask =
nullptr;
43 if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::kRectI)
44 m_pClipMask = pClipRgn->GetMask();
45 m_bVertical = bVertical;
48 m_bRgbByteOrder = bRgbByteOrder;
49 m_BlendMode = blend_mode;
52bool CFX_BitmapComposer::
SetInfo(
int width,
55 DataVector<uint32_t> src_palette) {
58 m_SrcFormat = src_format;
59 if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, src_palette,
60 m_MaskColor, m_BlendMode,
61 m_pClipMask || m_Alpha != 1.0f, m_bRgbByteOrder)) {
65 m_pScanlineV.resize(m_pBitmap->GetBPP() / 8 * width + 4);
66 m_pClipScanV.resize(m_pBitmap->GetHeight());
68 if (m_Alpha != 1.0f) {
69 m_pAddClipScan.resize(m_bVertical ? m_pBitmap->GetHeight()
70 : m_pBitmap->GetWidth());
75void CFX_BitmapComposer::DoCompose(pdfium::span<uint8_t> dest_scan,
76 pdfium::span<
const uint8_t> src_scan,
78 pdfium::span<
const uint8_t> clip_scan) {
79 if (m_Alpha != 1.0f) {
80 if (!clip_scan.empty()) {
81 for (
int i = 0; i < dest_width; ++i) {
82 m_pAddClipScan[i] = clip_scan[i] * m_Alpha;
85 fxcrt::spanset(pdfium::make_span(m_pAddClipScan).first(dest_width),
86 FXSYS_roundf(m_Alpha * 255));
88 clip_scan = m_pAddClipScan;
91 m_Compositor.CompositeByteMaskLine(dest_scan, src_scan, dest_width,
94 m_Compositor.CompositePalBitmapLine(dest_scan, src_scan, 0, dest_width,
97 m_Compositor.CompositeRgbBitmapLine(dest_scan, src_scan, dest_width,
103 pdfium::span<
const uint8_t> scanline) {
105 ComposeScanlineV(line, scanline);
108 pdfium::span<
const uint8_t> clip_scan;
112 ->GetWritableScanline(m_DestTop + line - m_pClipRgn->GetBox().top)
113 .subspan(m_DestLeft - m_pClipRgn->GetBox().left);
115 pdfium::span<uint8_t> dest_scan =
116 m_pBitmap->GetWritableScanline(line + m_DestTop);
117 if (!dest_scan.empty()) {
118 FX_SAFE_UINT32 offset = m_DestLeft;
119 offset *= m_pBitmap->GetBPP();
121 if (!offset.IsValid())
124 dest_scan = dest_scan.subspan(offset.ValueOrDie());
126 DoCompose(dest_scan, scanline, m_DestWidth, clip_scan);
129void CFX_BitmapComposer::ComposeScanlineV(
131 pdfium::span<
const uint8_t> scanline) {
132 int Bpp = m_pBitmap->GetBPP() / 8;
133 int dest_pitch = m_pBitmap->GetPitch();
134 int dest_x = m_DestLeft + (m_bFlipX ? (m_DestWidth - line - 1) : line);
135 pdfium::span<uint8_t> dest_span = m_pBitmap->GetWritableBuffer();
136 if (!dest_span.empty()) {
137 const size_t dest_x_offset = Fx2DSizeOrDie(dest_x, Bpp);
138 const size_t dest_y_offset = Fx2DSizeOrDie(m_DestTop, dest_pitch);
139 dest_span = dest_span.subspan(dest_y_offset).subspan(dest_x_offset);
141 const size_t dest_flip_offset =
142 Fx2DSizeOrDie(dest_pitch, m_DestHeight - 1);
143 dest_span = dest_span.subspan(dest_flip_offset);
146 uint8_t* dest_buf = dest_span.data();
147 const int y_step = m_bFlipY ? -dest_pitch : dest_pitch;
148 uint8_t* src_scan = m_pScanlineV.data();
149 uint8_t* dest_scan = dest_buf;
150 for (
int i = 0; i < m_DestHeight; ++i) {
151 for (
int j = 0; j < Bpp; ++j)
152 *src_scan++ = dest_scan[j];
155 pdfium::span<uint8_t> clip_scan;
157 clip_scan = m_pClipScanV;
158 int clip_pitch = m_pClipMask->GetPitch();
159 const uint8_t* src_clip =
160 m_pClipMask->GetScanline(m_DestTop - m_pClipRgn->GetBox().top)
161 .subspan(dest_x - m_pClipRgn->GetBox().left)
164 src_clip += Fx2DSizeOrDie(clip_pitch, m_DestHeight - 1);
165 clip_pitch = -clip_pitch;
167 for (
int i = 0; i < m_DestHeight; ++i) {
168 clip_scan[i] = *src_clip;
169 src_clip += clip_pitch;
172 DoCompose(m_pScanlineV, scanline, m_DestHeight, clip_scan);
173 src_scan = m_pScanlineV.data();
174 dest_scan = dest_buf;
175 for (
int i = 0; i < m_DestHeight; ++i) {
176 for (
int j = 0; j < Bpp; ++j)
177 dest_scan[j] = *src_scan++;
~CFX_BitmapComposer() override
void Compose(const RetainPtr< CFX_DIBitmap > &pDest, const CFX_ClipRgn *pClipRgn, float alpha, uint32_t mask_color, const FX_RECT &dest_rect, bool bVertical, bool bFlipX, bool bFlipY, bool bRgbByteOrder, BlendMode blend_mode)
void ComposeScanline(int line, pdfium::span< const uint8_t > scanline) override
bool SetInfo(int width, int height, FXDIB_Format src_format, DataVector< uint32_t > src_palette) override