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