1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef CORE_INCLUDE_FXGE_FX_DIB_H_
8 #define CORE_INCLUDE_FXGE_FX_DIB_H_
9
10 #include "core/include/fxcrt/fx_basic.h"
11 #include "core/include/fxcrt/fx_coordinates.h"
12
13 enum FXDIB_Format {
14 FXDIB_Invalid = 0,
15 FXDIB_1bppMask = 0x101,
16 FXDIB_1bppRgb = 0x001,
17 FXDIB_1bppCmyk = 0x401,
18 FXDIB_8bppMask = 0x108,
19 FXDIB_8bppRgb = 0x008,
20 FXDIB_8bppRgba = 0x208,
21 FXDIB_8bppCmyk = 0x408,
22 FXDIB_8bppCmyka = 0x608,
23 FXDIB_Rgb = 0x018,
24 FXDIB_Rgba = 0x218,
25 FXDIB_Rgb32 = 0x020,
26 FXDIB_Argb = 0x220,
27 FXDIB_Cmyk = 0x420,
28 FXDIB_Cmyka = 0x620,
29 };
30 enum FXDIB_Channel {
31 FXDIB_Red = 1,
32 FXDIB_Green,
33 FXDIB_Blue,
34 FXDIB_Cyan,
35 FXDIB_Magenta,
36 FXDIB_Yellow,
37 FXDIB_Black,
38 FXDIB_Alpha
39 };
40 #define FXDIB_DOWNSAMPLE 0x04
41 #define FXDIB_INTERPOL 0x20
42 #define FXDIB_BICUBIC_INTERPOL 0x80
43 #define FXDIB_NOSMOOTH 0x100
44 #define FXDIB_PALETTE_LOC 0x01
45 #define FXDIB_PALETTE_WIN 0x02
46 #define FXDIB_PALETTE_MAC 0x04
47 #define FXDIB_BLEND_NORMAL 0
48 #define FXDIB_BLEND_MULTIPLY 1
49 #define FXDIB_BLEND_SCREEN 2
50 #define FXDIB_BLEND_OVERLAY 3
51 #define FXDIB_BLEND_DARKEN 4
52 #define FXDIB_BLEND_LIGHTEN 5
53
54 #define FXDIB_BLEND_COLORDODGE 6
55 #define FXDIB_BLEND_COLORBURN 7
56 #define FXDIB_BLEND_HARDLIGHT 8
57 #define FXDIB_BLEND_SOFTLIGHT 9
58 #define FXDIB_BLEND_DIFFERENCE 10
59 #define FXDIB_BLEND_EXCLUSION 11
60 #define FXDIB_BLEND_NONSEPARABLE 21
61 #define FXDIB_BLEND_HUE 21
62 #define FXDIB_BLEND_SATURATION 22
63 #define FXDIB_BLEND_COLOR 23
64 #define FXDIB_BLEND_LUMINOSITY 24
65 #define FXDIB_BLEND_UNSUPPORTED -1
66 typedef FX_DWORD FX_ARGB;
67 typedef FX_DWORD FX_COLORREF;
68 typedef FX_DWORD FX_CMYK;
69 class CFX_ClipRgn;
70 class CFX_DIBSource;
71 class CFX_DIBitmap;
72 class CStretchEngine;
73
74 #define FXSYS_RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16))
75 #define FXSYS_GetRValue(rgb) ((rgb)&0xff)
76 #define FXSYS_GetGValue(rgb) (((rgb) >> 8) & 0xff)
77 #define FXSYS_GetBValue(rgb) (((rgb) >> 16) & 0xff)
78 #define FX_CCOLOR(val) (255 - (val))
79 #define FXSYS_CMYK(c, m, y, k) (((c) << 24) | ((m) << 16) | ((y) << 8) | (k))
80 #define FXSYS_GetCValue(cmyk) ((uint8_t)((cmyk) >> 24) & 0xff)
81 #define FXSYS_GetMValue(cmyk) ((uint8_t)((cmyk) >> 16) & 0xff)
82 #define FXSYS_GetYValue(cmyk) ((uint8_t)((cmyk) >> 8) & 0xff)
83 #define FXSYS_GetKValue(cmyk) ((uint8_t)(cmyk)&0xff)
84 void CmykDecode(FX_CMYK cmyk, int& c, int& m, int& y, int& k);
CmykEncode(int c,int m,int y,int k)85 inline FX_CMYK CmykEncode(int c, int m, int y, int k) {
86 return (c << 24) | (m << 16) | (y << 8) | k;
87 }
88 void ArgbDecode(FX_ARGB argb, int& a, int& r, int& g, int& b);
89 void ArgbDecode(FX_ARGB argb, int& a, FX_COLORREF& rgb);
ArgbEncode(int a,int r,int g,int b)90 inline FX_ARGB ArgbEncode(int a, int r, int g, int b) {
91 return (a << 24) | (r << 16) | (g << 8) | b;
92 }
93 FX_ARGB ArgbEncode(int a, FX_COLORREF rgb);
94 #define FXARGB_A(argb) ((uint8_t)((argb) >> 24))
95 #define FXARGB_R(argb) ((uint8_t)((argb) >> 16))
96 #define FXARGB_G(argb) ((uint8_t)((argb) >> 8))
97 #define FXARGB_B(argb) ((uint8_t)(argb))
98 #define FXARGB_MAKE(a, r, g, b) \
99 (((FX_DWORD)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
100 #define FXARGB_MUL_ALPHA(argb, alpha) \
101 (((((argb) >> 24) * (alpha) / 255) << 24) | ((argb)&0xffffff))
102 #define FXRGB2GRAY(r, g, b) (((b)*11 + (g)*59 + (r)*30) / 100)
103 #define FXCMYK2GRAY(c, m, y, k) \
104 (((255 - (c)) * (255 - (k)) * 30 + (255 - (m)) * (255 - (k)) * 59 + \
105 (255 - (y)) * (255 - (k)) * 11) / \
106 25500)
107 #define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha) \
108 (((backdrop) * (255 - (source_alpha)) + (source) * (source_alpha)) / 255)
109 #define FXDIB_ALPHA_UNION(dest, src) ((dest) + (src) - (dest) * (src) / 255)
110 #define FXCMYK_GETDIB(p) \
111 ((((uint8_t*)(p))[0] << 24 | (((uint8_t*)(p))[1] << 16) | \
112 (((uint8_t*)(p))[2] << 8) | ((uint8_t*)(p))[3]))
113 #define FXCMYK_SETDIB(p, cmyk) ((uint8_t*)(p))[0] = (uint8_t)((cmyk) >> 24), \
114 ((uint8_t*)(p))[1] = (uint8_t)((cmyk) >> 16), \
115 ((uint8_t*)(p))[2] = (uint8_t)((cmyk) >> 8), \
116 ((uint8_t*)(p))[3] = (uint8_t)(cmyk))
117 #define FXARGB_GETDIB(p) \
118 ((((uint8_t*)(p))[0]) | (((uint8_t*)(p))[1] << 8) | \
119 (((uint8_t*)(p))[2] << 16) | (((uint8_t*)(p))[3] << 24))
120 #define FXARGB_SETDIB(p, argb) \
121 ((uint8_t*)(p))[0] = (uint8_t)(argb), \
122 ((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8), \
123 ((uint8_t*)(p))[2] = (uint8_t)((argb) >> 16), \
124 ((uint8_t*)(p))[3] = (uint8_t)((argb) >> 24)
125 #define FXARGB_COPY(dest, src) \
126 *(uint8_t*)(dest) = *(uint8_t*)(src), \
127 *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \
128 *((uint8_t*)(dest) + 2) = *((uint8_t*)(src) + 2), \
129 *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3)
130 #define FXCMYK_COPY(dest, src) \
131 *(uint8_t*)(dest) = *(uint8_t*)(src), \
132 *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \
133 *((uint8_t*)(dest) + 2) = *((uint8_t*)(src) + 2), \
134 *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3)
135 #define FXARGB_SETRGBORDERDIB(p, argb) \
136 ((uint8_t*)(p))[3] = (uint8_t)(argb >> 24), \
137 ((uint8_t*)(p))[0] = (uint8_t)((argb) >> 16), \
138 ((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8), \
139 ((uint8_t*)(p))[2] = (uint8_t)(argb)
140 #define FXARGB_GETRGBORDERDIB(p) \
141 (((uint8_t*)(p))[2]) | (((uint8_t*)(p))[1] << 8) | \
142 (((uint8_t*)(p))[0] << 16) | (((uint8_t*)(p))[3] << 24)
143 #define FXARGB_RGBORDERCOPY(dest, src) \
144 *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3), \
145 *(uint8_t*)(dest) = *((uint8_t*)(src) + 2), \
146 *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \
147 *((uint8_t*)(dest) + 2) = *((uint8_t*)(src))
148 #define FXARGB_TODIB(argb) (argb)
149 #define FXCMYK_TODIB(cmyk) \
150 ((uint8_t)((cmyk) >> 24) | ((uint8_t)((cmyk) >> 16)) << 8 | \
151 ((uint8_t)((cmyk) >> 8)) << 16 | ((uint8_t)(cmyk) << 24))
152 #define FXARGB_TOBGRORDERDIB(argb) \
153 ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 | \
154 ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24))
155 #define FXGETFLAG_COLORTYPE(flag) (uint8_t)((flag) >> 8)
156 #define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag)
157 #define FXGETFLAG_ALPHA_STROKE(flag) (uint8_t)((flag) >> 16)
158 #define FXSETFLAG_COLORTYPE(flag, val) \
159 flag = (((val) << 8) | (flag & 0xffff00ff))
160 #define FXSETFLAG_ALPHA_FILL(flag, val) flag = ((val) | (flag & 0xffffff00))
161 #define FXSETFLAG_ALPHA_STROKE(flag, val) \
162 flag = (((val) << 16) | (flag & 0xff00ffff))
163 class CFX_DIBSource {
164 public:
165 virtual ~CFX_DIBSource();
166
GetWidth()167 int GetWidth() const { return m_Width; }
168
GetHeight()169 int GetHeight() const { return m_Height; }
170
GetFormat()171 FXDIB_Format GetFormat() const {
172 return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp);
173 }
174
GetPitch()175 FX_DWORD GetPitch() const { return m_Pitch; }
176
GetPalette()177 FX_DWORD* GetPalette() const { return m_pPalette; }
178
GetBuffer()179 virtual uint8_t* GetBuffer() const { return NULL; }
180
181 virtual const uint8_t* GetScanline(int line) const = 0;
182
SkipToScanline(int line,IFX_Pause * pPause)183 virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const {
184 return FALSE;
185 }
186
187 virtual void DownSampleScanline(int line,
188 uint8_t* dest_scan,
189 int dest_bpp,
190 int dest_width,
191 FX_BOOL bFlipX,
192 int clip_left,
193 int clip_width) const = 0;
194
SetDownSampleSize(int width,int height)195 virtual void SetDownSampleSize(int width, int height) const {}
196
GetBPP()197 int GetBPP() const { return m_bpp; }
198
199 // TODO(thestig): Investigate this. Given the possible values of FXDIB_Format,
200 // it feels as though this should be implemented as !!(m_AlphaFlag & 1) and
201 // IsOpaqueImage() below should never be able to return TRUE.
IsAlphaMask()202 FX_BOOL IsAlphaMask() const { return m_AlphaFlag == 1; }
203
HasAlpha()204 FX_BOOL HasAlpha() const { return !!(m_AlphaFlag & 2); }
205
IsOpaqueImage()206 FX_BOOL IsOpaqueImage() const { return !(m_AlphaFlag & 3); }
207
IsCmykImage()208 FX_BOOL IsCmykImage() const { return !!(m_AlphaFlag & 4); }
209
GetPaletteSize()210 int GetPaletteSize() const {
211 return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0));
212 }
213
214 FX_DWORD GetPaletteEntry(int index) const;
215
216 void SetPaletteEntry(int index, FX_DWORD color);
GetPaletteArgb(int index)217 FX_DWORD GetPaletteArgb(int index) const { return GetPaletteEntry(index); }
SetPaletteArgb(int index,FX_DWORD color)218 void SetPaletteArgb(int index, FX_DWORD color) {
219 SetPaletteEntry(index, color);
220 }
221
222 void CopyPalette(const FX_DWORD* pSrcPal, FX_DWORD size = 256);
223
224 CFX_DIBitmap* Clone(const FX_RECT* pClip = NULL) const;
225
226 CFX_DIBitmap* CloneConvert(FXDIB_Format format,
227 const FX_RECT* pClip = NULL,
228 void* pIccTransform = NULL) const;
229
230 CFX_DIBitmap* StretchTo(int dest_width,
231 int dest_height,
232 FX_DWORD flags = 0,
233 const FX_RECT* pClip = NULL) const;
234
235 CFX_DIBitmap* TransformTo(const CFX_Matrix* pMatrix,
236 int& left,
237 int& top,
238 FX_DWORD flags = 0,
239 const FX_RECT* pClip = NULL) const;
240
241 CFX_DIBitmap* GetAlphaMask(const FX_RECT* pClip = NULL) const;
242
243 FX_BOOL CopyAlphaMask(const CFX_DIBSource* pAlphaMask,
244 const FX_RECT* pClip = NULL);
245
246 CFX_DIBitmap* SwapXY(FX_BOOL bXFlip,
247 FX_BOOL bYFlip,
248 const FX_RECT* pClip = NULL) const;
249
250 CFX_DIBitmap* FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const;
251
252 void GetOverlapRect(int& dest_left,
253 int& dest_top,
254 int& width,
255 int& height,
256 int src_width,
257 int src_height,
258 int& src_left,
259 int& src_top,
260 const CFX_ClipRgn* pClipRgn);
261
262 CFX_DIBitmap* m_pAlphaMask;
263
264 protected:
265 CFX_DIBSource();
266
267 int m_Width;
268
269 int m_Height;
270
271 int m_bpp;
272
273 FX_DWORD m_AlphaFlag;
274
275 FX_DWORD m_Pitch;
276
277 FX_DWORD* m_pPalette;
278
279 void BuildPalette();
280
281 FX_BOOL BuildAlphaMask();
282
283 int FindPalette(FX_DWORD color) const;
284
285 void GetPalette(FX_DWORD* pal, int alpha) const;
286 };
287 class CFX_DIBitmap : public CFX_DIBSource {
288 public:
289 CFX_DIBitmap();
290 explicit CFX_DIBitmap(const CFX_DIBitmap& src);
291 ~CFX_DIBitmap() override;
292
293 FX_BOOL Create(int width,
294 int height,
295 FXDIB_Format format,
296 uint8_t* pBuffer = NULL,
297 int pitch = 0);
298
299 FX_BOOL Copy(const CFX_DIBSource* pSrc);
300
301 // CFX_DIBSource
GetBuffer()302 uint8_t* GetBuffer() const override { return m_pBuffer; }
GetScanline(int line)303 const uint8_t* GetScanline(int line) const override {
304 return m_pBuffer ? m_pBuffer + line * m_Pitch : NULL;
305 }
306 void DownSampleScanline(int line,
307 uint8_t* dest_scan,
308 int dest_bpp,
309 int dest_width,
310 FX_BOOL bFlipX,
311 int clip_left,
312 int clip_width) const override;
313
314 void TakeOver(CFX_DIBitmap* pSrcBitmap);
315
316 FX_BOOL ConvertFormat(FXDIB_Format format, void* pIccTransform = NULL);
317
318 void Clear(FX_DWORD color);
319
320 FX_DWORD GetPixel(int x, int y) const;
321
322 void SetPixel(int x, int y, FX_DWORD color);
323
324 FX_BOOL LoadChannel(FXDIB_Channel destChannel,
325 const CFX_DIBSource* pSrcBitmap,
326 FXDIB_Channel srcChannel);
327
328 FX_BOOL LoadChannel(FXDIB_Channel destChannel, int value);
329
330 FX_BOOL MultiplyAlpha(int alpha);
331
332 FX_BOOL MultiplyAlpha(const CFX_DIBSource* pAlphaMask);
333
334 FX_BOOL TransferBitmap(int dest_left,
335 int dest_top,
336 int width,
337 int height,
338 const CFX_DIBSource* pSrcBitmap,
339 int src_left,
340 int src_top,
341 void* pIccTransform = NULL);
342
343 FX_BOOL CompositeBitmap(int dest_left,
344 int dest_top,
345 int width,
346 int height,
347 const CFX_DIBSource* pSrcBitmap,
348 int src_left,
349 int src_top,
350 int blend_type = FXDIB_BLEND_NORMAL,
351 const CFX_ClipRgn* pClipRgn = NULL,
352 FX_BOOL bRgbByteOrder = FALSE,
353 void* pIccTransform = NULL);
354
355 FX_BOOL TransferMask(int dest_left,
356 int dest_top,
357 int width,
358 int height,
359 const CFX_DIBSource* pMask,
360 FX_DWORD color,
361 int src_left,
362 int src_top,
363 int alpha_flag = 0,
364 void* pIccTransform = NULL);
365
366 FX_BOOL CompositeMask(int dest_left,
367 int dest_top,
368 int width,
369 int height,
370 const CFX_DIBSource* pMask,
371 FX_DWORD color,
372 int src_left,
373 int src_top,
374 int blend_type = FXDIB_BLEND_NORMAL,
375 const CFX_ClipRgn* pClipRgn = NULL,
376 FX_BOOL bRgbByteOrder = FALSE,
377 int alpha_flag = 0,
378 void* pIccTransform = NULL);
379
380 FX_BOOL CompositeRect(int dest_left,
381 int dest_top,
382 int width,
383 int height,
384 FX_DWORD color,
385 int alpha_flag = 0,
386 void* pIccTransform = NULL);
387
388 FX_BOOL ConvertColorScale(FX_DWORD forecolor, FX_DWORD backcolor);
389
390 FX_BOOL DitherFS(const FX_DWORD* pPalette,
391 int pal_size,
392 const FX_RECT* pRect = NULL);
393
394 protected:
395 uint8_t* m_pBuffer;
396
397 FX_BOOL m_bExtBuf;
398
399 FX_BOOL GetGrayData(void* pIccTransform = NULL);
400 };
401 class CFX_DIBExtractor {
402 public:
403 CFX_DIBExtractor(const CFX_DIBSource* pSrc);
404
405 ~CFX_DIBExtractor();
406
407 operator CFX_DIBitmap*() { return m_pBitmap; }
408
409 private:
410 CFX_DIBitmap* m_pBitmap;
411 };
412
413 typedef CFX_CountRef<CFX_DIBitmap> CFX_DIBitmapRef;
414 class CFX_FilteredDIB : public CFX_DIBSource {
415 public:
416 CFX_FilteredDIB();
417 ~CFX_FilteredDIB() override;
418
419 void LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc = FALSE);
420
421 virtual FXDIB_Format GetDestFormat() = 0;
422
423 virtual FX_DWORD* GetDestPalette() = 0;
424
425 virtual void TranslateScanline(uint8_t* dest_buf,
426 const uint8_t* src_buf) const = 0;
427
428 virtual void TranslateDownSamples(uint8_t* dest_buf,
429 const uint8_t* src_buf,
430 int pixels,
431 int Bpp) const = 0;
432
433 protected:
434 // CFX_DIBSource
435 const uint8_t* GetScanline(int line) const override;
436 void DownSampleScanline(int line,
437 uint8_t* dest_scan,
438 int dest_bpp,
439 int dest_width,
440 FX_BOOL bFlipX,
441 int clip_left,
442 int clip_width) const override;
443
444 const CFX_DIBSource* m_pSrc;
445
446 FX_BOOL m_bAutoDropSrc;
447
448 uint8_t* m_pScanline;
449 };
450
451 class IFX_ScanlineComposer {
452 public:
~IFX_ScanlineComposer()453 virtual ~IFX_ScanlineComposer() {}
454
455 virtual void ComposeScanline(int line,
456 const uint8_t* scanline,
457 const uint8_t* scan_extra_alpha = NULL) = 0;
458
459 virtual FX_BOOL SetInfo(int width,
460 int height,
461 FXDIB_Format src_format,
462 FX_DWORD* pSrcPalette) = 0;
463 };
464 class CFX_ScanlineCompositor {
465 public:
466 CFX_ScanlineCompositor();
467
468 ~CFX_ScanlineCompositor();
469
470 FX_BOOL Init(FXDIB_Format dest_format,
471 FXDIB_Format src_format,
472 int32_t width,
473 FX_DWORD* pSrcPalette,
474 FX_DWORD mask_color,
475 int blend_type,
476 FX_BOOL bClip,
477 FX_BOOL bRgbByteOrder = FALSE,
478 int alpha_flag = 0,
479 void* pIccTransform = NULL);
480
481 void CompositeRgbBitmapLine(uint8_t* dest_scan,
482 const uint8_t* src_scan,
483 int width,
484 const uint8_t* clip_scan,
485 const uint8_t* src_extra_alpha = NULL,
486 uint8_t* dst_extra_alpha = NULL);
487
488 void CompositePalBitmapLine(uint8_t* dest_scan,
489 const uint8_t* src_scan,
490 int src_left,
491 int width,
492 const uint8_t* clip_scan,
493 const uint8_t* src_extra_alpha = NULL,
494 uint8_t* dst_extra_alpha = NULL);
495
496 void CompositeByteMaskLine(uint8_t* dest_scan,
497 const uint8_t* src_scan,
498 int width,
499 const uint8_t* clip_scan,
500 uint8_t* dst_extra_alpha = NULL);
501
502 void CompositeBitMaskLine(uint8_t* dest_scan,
503 const uint8_t* src_scan,
504 int src_left,
505 int width,
506 const uint8_t* clip_scan,
507 uint8_t* dst_extra_alpha = NULL);
508
509 protected:
510 int m_Transparency;
511 FXDIB_Format m_SrcFormat, m_DestFormat;
512 FX_DWORD* m_pSrcPalette;
513
514 int m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, m_MaskBlack;
515 int m_BlendType;
516 void* m_pIccTransform;
517 uint8_t* m_pCacheScanline;
518 int m_CacheSize;
519 FX_BOOL m_bRgbByteOrder;
520 };
521
522 class CFX_BitmapComposer : public IFX_ScanlineComposer {
523 public:
524 CFX_BitmapComposer();
525 ~CFX_BitmapComposer() override;
526
527 void Compose(CFX_DIBitmap* pDest,
528 const CFX_ClipRgn* pClipRgn,
529 int bitmap_alpha,
530 FX_DWORD mask_color,
531 FX_RECT& dest_rect,
532 FX_BOOL bVertical,
533 FX_BOOL bFlipX,
534 FX_BOOL bFlipY,
535 FX_BOOL bRgbByteOrder = FALSE,
536 int alpha_flag = 0,
537 void* pIccTransform = NULL,
538 int blend_type = FXDIB_BLEND_NORMAL);
539
540 // IFX_ScanlineComposer
541 FX_BOOL SetInfo(int width,
542 int height,
543 FXDIB_Format src_format,
544 FX_DWORD* pSrcPalette) override;
545
546 void ComposeScanline(int line,
547 const uint8_t* scanline,
548 const uint8_t* scan_extra_alpha) override;
549
550 protected:
551 void DoCompose(uint8_t* dest_scan,
552 const uint8_t* src_scan,
553 int dest_width,
554 const uint8_t* clip_scan,
555 const uint8_t* src_extra_alpha = NULL,
556 uint8_t* dst_extra_alpha = NULL);
557 CFX_DIBitmap* m_pBitmap;
558 const CFX_ClipRgn* m_pClipRgn;
559 FXDIB_Format m_SrcFormat;
560 int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha;
561 FX_DWORD m_MaskColor;
562 const CFX_DIBitmap* m_pClipMask;
563 CFX_ScanlineCompositor m_Compositor;
564 FX_BOOL m_bVertical, m_bFlipX, m_bFlipY;
565 int m_AlphaFlag;
566 void* m_pIccTransform;
567 FX_BOOL m_bRgbByteOrder;
568 int m_BlendType;
569 void ComposeScanlineV(int line,
570 const uint8_t* scanline,
571 const uint8_t* scan_extra_alpha = NULL);
572 uint8_t* m_pScanlineV;
573 uint8_t* m_pClipScanV;
574 uint8_t* m_pAddClipScan;
575 uint8_t* m_pScanlineAlphaV;
576 };
577
578 class CFX_BitmapStorer : public IFX_ScanlineComposer {
579 public:
580 CFX_BitmapStorer();
581 ~CFX_BitmapStorer() override;
582
583 // IFX_ScanlineComposer
584 void ComposeScanline(int line,
585 const uint8_t* scanline,
586 const uint8_t* scan_extra_alpha) override;
587
588 FX_BOOL SetInfo(int width,
589 int height,
590 FXDIB_Format src_format,
591 FX_DWORD* pSrcPalette) override;
592
GetBitmap()593 CFX_DIBitmap* GetBitmap() { return m_pBitmap; }
594
595 CFX_DIBitmap* Detach();
596
597 void Replace(CFX_DIBitmap* pBitmap);
598
599 private:
600 CFX_DIBitmap* m_pBitmap;
601 };
602
603 class CFX_ImageStretcher {
604 public:
605 CFX_ImageStretcher();
606 ~CFX_ImageStretcher();
607
608 FX_BOOL Start(IFX_ScanlineComposer* pDest,
609 const CFX_DIBSource* pBitmap,
610 int dest_width,
611 int dest_height,
612 const FX_RECT& bitmap_rect,
613 FX_DWORD flags);
614
615 FX_BOOL Continue(IFX_Pause* pPause);
616 FX_BOOL StartQuickStretch();
617 FX_BOOL StartStretch();
618 FX_BOOL ContinueQuickStretch(IFX_Pause* pPause);
619 FX_BOOL ContinueStretch(IFX_Pause* pPause);
620
621 IFX_ScanlineComposer* m_pDest;
622 const CFX_DIBSource* m_pSource;
623 CStretchEngine* m_pStretchEngine;
624 FX_DWORD m_Flags;
625 FX_BOOL m_bFlipX;
626 FX_BOOL m_bFlipY;
627 int m_DestWidth;
628 int m_DestHeight;
629 FX_RECT m_ClipRect;
630 int m_LineIndex;
631 int m_DestBPP;
632 uint8_t* m_pScanline;
633 uint8_t* m_pMaskScanline;
634 FXDIB_Format m_DestFormat;
635 };
636 class CFX_ImageTransformer {
637 public:
638 CFX_ImageTransformer();
639 ~CFX_ImageTransformer();
640
641 FX_BOOL Start(const CFX_DIBSource* pSrc,
642 const CFX_Matrix* pMatrix,
643 int flags,
644 const FX_RECT* pClip);
645
646 FX_BOOL Continue(IFX_Pause* pPause);
647
648 CFX_Matrix* m_pMatrix;
649 FX_RECT m_StretchClip;
650 int m_ResultLeft;
651 int m_ResultTop;
652 int m_ResultWidth;
653 int m_ResultHeight;
654 CFX_Matrix m_dest2stretch;
655 CFX_ImageStretcher m_Stretcher;
656 CFX_BitmapStorer m_Storer;
657 FX_DWORD m_Flags;
658 int m_Status;
659 };
660 class CFX_ImageRenderer {
661 public:
662 CFX_ImageRenderer();
663 ~CFX_ImageRenderer();
664
665 FX_BOOL Start(CFX_DIBitmap* pDevice,
666 const CFX_ClipRgn* pClipRgn,
667 const CFX_DIBSource* pSource,
668 int bitmap_alpha,
669 FX_DWORD mask_color,
670 const CFX_Matrix* pMatrix,
671 FX_DWORD dib_flags,
672 FX_BOOL bRgbByteOrder = FALSE,
673 int alpha_flag = 0,
674 void* pIccTransform = NULL,
675 int blend_type = FXDIB_BLEND_NORMAL);
676
677 FX_BOOL Continue(IFX_Pause* pPause);
678
679 protected:
680 CFX_DIBitmap* m_pDevice;
681 const CFX_ClipRgn* m_pClipRgn;
682 int m_BitmapAlpha;
683 FX_DWORD m_MaskColor;
684 CFX_Matrix m_Matrix;
685 CFX_ImageTransformer* m_pTransformer;
686 CFX_ImageStretcher m_Stretcher;
687 CFX_BitmapComposer m_Composer;
688 int m_Status;
689 FX_RECT m_ClipBox;
690 FX_DWORD m_Flags;
691 int m_AlphaFlag;
692 void* m_pIccTransform;
693 FX_BOOL m_bRgbByteOrder;
694 int m_BlendType;
695 };
696
697 #endif // CORE_INCLUDE_FXGE_FX_DIB_H_
698