diff options
Diffstat (limited to 'core/src/fxge/dib')
-rw-r--r-- | core/src/fxge/dib/dib_int.h | 88 | ||||
-rw-r--r-- | core/src/fxge/dib/fx_dib_composite.cpp | 4602 | ||||
-rw-r--r-- | core/src/fxge/dib/fx_dib_convert.cpp | 1090 | ||||
-rw-r--r-- | core/src/fxge/dib/fx_dib_engine.cpp | 867 | ||||
-rw-r--r-- | core/src/fxge/dib/fx_dib_main.cpp | 1734 | ||||
-rw-r--r-- | core/src/fxge/dib/fx_dib_transform.cpp | 797 |
6 files changed, 9178 insertions, 0 deletions
diff --git a/core/src/fxge/dib/dib_int.h b/core/src/fxge/dib/dib_int.h new file mode 100644 index 0000000000..a9d0b027c5 --- /dev/null +++ b/core/src/fxge/dib/dib_int.h @@ -0,0 +1,88 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+class CPDF_FixedMatrix : public CFX_Object
+{
+public:
+ CPDF_FixedMatrix(const CFX_AffineMatrix& src, int bits)
+ {
+ base = 1 << bits;
+ a = FXSYS_round(src.a * base);
+ b = FXSYS_round(src.b * base);
+ c = FXSYS_round(src.c * base);
+ d = FXSYS_round(src.d * base);
+ e = FXSYS_round(src.e * base);
+ f = FXSYS_round(src.f * base);
+ }
+ inline void Transform(int x, int y, int& x1, int& y1)
+ {
+ x1 = (a * x + c * y + e + base / 2) / base;
+ y1 = (b * x + d * y + f + base / 2) / base;
+ }
+ int a, b, c, d, e, f;
+ int base;
+};
+#define FPDF_HUGE_IMAGE_SIZE 60000000
+struct PixelWeight {
+ int m_SrcStart;
+ int m_SrcEnd;
+ int m_Weights[1];
+};
+class CWeightTable : public CFX_Object
+{
+public:
+ CWeightTable()
+ {
+ m_pWeightTables = NULL;
+ }
+ ~CWeightTable()
+ {
+ if(m_pWeightTables) {
+ FX_Free(m_pWeightTables);
+ }
+ m_pWeightTables = NULL;
+ }
+ void Calc(int dest_len, int dest_min, int dest_max, int src_len, int src_min, int src_max, int flags);
+ PixelWeight* GetPixelWeight(int pixel)
+ {
+ return (PixelWeight*)(m_pWeightTables + (pixel - m_DestMin) * m_ItemSize);
+ }
+ int m_DestMin, m_ItemSize;
+ FX_LPBYTE m_pWeightTables;
+};
+class CStretchEngine : public CFX_Object
+{
+public:
+ CStretchEngine(IFX_ScanlineComposer* pDestBitmap, FXDIB_Format dest_format,
+ int dest_width, int dest_height, const FX_RECT& clip_rect,
+ const CFX_DIBSource* pSrcBitmap, int flags);
+ ~CStretchEngine();
+ FX_BOOL Continue(IFX_Pause* pPause);
+public:
+ FXDIB_Format m_DestFormat;
+ int m_DestBpp, m_SrcBpp, m_bHasAlpha;
+ IFX_ScanlineComposer* m_pDestBitmap;
+ int m_DestWidth, m_DestHeight;
+ FX_RECT m_DestClip;
+ FX_LPBYTE m_pDestScanline;
+ FX_LPBYTE m_pDestMaskScanline;
+ FX_RECT m_SrcClip;
+ const CFX_DIBSource* m_pSource;
+ FX_DWORD* m_pSrcPalette;
+ int m_SrcWidth, m_SrcHeight;
+ int m_SrcPitch, m_InterPitch;
+ int m_ExtraMaskPitch;
+ unsigned char* m_pInterBuf;
+ unsigned char* m_pExtraAlphaBuf;
+ int m_TransMethod;
+ int m_Flags;
+ CWeightTable m_WeightTable;
+ int m_CurRow;
+ FX_BOOL StartStretchHorz();
+ FX_BOOL ContinueStretchHorz(IFX_Pause* pPause);
+ void StretchVert();
+ int m_State;
+};
diff --git a/core/src/fxge/dib/fx_dib_composite.cpp b/core/src/fxge/dib/fx_dib_composite.cpp new file mode 100644 index 0000000000..8e9b4912a8 --- /dev/null +++ b/core/src/fxge/dib/fx_dib_composite.cpp @@ -0,0 +1,4602 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../../include/fxge/fx_ge.h"
+#include "../../../include/fxcodec/fx_codec.h"
+#include "dib_int.h"
+const FX_BYTE g_GammaRamp[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7,
+ 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13,
+ 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 17, 18, 18, 19, 19, 20,
+ 20, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 29, 29,
+ 30, 30, 31, 32, 32, 33, 34, 35, 35, 36, 37, 37, 38, 39, 40, 41,
+ 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 51, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
+ 71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88,
+ 90, 91, 92, 93, 95, 96, 97, 99, 100, 101, 103, 104, 105, 107, 108, 109,
+ 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 130, 131, 133,
+ 134, 136, 138, 139, 141, 142, 144, 146, 147, 149, 151, 152, 154, 156, 157, 159,
+ 161, 163, 164, 166, 168, 170, 171, 173, 175, 177, 179, 181, 183, 184, 186, 188,
+ 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220,
+ 222, 224, 226, 229, 231, 233, 235, 237, 239, 242, 244, 246, 248, 250, 253, 255,
+};
+const FX_BYTE g_GammaInverse[256] = {
+ 0, 13, 22, 28, 34, 38, 42, 46, 50, 53, 56, 59, 61, 64, 66, 69,
+ 71, 73, 75, 77, 79, 81, 83, 85, 86, 88, 90, 92, 93, 95, 96, 98,
+ 99, 101, 102, 104, 105, 106, 108, 109, 110, 112, 113, 114, 115, 117, 118, 119,
+ 120, 121, 122, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
+ 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 148, 149, 150, 151,
+ 152, 153, 154, 155, 155, 156, 157, 158, 159, 159, 160, 161, 162, 163, 163, 164,
+ 165, 166, 167, 167, 168, 169, 170, 170, 171, 172, 173, 173, 174, 175, 175, 176,
+ 177, 178, 178, 179, 180, 180, 181, 182, 182, 183, 184, 185, 185, 186, 187, 187,
+ 188, 189, 189, 190, 190, 191, 192, 192, 193, 194, 194, 195, 196, 196, 197, 197,
+ 198, 199, 199, 200, 200, 201, 202, 202, 203, 203, 204, 205, 205, 206, 206, 207,
+ 208, 208, 209, 209, 210, 210, 211, 212, 212, 213, 213, 214, 214, 215, 215, 216,
+ 216, 217, 218, 218, 219, 219, 220, 220, 221, 221, 222, 222, 223, 223, 224, 224,
+ 225, 226, 226, 227, 227, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 233,
+ 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 238, 238, 239, 239, 240, 240,
+ 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, 246, 247, 247, 248,
+ 248, 249, 249, 250, 250, 251, 251, 251, 252, 252, 253, 253, 254, 254, 255, 255,
+};
+const FX_BYTE _color_sqrt[256] = {
+ 0x00, 0x03, 0x07, 0x0B, 0x0F, 0x12, 0x16, 0x19, 0x1D, 0x20, 0x23, 0x26, 0x29, 0x2C, 0x2F, 0x32,
+ 0x35, 0x37, 0x3A, 0x3C, 0x3F, 0x41, 0x43, 0x46, 0x48, 0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56,
+ 0x57, 0x59, 0x5B, 0x5C, 0x5E, 0x60, 0x61, 0x63, 0x64, 0x65, 0x67, 0x68, 0x69, 0x6B, 0x6C, 0x6D,
+ 0x6E, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E,
+ 0x8F, 0x90, 0x91, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C,
+ 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA4, 0xA5, 0xA6, 0xA7, 0xA7, 0xA8,
+ 0xA9, 0xAA, 0xAA, 0xAB, 0xAC, 0xAD, 0xAD, 0xAE, 0xAF, 0xB0, 0xB0, 0xB1, 0xB2, 0xB3, 0xB3, 0xB4,
+ 0xB5, 0xB5, 0xB6, 0xB7, 0xB7, 0xB8, 0xB9, 0xBA, 0xBA, 0xBB, 0xBC, 0xBC, 0xBD, 0xBE, 0xBE, 0xBF,
+ 0xC0, 0xC0, 0xC1, 0xC2, 0xC2, 0xC3, 0xC4, 0xC4, 0xC5, 0xC6, 0xC6, 0xC7, 0xC7, 0xC8, 0xC9, 0xC9,
+ 0xCA, 0xCB, 0xCB, 0xCC, 0xCC, 0xCD, 0xCE, 0xCE, 0xCF, 0xD0, 0xD0, 0xD1, 0xD1, 0xD2, 0xD3, 0xD3,
+ 0xD4, 0xD4, 0xD5, 0xD6, 0xD6, 0xD7, 0xD7, 0xD8, 0xD9, 0xD9, 0xDA, 0xDA, 0xDB, 0xDC, 0xDC, 0xDD,
+ 0xDD, 0xDE, 0xDE, 0xDF, 0xE0, 0xE0, 0xE1, 0xE1, 0xE2, 0xE2, 0xE3, 0xE4, 0xE4, 0xE5, 0xE5, 0xE6,
+ 0xE6, 0xE7, 0xE7, 0xE8, 0xE9, 0xE9, 0xEA, 0xEA, 0xEB, 0xEB, 0xEC, 0xEC, 0xED, 0xED, 0xEE, 0xEE,
+ 0xEF, 0xF0, 0xF0, 0xF1, 0xF1, 0xF2, 0xF2, 0xF3, 0xF3, 0xF4, 0xF4, 0xF5, 0xF5, 0xF6, 0xF6, 0xF7,
+ 0xF7, 0xF8, 0xF8, 0xF9, 0xF9, 0xFA, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC, 0xFD, 0xFD, 0xFE, 0xFE, 0xFF
+};
+int _BLEND(int blend_mode, int back_color, int src_color)
+{
+ switch (blend_mode) {
+ case FXDIB_BLEND_NORMAL:
+ return src_color;
+ case FXDIB_BLEND_MULTIPLY:
+ return src_color * back_color / 255;
+ case FXDIB_BLEND_SCREEN:
+ return src_color + back_color - src_color * back_color / 255;
+ case FXDIB_BLEND_OVERLAY:
+ return _BLEND(FXDIB_BLEND_HARDLIGHT, src_color, back_color);
+ case FXDIB_BLEND_DARKEN:
+ return src_color < back_color ? src_color : back_color;
+ case FXDIB_BLEND_LIGHTEN:
+ return src_color > back_color ? src_color : back_color;
+ case FXDIB_BLEND_COLORDODGE: {
+ if (src_color == 255) {
+ return src_color;
+ }
+ int result = back_color * 255 / (255 - src_color);
+ if (result > 255) {
+ return 255;
+ }
+ return result;
+ }
+ case FXDIB_BLEND_COLORBURN: {
+ if (src_color == 0) {
+ return src_color;
+ }
+ int result = (255 - back_color) * 255 / src_color;
+ if (result > 255) {
+ result = 255;
+ }
+ return 255 - result;
+ }
+ case FXDIB_BLEND_HARDLIGHT:
+ if (src_color < 128) {
+ return (src_color * back_color * 2) / 255;
+ }
+ return _BLEND(FXDIB_BLEND_SCREEN, back_color, 2 * src_color - 255);
+ case FXDIB_BLEND_SOFTLIGHT: {
+ if (src_color < 128) {
+ return back_color - (255 - 2 * src_color) * back_color * (255 - back_color) / 255 / 255;
+ }
+ return back_color + (2 * src_color - 255) * (_color_sqrt[back_color] - back_color) / 255;
+ }
+ case FXDIB_BLEND_DIFFERENCE:
+ return back_color < src_color ? src_color - back_color : back_color - src_color;
+ case FXDIB_BLEND_EXCLUSION:
+ return back_color + src_color - 2 * back_color * src_color / 255;
+ }
+ return src_color;
+}
+struct _RGB {
+ int red;
+ int green;
+ int blue;
+};
+static inline int _Lum(_RGB color)
+{
+ return (color.red * 30 + color.green * 59 + color.blue * 11) / 100;
+}
+static _RGB _ClipColor(_RGB color)
+{
+ int l = _Lum(color);
+ int n = color.red;
+ if (color.green < n) {
+ n = color.green;
+ }
+ if (color.blue < n) {
+ n = color.blue;
+ }
+ int x = color.red;
+ if (color.green > x) {
+ x = color.green;
+ }
+ if (color.blue > x) {
+ x = color.blue;
+ }
+ if (n < 0) {
+ color.red = l + ((color.red - l) * l / (l - n));
+ color.green = l + ((color.green - l) * l / (l - n));
+ color.blue = l + ((color.blue - l) * l / (l - n));
+ }
+ if (x > 255) {
+ color.red = l + ((color.red - l) * (255 - l) / (x - l));
+ color.green = l + ((color.green - l) * (255 - l) / (x - l));
+ color.blue = l + ((color.blue - l) * (255 - l) / (x - l));
+ }
+ return color;
+}
+static _RGB _SetLum(_RGB color, int l)
+{
+ int d = l - _Lum(color);
+ color.red += d;
+ color.green += d;
+ color.blue += d;
+ return _ClipColor(color);
+}
+static int _Sat(_RGB color)
+{
+ int n = color.red;
+ if (color.green < n) {
+ n = color.green;
+ }
+ if (color.blue < n) {
+ n = color.blue;
+ }
+ int x = color.red;
+ if (color.green > x) {
+ x = color.green;
+ }
+ if (color.blue > x) {
+ x = color.blue;
+ }
+ return x - n;
+}
+static _RGB _SetSat(_RGB color, int s)
+{
+ int* max = &color.red;
+ int* mid = &color.red;
+ int* min = &color.red;
+ if (color.green > *max) {
+ max = &color.green;
+ }
+ if (color.blue > *max) {
+ max = &color.blue;
+ }
+ if (color.green < *min) {
+ min = &color.green;
+ }
+ if (color.blue < *min) {
+ min = &color.blue;
+ }
+ if (*max == *min) {
+ color.red = 0;
+ color.green = 0;
+ color.blue = 0;
+ return color;
+ }
+ if (max == &color.red) {
+ if (min == &color.green) {
+ mid = &color.blue;
+ } else {
+ mid = &color.green;
+ }
+ } else if (max == &color.green) {
+ if (min == &color.red) {
+ mid = &color.blue;
+ } else {
+ mid = &color.red;
+ }
+ } else {
+ if (min == &color.green) {
+ mid = &color.red;
+ } else {
+ mid = &color.green;
+ }
+ }
+ if (*max > *min) {
+ *mid = (*mid - *min) * s / (*max - *min);
+ *max = s;
+ *min = 0;
+ }
+ return color;
+}
+void _RGB_Blend(int blend_mode, FX_LPCBYTE src_scan, FX_BYTE* dest_scan, int results[3])
+{
+ _RGB src, back, result;
+ src.red = src_scan[2];
+ src.green = src_scan[1];
+ src.blue = src_scan[0];
+ back.red = dest_scan[2];
+ back.green = dest_scan[1];
+ back.blue = dest_scan[0];
+ switch (blend_mode) {
+ case FXDIB_BLEND_HUE:
+ result = _SetLum(_SetSat(src, _Sat(back)), _Lum(back));
+ break;
+ case FXDIB_BLEND_SATURATION:
+ result = _SetLum(_SetSat(back, _Sat(src)), _Lum(back));
+ break;
+ case FXDIB_BLEND_COLOR:
+ result = _SetLum(src, _Lum(back));
+ break;
+ case FXDIB_BLEND_LUMINOSITY:
+ result = _SetLum(back, _Lum(src));
+ break;
+ }
+ results[0] = result.blue;
+ results[1] = result.green;
+ results[2] = result.red;
+}
+inline void _CompositeRow_Argb2Mask(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int pixel_count, FX_LPCBYTE clip_scan)
+{
+ src_scan += 3;
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha = *src_scan;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ FX_BYTE back_alpha = *dest_scan;
+ if (!back_alpha) {
+ *dest_scan = src_alpha;
+ } else if (src_alpha) {
+ *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ }
+ dest_scan ++;
+ src_scan += 4;
+ }
+}
+void _CompositeRow_Rgba2Mask(FX_LPBYTE dest_scan, FX_LPCBYTE src_alpha_scan, int pixel_count, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ FX_BYTE back_alpha = *dest_scan;
+ if (!back_alpha) {
+ *dest_scan = src_alpha;
+ } else if (src_alpha) {
+ *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ }
+ dest_scan ++;
+ }
+}
+void _CompositeRow_Rgb2Mask(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, FX_LPCBYTE clip_scan)
+{
+ if (clip_scan) {
+ for (int i = 0; i < width; i ++) {
+ *dest_scan = FXDIB_ALPHA_UNION(*dest_scan, *clip_scan);
+ dest_scan ++;
+ clip_scan ++;
+ }
+ } else {
+ FXSYS_memset8(dest_scan, 0xff, width);
+ }
+}
+void _CompositeRow_Argb2Graya(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int pixel_count, int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan, FX_LPBYTE dst_alpha_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = NULL;
+ if (pIccTransform) {
+ pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ }
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ if (src_alpha_scan) {
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE back_alpha = *dst_alpha_scan;
+ if (back_alpha == 0) {
+ int src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ } else {
+ *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dst_alpha_scan = src_alpha;
+ }
+ dest_scan ++;
+ dst_alpha_scan ++;
+ src_scan += 3;
+ continue;
+ }
+ FX_BYTE src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dst_alpha_scan ++;
+ src_scan += 3;
+ continue;
+ }
+ *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
+ int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
+ FX_BYTE gray;
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ dst_alpha_scan++;
+ src_scan += 3;
+ }
+ } else
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE back_alpha = *dst_alpha_scan;
+ if (back_alpha == 0) {
+ int src_alpha = src_scan[3];
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ } else {
+ *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dst_alpha_scan = src_alpha;
+ }
+ dest_scan ++;
+ dst_alpha_scan ++;
+ src_scan += 4;
+ continue;
+ }
+ FX_BYTE src_alpha = src_scan[3];
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dst_alpha_scan ++;
+ src_scan += 4;
+ continue;
+ }
+ *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
+ int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
+ FX_BYTE gray;
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ dst_alpha_scan++;
+ src_scan += 4;
+ }
+ return;
+ }
+ if (src_alpha_scan) {
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE back_alpha = *dst_alpha_scan;
+ if (back_alpha == 0) {
+ int src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ } else {
+ *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dst_alpha_scan = src_alpha;
+ }
+ dest_scan ++;
+ dst_alpha_scan ++;
+ src_scan += 3;
+ continue;
+ }
+ FX_BYTE src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dst_alpha_scan ++;
+ src_scan += 3;
+ continue;
+ }
+ *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
+ int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
+ FX_BYTE gray;
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ dst_alpha_scan++;
+ src_scan += 3;
+ }
+ } else
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE back_alpha = *dst_alpha_scan;
+ if (back_alpha == 0) {
+ int src_alpha = src_scan[3];
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ } else {
+ *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dst_alpha_scan = src_alpha;
+ }
+ dest_scan ++;
+ dst_alpha_scan ++;
+ src_scan += 4;
+ continue;
+ }
+ FX_BYTE src_alpha = src_scan[3];
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dst_alpha_scan ++;
+ src_scan += 4;
+ continue;
+ }
+ *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
+ int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
+ FX_BYTE gray;
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ dst_alpha_scan++;
+ src_scan += 4;
+ }
+}
+inline void _CompositeRow_Argb2Gray(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int pixel_count,
+ int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = NULL;
+ FX_BYTE gray;
+ if (pIccTransform) {
+ pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ }
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ if (src_alpha_scan) {
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+ }
+ dest_scan ++;
+ src_scan += 3;
+ }
+ } else
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha = src_scan[3];
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+ }
+ dest_scan ++;
+ src_scan += 4;
+ }
+ return;
+ }
+ if (src_alpha_scan) {
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+ }
+ dest_scan ++;
+ src_scan += 3;
+ }
+ } else
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha = src_scan[3];
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+ }
+ dest_scan ++;
+ src_scan += 4;
+ }
+}
+inline void _CompositeRow_Rgb2Gray(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_Bpp, int pixel_count,
+ int blend_type, FX_LPCBYTE clip_scan,
+ void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = NULL;
+ FX_BYTE gray;
+ if (pIccTransform) {
+ pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ }
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ for (int col = 0; col < pixel_count; col ++) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ if (clip_scan && clip_scan[col] < 255) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
+ } else {
+ *dest_scan = gray;
+ }
+ dest_scan ++;
+ src_scan += src_Bpp;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ if (clip_scan && clip_scan[col] < 255) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
+ } else {
+ *dest_scan = gray;
+ }
+ dest_scan ++;
+ src_scan += src_Bpp;
+ }
+}
+void _CompositeRow_Rgb2Graya(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_Bpp, int pixel_count,
+ int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = NULL;
+ if (pIccTransform) {
+ pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ }
+ if (blend_type) {
+ int blended_color;
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ for (int col = 0; col < pixel_count; col ++) {
+ int back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ } else {
+ *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ dest_scan ++;
+ dest_alpha_scan++;
+ src_scan += src_Bpp;
+ continue;
+ }
+ int src_alpha = 255;
+ if (clip_scan) {
+ src_alpha = clip_scan[col];
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ src_scan += src_Bpp;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ FX_BYTE gray;
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ src_scan += src_Bpp;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha = 255;
+ if (clip_scan) {
+ src_alpha = clip_scan[col];
+ }
+ if (src_alpha == 255) {
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ } else {
+ *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ dest_scan ++;
+ *dest_alpha_scan++ = 255;
+ src_scan += src_Bpp;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ src_scan += src_Bpp;
+ continue;
+ }
+ int back_alpha = *dest_alpha_scan;
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ FX_BYTE gray;
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ } else {
+ gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ src_scan += src_Bpp;
+ }
+}
+void _CompositeRow_Argb2Argb(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int pixel_count, int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan, FX_LPCBYTE src_alpha_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ if (dest_alpha_scan == NULL) {
+ if (src_alpha_scan == NULL) {
+ FX_BYTE back_alpha = 0;
+ for (int col = 0; col < pixel_count; col ++) {
+ back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ if (clip_scan) {
+ int src_alpha = clip_scan[col] * src_scan[3] / 255;
+ FXARGB_SETDIB(dest_scan, (FXARGB_GETDIB(src_scan) & 0xffffff) | (src_alpha << 24));
+ } else {
+ FXARGB_COPY(dest_scan, src_scan);
+ }
+ dest_scan += 4;
+ src_scan += 4;
+ continue;
+ }
+ FX_BYTE src_alpha;
+ if (clip_scan == NULL) {
+ src_alpha = src_scan[3];
+ } else {
+ src_alpha = clip_scan[col] * src_scan[3] / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan += 4;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ if (blend_type) {
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, *src_scan);
+ blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ } else {
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ if (clip_scan) {
+ int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE((src_alpha << 24), src_scan[2], src_scan[1], *src_scan));
+ } else {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE((*src_alpha_scan << 24), src_scan[2], src_scan[1], *src_scan));
+ }
+ dest_scan += 4;
+ src_scan += 3;
+ src_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE src_alpha;
+ if (clip_scan == NULL) {
+ src_alpha = *src_alpha_scan ++;
+ } else {
+ src_alpha = clip_scan[col] * (*src_alpha_scan ++) / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan += 3;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ if (blend_type) {
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, *src_scan);
+ blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan ++;
+ }
+ }
+ } else {
+ if (src_alpha_scan) {
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ if (clip_scan) {
+ int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
+ *dest_alpha_scan = src_alpha;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ } else {
+ *dest_alpha_scan = *src_alpha_scan;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ }
+ dest_alpha_scan ++;
+ src_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE src_alpha;
+ if (clip_scan == NULL) {
+ src_alpha = *src_alpha_scan ++;
+ } else {
+ src_alpha = clip_scan[col] * (*src_alpha_scan ++) / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ src_scan += 3;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ if (blend_type) {
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, *src_scan);
+ blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ }
+ } else {
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ if (clip_scan) {
+ int src_alpha = clip_scan[col] * src_scan[3] / 255;
+ *dest_alpha_scan = src_alpha;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ } else {
+ *dest_alpha_scan = src_scan[3];
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ }
+ dest_alpha_scan ++;
+ src_scan ++;
+ continue;
+ }
+ FX_BYTE src_alpha;
+ if (clip_scan == NULL) {
+ src_alpha = src_scan[3];
+ } else {
+ src_alpha = clip_scan[col] * src_scan[3] / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ src_scan += 4;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ if (blend_type) {
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, *src_scan);
+ blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ src_scan ++;
+ }
+ }
+ }
+}
+void _CompositeRow_Rgb2Argb_Blend_NoClip(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int src_Bpp,
+ FX_LPBYTE dest_alpha_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int src_gap = src_Bpp - 3;
+ if (dest_alpha_scan == NULL) {
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ if (src_Bpp == 4) {
+ FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
+ } else {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_scan[1], src_scan[0]));
+ }
+ dest_scan += 4;
+ src_scan += src_Bpp;
+ continue;
+ }
+ dest_scan[3] = 0xff;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int src_color = *src_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, src_color);
+ *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan ++;
+ src_scan += src_gap;
+ }
+ } else {
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_alpha_scan++ = 0xff;
+ src_scan += src_gap;
+ continue;
+ }
+ *dest_alpha_scan++ = 0xff;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int src_color = *src_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, src_color);
+ *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
+ dest_scan ++;
+ src_scan ++;
+ }
+ src_scan += src_gap;
+ }
+ }
+}
+inline void _CompositeRow_Rgb2Argb_Blend_Clip(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int src_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int src_gap = src_Bpp - 3;
+ if (dest_alpha_scan == NULL) {
+ for (int col = 0; col < width; col ++) {
+ int src_alpha = *clip_scan ++;
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ src_scan += src_gap;
+ dest_scan ++;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan += src_Bpp;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int src_color = *src_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, src_color);
+ blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan ++;
+ src_scan += src_gap;
+ }
+ } else {
+ for (int col = 0; col < width; col ++) {
+ int src_alpha = *clip_scan ++;
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ src_scan += src_gap;
+ dest_alpha_scan++;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ dest_alpha_scan++;
+ src_scan += src_Bpp;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int src_color = *src_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, src_color);
+ blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ src_scan ++;
+ }
+ src_scan += src_gap;
+ }
+ }
+}
+inline void _CompositeRow_Rgb2Argb_NoBlend_Clip(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int src_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan)
+{
+ int src_gap = src_Bpp - 3;
+ if (dest_alpha_scan == NULL) {
+ for (int col = 0; col < width; col ++) {
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 255) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = 255;
+ src_scan += src_gap;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan += src_Bpp;
+ continue;
+ }
+ int back_alpha = dest_scan[3];
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ for (int color = 0; color < 3; color ++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan ++;
+ src_scan += src_gap;
+ }
+ } else {
+ for (int col = 0; col < width; col ++) {
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 255) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_alpha_scan++ = 255;
+ src_scan += src_gap;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ dest_alpha_scan ++;
+ src_scan += src_Bpp;
+ continue;
+ }
+ int back_alpha = *dest_alpha_scan;
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ for (int color = 0; color < 3; color ++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
+ dest_scan ++;
+ src_scan ++;
+ }
+ src_scan += src_gap;
+ }
+ }
+}
+inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int src_Bpp,
+ FX_LPBYTE dest_alpha_scan)
+{
+ if (dest_alpha_scan == NULL) {
+ for (int col = 0; col < width; col ++) {
+ if (src_Bpp == 4) {
+ FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
+ } else {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_scan[1], src_scan[0]));
+ }
+ dest_scan += 4;
+ src_scan += src_Bpp;
+ }
+ } else {
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_alpha_scan++ = 0xff;
+ src_scan += src_gap;
+ }
+ }
+}
+inline void _CompositeRow_Argb2Rgb_Blend(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int dest_gap = dest_Bpp - 3;
+ if (src_alpha_scan == NULL) {
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE src_alpha;
+ if (clip_scan) {
+ src_alpha = src_scan[3] * (*clip_scan++) / 255;
+ } else {
+ src_alpha = src_scan[3];
+ }
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_scan += 4;
+ continue;
+ }
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int back_color = *dest_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, back_color, *src_scan);
+ *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan += dest_gap;
+ src_scan ++;
+ }
+ } else {
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE src_alpha;
+ if (clip_scan) {
+ src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
+ } else {
+ src_alpha = *src_alpha_scan++;
+ }
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_scan += 3;
+ continue;
+ }
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int back_color = *dest_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, back_color, *src_scan);
+ *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan += dest_gap;
+ }
+ }
+}
+inline void _CompositeRow_Argb2Rgb_NoBlend(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan)
+{
+ int dest_gap = dest_Bpp - 3;
+ if (src_alpha_scan == NULL) {
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE src_alpha;
+ if (clip_scan) {
+ src_alpha = src_scan[3] * (*clip_scan++) / 255;
+ } else {
+ src_alpha = src_scan[3];
+ }
+ if (src_alpha == 255) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ dest_scan += dest_gap;
+ src_scan ++;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_scan += 4;
+ continue;
+ }
+ for (int color = 0; color < 3; color ++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan += dest_gap;
+ src_scan ++;
+ }
+ } else {
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE src_alpha;
+ if (clip_scan) {
+ src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
+ } else {
+ src_alpha = *src_alpha_scan++;
+ }
+ if (src_alpha == 255) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ dest_scan += dest_gap;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_scan += 3;
+ continue;
+ }
+ for (int color = 0; color < 3; color ++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan += dest_gap;
+ }
+ }
+}
+inline void _CompositeRow_Rgb2Rgb_Blend_NoClip(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int dest_gap = dest_Bpp - 3;
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int back_color = *dest_scan;
+ int src_color = *src_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, back_color, src_color);
+ *dest_scan = blended;
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan += dest_gap;
+ src_scan += src_gap;
+ }
+}
+inline void _CompositeRow_Rgb2Rgb_Blend_Clip(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp, FX_LPCBYTE clip_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int dest_gap = dest_Bpp - 3;
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE src_alpha = *clip_scan ++;
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_scan += src_Bpp;
+ continue;
+ }
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int src_color = *src_scan;
+ int back_color = *dest_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, back_color, src_color);
+ *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
+ dest_scan ++;
+ src_scan ++;
+ }
+ dest_scan += dest_gap;
+ src_scan += src_gap;
+ }
+}
+inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, int src_Bpp)
+{
+ if (dest_Bpp == src_Bpp) {
+ FXSYS_memcpy32(dest_scan, src_scan, width * dest_Bpp);
+ return;
+ }
+ for (int col = 0; col < width; col ++) {
+ dest_scan[0] = src_scan[0];
+ dest_scan[1] = src_scan[1];
+ dest_scan[2] = src_scan[2];
+ dest_scan += dest_Bpp;
+ src_scan += src_Bpp;
+ }
+}
+inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, int src_Bpp, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < width; col ++) {
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 255) {
+ dest_scan[0] = src_scan[0];
+ dest_scan[1] = src_scan[1];
+ dest_scan[2] = src_scan[2];
+ } else if (src_alpha) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
+ dest_scan ++;
+ src_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
+ dest_scan ++;
+ src_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
+ dest_scan += dest_Bpp - 2;
+ src_scan += src_Bpp - 2;
+ continue;
+ }
+ dest_scan += dest_Bpp;
+ src_scan += src_Bpp;
+ }
+}
+void _CompositeRow_Argb2Argb_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int pixel_count, int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan, FX_LPCBYTE src_alpha_scan, FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ FX_LPBYTE dp = src_cache_scan;
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_alpha_scan) {
+ if (dest_alpha_scan == NULL) {
+ for (int col = 0; col < pixel_count; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ dp[3] = *src_alpha_scan++;
+ src_scan += 3;
+ dp += 4;
+ }
+ src_alpha_scan = NULL;
+ } else {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, pixel_count);
+ }
+ } else {
+ if (dest_alpha_scan == NULL) {
+ for (int col = 0; col < pixel_count; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ dp[3] = src_scan[3];
+ src_scan += 4;
+ dp += 4;
+ }
+ } else {
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ for (int col = 0; col < pixel_count; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, 1);
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ if (clip_scan) {
+ int src_alpha = clip_scan[col] * src_scan[3] / 255;
+ *dest_alpha_scan = src_alpha;
+ *dest_scan++ = *src_cache_scan++;
+ *dest_scan++ = *src_cache_scan++;
+ *dest_scan++ = *src_cache_scan++;
+ } else {
+ *dest_alpha_scan = src_scan[3];
+ *dest_scan++ = *src_cache_scan++;
+ *dest_scan++ = *src_cache_scan++;
+ *dest_scan++ = *src_cache_scan++;
+ }
+ dest_alpha_scan ++;
+ src_scan += 4;
+ continue;
+ }
+ FX_BYTE src_alpha;
+ if (clip_scan == NULL) {
+ src_alpha = src_scan[3];
+ } else {
+ src_alpha = clip_scan[col] * src_scan[3] / 255;
+ }
+ src_scan += 4;
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ src_cache_scan += 3;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_cache_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ if (blend_type) {
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, *dest_scan, *src_cache_scan);
+ blended = FXDIB_ALPHA_MERGE(*src_cache_scan, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_cache_scan, alpha_ratio);
+ }
+ dest_scan ++;
+ src_cache_scan ++;
+ }
+ }
+ return;
+ }
+ }
+ _CompositeRow_Argb2Argb(dest_scan, src_cache_scan, pixel_count, blend_type, clip_scan, dest_alpha_scan, src_alpha_scan);
+}
+void _CompositeRow_Rgb2Argb_Blend_NoClip_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int src_Bpp,
+ FX_LPBYTE dest_alpha_scan, FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_Bpp == 3) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ FX_LPBYTE dp = src_cache_scan;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ src_scan += 4;
+ dp += 3;
+ }
+ }
+ _CompositeRow_Rgb2Argb_Blend_NoClip(dest_scan, src_cache_scan, width, blend_type, 3, dest_alpha_scan);
+}
+inline void _CompositeRow_Rgb2Argb_Blend_Clip_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int src_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan, FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_Bpp == 3) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ FX_LPBYTE dp = src_cache_scan;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ src_scan += 4;
+ dp += 3;
+ }
+ }
+ _CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_cache_scan, width, blend_type, 3, clip_scan, dest_alpha_scan);
+}
+inline void _CompositeRow_Rgb2Argb_NoBlend_Clip_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int src_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan, FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_Bpp == 3) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ FX_LPBYTE dp = src_cache_scan;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ src_scan += 4;
+ dp += 3;
+ }
+ }
+ _CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_cache_scan, width, 3, clip_scan, dest_alpha_scan);
+}
+inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int src_Bpp,
+ FX_LPBYTE dest_alpha_scan, FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_Bpp == 3) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ FX_LPBYTE dp = src_cache_scan;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ src_scan += 4;
+ dp += 3;
+ }
+ }
+ _CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_cache_scan, width, 3, dest_alpha_scan);
+}
+inline void _CompositeRow_Argb2Rgb_Blend_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan, FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_alpha_scan) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int dest_gap = dest_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, 1);
+ FX_BYTE src_alpha;
+ if (clip_scan) {
+ src_alpha = src_scan[3] * (*clip_scan++) / 255;
+ } else {
+ src_alpha = src_scan[3];
+ }
+ src_scan += 4;
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_cache_scan += 3;
+ continue;
+ }
+ if (bNonseparableBlend) {
+ _RGB_Blend(blend_type, src_cache_scan, dest_scan, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int back_color = *dest_scan;
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, back_color, *src_cache_scan);
+ *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
+ dest_scan ++;
+ src_cache_scan ++;
+ }
+ dest_scan += dest_gap;
+ }
+ return;
+ }
+ _CompositeRow_Argb2Rgb_Blend(dest_scan, src_cache_scan, width, blend_type, dest_Bpp, clip_scan, src_alpha_scan);
+}
+inline void _CompositeRow_Argb2Rgb_NoBlend_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan, FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_alpha_scan) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ int dest_gap = dest_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, 1);
+ FX_BYTE src_alpha;
+ if (clip_scan) {
+ src_alpha = src_scan[3] * (*clip_scan++) / 255;
+ } else {
+ src_alpha = src_scan[3];
+ }
+ src_scan += 4;
+ if (src_alpha == 255) {
+ *dest_scan++ = *src_cache_scan++;
+ *dest_scan++ = *src_cache_scan++;
+ *dest_scan++ = *src_cache_scan++;
+ dest_scan += dest_gap;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_cache_scan += 3;
+ continue;
+ }
+ for (int color = 0; color < 3; color ++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_cache_scan, src_alpha);
+ dest_scan ++;
+ src_cache_scan ++;
+ }
+ dest_scan += dest_gap;
+ }
+ return;
+ }
+ _CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_cache_scan, width, dest_Bpp, clip_scan, src_alpha_scan);
+}
+inline void _CompositeRow_Rgb2Rgb_Blend_NoClip_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp,
+ FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_Bpp == 3) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ FX_LPBYTE dp = src_cache_scan;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ src_scan += 4;
+ dp += 3;
+ }
+ }
+ _CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_cache_scan, width, blend_type, dest_Bpp, 3);
+}
+inline void _CompositeRow_Rgb2Rgb_Blend_Clip_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_Bpp == 3) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ FX_LPBYTE dp = src_cache_scan;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ src_scan += 4;
+ dp += 3;
+ }
+ }
+ _CompositeRow_Rgb2Rgb_Blend_Clip(dest_scan, src_cache_scan, width, blend_type, dest_Bpp, 3, clip_scan);
+}
+inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, int src_Bpp,
+ FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_Bpp == 3) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ FX_LPBYTE dp = src_cache_scan;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ src_scan += 4;
+ dp += 3;
+ }
+ }
+ _CompositeRow_Rgb2Rgb_NoBlend_NoClip(dest_scan, src_cache_scan, width, dest_Bpp, 3);
+}
+inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip_Transform(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, int src_Bpp, FX_LPCBYTE clip_scan,
+ FX_LPBYTE src_cache_scan, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (src_Bpp == 3) {
+ pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, width);
+ } else {
+ FX_LPBYTE dp = src_cache_scan;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
+ src_scan += 4;
+ dp += 3;
+ }
+ }
+ _CompositeRow_Rgb2Rgb_NoBlend_Clip(dest_scan, src_cache_scan, width, dest_Bpp, 3, clip_scan);
+}
+inline void _CompositeRow_8bppPal2Gray(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, FX_LPCBYTE pPalette, int pixel_count,
+ int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan)
+{
+ if (src_alpha_scan) {
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = pPalette[*src_scan];
+ int src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ if (src_alpha) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+ } else {
+ *dest_scan = gray;
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = pPalette[*src_scan];
+ int src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+ } else {
+ *dest_scan = gray;
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ } else {
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = pPalette[*src_scan];
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ if (clip_scan && clip_scan[col] < 255) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
+ } else {
+ *dest_scan = gray;
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = pPalette[*src_scan];
+ if (clip_scan && clip_scan[col] < 255) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
+ } else {
+ *dest_scan = gray;
+ }
+ dest_scan ++;
+ src_scan ++;
+ }
+ }
+}
+inline void _CompositeRow_8bppPal2Graya(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, FX_LPCBYTE pPalette, int pixel_count,
+ int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan, FX_LPCBYTE src_alpha_scan)
+{
+ if (src_alpha_scan) {
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = pPalette[*src_scan];
+ src_scan ++;
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ int src_alpha = *src_alpha_scan ++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ *dest_scan = gray;
+ *dest_alpha_scan = src_alpha;
+ }
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ *dest_alpha_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ int alpha_ratio = src_alpha * 255 / (*dest_alpha_scan);
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_alpha_scan ++;
+ dest_scan ++;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = pPalette[*src_scan];
+ src_scan ++;
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ int src_alpha = *src_alpha_scan ++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha) {
+ *dest_scan = gray;
+ *dest_alpha_scan = src_alpha;
+ }
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE src_alpha = *src_alpha_scan++;
+ if (clip_scan) {
+ src_alpha = clip_scan[col] * src_alpha / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ *dest_alpha_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ int alpha_ratio = src_alpha * 255 / (*dest_alpha_scan);
+ dest_alpha_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ }
+ } else {
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = pPalette[*src_scan];
+ src_scan ++;
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ *dest_scan++ = gray;
+ *dest_alpha_scan++ = 255;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ int back_alpha = *dest_alpha_scan;
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = pPalette[*src_scan];
+ src_scan ++;
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ *dest_scan++ = gray;
+ *dest_alpha_scan++ = 255;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ int back_alpha = *dest_alpha_scan;
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ }
+ }
+}
+inline void _CompositeRow_1bppPal2Gray(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left,
+ FX_LPCBYTE pPalette, int pixel_count, int blend_type, FX_LPCBYTE clip_scan)
+{
+ int reset_gray = pPalette[0];
+ int set_gray = pPalette[1];
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) ? set_gray : reset_gray;
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ if (clip_scan && clip_scan[col] < 255) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
+ } else {
+ *dest_scan = gray;
+ }
+ dest_scan ++;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) ? set_gray : reset_gray;
+ if (clip_scan && clip_scan[col] < 255) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
+ } else {
+ *dest_scan = gray;
+ }
+ dest_scan ++;
+ }
+}
+inline void _CompositeRow_1bppPal2Graya(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left,
+ FX_LPCBYTE pPalette, int pixel_count, int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan)
+{
+ int reset_gray = pPalette[0];
+ int set_gray = pPalette[1];
+ if (blend_type) {
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int blended_color;
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) ? set_gray : reset_gray;
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ *dest_scan++ = gray;
+ *dest_alpha_scan ++ = 255;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ int back_alpha = *dest_alpha_scan;
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ }
+ gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest_scan, gray);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) ? set_gray : reset_gray;
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ *dest_scan++ = gray;
+ *dest_alpha_scan ++ = 255;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ int back_alpha = *dest_alpha_scan;
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ dest_scan ++;
+ }
+}
+inline void _CompositeRow_8bppRgb2Rgb_NoBlend(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, FX_DWORD* pPalette, int pixel_count,
+ int DestBpp, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan)
+{
+ if (src_alpha_scan) {
+ int dest_gap = DestBpp - 3;
+ FX_ARGB argb = 0;
+ for (int col = 0; col < pixel_count; col ++) {
+ argb = pPalette[*src_scan];
+ int src_r = FXARGB_R(argb);
+ int src_g = FXARGB_G(argb);
+ int src_b = FXARGB_B(argb);
+ src_scan ++;
+ FX_BYTE src_alpha = 0;
+ if (clip_scan) {
+ src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
+ } else {
+ src_alpha = *src_alpha_scan++;
+ }
+ if (src_alpha == 255) {
+ *dest_scan++ = src_b;
+ *dest_scan++ = src_g;
+ *dest_scan++ = src_r;
+ dest_scan += dest_gap;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += DestBpp;
+ continue;
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
+ dest_scan ++;
+ dest_scan += dest_gap;
+ }
+ } else {
+ FX_ARGB argb = 0;
+ for (int col = 0; col < pixel_count; col ++) {
+ argb = pPalette[*src_scan];
+ int src_r = FXARGB_R(argb);
+ int src_g = FXARGB_G(argb);
+ int src_b = FXARGB_B(argb);
+ if (clip_scan && clip_scan[col] < 255) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, clip_scan[col]);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, clip_scan[col]);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, clip_scan[col]);
+ dest_scan ++;
+ } else {
+ *dest_scan++ = src_b;
+ *dest_scan++ = src_g;
+ *dest_scan++ = src_r;
+ }
+ if (DestBpp == 4) {
+ dest_scan++;
+ }
+ src_scan ++;
+ }
+ }
+}
+inline void _CompositeRow_1bppRgb2Rgb_NoBlend(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left,
+ FX_DWORD* pPalette, int pixel_count, int DestBpp, FX_LPCBYTE clip_scan)
+{
+ int reset_r, reset_g, reset_b;
+ int set_r, set_g, set_b;
+ reset_r = FXARGB_R(pPalette[0]);
+ reset_g = FXARGB_G(pPalette[0]);
+ reset_b = FXARGB_B(pPalette[0]);
+ set_r = FXARGB_R(pPalette[1]);
+ set_g = FXARGB_G(pPalette[1]);
+ set_b = FXARGB_B(pPalette[1]);
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_r, src_g, src_b;
+ if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
+ src_r = set_r;
+ src_g = set_g;
+ src_b = set_b;
+ } else {
+ src_r = reset_r;
+ src_g = reset_g;
+ src_b = reset_b;
+ }
+ if (clip_scan && clip_scan[col] < 255) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, clip_scan[col]);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, clip_scan[col]);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, clip_scan[col]);
+ dest_scan ++;
+ } else {
+ *dest_scan++ = src_b;
+ *dest_scan++ = src_g;
+ *dest_scan++ = src_r;
+ }
+ if (DestBpp == 4) {
+ dest_scan++;
+ }
+ }
+}
+inline void _CompositeRow_8bppRgb2Argb_NoBlend(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width,
+ FX_DWORD* pPalette, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_alpha_scan)
+{
+ if (src_alpha_scan) {
+ for (int col = 0; col < width; col ++) {
+ FX_ARGB argb = pPalette[*src_scan];
+ src_scan ++;
+ int src_r = FXARGB_R(argb);
+ int src_g = FXARGB_G(argb);
+ int src_b = FXARGB_B(argb);
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ if (clip_scan) {
+ int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
+ } else {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(*src_alpha_scan, src_r, src_g, src_b));
+ }
+ dest_scan += 4;
+ src_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE src_alpha;
+ if (clip_scan == NULL) {
+ src_alpha = *src_alpha_scan ++;
+ } else {
+ src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ dest_scan ++;
+ dest_scan ++;
+ }
+ } else
+ for (int col = 0; col < width; col ++) {
+ FX_ARGB argb = pPalette[*src_scan];
+ int src_r = FXARGB_R(argb);
+ int src_g = FXARGB_G(argb);
+ int src_b = FXARGB_B(argb);
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ *dest_scan++ = src_b;
+ *dest_scan++ = src_g;
+ *dest_scan++ = src_r;
+ *dest_scan++ = 255;
+ src_scan ++;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan ++;
+ continue;
+ }
+ int back_alpha = dest_scan[3];
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ dest_scan ++;
+ dest_scan ++;
+ src_scan ++;
+ }
+}
+void _CompositeRow_8bppRgb2Rgba_NoBlend(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width,
+ FX_DWORD* pPalette, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan, FX_LPCBYTE src_alpha_scan)
+{
+ if (src_alpha_scan) {
+ for (int col = 0; col < width; col ++) {
+ FX_ARGB argb = pPalette[*src_scan];
+ src_scan ++;
+ int src_r = FXARGB_R(argb);
+ int src_g = FXARGB_G(argb);
+ int src_b = FXARGB_B(argb);
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ if (clip_scan) {
+ int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
+ *dest_alpha_scan ++ = src_alpha;
+ } else {
+ *dest_alpha_scan ++ = *src_alpha_scan;
+ }
+ *dest_scan ++ = src_b;
+ *dest_scan ++ = src_g;
+ *dest_scan ++ = src_r;
+ src_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE src_alpha;
+ if (clip_scan == NULL) {
+ src_alpha = *src_alpha_scan++;
+ } else {
+ src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ dest_scan ++;
+ }
+ } else
+ for (int col = 0; col < width; col ++) {
+ FX_ARGB argb = pPalette[*src_scan];
+ int src_r = FXARGB_R(argb);
+ int src_g = FXARGB_G(argb);
+ int src_b = FXARGB_B(argb);
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ *dest_scan++ = src_b;
+ *dest_scan++ = src_g;
+ *dest_scan++ = src_r;
+ *dest_alpha_scan++ = 255;
+ src_scan ++;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ dest_alpha_scan ++;
+ src_scan ++;
+ continue;
+ }
+ int back_alpha = *dest_alpha_scan;
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ dest_scan ++;
+ src_scan ++;
+ }
+}
+inline void _CompositeRow_1bppRgb2Argb_NoBlend(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width,
+ FX_DWORD* pPalette, FX_LPCBYTE clip_scan)
+{
+ int reset_r, reset_g, reset_b;
+ int set_r, set_g, set_b;
+ reset_r = FXARGB_R(pPalette[0]);
+ reset_g = FXARGB_G(pPalette[0]);
+ reset_b = FXARGB_B(pPalette[0]);
+ set_r = FXARGB_R(pPalette[1]);
+ set_g = FXARGB_G(pPalette[1]);
+ set_b = FXARGB_B(pPalette[1]);
+ for (int col = 0; col < width; col ++) {
+ int src_r, src_g, src_b;
+ if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
+ src_r = set_r;
+ src_g = set_g;
+ src_b = set_b;
+ } else {
+ src_r = reset_r;
+ src_g = reset_g;
+ src_b = reset_b;
+ }
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ *dest_scan++ = src_b;
+ *dest_scan++ = src_g;
+ *dest_scan++ = src_r;
+ *dest_scan++ = 255;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ continue;
+ }
+ int back_alpha = dest_scan[3];
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ dest_scan ++;
+ dest_scan ++;
+ }
+}
+void _CompositeRow_1bppRgb2Rgba_NoBlend(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width,
+ FX_DWORD* pPalette, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan)
+{
+ int reset_r, reset_g, reset_b;
+ int set_r, set_g, set_b;
+ reset_r = FXARGB_R(pPalette[0]);
+ reset_g = FXARGB_G(pPalette[0]);
+ reset_b = FXARGB_B(pPalette[0]);
+ set_r = FXARGB_R(pPalette[1]);
+ set_g = FXARGB_G(pPalette[1]);
+ set_b = FXARGB_B(pPalette[1]);
+ for (int col = 0; col < width; col ++) {
+ int src_r, src_g, src_b;
+ if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
+ src_r = set_r;
+ src_g = set_g;
+ src_b = set_b;
+ } else {
+ src_r = reset_r;
+ src_g = reset_g;
+ src_b = reset_b;
+ }
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ *dest_scan++ = src_b;
+ *dest_scan++ = src_g;
+ *dest_scan++ = src_r;
+ *dest_alpha_scan++ = 255;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ dest_alpha_scan ++;
+ continue;
+ }
+ int back_alpha = *dest_alpha_scan;
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ dest_scan ++;
+ }
+}
+void _CompositeRow_ByteMask2Argb(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
+ int blend_type, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
+ } else {
+ src_alpha = mask_alpha * src_scan[col] / 255;
+ }
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
+ dest_scan += 4;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ratio);
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, *dest_scan, src_b);
+ blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_g);
+ blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_r);
+ blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ }
+ dest_scan += 2;
+ }
+}
+void _CompositeRow_ByteMask2Rgba(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
+ int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
+ } else {
+ src_alpha = mask_alpha * src_scan[col] / 255;
+ }
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ *dest_scan ++ = src_b;
+ *dest_scan ++ = src_g;
+ *dest_scan ++ = src_r;
+ *dest_alpha_scan ++ = src_alpha;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 3;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ratio);
+ dest_scan ++;
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, *dest_scan, src_b);
+ blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_g);
+ blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_r);
+ blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ dest_scan ++;
+ }
+ }
+}
+void _CompositeRow_ByteMask2Rgb(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
+ int blend_type, int Bpp, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
+ } else {
+ src_alpha = mask_alpha * src_scan[col] / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += Bpp;
+ continue;
+ }
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], src_alpha);
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, *dest_scan, src_b);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_g);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_r);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
+ }
+ dest_scan += Bpp - 2;
+ }
+}
+void _CompositeRow_ByteMask2Mask(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int pixel_count,
+ FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
+ } else {
+ src_alpha = mask_alpha * src_scan[col] / 255;
+ }
+ FX_BYTE back_alpha = *dest_scan;
+ if (!back_alpha) {
+ *dest_scan = src_alpha;
+ } else if (src_alpha) {
+ *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ }
+ dest_scan ++;
+ }
+}
+void _CompositeRow_ByteMask2Gray(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_gray,
+ int pixel_count, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
+ } else {
+ src_alpha = mask_alpha * src_scan[col] / 255;
+ }
+ if (src_alpha) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, src_alpha);
+ }
+ dest_scan ++;
+ }
+}
+void _CompositeRow_ByteMask2Graya(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_gray,
+ int pixel_count, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
+ } else {
+ src_alpha = mask_alpha * src_scan[col] / 255;
+ }
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ *dest_scan ++ = src_gray;
+ *dest_alpha_scan ++ = src_alpha;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, alpha_ratio);
+ dest_scan ++;
+ }
+}
+void _CompositeRow_BitMask2Argb(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b,
+ int src_left, int pixel_count, int blend_type, FX_LPCBYTE clip_scan)
+{
+ if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 255) {
+ FX_ARGB argb = FXARGB_MAKE(0xff, src_r, src_g, src_b);
+ for (int col = 0; col < pixel_count; col ++) {
+ if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
+ FXARGB_SETDIB(dest_scan, argb);
+ }
+ dest_scan += 4;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
+ dest_scan += 4;
+ continue;
+ }
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] / 255;
+ } else {
+ src_alpha = mask_alpha;
+ }
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
+ dest_scan += 4;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ratio);
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, *dest_scan, src_b);
+ blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_g);
+ blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_r);
+ blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ }
+ dest_scan += 2;
+ }
+}
+void _CompositeRow_BitMask2Rgba(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b,
+ int src_left, int pixel_count, int blend_type, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan)
+{
+ if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 255) {
+ for (int col = 0; col < pixel_count; col ++) {
+ if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
+ dest_scan[0] = src_b;
+ dest_scan[1] = src_g;
+ dest_scan[2] = src_r;
+ *dest_alpha_scan = mask_alpha;
+ }
+ dest_scan += 3;
+ dest_alpha_scan ++;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
+ dest_scan += 3;
+ dest_alpha_scan ++;
+ continue;
+ }
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] / 255;
+ } else {
+ src_alpha = mask_alpha;
+ }
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ *dest_scan ++ = src_b;
+ *dest_scan ++ = src_g;
+ *dest_scan ++ = src_r;
+ *dest_alpha_scan ++ = mask_alpha;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ratio);
+ dest_scan ++;
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, *dest_scan, src_b);
+ blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_g);
+ blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ blended = _BLEND(blend_type, *dest_scan, src_r);
+ blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ dest_scan ++;
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+ dest_scan ++;
+ }
+ }
+}
+void _CompositeRow_BitMask2Rgb(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b,
+ int src_left, int pixel_count, int blend_type, int Bpp, FX_LPCBYTE clip_scan)
+{
+ if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 255) {
+ for (int col = 0; col < pixel_count; col ++) {
+ if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
+ dest_scan[2] = src_r;
+ dest_scan[1] = src_g;
+ dest_scan[0] = src_b;
+ }
+ dest_scan += Bpp;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
+ dest_scan += Bpp;
+ continue;
+ }
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] / 255;
+ } else {
+ src_alpha = mask_alpha;
+ }
+ if (src_alpha == 0) {
+ dest_scan += Bpp;
+ continue;
+ }
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], src_alpha);
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, *dest_scan, src_b);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
+ dest_scan++;
+ blended = _BLEND(blend_type, *dest_scan, src_g);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
+ dest_scan++;
+ blended = _BLEND(blend_type, *dest_scan, src_r);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
+ }
+ dest_scan += Bpp - 2;
+ }
+}
+void _CompositeRow_BitMask2Mask(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_left,
+ int pixel_count, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
+ dest_scan ++;
+ continue;
+ }
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] / 255;
+ } else {
+ src_alpha = mask_alpha;
+ }
+ FX_BYTE back_alpha = *dest_scan;
+ if (!back_alpha) {
+ *dest_scan = src_alpha;
+ } else if (src_alpha) {
+ *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ }
+ dest_scan ++;
+ }
+}
+void _CompositeRow_BitMask2Gray(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_gray,
+ int src_left, int pixel_count, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
+ dest_scan ++;
+ continue;
+ }
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] / 255;
+ } else {
+ src_alpha = mask_alpha;
+ }
+ if (src_alpha) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, src_alpha);
+ }
+ dest_scan ++;
+ }
+}
+void _CompositeRow_BitMask2Graya(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_gray,
+ int src_left, int pixel_count, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dest_alpha_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] / 255;
+ } else {
+ src_alpha = mask_alpha;
+ }
+ FX_BYTE back_alpha = *dest_alpha_scan;
+ if (back_alpha == 0) {
+ *dest_scan ++ = src_gray;
+ *dest_alpha_scan ++ = src_alpha;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan ++;
+ dest_alpha_scan ++;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, alpha_ratio);
+ dest_scan ++;
+ }
+}
+void _CompositeRow_Argb2Argb_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int pixel_count, int blend_type, FX_LPCBYTE clip_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ if (clip_scan) {
+ int src_alpha = clip_scan[col] * src_scan[3] / 255;
+ dest_scan[3] = src_alpha;
+ dest_scan[0] = src_scan[2];
+ dest_scan[1] = src_scan[1];
+ dest_scan[2] = src_scan[0];
+ } else {
+ FXARGB_RGBORDERCOPY(dest_scan, src_scan);
+ }
+ dest_scan += 4;
+ src_scan += 4;
+ continue;
+ }
+ FX_BYTE src_alpha;
+ if (clip_scan == NULL) {
+ src_alpha = src_scan[3];
+ } else {
+ src_alpha = clip_scan[col] * src_scan[3] / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan += 4;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ FX_BYTE dest_scan_o[3];
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int index = 2 - color;
+ if (blend_type) {
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, dest_scan[index], *src_scan);
+ blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
+ dest_scan[index] = FXDIB_ALPHA_MERGE(dest_scan[index], blended, alpha_ratio);
+ } else {
+ dest_scan[index] = FXDIB_ALPHA_MERGE(dest_scan[index], *src_scan, alpha_ratio);
+ }
+ src_scan ++;
+ }
+ dest_scan += 4;
+ src_scan++;
+ }
+}
+void _CompositeRow_Rgb2Argb_Blend_NoClip_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int src_Bpp)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ if (src_Bpp == 4) {
+ FXARGB_SETRGBORDERDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
+ } else {
+ FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_scan[1], src_scan[0]));
+ }
+ dest_scan += 4;
+ src_scan += src_Bpp;
+ continue;
+ }
+ dest_scan[3] = 0xff;
+ if (bNonseparableBlend) {
+ FX_BYTE dest_scan_o[3];
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int index = 2 - color;
+ int src_color = FX_GAMMA(*src_scan);
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, dest_scan[index], src_color);
+ dest_scan[index] = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
+ src_scan ++;
+ }
+ dest_scan += 4;
+ src_scan += src_gap;
+ }
+}
+inline void _CompositeRow_Argb2Rgb_Blend_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, FX_LPCBYTE clip_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE src_alpha;
+ if (clip_scan) {
+ src_alpha = src_scan[3] * (*clip_scan++) / 255;
+ } else {
+ src_alpha = src_scan[3];
+ }
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_scan += 4;
+ continue;
+ }
+ if (bNonseparableBlend) {
+ FX_BYTE dest_scan_o[3];
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int index = 2 - color;
+ int back_color = FX_GAMMA(dest_scan[index]);
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, back_color, *src_scan);
+ dest_scan[index] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
+ src_scan ++;
+ }
+ dest_scan += dest_Bpp;
+ src_scan ++;
+ }
+}
+inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int src_Bpp)
+{
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ if (src_Bpp == 4) {
+ FXARGB_SETRGBORDERDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
+ } else {
+ FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_scan[1], src_scan[0]));
+ }
+ dest_scan += 4;
+ src_scan += src_Bpp;
+ }
+}
+inline void _CompositeRow_Rgb2Rgb_Blend_NoClip_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ if (bNonseparableBlend) {
+ FX_BYTE dest_scan_o[3];
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int index = 2 - color;
+ int back_color = FX_GAMMA(dest_scan[index]);
+ int src_color = FX_GAMMA(*src_scan);
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, back_color, src_color);
+ dest_scan[index] = FX_GAMMA_INVERSE(blended);
+ src_scan ++;
+ }
+ dest_scan += dest_Bpp;
+ src_scan += src_gap;
+ }
+}
+inline void _CompositeRow_Argb2Rgb_NoBlend_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE src_alpha;
+ if (clip_scan) {
+ src_alpha = src_scan[3] * (*clip_scan++) / 255;
+ } else {
+ src_alpha = src_scan[3];
+ }
+ if (src_alpha == 255) {
+ dest_scan[2] = FX_GAMMA_INVERSE(*src_scan++);
+ dest_scan[1] = FX_GAMMA_INVERSE(*src_scan++);
+ dest_scan[0] = FX_GAMMA_INVERSE(*src_scan++);
+ dest_scan += dest_Bpp;
+ src_scan ++;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_scan += 4;
+ continue;
+ }
+ for (int color = 0; color < 3; color ++) {
+ int index = 2 - color;
+ dest_scan[index] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[index]), *src_scan, src_alpha));
+ src_scan ++;
+ }
+ dest_scan += dest_Bpp;
+ src_scan ++;
+ }
+}
+inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, int src_Bpp)
+{
+ for (int col = 0; col < width; col ++) {
+ dest_scan[2] = src_scan[0];
+ dest_scan[1] = src_scan[1];
+ dest_scan[0] = src_scan[2];
+ dest_scan += dest_Bpp;
+ src_scan += src_Bpp;
+ }
+}
+inline void _CompositeRow_Rgb2Argb_Blend_Clip_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int src_Bpp, FX_LPCBYTE clip_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ int src_alpha = *clip_scan ++;
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ dest_scan[2] = FX_GAMMA(*src_scan++);
+ dest_scan[1] = FX_GAMMA(*src_scan++);
+ dest_scan[0] = FX_GAMMA(*src_scan++);
+ src_scan += src_gap;
+ dest_scan += 4;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan += src_Bpp;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend) {
+ FX_BYTE dest_scan_o[3];
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int index = 2 - color;
+ int src_color = FX_GAMMA(*src_scan);
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, dest_scan[index], src_color);
+ blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
+ dest_scan[index] = FXDIB_ALPHA_MERGE(dest_scan[index], blended, alpha_ratio);
+ src_scan ++;
+ }
+ dest_scan += 4;
+ src_scan += src_gap;
+ }
+}
+inline void _CompositeRow_Rgb2Rgb_Blend_Clip_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp, FX_LPCBYTE clip_scan)
+{
+ int blended_colors[3];
+ FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE src_alpha = *clip_scan ++;
+ if (src_alpha == 0) {
+ dest_scan += dest_Bpp;
+ src_scan += src_Bpp;
+ continue;
+ }
+ if (bNonseparableBlend) {
+ FX_BYTE dest_scan_o[3];
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ }
+ for (int color = 0; color < 3; color ++) {
+ int index = 2 - color;
+ int src_color = FX_GAMMA(*src_scan);
+ int back_color = FX_GAMMA(dest_scan[index]);
+ int blended = bNonseparableBlend ? blended_colors[color] :
+ _BLEND(blend_type, back_color, src_color);
+ dest_scan[index] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
+ src_scan ++;
+ }
+ dest_scan += dest_Bpp;
+ src_scan += src_gap;
+ }
+}
+inline void _CompositeRow_Rgb2Argb_NoBlend_Clip_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int src_Bpp, FX_LPCBYTE clip_scan)
+{
+ int src_gap = src_Bpp - 3;
+ for (int col = 0; col < width; col ++) {
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 255) {
+ dest_scan[2] = FX_GAMMA(*src_scan++);
+ dest_scan[1] = FX_GAMMA(*src_scan++);
+ dest_scan[0] = FX_GAMMA(*src_scan++);
+ dest_scan[3] = 255;
+ dest_scan += 4;
+ src_scan += src_gap;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan += src_Bpp;
+ continue;
+ }
+ int back_alpha = dest_scan[3];
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ for (int color = 0; color < 3; color ++) {
+ int index = 2 - color;
+ dest_scan[index] = FXDIB_ALPHA_MERGE(dest_scan[index], FX_GAMMA(*src_scan), alpha_ratio);
+ src_scan ++;
+ }
+ dest_scan += 4;
+ src_scan += src_gap;
+ }
+}
+inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, int dest_Bpp, int src_Bpp, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < width; col ++) {
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 255) {
+ dest_scan[2] = src_scan[0];
+ dest_scan[1] = src_scan[1];
+ dest_scan[0] = src_scan[2];
+ } else if (src_alpha) {
+ dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), FX_GAMMA(*src_scan), src_alpha));
+ src_scan ++;
+ dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), FX_GAMMA(*src_scan), src_alpha));
+ src_scan ++;
+ dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), FX_GAMMA(*src_scan), src_alpha));
+ dest_scan += dest_Bpp;
+ src_scan += src_Bpp - 2;
+ continue;
+ }
+ dest_scan += dest_Bpp;
+ src_scan += src_Bpp;
+ }
+}
+inline void _CompositeRow_8bppRgb2Rgb_NoBlend_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, FX_ARGB* pPalette, int pixel_count,
+ int DestBpp, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ FX_ARGB argb = pPalette ? pPalette[*src_scan] : (*src_scan) * 0x010101;
+ int src_r = FXARGB_R(argb);
+ int src_g = FXARGB_G(argb);
+ int src_b = FXARGB_B(argb);
+ if (clip_scan && clip_scan[col] < 255) {
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, clip_scan[col]);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, clip_scan[col]);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, clip_scan[col]);
+ } else {
+ dest_scan[2] = src_b;
+ dest_scan[1] = src_g;
+ dest_scan[0] = src_r;
+ }
+ dest_scan += DestBpp;
+ src_scan ++;
+ }
+}
+inline void _CompositeRow_1bppRgb2Rgb_NoBlend_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left,
+ FX_ARGB* pPalette, int pixel_count, int DestBpp, FX_LPCBYTE clip_scan)
+{
+ int reset_r, reset_g, reset_b;
+ int set_r, set_g, set_b;
+ if (pPalette) {
+ reset_r = FXARGB_R(pPalette[0]);
+ reset_g = FXARGB_G(pPalette[0]);
+ reset_b = FXARGB_B(pPalette[0]);
+ set_r = FXARGB_R(pPalette[1]);
+ set_g = FXARGB_G(pPalette[1]);
+ set_b = FXARGB_B(pPalette[1]);
+ } else {
+ reset_r = reset_g = reset_b = 0;
+ set_r = set_g = set_b = 255;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_r, src_g, src_b;
+ if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
+ src_r = set_r;
+ src_g = set_g;
+ src_b = set_b;
+ } else {
+ src_r = reset_r;
+ src_g = reset_g;
+ src_b = reset_b;
+ }
+ if (clip_scan && clip_scan[col] < 255) {
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, clip_scan[col]);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, clip_scan[col]);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, clip_scan[col]);
+ } else {
+ dest_scan[2] = src_b;
+ dest_scan[1] = src_g;
+ dest_scan[0] = src_r;
+ }
+ dest_scan += DestBpp;
+ }
+}
+inline void _CompositeRow_8bppRgb2Argb_NoBlend_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width,
+ FX_ARGB* pPalette, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < width; col ++) {
+ int src_r, src_g, src_b;
+ if (pPalette) {
+ FX_ARGB argb = pPalette[*src_scan];
+ src_r = FXARGB_R(argb);
+ src_g = FXARGB_G(argb);
+ src_b = FXARGB_B(argb);
+ } else {
+ src_r = src_g = src_b = *src_scan;
+ }
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ dest_scan[2] = FX_GAMMA(src_b);
+ dest_scan[1] = FX_GAMMA(src_g);
+ dest_scan[0] = FX_GAMMA(src_r);
+ dest_scan[3] = 255;
+ src_scan ++;
+ dest_scan += 4;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ src_scan ++;
+ continue;
+ }
+ int back_alpha = dest_scan[3];
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], FX_GAMMA(src_b), alpha_ratio);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], FX_GAMMA(src_g), alpha_ratio);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], FX_GAMMA(src_r), alpha_ratio);
+ dest_scan += 4;
+ src_scan ++;
+ }
+}
+inline void _CompositeRow_1bppRgb2Argb_NoBlend_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width,
+ FX_ARGB* pPalette, FX_LPCBYTE clip_scan)
+{
+ int reset_r, reset_g, reset_b;
+ int set_r, set_g, set_b;
+ if (pPalette) {
+ reset_r = FXARGB_R(pPalette[0]);
+ reset_g = FXARGB_G(pPalette[0]);
+ reset_b = FXARGB_B(pPalette[0]);
+ set_r = FXARGB_R(pPalette[1]);
+ set_g = FXARGB_G(pPalette[1]);
+ set_b = FXARGB_B(pPalette[1]);
+ } else {
+ reset_r = reset_g = reset_b = 0;
+ set_r = set_g = set_b = 255;
+ }
+ for (int col = 0; col < width; col ++) {
+ int src_r, src_g, src_b;
+ if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
+ src_r = set_r;
+ src_g = set_g;
+ src_b = set_b;
+ } else {
+ src_r = reset_r;
+ src_g = reset_g;
+ src_b = reset_b;
+ }
+ if (clip_scan == NULL || clip_scan[col] == 255) {
+ dest_scan[2] = FX_GAMMA(src_b);
+ dest_scan[1] = FX_GAMMA(src_g);
+ dest_scan[0] = FX_GAMMA(src_r);
+ dest_scan[3] = 255;
+ dest_scan += 4;
+ continue;
+ }
+ int src_alpha = clip_scan[col];
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ continue;
+ }
+ int back_alpha = dest_scan[3];
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], FX_GAMMA(src_b), alpha_ratio);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], FX_GAMMA(src_g), alpha_ratio);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], FX_GAMMA(src_r), alpha_ratio);
+ dest_scan += 4;
+ }
+}
+void _CompositeRow_ByteMask2Argb_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
+ int blend_type, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
+ } else {
+ src_alpha = mask_alpha * src_scan[col] / 255;
+ }
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
+ dest_scan += 4;
+ continue;
+ }
+ if (src_alpha == 0) {
+ dest_scan += 4;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ FX_BYTE dest_scan_o[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], alpha_ratio);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], alpha_ratio);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], alpha_ratio);
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, dest_scan[2], src_b);
+ blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, alpha_ratio);
+ blended = _BLEND(blend_type, dest_scan[1], src_g);
+ blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, alpha_ratio);
+ blended = _BLEND(blend_type, dest_scan[0], src_r);
+ blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, alpha_ratio);
+ } else {
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, alpha_ratio);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, alpha_ratio);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, alpha_ratio);
+ }
+ dest_scan += 4;
+ }
+}
+void _CompositeRow_ByteMask2Rgb_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
+ int blend_type, int Bpp, FX_LPCBYTE clip_scan)
+{
+ for (int col = 0; col < pixel_count; col ++) {
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
+ } else {
+ src_alpha = mask_alpha * src_scan[col] / 255;
+ }
+ if (src_alpha == 0) {
+ dest_scan += Bpp;
+ continue;
+ }
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ FX_BYTE dest_scan_o[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], src_alpha);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], src_alpha);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], src_alpha);
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, dest_scan[2], src_b);
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, src_alpha);
+ blended = _BLEND(blend_type, dest_scan[1], src_g);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, src_alpha);
+ blended = _BLEND(blend_type, dest_scan[0], src_r);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, src_alpha);
+ } else {
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, src_alpha);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, src_alpha);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, src_alpha);
+ }
+ dest_scan += Bpp;
+ }
+}
+void _CompositeRow_BitMask2Argb_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b,
+ int src_left, int pixel_count, int blend_type, FX_LPCBYTE clip_scan)
+{
+ if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 255) {
+ FX_ARGB argb = FXARGB_MAKE(0xff, src_r, src_g, src_b);
+ for (int col = 0; col < pixel_count; col ++) {
+ if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
+ FXARGB_SETRGBORDERDIB(dest_scan, argb);
+ }
+ dest_scan += 4;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
+ dest_scan += 4;
+ continue;
+ }
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] / 255;
+ } else {
+ src_alpha = mask_alpha;
+ }
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
+ dest_scan += 4;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ FX_BYTE dest_scan_o[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], alpha_ratio);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], alpha_ratio);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], alpha_ratio);
+ } else if (blend_type) {
+ int blended = _BLEND(blend_type, dest_scan[2], src_b);
+ blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, alpha_ratio);
+ blended = _BLEND(blend_type, dest_scan[1], src_g);
+ blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, alpha_ratio);
+ blended = _BLEND(blend_type, dest_scan[0], src_r);
+ blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, alpha_ratio);
+ } else {
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, alpha_ratio);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, alpha_ratio);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, alpha_ratio);
+ }
+ dest_scan += 4;
+ }
+}
+void _CompositeRow_BitMask2Rgb_RgbByteOrder(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int mask_alpha, int src_r, int src_g, int src_b,
+ int src_left, int pixel_count, int blend_type, int Bpp, FX_LPCBYTE clip_scan)
+{
+ if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 255) {
+ for (int col = 0; col < pixel_count; col ++) {
+ if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
+ dest_scan[2] = src_b;
+ dest_scan[1] = src_g;
+ dest_scan[0] = src_r;
+ }
+ dest_scan += Bpp;
+ }
+ return;
+ }
+ for (int col = 0; col < pixel_count; col ++) {
+ if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
+ dest_scan += Bpp;
+ continue;
+ }
+ int src_alpha;
+ if (clip_scan) {
+ src_alpha = mask_alpha * clip_scan[col] / 255;
+ } else {
+ src_alpha = mask_alpha;
+ }
+ if (src_alpha == 0) {
+ dest_scan += Bpp;
+ continue;
+ }
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
+ int blended_colors[3];
+ FX_BYTE src_scan[3];
+ FX_BYTE dest_scan_o[3];
+ src_scan[0] = src_b;
+ src_scan[1] = src_g;
+ src_scan[2] = src_r;
+ dest_scan_o[0] = dest_scan[2];
+ dest_scan_o[1] = dest_scan[1];
+ dest_scan_o[2] = dest_scan[0];
+ _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
+ dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], src_alpha);
+ dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], src_alpha);
+ dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], src_alpha);
+ } else if (blend_type) {
+ int back_color = FX_GAMMA(dest_scan[2]);
+ int blended = _BLEND(blend_type, back_color, src_b);
+ dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
+ back_color = FX_GAMMA(dest_scan[1]);
+ blended = _BLEND(blend_type, back_color, src_g);
+ dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
+ back_color = FX_GAMMA(dest_scan[0]);
+ blended = _BLEND(blend_type, back_color, src_r);
+ dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
+ } else {
+ dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), src_b, src_alpha));
+ dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), src_g, src_alpha));
+ dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), src_r, src_alpha));
+ }
+ dest_scan += Bpp;
+ }
+}
+inline FX_BOOL _ScanlineCompositor_InitSourceMask(FXDIB_Format dest_format, int alpha_flag, FX_DWORD mask_color, int& mask_alpha,
+ int& mask_red, int& mask_green, int& mask_blue, int& mask_black,
+ void* icc_module, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = (ICodec_IccModule*)icc_module;
+ if (alpha_flag >> 8) {
+ mask_alpha = alpha_flag & 0xff;
+ mask_red = FXSYS_GetCValue(mask_color);
+ mask_green = FXSYS_GetMValue(mask_color);
+ mask_blue = FXSYS_GetYValue(mask_color);
+ mask_black = FXSYS_GetKValue(mask_color);
+ } else {
+ mask_alpha = FXARGB_A(mask_color);
+ mask_red = FXARGB_R(mask_color);
+ mask_green = FXARGB_G(mask_color);
+ mask_blue = FXARGB_B(mask_color);
+ }
+ if (dest_format == FXDIB_8bppMask) {
+ return TRUE;
+ }
+ if ((dest_format & 0xff) == 8) {
+ if (pIccTransform) {
+ mask_color = (alpha_flag >> 8) ? FXCMYK_TODIB(mask_color) : FXARGB_TODIB(mask_color);
+ FX_LPBYTE gray_p = (FX_LPBYTE)&mask_color;
+ pIccModule->TranslateScanline(pIccTransform, gray_p, gray_p, 1);
+ mask_red = dest_format & 0x0400 ? FX_CCOLOR(gray_p[0]) : gray_p[0];
+ } else {
+ if (alpha_flag >> 8) {
+ FX_BYTE r, g, b;
+ AdobeCMYK_to_sRGB1(mask_red, mask_green, mask_blue, mask_black,
+ r, g, b);
+ mask_red = FXRGB2GRAY(r, g, b);
+ } else {
+ mask_red = FXRGB2GRAY(mask_red, mask_green, mask_blue);
+ }
+ if (dest_format & 0x0400) {
+ mask_red = FX_CCOLOR(mask_red);
+ }
+ }
+ } else {
+ FX_LPBYTE mask_color_p = (FX_LPBYTE)&mask_color;
+ mask_color = (alpha_flag >> 8) ? FXCMYK_TODIB(mask_color) : FXARGB_TODIB(mask_color);
+ if (pIccTransform) {
+ pIccModule->TranslateScanline(pIccTransform, mask_color_p, mask_color_p, 1);
+ mask_red = mask_color_p[2];
+ mask_green = mask_color_p[1];
+ mask_blue = mask_color_p[0];
+ } else if (alpha_flag >> 8) {
+ AdobeCMYK_to_sRGB1(mask_color_p[0], mask_color_p[1], mask_color_p[2], mask_color_p[3],
+ mask_color_p[2], mask_color_p[1], mask_color_p[0]);
+ mask_red = mask_color_p[2];
+ mask_green = mask_color_p[1];
+ mask_blue = mask_color_p[0];
+ }
+ }
+ return TRUE;
+}
+inline void _ScanlineCompositor_InitSourcePalette(FXDIB_Format src_format, FXDIB_Format dest_format,
+ FX_DWORD*& pDestPalette, FX_DWORD* pSrcPalette,
+ void* icc_module, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = (ICodec_IccModule*)icc_module;
+ FX_BOOL isSrcCmyk = src_format & 0x0400 ? TRUE : FALSE;
+ FX_BOOL isDstCmyk = dest_format & 0x0400 ? TRUE : FALSE;
+ pDestPalette = NULL;
+ if (pIccTransform) {
+ if (pSrcPalette) {
+ if ((dest_format & 0xff) == 8) {
+ int pal_count = 1 << (src_format & 0xff);
+ FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count);
+ if (!gray_pal) {
+ return;
+ }
+ pDestPalette = (FX_DWORD*)gray_pal;
+ for (int i = 0; i < pal_count; i ++) {
+ FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i]) : FXARGB_TODIB(pSrcPalette[i]);
+ pIccModule->TranslateScanline(pIccTransform, gray_pal, (FX_LPCBYTE)&color, 1);
+ gray_pal ++;
+ }
+ } else {
+ int palsize = 1 << (src_format & 0xff);
+ pDestPalette = FX_Alloc(FX_DWORD, palsize);
+ if (!pDestPalette) {
+ return;
+ }
+ for (int i = 0; i < palsize; i ++) {
+ FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i]) : FXARGB_TODIB(pSrcPalette[i]);
+ pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&color, (FX_LPCBYTE)&color, 1);
+ pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
+ }
+ }
+ } else {
+ int pal_count = 1 << (src_format & 0xff);
+ FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count);
+ if (!gray_pal) {
+ return;
+ }
+ if (pal_count == 2) {
+ gray_pal[0] = 0;
+ gray_pal[1] = 255;
+ } else {
+ for (int i = 0; i < pal_count; i++) {
+ gray_pal[i] = i;
+ }
+ }
+ if ((dest_format & 0xff) == 8) {
+ pIccModule->TranslateScanline(pIccTransform, gray_pal, gray_pal, pal_count);
+ pDestPalette = (FX_DWORD*)gray_pal;
+ } else {
+ pDestPalette = FX_Alloc(FX_DWORD, pal_count);
+ if (!pDestPalette) {
+ FX_Free(gray_pal);
+ return;
+ }
+ for (int i = 0; i < pal_count; i ++) {
+ pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&pDestPalette[i], &gray_pal[i], 1);
+ pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(pDestPalette[i]) : FXARGB_TODIB(pDestPalette[i]);
+ }
+ FX_Free(gray_pal);
+ }
+ }
+ } else {
+ if (pSrcPalette) {
+ if ((dest_format & 0xff) == 8) {
+ int pal_count = 1 << (src_format & 0xff);
+ FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count);
+ if (!gray_pal) {
+ return;
+ }
+ pDestPalette = (FX_DWORD*)gray_pal;
+ if (isSrcCmyk) {
+ for (int i = 0; i < pal_count; i ++) {
+ FX_CMYK cmyk = pSrcPalette[i];
+ FX_BYTE r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk),
+ r, g, b);
+ *gray_pal ++ = FXRGB2GRAY(r, g, b);
+ }
+ } else
+ for (int i = 0; i < pal_count; i ++) {
+ FX_ARGB argb = pSrcPalette[i];
+ *gray_pal ++ = FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb));
+ }
+ } else {
+ int palsize = 1 << (src_format & 0xff);
+ pDestPalette = FX_Alloc(FX_DWORD, palsize);
+ if (!pDestPalette) {
+ return;
+ }
+ if (isDstCmyk == isSrcCmyk) {
+ FXSYS_memcpy32(pDestPalette, pSrcPalette, palsize * sizeof(FX_DWORD));
+ } else {
+ for (int i = 0; i < palsize; i ++) {
+ FX_CMYK cmyk = pSrcPalette[i];
+ FX_BYTE r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk),
+ r, g, b);
+ pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
+ }
+ }
+ }
+ } else {
+ if ((dest_format & 0xff) == 8) {
+ int pal_count = 1 << (src_format & 0xff);
+ FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count);
+ if (!gray_pal) {
+ return;
+ }
+ if (pal_count == 2) {
+ gray_pal[0] = 0;
+ gray_pal[1] = 255;
+ } else {
+ for (int i = 0; i < pal_count; i++) {
+ gray_pal[i] = i;
+ }
+ }
+ pDestPalette = (FX_DWORD*)gray_pal;
+ } else {
+ int palsize = 1 << (src_format & 0xff);
+ pDestPalette = FX_Alloc(FX_DWORD, palsize);
+ if (!pDestPalette) {
+ return;
+ }
+ if (palsize == 2) {
+ pDestPalette[0] = isSrcCmyk ? 255 : 0xff000000;
+ pDestPalette[1] = isSrcCmyk ? 0 : 0xffffffff;
+ } else {
+ for (int i = 0; i < palsize; i++) {
+ pDestPalette[i] = isSrcCmyk ? FX_CCOLOR(i) : (i * 0x10101);
+ }
+ }
+ if (isSrcCmyk != isDstCmyk) {
+ for (int i = 0; i < palsize; i ++) {
+ FX_CMYK cmyk = pDestPalette[i];
+ FX_BYTE r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk),
+ r, g, b);
+ pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
+ }
+ }
+ }
+ }
+ }
+}
+CFX_ScanlineCompositor::CFX_ScanlineCompositor()
+{
+ m_pSrcPalette = NULL;
+ m_pCacheScanline = NULL;
+ m_CacheSize = 0;
+ m_bRgbByteOrder = FALSE;
+ m_BlendType = FXDIB_BLEND_NORMAL;
+}
+CFX_ScanlineCompositor::~CFX_ScanlineCompositor()
+{
+ if (m_pSrcPalette) {
+ FX_Free(m_pSrcPalette);
+ }
+ if (m_pCacheScanline) {
+ FX_Free(m_pCacheScanline);
+ }
+}
+FX_BOOL CFX_ScanlineCompositor::Init(FXDIB_Format dest_format, FXDIB_Format src_format, FX_INT32 width, FX_DWORD* pSrcPalette,
+ FX_DWORD mask_color, int blend_type, FX_BOOL bClip, FX_BOOL bRgbByteOrder, int alpha_flag, void* pIccTransform)
+{
+ m_SrcFormat = src_format;
+ m_DestFormat = dest_format;
+ m_BlendType = blend_type;
+ m_bRgbByteOrder = bRgbByteOrder;
+ ICodec_IccModule* pIccModule = NULL;
+ if (CFX_GEModule::Get()->GetCodecModule()) {
+ pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ }
+ if (pIccModule == NULL) {
+ pIccTransform = NULL;
+ }
+ m_pIccTransform = pIccTransform;
+ if ((dest_format & 0xff) == 1) {
+ return FALSE;
+ }
+ if (m_SrcFormat == FXDIB_1bppMask || m_SrcFormat == FXDIB_8bppMask) {
+ return _ScanlineCompositor_InitSourceMask(dest_format, alpha_flag, mask_color,
+ m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, m_MaskBlack,
+ pIccModule, pIccTransform);
+ }
+ if (pIccTransform == NULL && (~src_format & 0x0400) && (dest_format & 0x0400)) {
+ return FALSE;
+ }
+ if ((m_SrcFormat & 0xff) <= 8) {
+ if (dest_format == FXDIB_8bppMask) {
+ return TRUE;
+ }
+ _ScanlineCompositor_InitSourcePalette(src_format, dest_format, m_pSrcPalette, pSrcPalette,
+ pIccModule, pIccTransform);
+ m_Transparency = (dest_format == FXDIB_Argb ? 1 : 0)
+ + (dest_format & 0x0200 ? 2 : 0)
+ + (dest_format & 0x0400 ? 4 : 0)
+ + ((src_format & 0xff) == 1 ? 8 : 0);
+ return TRUE;
+ }
+ m_Transparency = (src_format & 0x0200 ? 0 : 1)
+ + (dest_format & 0x0200 ? 0 : 2)
+ + (blend_type == FXDIB_BLEND_NORMAL ? 4 : 0)
+ + (bClip ? 8 : 0)
+ + (src_format & 0x0400 ? 16 : 0)
+ + (dest_format & 0x0400 ? 32 : 0)
+ + (pIccTransform ? 64 : 0);
+ return TRUE;
+}
+void CFX_ScanlineCompositor::CompositeRgbBitmapLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_extra_alpha, FX_LPBYTE dst_extra_alpha)
+{
+ int src_Bpp = (m_SrcFormat & 0xff) >> 3;
+ int dest_Bpp = (m_DestFormat & 0xff) >> 3;
+ int dest_Size = width * dest_Bpp + 4;
+ if (m_bRgbByteOrder) {
+ switch (m_Transparency) {
+ case 0:
+ case 4:
+ case 8:
+ case 12:
+ _CompositeRow_Argb2Argb_RgbByteOrder(dest_scan, src_scan, width, m_BlendType, clip_scan);
+ break;
+ case 1:
+ _CompositeRow_Rgb2Argb_Blend_NoClip_RgbByteOrder(dest_scan, src_scan, width, m_BlendType, src_Bpp);
+ break;
+ case 2:
+ case 10:
+ _CompositeRow_Argb2Rgb_Blend_RgbByteOrder(dest_scan, src_scan, width, m_BlendType, dest_Bpp, clip_scan);
+ break;
+ case 3:
+ _CompositeRow_Rgb2Rgb_Blend_NoClip_RgbByteOrder(dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp);
+ break;
+ case 5:
+ _CompositeRow_Rgb2Argb_NoBlend_NoClip_RgbByteOrder(dest_scan, src_scan, width, src_Bpp);
+ break;
+ case 6:
+ case 14:
+ _CompositeRow_Argb2Rgb_NoBlend_RgbByteOrder(dest_scan, src_scan, width, dest_Bpp, clip_scan);
+ break;
+ case 7:
+ _CompositeRow_Rgb2Rgb_NoBlend_NoClip_RgbByteOrder(dest_scan, src_scan, width, dest_Bpp, src_Bpp);
+ break;
+ case 9:
+ _CompositeRow_Rgb2Argb_Blend_Clip_RgbByteOrder(dest_scan, src_scan, width, m_BlendType, src_Bpp, clip_scan);
+ break;
+ case 11:
+ _CompositeRow_Rgb2Rgb_Blend_Clip_RgbByteOrder(dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp, clip_scan);
+ break;
+ case 13:
+ _CompositeRow_Rgb2Argb_NoBlend_Clip_RgbByteOrder(dest_scan, src_scan, width, src_Bpp, clip_scan);
+ break;
+ case 15:
+ _CompositeRow_Rgb2Rgb_NoBlend_Clip_RgbByteOrder(dest_scan, src_scan, width, dest_Bpp, src_Bpp, clip_scan);
+ break;
+ }
+ return;
+ }
+ if (m_DestFormat == FXDIB_8bppMask) {
+ if (m_SrcFormat & 0x0200) {
+ if (m_SrcFormat == FXDIB_Argb) {
+ _CompositeRow_Argb2Mask(dest_scan, src_scan, width, clip_scan);
+ } else {
+ _CompositeRow_Rgba2Mask(dest_scan, src_extra_alpha, width, clip_scan);
+ }
+ } else {
+ _CompositeRow_Rgb2Mask(dest_scan, src_scan, width, clip_scan);
+ }
+ } else if ((m_DestFormat & 0xff) == 8) {
+ if (m_DestFormat & 0x0400) {
+ for (int i = 0; i < width; i ++) {
+ *dest_scan = ~*dest_scan;
+ dest_scan++;
+ }
+ }
+ if (m_SrcFormat & 0x0200) {
+ if (m_DestFormat & 0x0200) {
+ _CompositeRow_Argb2Graya(dest_scan, src_scan, width, m_BlendType, clip_scan, src_extra_alpha, dst_extra_alpha, m_pIccTransform);
+ } else {
+ _CompositeRow_Argb2Gray(dest_scan, src_scan, width, m_BlendType, clip_scan, src_extra_alpha, m_pIccTransform);
+ }
+ } else {
+ if (m_DestFormat & 0x0200) {
+ _CompositeRow_Rgb2Graya(dest_scan, src_scan, src_Bpp, width, m_BlendType, clip_scan, dst_extra_alpha, m_pIccTransform);
+ } else {
+ _CompositeRow_Rgb2Gray(dest_scan, src_scan, src_Bpp, width, m_BlendType, clip_scan, m_pIccTransform);
+ }
+ }
+ if (m_DestFormat & 0x0400) {
+ for (int i = 0; i < width; i ++) {
+ *dest_scan = ~*dest_scan;
+ dest_scan++;
+ }
+ }
+ } else {
+ if (dest_Size > m_CacheSize) {
+ m_pCacheScanline = FX_Realloc(FX_BYTE, m_pCacheScanline, dest_Size);
+ if (!m_pCacheScanline) {
+ return;
+ }
+ m_CacheSize = dest_Size;
+ }
+ switch (m_Transparency) {
+ case 0:
+ case 4:
+ case 8:
+ case 4+8: {
+ _CompositeRow_Argb2Argb(dest_scan, src_scan, width, m_BlendType, clip_scan,
+ dst_extra_alpha, src_extra_alpha);
+ }
+ break;
+ case 64:
+ case 4+64:
+ case 8+64:
+ case 4+8+64: {
+ _CompositeRow_Argb2Argb_Transform(dest_scan, src_scan, width, m_BlendType, clip_scan,
+ dst_extra_alpha, src_extra_alpha, m_pCacheScanline, m_pIccTransform);
+ }
+ break;
+ case 1:
+ _CompositeRow_Rgb2Argb_Blend_NoClip(dest_scan, src_scan, width, m_BlendType, src_Bpp,
+ dst_extra_alpha);
+ break;
+ case 1+64:
+ _CompositeRow_Rgb2Argb_Blend_NoClip_Transform(dest_scan, src_scan, width, m_BlendType, src_Bpp,
+ dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
+ break;
+ case 1+8:
+ _CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_scan, width, m_BlendType, src_Bpp, clip_scan,
+ dst_extra_alpha);
+ break;
+ case 1+8+64:
+ _CompositeRow_Rgb2Argb_Blend_Clip_Transform(dest_scan, src_scan, width, m_BlendType, src_Bpp, clip_scan,
+ dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
+ break;
+ case 1+4:
+ _CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_scan, width, src_Bpp,
+ dst_extra_alpha);
+ break;
+ case 1+4+64:
+ _CompositeRow_Rgb2Argb_NoBlend_NoClip_Transform(dest_scan, src_scan, width, src_Bpp,
+ dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
+ break;
+ case 1+4+8:
+ _CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_scan, width, src_Bpp, clip_scan,
+ dst_extra_alpha);
+ break;
+ case 1+4+8+64:
+ _CompositeRow_Rgb2Argb_NoBlend_Clip_Transform(dest_scan, src_scan, width, src_Bpp, clip_scan,
+ dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
+ break;
+ case 2:
+ case 2+8:
+ _CompositeRow_Argb2Rgb_Blend(dest_scan, src_scan, width, m_BlendType, dest_Bpp, clip_scan,
+ src_extra_alpha);
+ break;
+ case 2+64:
+ case 2+8+64:
+ _CompositeRow_Argb2Rgb_Blend_Transform(dest_scan, src_scan, width, m_BlendType, dest_Bpp, clip_scan,
+ src_extra_alpha, m_pCacheScanline, m_pIccTransform);
+ break;
+ case 2+4:
+ case 2+4+8:
+ _CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_scan, width, dest_Bpp, clip_scan,
+ src_extra_alpha);
+ break;
+ case 2+4+64:
+ case 2+4+8+64:
+ _CompositeRow_Argb2Rgb_NoBlend_Transform(dest_scan, src_scan, width, dest_Bpp, clip_scan,
+ src_extra_alpha, m_pCacheScanline, m_pIccTransform);
+ break;
+ case 1+2:
+ _CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp);
+ break;
+ case 1+2+64:
+ _CompositeRow_Rgb2Rgb_Blend_NoClip_Transform(dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp,
+ m_pCacheScanline, m_pIccTransform);
+ break;
+ case 1+2+8:
+ _CompositeRow_Rgb2Rgb_Blend_Clip(dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp, clip_scan);
+ break;
+ case 1+2+8+64:
+ _CompositeRow_Rgb2Rgb_Blend_Clip_Transform(dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp, clip_scan,
+ m_pCacheScanline, m_pIccTransform);
+ break;
+ case 1+2+4:
+ _CompositeRow_Rgb2Rgb_NoBlend_NoClip(dest_scan, src_scan, width, dest_Bpp, src_Bpp);
+ break;
+ case 1+2+4+64:
+ _CompositeRow_Rgb2Rgb_NoBlend_NoClip_Transform(dest_scan, src_scan, width, dest_Bpp, src_Bpp,
+ m_pCacheScanline, m_pIccTransform);
+ break;
+ case 1+2+4+8:
+ _CompositeRow_Rgb2Rgb_NoBlend_Clip(dest_scan, src_scan, width, dest_Bpp, src_Bpp, clip_scan);
+ break;
+ case 1+2+4+8+64:
+ _CompositeRow_Rgb2Rgb_NoBlend_Clip_Transform(dest_scan, src_scan, width, dest_Bpp, src_Bpp, clip_scan,
+ m_pCacheScanline, m_pIccTransform);
+ break;
+ }
+ }
+}
+void CFX_ScanlineCompositor::CompositePalBitmapLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_extra_alpha, FX_LPBYTE dst_extra_alpha)
+{
+ if (m_bRgbByteOrder) {
+ if (m_SrcFormat == FXDIB_1bppRgb) {
+ if (m_DestFormat == FXDIB_8bppRgb) {
+ return;
+ } else if(m_DestFormat == FXDIB_Argb) {
+ _CompositeRow_1bppRgb2Argb_NoBlend_RgbByteOrder(dest_scan, src_scan, src_left, width, m_pSrcPalette, clip_scan);
+ } else {
+ _CompositeRow_1bppRgb2Rgb_NoBlend_RgbByteOrder(dest_scan, src_scan, src_left, m_pSrcPalette, width, (m_DestFormat & 0xff) >> 3, clip_scan);
+ }
+ } else {
+ if (m_DestFormat == FXDIB_8bppRgb) {
+ return;
+ } else if (m_DestFormat == FXDIB_Argb) {
+ _CompositeRow_8bppRgb2Argb_NoBlend_RgbByteOrder(dest_scan, src_scan, width, m_pSrcPalette, clip_scan);
+ } else {
+ _CompositeRow_8bppRgb2Rgb_NoBlend_RgbByteOrder(dest_scan, src_scan, m_pSrcPalette, width, (m_DestFormat & 0xff) >> 3, clip_scan);
+ }
+ }
+ return;
+ }
+ if (m_DestFormat == FXDIB_8bppMask) {
+ _CompositeRow_Rgb2Mask(dest_scan, src_scan, width, clip_scan);
+ return;
+ } else if ((m_DestFormat & 0xff) == 8) {
+ if (m_Transparency & 8) {
+ if (m_DestFormat & 0x0200) {
+ _CompositeRow_1bppPal2Graya(dest_scan, src_scan, src_left, (FX_LPCBYTE)m_pSrcPalette, width, m_BlendType, clip_scan, dst_extra_alpha);
+ } else {
+ _CompositeRow_1bppPal2Gray(dest_scan, src_scan, src_left, (FX_LPCBYTE)m_pSrcPalette, width, m_BlendType, clip_scan);
+ }
+ } else {
+ if (m_DestFormat & 0x0200)
+ _CompositeRow_8bppPal2Graya(dest_scan, src_scan, (FX_LPCBYTE)m_pSrcPalette, width, m_BlendType, clip_scan,
+ dst_extra_alpha, src_extra_alpha);
+ else
+ _CompositeRow_8bppPal2Gray(dest_scan, src_scan, (FX_LPCBYTE)m_pSrcPalette, width, m_BlendType, clip_scan,
+ src_extra_alpha);
+ }
+ } else {
+ switch (m_Transparency) {
+ case 1+2:
+ _CompositeRow_8bppRgb2Argb_NoBlend(dest_scan, src_scan, width, m_pSrcPalette, clip_scan,
+ src_extra_alpha);
+ break;
+ case 1+2+8:
+ _CompositeRow_1bppRgb2Argb_NoBlend(dest_scan, src_scan, src_left, width, m_pSrcPalette, clip_scan);
+ break;
+ case 0:
+ _CompositeRow_8bppRgb2Rgb_NoBlend(dest_scan, src_scan, m_pSrcPalette, width, (m_DestFormat & 0xff) >> 3, clip_scan,
+ src_extra_alpha);
+ break;
+ case 0+8:
+ _CompositeRow_1bppRgb2Rgb_NoBlend(dest_scan, src_scan, src_left, m_pSrcPalette, width, (m_DestFormat & 0xff) >> 3, clip_scan);
+ break;
+ case 0+2:
+ _CompositeRow_8bppRgb2Rgb_NoBlend(dest_scan, src_scan, m_pSrcPalette, width, (m_DestFormat & 0xff) >> 3, clip_scan,
+ src_extra_alpha);
+ break;
+ case 0+2+8:
+ _CompositeRow_1bppRgb2Rgba_NoBlend(dest_scan, src_scan, src_left, width, m_pSrcPalette, clip_scan,
+ dst_extra_alpha);
+ break;
+ break;
+ }
+ }
+}
+void CFX_ScanlineCompositor::CompositeByteMaskLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dst_extra_alpha)
+{
+ if (m_DestFormat == FXDIB_8bppMask) {
+ _CompositeRow_ByteMask2Mask(dest_scan, src_scan, m_MaskAlpha, width, clip_scan);
+ } else if ((m_DestFormat & 0xff) == 8) {
+ if (m_DestFormat & 0x0200) {
+ _CompositeRow_ByteMask2Graya(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, width, clip_scan, dst_extra_alpha);
+ } else {
+ _CompositeRow_ByteMask2Gray(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, width, clip_scan);
+ }
+ } else if (m_bRgbByteOrder) {
+ if (m_DestFormat == FXDIB_Argb)
+ _CompositeRow_ByteMask2Argb_RgbByteOrder(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ width, m_BlendType, clip_scan);
+ else
+ _CompositeRow_ByteMask2Rgb_RgbByteOrder(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
+ return;
+ } else if (m_DestFormat == FXDIB_Argb)
+ _CompositeRow_ByteMask2Argb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ width, m_BlendType, clip_scan);
+ else if (m_DestFormat == FXDIB_Rgb || m_DestFormat == FXDIB_Rgb32)
+ _CompositeRow_ByteMask2Rgb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
+ else if (m_DestFormat == FXDIB_Rgba)
+ _CompositeRow_ByteMask2Rgba(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ width, m_BlendType, clip_scan, dst_extra_alpha);
+}
+void CFX_ScanlineCompositor::CompositeBitMaskLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width, FX_LPCBYTE clip_scan,
+ FX_LPBYTE dst_extra_alpha)
+{
+ if (m_DestFormat == FXDIB_8bppMask) {
+ _CompositeRow_BitMask2Mask(dest_scan, src_scan, m_MaskAlpha, src_left, width, clip_scan);
+ } else if ((m_DestFormat & 0xff) == 8) {
+ if (m_DestFormat & 0x0200)
+ _CompositeRow_BitMask2Graya(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, src_left, width, clip_scan,
+ dst_extra_alpha);
+ else {
+ _CompositeRow_BitMask2Gray(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, src_left, width, clip_scan);
+ }
+ } else if (m_bRgbByteOrder) {
+ if (m_DestFormat == FXDIB_Argb)
+ _CompositeRow_BitMask2Argb_RgbByteOrder(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ src_left, width, m_BlendType, clip_scan);
+ else
+ _CompositeRow_BitMask2Rgb_RgbByteOrder(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ src_left, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
+ return;
+ } else if (m_DestFormat == FXDIB_Argb)
+ _CompositeRow_BitMask2Argb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ src_left, width, m_BlendType, clip_scan);
+ else if (m_DestFormat == FXDIB_Rgb || m_DestFormat == FXDIB_Rgb32)
+ _CompositeRow_BitMask2Rgb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
+ src_left, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
+}
+FX_BOOL CFX_DIBitmap::CompositeBitmap(int dest_left, int dest_top, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top,
+ int blend_type, const CFX_ClipRgn* pClipRgn, FX_BOOL bRgbByteOrder, void* pIccTransform)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ ASSERT(!pSrcBitmap->IsAlphaMask());
+ ASSERT(m_bpp >= 8);
+ if (pSrcBitmap->IsAlphaMask() || m_bpp < 8) {
+ return FALSE;
+ }
+ GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(),
+ src_left, src_top, pClipRgn);
+ if (width == 0 || height == 0) {
+ return TRUE;
+ }
+ const CFX_DIBitmap* pClipMask = NULL;
+ FX_RECT clip_box;
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
+ ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
+ pClipMask = pClipRgn->GetMask();
+ clip_box = pClipRgn->GetBox();
+ }
+ CFX_ScanlineCompositor compositor;
+ if (!compositor.Init(GetFormat(), pSrcBitmap->GetFormat(), width, pSrcBitmap->GetPalette(), 0, blend_type,
+ pClipMask != NULL, bRgbByteOrder, 0, pIccTransform)) {
+ return FALSE;
+ }
+ int dest_Bpp = m_bpp / 8;
+ int src_Bpp = pSrcBitmap->GetBPP() / 8;
+ FX_BOOL bRgb = FALSE;
+ FX_BOOL bCmyk = FALSE;
+ if (src_Bpp > 1) {
+ if (pSrcBitmap->IsCmykImage()) {
+ bCmyk = TRUE;
+ } else {
+ bRgb = TRUE;
+ }
+ }
+ CFX_DIBitmap* pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + (dest_top + row) * m_Pitch + dest_left * dest_Bpp;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * src_Bpp;
+ FX_LPCBYTE src_scan_extra_alpha = pSrcAlphaMask ? pSrcAlphaMask->GetScanline(src_top + row) + src_left : NULL;
+ FX_LPBYTE dst_scan_extra_alpha = m_pAlphaMask ? (FX_LPBYTE)m_pAlphaMask->GetScanline(dest_top + row) + dest_left : NULL;
+ FX_LPCBYTE clip_scan = NULL;
+ if (pClipMask) {
+ clip_scan = pClipMask->m_pBuffer + (dest_top + row - clip_box.top) * pClipMask->m_Pitch + (dest_left - clip_box.left);
+ }
+ if (bRgb) {
+ compositor.CompositeRgbBitmapLine(dest_scan, src_scan, width, clip_scan, src_scan_extra_alpha, dst_scan_extra_alpha);
+ } else {
+ compositor.CompositePalBitmapLine(dest_scan, src_scan, src_left, width, clip_scan, src_scan_extra_alpha, dst_scan_extra_alpha);
+ }
+ }
+ return TRUE;
+}
+FX_BOOL CFX_DIBitmap::CompositeMask(int dest_left, int dest_top, int width, int height,
+ const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top,
+ int blend_type, const CFX_ClipRgn* pClipRgn, FX_BOOL bRgbByteOrder, int alpha_flag, void* pIccTransform)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ ASSERT(pMask->IsAlphaMask());
+ ASSERT(m_bpp >= 8);
+ if (!pMask->IsAlphaMask() || m_bpp < 8) {
+ return FALSE;
+ }
+ GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(), pMask->GetHeight(), src_left, src_top, pClipRgn);
+ if (width == 0 || height == 0) {
+ return TRUE;
+ }
+ int src_alpha = (FX_BYTE)(alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
+ if (src_alpha == 0) {
+ return TRUE;
+ }
+ const CFX_DIBitmap* pClipMask = NULL;
+ FX_RECT clip_box;
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
+ ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
+ pClipMask = pClipRgn->GetMask();
+ clip_box = pClipRgn->GetBox();
+ }
+ int src_bpp = pMask->GetBPP();
+ int Bpp = GetBPP() / 8;
+ CFX_ScanlineCompositor compositor;
+ if (!compositor.Init(GetFormat(), pMask->GetFormat(), width, NULL, color, blend_type, pClipMask != NULL, bRgbByteOrder, alpha_flag, pIccTransform)) {
+ return FALSE;
+ }
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp;
+ FX_LPCBYTE src_scan = pMask->GetScanline(src_top + row);
+ FX_LPBYTE dst_scan_extra_alpha = m_pAlphaMask ? (FX_LPBYTE)m_pAlphaMask->GetScanline(dest_top + row) + dest_left : NULL;
+ FX_LPCBYTE clip_scan = NULL;
+ if (pClipMask) {
+ clip_scan = pClipMask->m_pBuffer + (dest_top + row - clip_box.top) * pClipMask->m_Pitch + (dest_left - clip_box.left);
+ }
+ if (src_bpp == 1) {
+ compositor.CompositeBitMaskLine(dest_scan, src_scan, src_left, width, clip_scan, dst_scan_extra_alpha);
+ } else {
+ compositor.CompositeByteMaskLine(dest_scan, src_scan + src_left, width, clip_scan, dst_scan_extra_alpha);
+ }
+ }
+ return TRUE;
+}
+FX_BOOL CFX_DIBitmap::CompositeRect(int left, int top, int width, int height, FX_DWORD color, int alpha_flag, void* pIccTransform)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ int src_alpha = (alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
+ if (src_alpha == 0) {
+ return TRUE;
+ }
+ FX_RECT rect(left, top, left + width, top + height);
+ rect.Intersect(0, 0, m_Width, m_Height);
+ if (rect.IsEmpty()) {
+ return TRUE;
+ }
+ width = rect.Width();
+ FX_DWORD dst_color;
+ if (alpha_flag >> 8) {
+ dst_color = FXCMYK_TODIB(color);
+ } else {
+ dst_color = FXARGB_TODIB(color);
+ }
+ FX_LPBYTE color_p = (FX_LPBYTE)&dst_color;
+ if (m_bpp == 8) {
+ FX_BYTE gray = 255;
+ if (!IsAlphaMask()) {
+ if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() && CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ pIccModule->TranslateScanline(pIccTransform, &gray, color_p, 1);
+ } else {
+ if (alpha_flag >> 8) {
+ FX_BYTE r, g, b;
+ AdobeCMYK_to_sRGB1(color_p[0], color_p[1], color_p[2], color_p[3],
+ r, g, b);
+ gray = FXRGB2GRAY(r, g, b);
+ } else {
+ gray = (FX_BYTE)FXRGB2GRAY((int)color_p[2], color_p[1], color_p[0]);
+ }
+ }
+ if (IsCmykImage()) {
+ gray = ~gray;
+ }
+ }
+ for (int row = rect.top; row < rect.bottom; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + row * m_Pitch + rect.left;
+ if (src_alpha == 255) {
+ FXSYS_memset8(dest_scan, gray, width);
+ } else
+ for (int col = 0; col < width; col ++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+ dest_scan ++;
+ }
+ }
+ return TRUE;
+ } else if (m_bpp == 1) {
+ ASSERT(!IsCmykImage() && (FX_BYTE)(alpha_flag >> 8) == 0);
+ int left_shift = rect.left % 8;
+ int right_shift = rect.right % 8;
+ int width = rect.right / 8 - rect.left / 8;
+ int index = 0;
+ if (m_pPalette == NULL) {
+ index = ((FX_BYTE)color == 0xff) ? 1 : 0;
+ } else {
+ for (int i = 0; i < 2; i ++)
+ if (m_pPalette[i] == color) {
+ index = i;
+ }
+ }
+ for (int row = rect.top; row < rect.bottom; row ++) {
+ FX_BYTE* dest_scan_top = (FX_BYTE*)GetScanline(row) + rect.left / 8;
+ FX_BYTE* dest_scan_top_r = (FX_BYTE*)GetScanline(row) + rect.right / 8;
+ FX_BYTE left_flag = *dest_scan_top & (255 << (8 - left_shift));
+ FX_BYTE right_flag = *dest_scan_top_r & (255 >> right_shift);
+ if (width) {
+ FXSYS_memset8(dest_scan_top + 1, index ? 255 : 0, width - 1);
+ if (!index) {
+ *dest_scan_top &= left_flag;
+ *dest_scan_top_r &= right_flag;
+ } else {
+ *dest_scan_top |= ~left_flag;
+ *dest_scan_top_r |= ~right_flag;
+ }
+ } else {
+ if (!index) {
+ *dest_scan_top &= left_flag | right_flag;
+ } else {
+ *dest_scan_top |= ~(left_flag | right_flag);
+ }
+ }
+ }
+ return TRUE;
+ }
+ ASSERT(m_bpp >= 24);
+ if (m_bpp < 24) {
+ return FALSE;
+ }
+ if (pIccTransform && CFX_GEModule::Get()->GetCodecModule()) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1);
+ } else {
+ if (alpha_flag >> 8 && !IsCmykImage())
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), FXSYS_GetYValue(color), FXSYS_GetKValue(color),
+ color_p[2], color_p[1], color_p[0]);
+ else if (!(alpha_flag >> 8) && IsCmykImage()) {
+ return FALSE;
+ }
+ }
+ if(!IsCmykImage()) {
+ color_p[3] = (FX_BYTE)src_alpha;
+ }
+ int Bpp = m_bpp / 8;
+ FX_BOOL bAlpha = HasAlpha();
+ FX_BOOL bArgb = GetFormat() == FXDIB_Argb ? TRUE : FALSE;
+ if (src_alpha == 255) {
+ for (int row = rect.top; row < rect.bottom; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp;
+ FX_LPBYTE dest_scan_alpha = m_pAlphaMask ? (FX_LPBYTE)m_pAlphaMask->GetScanline(row) + rect.left : NULL;
+ if (dest_scan_alpha) {
+ FXSYS_memset8(dest_scan_alpha, 0xff, width);
+ }
+ if (Bpp == 4) {
+ FX_DWORD* scan = (FX_DWORD*)dest_scan;
+ for (int col = 0; col < width; col ++) {
+ *scan ++ = dst_color;
+ }
+ } else {
+ for (int col = 0; col < width; col ++) {
+ *dest_scan ++ = color_p[0];
+ *dest_scan ++ = color_p[1];
+ *dest_scan ++ = color_p[2];
+ }
+ }
+ }
+ return TRUE;
+ }
+ for (int row = rect.top; row < rect.bottom; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp;
+ if (bAlpha) {
+ if (bArgb) {
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, color_p[2], color_p[1], color_p[0]));
+ dest_scan += 4;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[0], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[1], alpha_ratio);
+ dest_scan ++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[2], alpha_ratio);
+ dest_scan ++;
+ *dest_scan++ = dest_alpha;
+ }
+ } else {
+ FX_LPBYTE dest_scan_alpha = (FX_LPBYTE)m_pAlphaMask->GetScanline(row) + rect.left;
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE back_alpha = *dest_scan_alpha;
+ if (back_alpha == 0) {
+ *dest_scan_alpha++ = src_alpha;
+ FXSYS_memcpy32(dest_scan, color_p, Bpp);
+ dest_scan += Bpp;
+ continue;
+ }
+ FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_scan_alpha ++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ for(int comps = 0; comps < Bpp; comps ++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], alpha_ratio);
+ dest_scan ++;
+ }
+ }
+ }
+ } else {
+ for (int col = 0; col < width; col ++) {
+ for(int comps = 0; comps < Bpp; comps ++) {
+ if (comps == 3) {
+ *dest_scan ++ = 255;
+ continue;
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], src_alpha);
+ dest_scan ++;
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+CFX_BitmapComposer::CFX_BitmapComposer()
+{
+ m_pScanlineV = NULL;
+ m_pScanlineAlphaV = NULL;
+ m_pClipScanV = NULL;
+ m_pAddClipScan = NULL;
+ m_bRgbByteOrder = FALSE;
+ m_BlendType = FXDIB_BLEND_NORMAL;
+}
+CFX_BitmapComposer::~CFX_BitmapComposer()
+{
+ if (m_pScanlineV) {
+ FX_Free(m_pScanlineV);
+ }
+ if (m_pScanlineAlphaV) {
+ FX_Free(m_pScanlineAlphaV);
+ }
+ if (m_pClipScanV) {
+ FX_Free(m_pClipScanV);
+ }
+ if (m_pAddClipScan) {
+ FX_Free(m_pAddClipScan);
+ }
+}
+void CFX_BitmapComposer::Compose(CFX_DIBitmap* pDest, const CFX_ClipRgn* pClipRgn, int bitmap_alpha,
+ FX_DWORD mask_color, FX_RECT& dest_rect, FX_BOOL bVertical,
+ FX_BOOL bFlipX, FX_BOOL bFlipY, FX_BOOL bRgbByteOrder,
+ int alpha_flag, void* pIccTransform, int blend_type)
+{
+ m_pBitmap = pDest;
+ m_pClipRgn = pClipRgn;
+ m_DestLeft = dest_rect.left;
+ m_DestTop = dest_rect.top;
+ m_DestWidth = dest_rect.Width();
+ m_DestHeight = dest_rect.Height();
+ m_BitmapAlpha = bitmap_alpha;
+ m_MaskColor = mask_color;
+ m_pClipMask = NULL;
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
+ m_pClipMask = pClipRgn->GetMask();
+ }
+ m_bVertical = bVertical;
+ m_bFlipX = bFlipX;
+ m_bFlipY = bFlipY;
+ m_AlphaFlag = alpha_flag;
+ m_pIccTransform = pIccTransform;
+ m_bRgbByteOrder = bRgbByteOrder;
+ m_BlendType = blend_type;
+}
+FX_BOOL CFX_BitmapComposer::SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette)
+{
+ m_SrcFormat = src_format;
+ if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, pSrcPalette, m_MaskColor, FXDIB_BLEND_NORMAL,
+ m_pClipMask != NULL || (m_BitmapAlpha < 255), m_bRgbByteOrder, m_AlphaFlag, m_pIccTransform)) {
+ return FALSE;
+ }
+ if (m_bVertical) {
+ m_pScanlineV = FX_Alloc(FX_BYTE, m_pBitmap->GetBPP() / 8 * width + 4);
+ if (!m_pScanlineV) {
+ return FALSE;
+ }
+ m_pClipScanV = FX_Alloc(FX_BYTE, m_pBitmap->GetHeight());
+ if (!m_pClipScanV) {
+ return FALSE;
+ }
+ if (m_pBitmap->m_pAlphaMask) {
+ m_pScanlineAlphaV = FX_Alloc(FX_BYTE, width + 4);
+ if (!m_pScanlineAlphaV) {
+ return FALSE;
+ }
+ }
+ }
+ if (m_BitmapAlpha < 255) {
+ m_pAddClipScan = FX_Alloc(FX_BYTE, m_bVertical ? m_pBitmap->GetHeight() : m_pBitmap->GetWidth());
+ if (!m_pAddClipScan) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+void CFX_BitmapComposer::DoCompose(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int dest_width, FX_LPCBYTE clip_scan,
+ FX_LPCBYTE src_extra_alpha, FX_LPBYTE dst_extra_alpha)
+{
+ if (m_BitmapAlpha < 255) {
+ if (clip_scan) {
+ for (int i = 0; i < dest_width; i ++) {
+ m_pAddClipScan[i] = clip_scan[i] * m_BitmapAlpha / 255;
+ }
+ } else {
+ FXSYS_memset8(m_pAddClipScan, m_BitmapAlpha, dest_width);
+ }
+ clip_scan = m_pAddClipScan;
+ }
+ if (m_SrcFormat == FXDIB_8bppMask) {
+ m_Compositor.CompositeByteMaskLine(dest_scan, src_scan, dest_width, clip_scan, dst_extra_alpha);
+ } else if ((m_SrcFormat & 0xff) == 8) {
+ m_Compositor.CompositePalBitmapLine(dest_scan, src_scan, 0, dest_width, clip_scan, src_extra_alpha, dst_extra_alpha);
+ } else {
+ m_Compositor.CompositeRgbBitmapLine(dest_scan, src_scan, dest_width, clip_scan, src_extra_alpha, dst_extra_alpha);
+ }
+}
+void CFX_BitmapComposer::ComposeScanline(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha)
+{
+ if (m_bVertical) {
+ ComposeScanlineV(line, scanline, scan_extra_alpha);
+ return;
+ }
+ FX_LPCBYTE clip_scan = NULL;
+ if (m_pClipMask)
+ clip_scan = m_pClipMask->GetBuffer() + (m_DestTop + line - m_pClipRgn->GetBox().top) *
+ m_pClipMask->GetPitch() + (m_DestLeft - m_pClipRgn->GetBox().left);
+ FX_LPBYTE dest_scan = (FX_LPBYTE)m_pBitmap->GetScanline(line + m_DestTop) +
+ m_DestLeft * m_pBitmap->GetBPP() / 8;
+ FX_LPBYTE dest_alpha_scan = m_pBitmap->m_pAlphaMask ?
+ (FX_LPBYTE)m_pBitmap->m_pAlphaMask->GetScanline(line + m_DestTop) + m_DestLeft : NULL;
+ DoCompose(dest_scan, scanline, m_DestWidth, clip_scan, scan_extra_alpha, dest_alpha_scan);
+}
+void CFX_BitmapComposer::ComposeScanlineV(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha)
+{
+ int i;
+ int Bpp = m_pBitmap->GetBPP() / 8;
+ int dest_pitch = m_pBitmap->GetPitch();
+ int dest_alpha_pitch = m_pBitmap->m_pAlphaMask ? m_pBitmap->m_pAlphaMask->GetPitch() : 0;
+ int dest_x = m_DestLeft + (m_bFlipX ? (m_DestWidth - line - 1) : line);
+ FX_LPBYTE dest_buf = m_pBitmap->GetBuffer() + dest_x * Bpp + m_DestTop * dest_pitch;
+ FX_LPBYTE dest_alpha_buf = m_pBitmap->m_pAlphaMask ?
+ m_pBitmap->m_pAlphaMask->GetBuffer() + dest_x + m_DestTop * dest_alpha_pitch : NULL;
+ if (m_bFlipY) {
+ dest_buf += dest_pitch * (m_DestHeight - 1);
+ dest_alpha_buf += dest_alpha_pitch * (m_DestHeight - 1);
+ }
+ int y_step = dest_pitch;
+ int y_alpha_step = dest_alpha_pitch;
+ if (m_bFlipY) {
+ y_step = -y_step;
+ y_alpha_step = -y_alpha_step;
+ }
+ FX_LPBYTE src_scan = m_pScanlineV;
+ FX_LPBYTE dest_scan = dest_buf;
+ for (i = 0; i < m_DestHeight; i ++) {
+ for (int j = 0; j < Bpp; j ++) {
+ *src_scan++ = dest_scan[j];
+ }
+ dest_scan += y_step;
+ }
+ FX_LPBYTE src_alpha_scan = m_pScanlineAlphaV;
+ FX_LPBYTE dest_alpha_scan = dest_alpha_buf;
+ if (dest_alpha_scan) {
+ for (i = 0; i < m_DestHeight; i ++) {
+ *src_alpha_scan++ = *dest_alpha_scan;
+ dest_alpha_scan += y_alpha_step;
+ }
+ }
+ FX_LPBYTE clip_scan = NULL;
+ if (m_pClipMask) {
+ clip_scan = m_pClipScanV;
+ int clip_pitch = m_pClipMask->GetPitch();
+ FX_LPCBYTE src_clip = m_pClipMask->GetBuffer() + (m_DestTop - m_pClipRgn->GetBox().top) *
+ clip_pitch + (dest_x - m_pClipRgn->GetBox().left);
+ if (m_bFlipY) {
+ src_clip += clip_pitch * (m_DestHeight - 1);
+ clip_pitch = -clip_pitch;
+ }
+ for (i = 0; i < m_DestHeight; i ++) {
+ clip_scan[i] = *src_clip;
+ src_clip += clip_pitch;
+ }
+ }
+ DoCompose(m_pScanlineV, scanline, m_DestHeight, clip_scan, scan_extra_alpha, m_pScanlineAlphaV);
+ src_scan = m_pScanlineV;
+ dest_scan = dest_buf;
+ for (i = 0; i < m_DestHeight; i ++) {
+ for (int j = 0; j < Bpp; j ++) {
+ dest_scan[j] = *src_scan++;
+ }
+ dest_scan += y_step;
+ }
+ src_alpha_scan = m_pScanlineAlphaV;
+ dest_alpha_scan = dest_alpha_buf;
+ if (dest_alpha_scan) {
+ for (i = 0; i < m_DestHeight; i ++) {
+ *dest_alpha_scan = *src_alpha_scan++;
+ dest_alpha_scan += y_alpha_step;
+ }
+ }
+}
diff --git a/core/src/fxge/dib/fx_dib_convert.cpp b/core/src/fxge/dib/fx_dib_convert.cpp new file mode 100644 index 0000000000..fe4a7bfd9a --- /dev/null +++ b/core/src/fxge/dib/fx_dib_convert.cpp @@ -0,0 +1,1090 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../../include/fxge/fx_dib.h"
+#include "../../../include/fxge/fx_ge.h"
+#include "../../../include/fxcodec/fx_codec.h"
+const FX_DWORD g_dwWinPalette[256] = {
+ 0xff000000, 0xff800000, 0xff008000, 0xff808000, 0xff000080, 0xff800080,
+ 0xff008080, 0xff808080, 0xffC0DCC0, 0xffA6CAF0, 0xff2A3FAA, 0xff2A3FFF,
+ 0xff2A5F00, 0xff2A5F55, 0xff2A5FAA, 0xff2A5FFF, 0xff2A7F00, 0xff2A7F55,
+ 0xff2A7FAA, 0xff2A7FFF, 0xff2A9F00, 0xff2A9F55, 0xff2A9FAA, 0xff2A9FFF,
+ 0xff2ABF00, 0xff2ABF55, 0xff2ABFAA, 0xff2ABFFF, 0xff2ADF00, 0xff2ADF55,
+ 0xff2ADFAA, 0xff2ADFFF, 0xff2AFF00, 0xff2AFF55, 0xff2AFFAA, 0xff2AFFFF,
+ 0xff550000, 0xff550055, 0xff5500AA, 0xff5500FF, 0xff551F00, 0xff551F55,
+ 0xff551FAA, 0xff551FFF, 0xff553F00, 0xff553F55, 0xff553FAA, 0xff553FFF,
+ 0xff555F00, 0xff555F55, 0xff555FAA, 0xff555FFF, 0xff557F00, 0xff557F55,
+ 0xff557FAA, 0xff557FFF, 0xff559F00, 0xff559F55, 0xff559FAA, 0xff559FFF,
+ 0xff55BF00, 0xff55BF55, 0xff55BFAA, 0xff55BFFF, 0xff55DF00, 0xff55DF55,
+ 0xff55DFAA, 0xff55DFFF, 0xff55FF00, 0xff55FF55, 0xff55FFAA, 0xff55FFFF,
+ 0xff7F0000, 0xff7F0055, 0xff7F00AA, 0xff7F00FF, 0xff7F1F00, 0xff7F1F55,
+ 0xff7F1FAA, 0xff7F1FFF, 0xff7F3F00, 0xff7F3F55, 0xff7F3FAA, 0xff7F3FFF,
+ 0xff7F5F00, 0xff7F5F55, 0xff7F5FAA, 0xff7F5FFF, 0xff7F7F00, 0xff7F7F55,
+ 0xff7F7FAA, 0xff7F7FFF, 0xff7F9F00, 0xff7F9F55, 0xff7F9FAA, 0xff7F9FFF,
+ 0xff7FBF00, 0xff7FBF55, 0xff7FBFAA, 0xff7FBFFF, 0xff7FDF00, 0xff7FDF55,
+ 0xff7FDFAA, 0xff7FDFFF, 0xff00FF7F, 0xff7FFF55, 0xff7FFFAA, 0xff7FFFFF,
+ 0xffAA0000, 0xffAA0055, 0xffAA00AA, 0xffAA00FF, 0xffAA1F00, 0xffAA1F55,
+ 0xffAA1FAA, 0xffAA1FFF, 0xffAA3F00, 0xffAA3F55, 0xffAA3FAA, 0xffAA3FFF,
+ 0xffAA5F00, 0xffAA5F55, 0xffAA5FAA, 0xffAA5FFF, 0xffAA7F00, 0xffAA7F55,
+ 0xffAA7FAA, 0xffAA7FFF, 0xffAA9F00, 0xffAA9F55, 0xffAA9FAA, 0xffAA9FFF,
+ 0xffAABF00, 0xffAABF55, 0xffAABFAA, 0xffAABFFF, 0xffAADF00, 0xffAADF55,
+ 0xffAADFAA, 0xffAADFFF, 0xffAAFF00, 0xffAAFF55, 0xffAAFFAA, 0xffAAFFFF,
+ 0xffD40000, 0xffD40055, 0xffD400AA, 0xffD400FF, 0xffD41F00, 0xffD41F55,
+ 0xffD41FAA, 0xffD41FFF, 0xffD43F00, 0xffD43F55, 0xffD43FAA, 0xffD43FFF,
+ 0xffD45F00, 0xffD45F55, 0xffD45FAA, 0xffD45FFF, 0xffD47F00, 0xffD47F55,
+ 0xffD47FAA, 0xffD4F7FF, 0xffD49F00, 0xffD49F55, 0xffD49FAA, 0xffD49FFF,
+ 0xffD4BF00, 0xffD4BF55, 0xffD4BFAA, 0xffD4BFFF, 0xffD4DF00, 0xffD4DF55,
+ 0xffD4DFAA, 0xffD4DFFF, 0xffD4FF00, 0xffD4FF55, 0xffD4FFAA, 0xffD4FFFF,
+ 0xffFF0055, 0xffFF00AA, 0xffFF1F00, 0xffFF1F55, 0xffFF1FAA, 0xffFF1FFF,
+ 0xffFF3F00, 0xffFF3F55, 0xffFF3FAA, 0xffFF3FFF, 0xffFF5F00, 0xffFF5F55,
+ 0xffFF5FAA, 0xffFF5FFF, 0xffFF7F00, 0xffFF7F55, 0xffFF7FAA, 0xffFF7FFF,
+ 0xffFF9F00, 0xffFF9F55, 0xffFF9FAA, 0xffFF9FFF, 0xffFFBF00, 0xffFFBF55,
+ 0xffFFBFAA, 0xffFFBFFF, 0xffFFDF00, 0xffFFDF55, 0xffFFDFAA, 0xffFFDFFF,
+ 0xffFFFF55, 0xffFFFFAA, 0xffCCCCFF, 0xffFFCCFF, 0xff33FFFF, 0xff66FFFF,
+ 0xff99FFFF, 0xffCCFFFF, 0xff007F00, 0xff007F55, 0xff007FAA, 0xff007FFF,
+ 0xff009F00, 0xff009F55, 0xff009FAA, 0xff009FFF, 0xff00BF00, 0xff00BF55,
+ 0xff00BFAA, 0xff00BFFF, 0xff00DF00, 0xff00DF55, 0xff00DFAA, 0xff00DFFF,
+ 0xff00FF55, 0xff00FFAA, 0xff2A0000, 0xff2A0055, 0xff2A00AA, 0xff2A00FF,
+ 0xff2A1F00, 0xff2A1F55, 0xff2A1FAA, 0xff2A1FFF, 0xff2A3F00, 0xff2A3F55,
+ 0xffFFFBF0, 0xffA0A0A4, 0xff808080, 0xffFF0000, 0xff00FF00, 0xffFF0000,
+ 0xff0000FF, 0xffFF00FF, 0xff00FFFF, 0xffFFFFFF
+};
+const FX_DWORD g_dwMacPalette[256] = {
+ 0xffFFFFFF, 0xffFFFFCC, 0xffFFFF99, 0xffFFFF66, 0xffFFFF33, 0xffFFFF00,
+ 0xffFFCCFF, 0xffFFCCCC, 0xffFFCC99, 0xffFFCC66, 0xffFFCC33, 0xffFFCC00,
+ 0xffFF99FF, 0xffFF99CC, 0xffFF9999, 0xffFF9966, 0xffFF9933, 0xffFF9900,
+ 0xffFF66FF, 0xffFF66CC, 0xffFF6699, 0xffFF6666, 0xffFF6633, 0xffFF6600,
+ 0xffFF33FF, 0xffFF33CC, 0xffFF3399, 0xffFF3366, 0xffFF3333, 0xffFF3300,
+ 0xffFF00FF, 0xffFF00CC, 0xffFF0099, 0xffFF0066, 0xffFF0033, 0xffFF0000,
+ 0xffCCFFFF, 0xffCCFFCC, 0xffCCFF99, 0xffCCFF66, 0xffCCFF33, 0xffCCFF00,
+ 0xffCCCCFF, 0xffCCCCCC, 0xffCCCC99, 0xffCCCC66, 0xffCCCC33, 0xffCCCC00,
+ 0xffCC99FF, 0xffCC99CC, 0xffCC9999, 0xffCC9966, 0xffCC9933, 0xffCC9900,
+ 0xffCC66FF, 0xffCC66CC, 0xffCC6699, 0xffCC6666, 0xffCC6633, 0xffCC6600,
+ 0xffCC33FF, 0xffCC33CC, 0xffCC3399, 0xffCC3366, 0xffCC3333, 0xffCC3300,
+ 0xffCC00FF, 0xffCC00CC, 0xffCC0099, 0xffCC0066, 0xffCC0033, 0xffCC0000,
+ 0xff99FFFF, 0xff99FFCC, 0xff99FF99, 0xff99FF66, 0xff99FF33, 0xff99FF00,
+ 0xff99CCFF, 0xff99CCCC, 0xff99CC99, 0xff99CC66, 0xff99CC33, 0xff99CC00,
+ 0xff9999FF, 0xff9999CC, 0xff999999, 0xff999966, 0xff999933, 0xff999900,
+ 0xff9966FF, 0xff9966CC, 0xff996699, 0xff996666, 0xff996633, 0xff996600,
+ 0xff9933FF, 0xff9933CC, 0xff993399, 0xff993366, 0xff993333, 0xff993300,
+ 0xff9900FF, 0xff9900CC, 0xff990099, 0xff990066, 0xff990033, 0xff990000,
+ 0xff66FFFF, 0xff66FFCC, 0xff66FF99, 0xff66FF66, 0xff66FF33, 0xff66FF00,
+ 0xff66CCFF, 0xff66CCCC, 0xff66CC99, 0xff66CC66, 0xff66CC33, 0xff66CC00,
+ 0xff6699FF, 0xff6699CC, 0xff669999, 0xff669966, 0xff669933, 0xff669900,
+ 0xff6666FF, 0xff6666CC, 0xff666699, 0xff666666, 0xff666633, 0xff666600,
+ 0xff6633FF, 0xff6633CC, 0xff663399, 0xff663366, 0xff663333, 0xff663300,
+ 0xff6600FF, 0xff6600CC, 0xff660099, 0xff660066, 0xff660033, 0xff660000,
+ 0xff33FFFF, 0xff33FFCC, 0xff33FF99, 0xff33FF66, 0xff33FF33, 0xff33FF00,
+ 0xff33CCFF, 0xff33CCCC, 0xff33CC99, 0xff33CC66, 0xff33CC33, 0xff33CC00,
+ 0xff3399FF, 0xff3399CC, 0xff339999, 0xff339966, 0xff339933, 0xff339900,
+ 0xff3366FF, 0xff3366CC, 0xff336699, 0xff336666, 0xff336633, 0xff336600,
+ 0xff3333FF, 0xff3333CC, 0xff333399, 0xff333366, 0xff333333, 0xff333300,
+ 0xff3300FF, 0xff3300CC, 0xff330099, 0xff330066, 0xff330033, 0xff330000,
+ 0xff00FFFF, 0xff00FFCC, 0xff00FF99, 0xff00FF66, 0xff00FF33, 0xff00FF00,
+ 0xff00CCFF, 0xff00CCCC, 0xff00CC99, 0xff00CC66, 0xff00CC33, 0xff00CC00,
+ 0xff0099FF, 0xff0099CC, 0xff009999, 0xff009966, 0xff009933, 0xff009900,
+ 0xff0066FF, 0xff0066CC, 0xff006699, 0xff006666, 0xff006633, 0xff006600,
+ 0xff0033FF, 0xff0033CC, 0xff003399, 0xff003366, 0xff003333, 0xff003300,
+ 0xff0000FF, 0xff0000CC, 0xff000099, 0xff000066, 0xff000033,
+ 0xffEE0000, 0xffDD0000, 0xffBB0000, 0xffAA0000, 0xff880000, 0xff770000,
+ 0xff550000, 0xff440000, 0xff220000, 0xff110000, 0xff00EE00, 0xff00DD00,
+ 0xff00BB00, 0xff00AA00, 0xff008800, 0xff007700, 0xff005500, 0xff004400,
+ 0xff002200, 0xff001100, 0xff0000EE, 0xff0000DD, 0xff0000BB, 0xff0000AA,
+ 0xff000088, 0xff000077, 0xff000055, 0xff000044, 0xff000022, 0xff000011,
+ 0xffEEEEEE, 0xffDDDDDD, 0xffBBBBBB, 0xffAAAAAA, 0xff888888, 0xff777777,
+ 0xff555555, 0xff444444, 0xff222222, 0xff111111, 0xff000000
+};
+class CFX_Palette : public CFX_Object
+{
+public:
+ CFX_Palette();
+ ~CFX_Palette();
+public:
+ FX_BOOL BuildPalette(const CFX_DIBSource* pBitmap, int dwPaletteType);
+ FX_DWORD* GetPalette() const
+ {
+ return m_pPalette;
+ }
+
+ FX_DWORD* GetColorLut()const
+ {
+ return m_cLut;
+ }
+ FX_DWORD* GetAmountLut()const
+ {
+ return m_aLut;
+ }
+ FX_INT32 Getlut()const
+ {
+ return m_lut;
+ }
+protected:
+ FX_DWORD* m_pPalette;
+ FX_DWORD* m_cLut;
+ FX_DWORD* m_aLut;
+ int m_lut;
+};
+int _Partition(FX_DWORD* alut, FX_DWORD* clut, int l, int r)
+{
+ FX_DWORD p_a = alut[l];
+ FX_DWORD p_c = clut[l];
+ while(l < r) {
+ while(l < r && alut[r] >= p_a) {
+ r--;
+ }
+ if (l < r) {
+ alut[l] = alut[r];
+ clut[l++] = clut[r];
+ }
+ while(l < r && alut[l] <= p_a) {
+ l++;
+ }
+ if (l < r) {
+ alut[r] = alut[l];
+ clut[r--] = clut[l];
+ }
+ }
+ alut[l] = p_a;
+ clut[l] = p_c;
+ return l;
+}
+void _Qsort(FX_DWORD* alut, FX_DWORD* clut, int l, int r)
+{
+ if(l < r) {
+ int pI = _Partition(alut, clut, l, r);
+ _Qsort(alut, clut, l, pI - 1);
+ _Qsort(alut, clut, pI + 1, r);
+ }
+}
+void _ColorDecode(FX_DWORD pal_v, FX_BYTE& r, FX_BYTE& g, FX_BYTE& b)
+{
+ r = (FX_BYTE)((pal_v & 0xf00) >> 4);
+ g = (FX_BYTE)(pal_v & 0x0f0);
+ b = (FX_BYTE)((pal_v & 0x00f) << 4);
+}
+void _Obtain_Pal(FX_DWORD* aLut, FX_DWORD*cLut, FX_DWORD* dest_pal, int pal_type, FX_DWORD* win_mac_pal, FX_DWORD lut)
+{
+ int row, col;
+ FX_DWORD lut_1 = lut - 1;
+ if (pal_type == FXDIB_PALETTE_LOC) {
+ for (row = 0; row < 256; row++) {
+ int lut_offset = lut_1 - row;
+ if (lut_offset < 0) {
+ lut_offset += 256;
+ }
+ FX_DWORD color = cLut[lut_offset];
+ FX_BYTE r, g, b;
+ _ColorDecode(color, r, g, b);
+ dest_pal[row] = ((FX_DWORD)r << 16) | ((FX_DWORD)g << 8) | b | 0xff000000;
+ aLut[lut_offset] = row;
+ }
+ } else {
+ for (row = 0; row < 256; row++) {
+ int lut_offset = lut_1 - row;
+ if (lut_offset < 0) {
+ lut_offset += 256;
+ }
+ FX_BYTE r, g, b;
+ _ColorDecode(cLut[lut_offset], r, g, b);
+ int error, min_error = 1000000;
+ int c_index = 0;
+ for (col = 0; col < 256; col++) {
+ FX_DWORD p_color = win_mac_pal[col];
+ int d_r = r - (FX_BYTE)(p_color >> 16);
+ int d_g = g - (FX_BYTE)(p_color >> 8);
+ int d_b = b - (FX_BYTE)p_color;
+ error = d_r * d_r + d_g * d_g + d_b * d_b;
+ if (error < min_error) {
+ min_error = error;
+ c_index = col;
+ }
+ }
+ dest_pal[row] = win_mac_pal[c_index];
+ aLut[lut_offset] = row;
+ }
+ }
+}
+CFX_Palette::CFX_Palette()
+{
+ m_pPalette = NULL;
+ m_cLut = NULL;
+ m_aLut = NULL;
+ m_lut = 0;
+}
+CFX_Palette::~CFX_Palette()
+{
+ if (m_pPalette) {
+ FX_Free(m_pPalette);
+ }
+ if (m_cLut) {
+ FX_Free(m_cLut);
+ }
+ if (m_aLut) {
+ FX_Free(m_aLut);
+ }
+ m_lut = 0;
+}
+FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type)
+{
+ if (pBitmap == NULL) {
+ return FALSE;
+ }
+ if (m_pPalette != NULL) {
+ FX_Free(m_pPalette);
+ }
+ m_pPalette = FX_Alloc(FX_DWORD, 256);
+ if (!m_pPalette) {
+ return FALSE;
+ }
+ FXSYS_memset32(m_pPalette, 0, sizeof(FX_DWORD) * 256);
+ int bpp = pBitmap->GetBPP() / 8;
+ int width = pBitmap->GetWidth();
+ int height = pBitmap->GetHeight();
+ if (m_cLut) {
+ FX_Free(m_cLut);
+ m_cLut = NULL;
+ }
+ if (m_aLut) {
+ FX_Free(m_aLut);
+ m_aLut = NULL;
+ }
+ m_cLut = FX_Alloc(FX_DWORD, 4096);
+ if (!m_cLut) {
+ return FALSE;
+ }
+ m_aLut = FX_Alloc(FX_DWORD, 4096);
+ if (!m_aLut) {
+ return FALSE;
+ }
+ FXSYS_memset32(m_aLut, 0, sizeof(FX_DWORD) * 4096);
+ FXSYS_memset32(m_cLut, 0, sizeof(FX_DWORD) * 4096);
+ int row, col;
+ m_lut = 0;
+ for (row = 0; row < height; row++) {
+ FX_BYTE* scan_line = (FX_BYTE*)pBitmap->GetScanline(row);
+ for (col = 0; col < width; col++) {
+ FX_BYTE* src_port = scan_line + col * bpp;
+ FX_DWORD b = src_port[0] & 0xf0;
+ FX_DWORD g = src_port[1] & 0xf0;
+ FX_DWORD r = src_port[2] & 0xf0;
+ FX_DWORD index = (r << 4) + g + (b >> 4);
+ m_aLut[index]++;
+ }
+ }
+ for (row = 0; row < 4096; row++) {
+ if (m_aLut[row] != 0) {
+ m_aLut[m_lut] = m_aLut[row];
+ m_cLut[m_lut] = row;
+ m_lut++;
+ }
+ }
+ _Qsort(m_aLut, m_cLut, 0, m_lut - 1);
+ FX_DWORD* win_mac_pal = NULL;
+ if (pal_type == FXDIB_PALETTE_WIN) {
+ win_mac_pal = (FX_DWORD*)g_dwWinPalette;
+ } else if (pal_type == FXDIB_PALETTE_MAC) {
+ win_mac_pal = (FX_DWORD*)g_dwMacPalette;
+ }
+ _Obtain_Pal(m_aLut, m_cLut, m_pPalette, pal_type, win_mac_pal, m_lut);
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_1bppMask2Gray(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top)
+{
+ FX_BYTE set_gray, reset_gray;
+ set_gray = 0xff;
+ reset_gray = 0x00;
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FXSYS_memset8(dest_scan, reset_gray, width);
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col ++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ *dest_scan = set_gray;
+ }
+ dest_scan ++;
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_8bppMask2Gray(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top)
+{
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ FXSYS_memcpy32(dest_scan, src_scan, width);
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_1bppPlt2Gray(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ FX_DWORD* src_plt = pSrcBitmap->GetPalette();
+ FX_BYTE gray[2];
+ if (pIccTransform) {
+ FX_DWORD plt[2];
+ if (pSrcBitmap->IsCmykImage()) {
+ plt[0] = FXCMYK_TODIB(src_plt[0]);
+ plt[1] = FXCMYK_TODIB(src_plt[1]);
+ } else {
+ FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt;
+ bgr_ptr[0] = FXARGB_B(src_plt[0]);
+ bgr_ptr[1] = FXARGB_G(src_plt[0]);
+ bgr_ptr[2] = FXARGB_R(src_plt[0]);
+ bgr_ptr[3] = FXARGB_B(src_plt[1]);
+ bgr_ptr[4] = FXARGB_G(src_plt[1]);
+ bgr_ptr[5] = FXARGB_R(src_plt[1]);
+ }
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 2);
+ } else {
+ FX_BYTE reset_r, reset_g, reset_b,
+ set_r, set_g, set_b;
+ if (pSrcBitmap->IsCmykImage()) {
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]), FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]),
+ reset_r, reset_g, reset_b);
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]), FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]),
+ set_r, set_g, set_b);
+ } else {
+ reset_r = FXARGB_R(src_plt[0]);
+ reset_g = FXARGB_G(src_plt[0]);
+ reset_b = FXARGB_B(src_plt[0]);
+ set_r = FXARGB_R(src_plt[1]);
+ set_g = FXARGB_G(src_plt[1]);
+ set_b = FXARGB_B(src_plt[1]);
+ }
+ gray[0] = FXRGB2GRAY(reset_r, reset_g, reset_b);
+ gray[1] = FXRGB2GRAY(set_r, set_g, set_b);
+ }
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FXSYS_memset8(dest_scan, gray[0], width);
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col ++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ *dest_scan = gray[1];
+ }
+ dest_scan ++;
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_8bppPlt2Gray(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ FX_DWORD* src_plt = pSrcBitmap->GetPalette();
+ FX_BYTE gray[256];
+ if (pIccTransform) {
+ FX_DWORD plt[256];
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < 256; i ++) {
+ plt[i] = FXCMYK_TODIB(src_plt[i]);
+ }
+ } else {
+ FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt;
+ for (int i = 0; i < 256; i ++) {
+ *bgr_ptr++ = FXARGB_B(src_plt[i]);
+ *bgr_ptr++ = FXARGB_G(src_plt[i]);
+ *bgr_ptr++ = FXARGB_R(src_plt[i]);
+ }
+ }
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 256);
+ } else {
+ if (pSrcBitmap->IsCmykImage()) {
+ FX_BYTE r, g, b;
+ for (int i = 0; i < 256; i ++) {
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]),
+ r, g, b);
+ gray[i] = FXRGB2GRAY(r, g, b);
+ }
+ } else
+ for (int i = 0; i < 256; i ++) {
+ gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]), FXARGB_B(src_plt[i]));
+ }
+ }
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ for (int col = 0; col < width; col ++) {
+ *dest_scan++ = gray[*src_scan++];
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_RgbOrCmyk2Gray(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ int Bpp = pSrcBitmap->GetBPP() / 8;
+ if (pIccTransform) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ if (Bpp == 3 || pSrcBitmap->IsCmykImage()) {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, width);
+ }
+ } else {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ dest_scan++;
+ src_scan += 4;
+ }
+ }
+ }
+ } else {
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
+ for (int col = 0; col < width; col ++) {
+ FX_BYTE r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue((FX_DWORD)src_scan[0]), FXSYS_GetMValue((FX_DWORD)src_scan[1]), FXSYS_GetYValue((FX_DWORD)src_scan[2]), FXSYS_GetKValue((FX_DWORD)src_scan[3]),
+ r, g, b);
+ *dest_scan++ = FXRGB2GRAY(r, g, b);
+ src_scan += 4;
+ }
+ }
+ } else
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
+ for (int col = 0; col < width; col ++) {
+ *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan[0]);
+ src_scan += Bpp;
+ }
+ }
+ }
+ return TRUE;
+}
+inline void _ConvertBuffer_IndexCopy(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top)
+{
+ if (pSrcBitmap->GetBPP() == 1) {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FXSYS_memset32(dest_scan, 0, width);
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col ++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ *dest_scan = 1;
+ }
+ dest_scan ++;
+ }
+ }
+ } else {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ FXSYS_memcpy32(dest_scan, src_scan, width);
+ }
+ }
+}
+FX_BOOL _ConvertBuffer_Plt2PltRgb8(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD* dst_plt, void* pIccTransform)
+{
+ _ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top);
+ FX_DWORD* src_plt = pSrcBitmap->GetPalette();
+ int plt_size = pSrcBitmap->GetPaletteSize();
+ if (pIccTransform) {
+ FX_DWORD plt[256];
+ FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt;
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < plt_size; i ++) {
+ plt[i] = FXCMYK_TODIB(src_plt[i]);
+ }
+ } else {
+ for (int i = 0; i < plt_size; i ++) {
+ *bgr_ptr++ = FXARGB_B(src_plt[i]);
+ *bgr_ptr++ = FXARGB_G(src_plt[i]);
+ *bgr_ptr++ = FXARGB_R(src_plt[i]);
+ }
+ bgr_ptr = (FX_LPBYTE)plt;
+ }
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE)plt, plt_size);
+ for (int i = 0; i < plt_size; i ++) {
+ dst_plt[i] = FXARGB_MAKE(0xff, bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
+ bgr_ptr += 3;
+ }
+ } else {
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < plt_size; i ++) {
+ FX_BYTE r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]),
+ r, g, b);
+ dst_plt[i] = FXARGB_MAKE(0xff, r, g, b);
+ }
+ } else {
+ FXSYS_memcpy32(dst_plt, src_plt, plt_size * 4);
+ }
+ }
+ return TRUE;
+}
+inline FX_BOOL _ConvertBuffer_Rgb2PltRgb8_NoTransform(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD* dst_plt)
+{
+ int bpp = pSrcBitmap->GetBPP() / 8;
+ int row, col;
+ CFX_Palette palette;
+ palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC);
+ FX_DWORD* cLut = palette.GetColorLut();
+ FX_DWORD* aLut = palette.GetAmountLut();
+ if (cLut == NULL || aLut == NULL) {
+ return FALSE;
+ }
+ int lut = palette.Getlut();
+ FX_DWORD* pPalette = palette.GetPalette();
+ if (lut > 256) {
+ int err, min_err;
+ int lut_256 = lut - 256;
+ for (row = 0; row < lut_256; row++) {
+ min_err = 1000000;
+ FX_BYTE r, g, b;
+ _ColorDecode(cLut[row], r, g, b);
+ int clrindex = 0;
+ for (int col = 0; col < 256; col++) {
+ FX_DWORD p_color = *(pPalette + col);
+ int d_r = r - (FX_BYTE)(p_color >> 16);
+ int d_g = g - (FX_BYTE)(p_color >> 8);
+ int d_b = b - (FX_BYTE)(p_color);
+ err = d_r * d_r + d_g * d_g + d_b * d_b;
+ if (err < min_err) {
+ min_err = err;
+ clrindex = col;
+ }
+ }
+ aLut[row] = clrindex;
+ }
+ }
+ FX_INT32 lut_1 = lut - 1;
+ for (row = 0; row < height; row ++) {
+ FX_BYTE* src_scan = (FX_BYTE*)pSrcBitmap->GetScanline(src_top + row) + src_left;
+ FX_BYTE* dest_scan = dest_buf + row * dest_pitch;
+ for (col = 0; col < width; col++) {
+ FX_BYTE* src_port = src_scan + col * bpp;
+ int r = src_port[2] & 0xf0;
+ int g = src_port[1] & 0xf0;
+ int b = src_port[0] & 0xf0;
+ FX_DWORD clrindex = (r << 4) + g + (b >> 4);
+ for (int i = lut_1; i >= 0; i--)
+ if (clrindex == cLut[i]) {
+ *(dest_scan + col) = (FX_BYTE)(aLut[i]);
+ break;
+ }
+ }
+ }
+ FXSYS_memcpy32(dst_plt, pPalette, sizeof(FX_DWORD) * 256);
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_Rgb2PltRgb8(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD* dst_plt, void* pIccTransform)
+{
+ ICodec_IccModule* pIccModule = NULL;
+ if (pIccTransform) {
+ pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ }
+ FX_BOOL ret = _ConvertBuffer_Rgb2PltRgb8_NoTransform(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, dst_plt);
+ if (ret && pIccTransform) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ for (int i = 0; i < 256; i++) {
+ FX_ARGB* plt = dst_plt + i;
+ FX_ARGB plt_entry = FXARGB_TODIB(*plt);
+ pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&plt_entry, (FX_LPCBYTE)&plt_entry, 1);
+ *plt = FXARGB_TODIB(plt_entry);
+ }
+ }
+ return ret;
+}
+FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top)
+{
+ int comps = (dst_format & 0xff) / 8;
+ FX_BYTE set_gray, reset_gray;
+ set_gray = 0xff;
+ reset_gray = 0x00;
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col ++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ dest_scan[0] = set_gray;
+ dest_scan[1] = set_gray;
+ dest_scan[2] = set_gray;
+ } else {
+ dest_scan[0] = reset_gray;
+ dest_scan[1] = reset_gray;
+ dest_scan[2] = reset_gray;
+ }
+ dest_scan += comps;
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top)
+{
+ int comps = (dst_format & 0xff) / 8;
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ FX_BYTE src_pixel;
+ for (int col = 0; col < width; col ++) {
+ src_pixel = *src_scan++;
+ *dest_scan++ = src_pixel;
+ *dest_scan++ = src_pixel;
+ *dest_scan = src_pixel;
+ dest_scan += comps - 2;
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ int comps = (dst_format & 0xff) / 8;
+ FX_DWORD* src_plt = pSrcBitmap->GetPalette();
+ FX_DWORD plt[2];
+ FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt;
+ if (pSrcBitmap->IsCmykImage()) {
+ plt[0] = FXCMYK_TODIB(src_plt[0]);
+ plt[1] = FXCMYK_TODIB(src_plt[1]);
+ } else {
+ bgr_ptr[0] = FXARGB_B(src_plt[0]);
+ bgr_ptr[1] = FXARGB_G(src_plt[0]);
+ bgr_ptr[2] = FXARGB_R(src_plt[0]);
+ bgr_ptr[3] = FXARGB_B(src_plt[1]);
+ bgr_ptr[4] = FXARGB_G(src_plt[1]);
+ bgr_ptr[5] = FXARGB_R(src_plt[1]);
+ }
+ if (pIccTransform) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE)plt, 2);
+ } else {
+ if (pSrcBitmap->IsCmykImage()) {
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]), FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]),
+ bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]), FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]),
+ bgr_ptr[5], bgr_ptr[4], bgr_ptr[3]);
+ }
+ }
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col ++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ *dest_scan++ = bgr_ptr[3];
+ *dest_scan++ = bgr_ptr[4];
+ *dest_scan = bgr_ptr[5];
+ } else {
+ *dest_scan++ = bgr_ptr[0];
+ *dest_scan++ = bgr_ptr[1];
+ *dest_scan = bgr_ptr[2];
+ }
+ dest_scan += comps - 2;
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ int comps = (dst_format & 0xff) / 8;
+ FX_DWORD* src_plt = pSrcBitmap->GetPalette();
+ FX_DWORD plt[256];
+ FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt;
+ if (!pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < 256; i++) {
+ *bgr_ptr++ = FXARGB_B(src_plt[i]);
+ *bgr_ptr++ = FXARGB_G(src_plt[i]);
+ *bgr_ptr++ = FXARGB_R(src_plt[i]);
+ }
+ bgr_ptr = (FX_LPBYTE)plt;
+ }
+ if (pIccTransform) {
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < 256; i++) {
+ plt[i] = FXCMYK_TODIB(src_plt[i]);
+ }
+ }
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE)plt, 256);
+ } else {
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < 256; i++) {
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]),
+ bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
+ bgr_ptr += 3;
+ }
+ bgr_ptr = (FX_LPBYTE)plt;
+ }
+ }
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ for (int col = 0; col < width; col ++) {
+ FX_LPBYTE src_pixel = bgr_ptr + 3 * (*src_scan++);
+ *dest_scan++ = *src_pixel++;
+ *dest_scan++ = *src_pixel++;
+ *dest_scan = *src_pixel++;
+ dest_scan += comps - 2;
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_24bppRgb2Rgb24(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ if (pIccTransform) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, width);
+ }
+ } else {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
+ FXSYS_memcpy32(dest_scan, src_scan, width * 3);
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_32bppRgb2Rgb24(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
+ for (int col = 0; col < width; col ++) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ src_scan++;
+ }
+ }
+ if (pIccTransform) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, dest_scan, width);
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_Rgb2Rgb32(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ int comps = pSrcBitmap->GetBPP() / 8;
+ if (pIccTransform) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * comps;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ dest_scan += 4;
+ src_scan += comps;
+ }
+ }
+ } else {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * comps;
+ for (int col = 0; col < width; col ++) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ dest_scan++;
+ src_scan += comps - 3;
+ }
+ }
+ }
+ return TRUE;
+}
+FX_BOOL _ConvertBuffer_32bppCmyk2Rgb32(FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ if (pIccTransform) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
+ for (int col = 0; col < width; col ++) {
+ pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
+ dest_scan += 4;
+ src_scan += 4;
+ }
+ }
+ } else {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
+ for (int col = 0; col < width; col ++) {
+ AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_scan[3],
+ dest_scan[2], dest_scan[1], dest_scan[0]);
+ dest_scan += 4;
+ src_scan += 4;
+ }
+ }
+ }
+ return TRUE;
+}
+FX_BOOL ConvertBuffer(FXDIB_Format dest_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD*& d_pal, void* pIccTransform)
+{
+ FXDIB_Format src_format = pSrcBitmap->GetFormat();
+ if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
+ pIccTransform = NULL;
+ }
+ switch (dest_format) {
+ case FXDIB_Invalid:
+ case FXDIB_1bppCmyk:
+ case FXDIB_1bppMask:
+ case FXDIB_1bppRgb:
+ ASSERT(FALSE);
+ return FALSE;
+ case FXDIB_8bppMask: {
+ if ((src_format & 0xff) == 1) {
+ if (pSrcBitmap->GetPalette()) {
+ return _ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return _ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top);
+ } else if ((src_format & 0xff) == 8) {
+ if (pSrcBitmap->GetPalette()) {
+ return _ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return _ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top);
+ } else if ((src_format & 0xff) >= 24) {
+ return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return FALSE;
+ }
+ case FXDIB_8bppRgb:
+ case FXDIB_8bppRgba: {
+ if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL) {
+ return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform);
+ }
+ d_pal = FX_Alloc(FX_DWORD, 256);
+ if (!d_pal) {
+ return FALSE;
+ }
+ FXSYS_memset32(d_pal, 0, sizeof(FX_DWORD) * 256);
+ if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && pSrcBitmap->GetPalette()) {
+ return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform);
+ } else if ((src_format & 0xff) >= 24) {
+ return _ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform);
+ }
+ return FALSE;
+ }
+ case FXDIB_Rgb:
+ case FXDIB_Rgba: {
+ if ((src_format & 0xff) == 1) {
+ if (pSrcBitmap->GetPalette()) {
+ return _ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return _ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top);
+ } else if ((src_format & 0xff) == 8) {
+ if (pSrcBitmap->GetPalette()) {
+ return _ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return _ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top);
+ } else if ((src_format & 0xff) == 24) {
+ return _ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ } else if ((src_format & 0xff) == 32) {
+ return _ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return FALSE;
+ }
+ case FXDIB_Argb:
+ case FXDIB_Rgb32: {
+ if ((src_format & 0xff) == 1) {
+ if (pSrcBitmap->GetPalette()) {
+ return _ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return _ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top);
+ } else if ((src_format & 0xff) == 8) {
+ if (pSrcBitmap->GetPalette()) {
+ return _ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return _ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top);
+ } else if ((src_format & 0xff) >= 24) {
+ if (src_format & 0x0400) {
+ return _ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return _ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
+ }
+ return FALSE;
+ }
+ default:
+ return FALSE;
+ }
+ return FALSE;
+}
+CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, const FX_RECT* pClip, void* pIccTransform) const
+{
+ if(dest_format == GetFormat() && pIccTransform == NULL) {
+ return Clone(pClip);
+ }
+ if (pClip) {
+ CFX_DIBitmap* pClone = Clone(pClip);
+ if (pClone == NULL) {
+ return NULL;
+ }
+ if(!pClone->ConvertFormat(dest_format, pIccTransform)) {
+ delete pClone;
+ return NULL;
+ }
+ return pClone;
+ }
+ CFX_DIBitmap* pClone = FX_NEW CFX_DIBitmap;
+ if (!pClone) {
+ return NULL;
+ }
+ if(!pClone->Create(m_Width, m_Height, dest_format)) {
+ delete pClone;
+ return NULL;
+ }
+ FX_BOOL ret = TRUE;
+ CFX_DIBitmap* pSrcAlpha = NULL;
+ if (m_AlphaFlag & 2) {
+ pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask;
+ if (pSrcAlpha == NULL) {
+ delete pClone;
+ return NULL;
+ }
+ }
+ if (dest_format & 0x0200) {
+ if (dest_format == FXDIB_Argb)
+ ret = pSrcAlpha ?
+ pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) :
+ pClone->LoadChannel(FXDIB_Alpha, 0xff);
+ else {
+ ret = pClone->CopyAlphaMask(pSrcAlpha);
+ }
+ }
+ if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) {
+ delete pSrcAlpha;
+ pSrcAlpha = NULL;
+ }
+ if (!ret) {
+ delete pClone;
+ return NULL;
+ }
+ FX_DWORD* pal_8bpp = NULL;
+ ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform);
+ if (!ret) {
+ if (pal_8bpp) {
+ FX_Free(pal_8bpp);
+ }
+ delete pClone;
+ return NULL;
+ }
+ if (pal_8bpp) {
+ pClone->CopyPalette(pal_8bpp);
+ FX_Free(pal_8bpp);
+ pal_8bpp = NULL;
+ }
+ return pClone;
+}
+FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, void* pIccTransform)
+{
+ FXDIB_Format src_format = GetFormat();
+ if (dest_format == src_format && pIccTransform == NULL) {
+ return TRUE;
+ }
+ if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && m_pPalette == NULL) {
+ m_AlphaFlag = 1;
+ return TRUE;
+ }
+ if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 && pIccTransform == NULL) {
+ m_AlphaFlag = 2;
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE scanline = m_pBuffer + row * m_Pitch + 3;
+ for (int col = 0; col < m_Width; col ++) {
+ *scanline = 0xff;
+ scanline += 4;
+ }
+ }
+ return TRUE;
+ }
+ int dest_bpp = dest_format & 0xff;
+ int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4;
+ FX_LPBYTE dest_buf = FX_AllocNL(FX_BYTE, dest_pitch * m_Height + 4);
+ if (dest_buf == NULL) {
+ return FALSE;
+ }
+ CFX_DIBitmap* pAlphaMask = NULL;
+ if (dest_format == FXDIB_Argb) {
+ FXSYS_memset8(dest_buf, 0xff, dest_pitch * m_Height + 4);
+ if (m_pAlphaMask) {
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE pDstScanline = dest_buf + row * dest_pitch + 3;
+ FX_LPCBYTE pSrcScanline = m_pAlphaMask->GetScanline(row);
+ for (int col = 0; col < m_Width; col ++) {
+ *pDstScanline = *pSrcScanline++;
+ pDstScanline += 4;
+ }
+ }
+ }
+ } else if (dest_format & 0x0200) {
+ if (src_format == FXDIB_Argb) {
+ pAlphaMask = GetAlphaMask();
+ if (pAlphaMask == NULL) {
+ FX_Free(dest_buf);
+ return FALSE;
+ }
+ } else {
+ if (m_pAlphaMask == NULL) {
+ if (!BuildAlphaMask()) {
+ FX_Free(dest_buf);
+ return FALSE;
+ }
+ pAlphaMask = m_pAlphaMask;
+ m_pAlphaMask = NULL;
+ } else {
+ pAlphaMask = m_pAlphaMask;
+ }
+ }
+ }
+ FX_BOOL ret = FALSE;
+ FX_DWORD* pal_8bpp = NULL;
+ ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform);
+ if (!ret) {
+ if (pal_8bpp) {
+ FX_Free(pal_8bpp);
+ }
+ if (pAlphaMask != m_pAlphaMask) {
+ delete pAlphaMask;
+ }
+ if (dest_buf) {
+ FX_Free(dest_buf);
+ }
+ return FALSE;
+ }
+ if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) {
+ delete m_pAlphaMask;
+ }
+ m_pAlphaMask = pAlphaMask;
+ if (m_pPalette) {
+ FX_Free(m_pPalette);
+ }
+ m_pPalette = pal_8bpp;
+ if (!m_bExtBuf) {
+ FX_Free(m_pBuffer);
+ }
+ m_bExtBuf = FALSE;
+ m_pBuffer = dest_buf;
+ m_bpp = (FX_BYTE)dest_format;
+ m_AlphaFlag = (FX_BYTE)(dest_format >> 8);
+ m_Pitch = dest_pitch;
+ return TRUE;
+}
diff --git a/core/src/fxge/dib/fx_dib_engine.cpp b/core/src/fxge/dib/fx_dib_engine.cpp new file mode 100644 index 0000000000..3ddbff6409 --- /dev/null +++ b/core/src/fxge/dib/fx_dib_engine.cpp @@ -0,0 +1,867 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../../include/fxge/fx_dib.h"
+#include "../../../include/fxge/fx_ge.h"
+#include "dib_int.h"
+#include <limits.h>
+extern int SDP_Table[513];
+void CWeightTable::Calc(int dest_len, int dest_min, int dest_max, int src_len, int src_min, int src_max, int flags)
+{
+ if (m_pWeightTables) {
+ FX_Free(m_pWeightTables);
+ m_pWeightTables = NULL;
+ }
+ double scale, base;
+ scale = FXSYS_Div((FX_FLOAT)(src_len), (FX_FLOAT)(dest_len));
+ if (dest_len < 0) {
+ base = (FX_FLOAT)(src_len);
+ } else {
+ base = 0;
+ }
+ int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1;
+ m_ItemSize = sizeof(int) * 2 + (int)(sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + ext_size));
+ m_DestMin = dest_min;
+ if ((dest_max - dest_min) > (int)((1U << 30) - 4) / m_ItemSize) {
+ return;
+ }
+ m_pWeightTables = FX_AllocNL(FX_BYTE, (dest_max - dest_min) * m_ItemSize + 4);
+ if (m_pWeightTables == NULL) {
+ return;
+ }
+ FXSYS_memset32(m_pWeightTables, 0, sizeof(FX_BYTE) * ((dest_max - dest_min)*m_ItemSize + 4));
+ if ((flags & FXDIB_NOSMOOTH) != 0 || FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
+ for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel ++) {
+ PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
+ double src_pos = dest_pixel * scale + scale / 2 + base;
+ if (flags & FXDIB_INTERPOL) {
+ pixel_weights.m_SrcStart = (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2);
+ pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2);
+ if (pixel_weights.m_SrcStart < src_min) {
+ pixel_weights.m_SrcStart = src_min;
+ }
+ if (pixel_weights.m_SrcEnd >= src_max) {
+ pixel_weights.m_SrcEnd = src_max - 1;
+ }
+ if (pixel_weights.m_SrcStart == pixel_weights.m_SrcEnd) {
+ pixel_weights.m_Weights[0] = 65536;
+ } else {
+ pixel_weights.m_Weights[1] = FXSYS_round((FX_FLOAT)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) * 65536);
+ pixel_weights.m_Weights[0] = 65536 - pixel_weights.m_Weights[1];
+ }
+ } else if (flags & FXDIB_BICUBIC_INTERPOL) {
+ pixel_weights.m_SrcStart = (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2);
+ pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2);
+ int start = pixel_weights.m_SrcStart - 1;
+ int end = pixel_weights.m_SrcEnd + 1;
+ if (start < src_min) {
+ start = src_min;
+ }
+ if (end >= src_max) {
+ end = src_max - 1;
+ }
+ if (pixel_weights.m_SrcStart < src_min) {
+ src_pos += src_min - pixel_weights.m_SrcStart;
+ pixel_weights.m_SrcStart = src_min;
+ }
+ if (pixel_weights.m_SrcEnd >= src_max) {
+ pixel_weights.m_SrcEnd = src_max - 1;
+ }
+ int weight;
+ weight = FXSYS_round((FX_FLOAT)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) * 256);
+ if (start == end) {
+ pixel_weights.m_Weights[0] = (SDP_Table[256 + weight] + SDP_Table[weight] + SDP_Table[256 - weight] + SDP_Table[512 - weight]) << 8;
+ } else if ((start == pixel_weights.m_SrcStart && (pixel_weights.m_SrcStart == pixel_weights.m_SrcEnd ||
+ end == pixel_weights.m_SrcEnd) && start < end) || (start < pixel_weights.m_SrcStart && pixel_weights.m_SrcStart == pixel_weights.m_SrcEnd && end == pixel_weights.m_SrcEnd)) {
+ if (start < pixel_weights.m_SrcStart) {
+ pixel_weights.m_Weights[0] = SDP_Table[256 + weight] << 8;
+ pixel_weights.m_Weights[1] = (SDP_Table[weight] + SDP_Table[256 - weight] + SDP_Table[512 - weight]) << 8;
+ } else {
+ if (pixel_weights.m_SrcStart == pixel_weights.m_SrcEnd) {
+ pixel_weights.m_Weights[0] = (SDP_Table[256 + weight] + SDP_Table[weight] + SDP_Table[256 - weight]) << 8;
+ pixel_weights.m_Weights[1] = SDP_Table[512 - weight] << 8;
+ } else {
+ pixel_weights.m_Weights[0] = (SDP_Table[256 + weight] + SDP_Table[weight]) << 8;
+ pixel_weights.m_Weights[1] = (SDP_Table[256 - weight] + SDP_Table[512 - weight]) << 8;
+ }
+ }
+ if (pixel_weights.m_SrcStart == pixel_weights.m_SrcEnd) {
+ pixel_weights.m_SrcEnd = end;
+ }
+ if (start < pixel_weights.m_SrcStart) {
+ pixel_weights.m_SrcStart = start;
+ }
+ } else if (start == pixel_weights.m_SrcStart &&
+ start < pixel_weights.m_SrcEnd &&
+ pixel_weights.m_SrcEnd < end) {
+ pixel_weights.m_Weights[0] = (SDP_Table[256 + weight] + SDP_Table[weight]) << 8;
+ pixel_weights.m_Weights[1] = SDP_Table[256 - weight] << 8;
+ pixel_weights.m_Weights[2] = SDP_Table[512 - weight] << 8;
+ pixel_weights.m_SrcEnd = end;
+ } else if (start < pixel_weights.m_SrcStart &&
+ pixel_weights.m_SrcStart < pixel_weights.m_SrcEnd &&
+ pixel_weights.m_SrcEnd == end) {
+ pixel_weights.m_Weights[0] = SDP_Table[256 + weight] << 8;
+ pixel_weights.m_Weights[1] = SDP_Table[weight] << 8;
+ pixel_weights.m_Weights[2] = (SDP_Table[256 - weight] + SDP_Table[512 - weight]) << 8;
+ pixel_weights.m_SrcStart = start;
+ } else {
+ pixel_weights.m_Weights[0] = SDP_Table[256 + weight] << 8;
+ pixel_weights.m_Weights[1] = SDP_Table[weight] << 8;
+ pixel_weights.m_Weights[2] = SDP_Table[256 - weight] << 8;
+ pixel_weights.m_Weights[3] = SDP_Table[512 - weight] << 8;
+ pixel_weights.m_SrcStart = start;
+ pixel_weights.m_SrcEnd = end;
+ }
+ } else {
+ pixel_weights.m_SrcStart = pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos);
+ if (pixel_weights.m_SrcStart < src_min) {
+ pixel_weights.m_SrcStart = src_min;
+ }
+ if (pixel_weights.m_SrcEnd >= src_max) {
+ pixel_weights.m_SrcEnd = src_max - 1;
+ }
+ pixel_weights.m_Weights[0] = 65536;
+ }
+ }
+ return;
+ }
+ for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel ++) {
+ PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
+ double src_start = dest_pixel * scale + base;
+ double src_end = src_start + scale;
+ int start_i, end_i;
+ if (src_start < src_end) {
+ start_i = (int)FXSYS_floor((FX_FLOAT)src_start);
+ end_i = (int)FXSYS_ceil((FX_FLOAT)src_end);
+ } else {
+ start_i = (int)FXSYS_floor((FX_FLOAT)src_end);
+ end_i = (int)FXSYS_ceil((FX_FLOAT)src_start);
+ }
+ if (start_i < src_min) {
+ start_i = src_min;
+ }
+ if (end_i >= src_max) {
+ end_i = src_max - 1;
+ }
+ if (start_i > end_i) {
+ if (start_i >= src_max) {
+ start_i = src_max - 1;
+ }
+ pixel_weights.m_SrcStart = start_i;
+ pixel_weights.m_SrcEnd = start_i;
+ continue;
+ }
+ pixel_weights.m_SrcStart = start_i;
+ pixel_weights.m_SrcEnd = end_i;
+ for (int j = start_i; j <= end_i; j ++) {
+ double dest_start = FXSYS_Div((FX_FLOAT)(j) - base, scale);
+ double dest_end = FXSYS_Div((FX_FLOAT)(j + 1) - base, scale);
+ if (dest_start > dest_end) {
+ double temp = dest_start;
+ dest_start = dest_end;
+ dest_end = temp;
+ }
+ double area_start = dest_start > (FX_FLOAT)(dest_pixel) ? dest_start : (FX_FLOAT)(dest_pixel);
+ double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1) ? (FX_FLOAT)(dest_pixel + 1) : dest_end;
+ double weight = area_start >= area_end ? 0.0f : area_end - area_start;
+ if (weight == 0 && j == end_i) {
+ pixel_weights.m_SrcEnd --;
+ break;
+ }
+ pixel_weights.m_Weights[j - start_i] = FXSYS_round((FX_FLOAT)(weight * 65536));
+ }
+ }
+}
+CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap, FXDIB_Format dest_format,
+ int dest_width, int dest_height, const FX_RECT& clip_rect,
+ const CFX_DIBSource* pSrcBitmap, int flags)
+{
+ m_State = 0;
+ m_DestFormat = dest_format;
+ m_DestBpp = dest_format & 0xff;
+ m_SrcBpp = pSrcBitmap->GetFormat() & 0xff;
+ m_bHasAlpha = pSrcBitmap->GetFormat() & 0x200;
+ m_pSrcPalette = pSrcBitmap->GetPalette();
+ m_pDestBitmap = pDestBitmap;
+ m_DestWidth = dest_width;
+ m_DestHeight = dest_height;
+ m_pInterBuf = NULL;
+ m_pExtraAlphaBuf = NULL;
+ m_pDestMaskScanline = NULL;
+ m_DestClip = clip_rect;
+ FX_DWORD size = clip_rect.Width();
+ if (size && m_DestBpp > (int)(INT_MAX / size)) {
+ return;
+ }
+ size *= m_DestBpp;
+ if (size > INT_MAX - 31) {
+ return;
+ }
+ size += 31;
+ size = size / 32 * 4;
+ m_pDestScanline = FX_AllocNL(FX_BYTE, size);
+ if (m_pDestScanline == NULL) {
+ return;
+ }
+ FXSYS_memset32(m_pDestScanline, 0, sizeof(FX_BYTE) * size);
+ if (dest_format == FXDIB_Rgb32) {
+ FXSYS_memset8(m_pDestScanline, 255, size);
+ }
+ m_InterPitch = (m_DestClip.Width() * m_DestBpp + 31) / 32 * 4;
+ m_ExtraMaskPitch = (m_DestClip.Width() * 8 + 31) / 32 * 4;
+ m_pInterBuf = NULL;
+ m_pSource = pSrcBitmap;
+ m_SrcWidth = pSrcBitmap->GetWidth();
+ m_SrcHeight = pSrcBitmap->GetHeight();
+ m_SrcPitch = (m_SrcWidth * m_SrcBpp + 31) / 32 * 4;
+ if ((flags & FXDIB_NOSMOOTH) == 0) {
+ FX_BOOL bInterpol = flags & FXDIB_INTERPOL || flags & FXDIB_BICUBIC_INTERPOL;
+ if (!bInterpol && FXSYS_abs(dest_width) != 0 && FXSYS_abs(dest_height) < m_SrcWidth * m_SrcHeight * 8 / FXSYS_abs(dest_width)) {
+ flags = FXDIB_INTERPOL;
+ }
+ m_Flags = flags;
+ } else {
+ m_Flags = FXDIB_NOSMOOTH;
+ if (flags & FXDIB_DOWNSAMPLE) {
+ m_Flags |= FXDIB_DOWNSAMPLE;
+ }
+ }
+ double scale_x = FXSYS_Div((FX_FLOAT)(m_SrcWidth), (FX_FLOAT)(m_DestWidth));
+ double scale_y = FXSYS_Div((FX_FLOAT)(m_SrcHeight), (FX_FLOAT)(m_DestHeight));
+ double base_x = m_DestWidth > 0 ? 0.0f : (FX_FLOAT)(m_DestWidth);
+ double base_y = m_DestHeight > 0 ? 0.0f : (FX_FLOAT)(m_DestHeight);
+ double src_left = FXSYS_Mul(scale_x, (FX_FLOAT)(clip_rect.left) + base_x);
+ double src_right = FXSYS_Mul(scale_x, (FX_FLOAT)(clip_rect.right) + base_x);
+ double src_top = FXSYS_Mul(scale_y, (FX_FLOAT)(clip_rect.top) + base_y);
+ double src_bottom = FXSYS_Mul(scale_y, (FX_FLOAT)(clip_rect.bottom) + base_y);
+ if (src_left > src_right) {
+ double temp = src_left;
+ src_left = src_right;
+ src_right = temp;
+ }
+ if (src_top > src_bottom) {
+ double temp = src_top;
+ src_top = src_bottom;
+ src_bottom = temp;
+ }
+ m_SrcClip.left = (int)FXSYS_floor((FX_FLOAT)src_left);
+ m_SrcClip.right = (int)FXSYS_ceil((FX_FLOAT)src_right);
+ m_SrcClip.top = (int)FXSYS_floor((FX_FLOAT)src_top);
+ m_SrcClip.bottom = (int)FXSYS_ceil((FX_FLOAT)src_bottom);
+ FX_RECT src_rect(0, 0, m_SrcWidth, m_SrcHeight);
+ m_SrcClip.Intersect(src_rect);
+ if (m_SrcBpp == 1) {
+ if (m_DestBpp == 8) {
+ m_TransMethod = 1;
+ } else {
+ m_TransMethod = 2;
+ }
+ } else if (m_SrcBpp == 8) {
+ if (m_DestBpp == 8) {
+ if (!m_bHasAlpha) {
+ m_TransMethod = 3;
+ } else {
+ m_TransMethod = 4;
+ }
+ } else {
+ if (!m_bHasAlpha) {
+ m_TransMethod = 5;
+ } else {
+ m_TransMethod = 6;
+ }
+ }
+ } else {
+ if (!m_bHasAlpha) {
+ m_TransMethod = 7;
+ } else {
+ m_TransMethod = 8;
+ }
+ }
+}
+FX_BOOL CStretchEngine::Continue(IFX_Pause* pPause)
+{
+ while (m_State == 1) {
+ if (ContinueStretchHorz(pPause)) {
+ return TRUE;
+ }
+ m_State = 2;
+ StretchVert();
+ }
+ return FALSE;
+}
+CStretchEngine::~CStretchEngine()
+{
+ if (m_pDestScanline) {
+ FX_Free(m_pDestScanline);
+ }
+ if (m_pInterBuf) {
+ FX_Free(m_pInterBuf);
+ }
+ if (m_pExtraAlphaBuf) {
+ FX_Free(m_pExtraAlphaBuf);
+ }
+ if (m_pDestMaskScanline) {
+ FX_Free(m_pDestMaskScanline);
+ }
+}
+FX_BOOL CStretchEngine::StartStretchHorz()
+{
+ if (m_DestWidth == 0 || m_pDestScanline == NULL || m_SrcClip.Height() > (int)((1U << 29) / m_InterPitch) || m_SrcClip.Height() == 0) {
+ return FALSE;
+ }
+#ifndef _FPDFAPI_MINI_
+ m_pInterBuf = FX_AllocNL(unsigned char, m_SrcClip.Height() * m_InterPitch);
+#else
+ m_pInterBuf = FX_Alloc(unsigned char, m_SrcClip.Height() * m_InterPitch);
+#endif
+ if (m_pInterBuf == NULL) {
+ return FALSE;
+ }
+ if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) {
+ m_pExtraAlphaBuf = FX_Alloc(unsigned char, m_SrcClip.Height() * m_ExtraMaskPitch);
+ if (!m_pExtraAlphaBuf) {
+ return FALSE;
+ }
+ FX_DWORD size = (m_DestClip.Width() * 8 + 31) / 32 * 4;
+ m_pDestMaskScanline = FX_AllocNL(unsigned char, size);
+ if (!m_pDestMaskScanline) {
+ return FALSE;
+ }
+ }
+ m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right, m_SrcWidth, m_SrcClip.left, m_SrcClip.right, m_Flags);
+ if (m_WeightTable.m_pWeightTables == NULL) {
+ return FALSE;
+ }
+ m_CurRow = m_SrcClip.top;
+ m_State = 1;
+ return TRUE;
+}
+#define FX_STRECH_PAUSE_ROWS 10
+FX_BOOL CStretchEngine::ContinueStretchHorz(IFX_Pause* pPause)
+{
+ if (!m_DestWidth) {
+ return 0;
+ }
+ if (m_pSource->SkipToScanline(m_CurRow, pPause)) {
+ return TRUE;
+ }
+ int Bpp = m_DestBpp / 8;
+ int rows_to_go = FX_STRECH_PAUSE_ROWS;
+ for (; m_CurRow < m_SrcClip.bottom; m_CurRow ++) {
+ if (rows_to_go == 0) {
+ if (pPause && pPause->NeedToPauseNow()) {
+ return TRUE;
+ } else {
+ rows_to_go = FX_STRECH_PAUSE_ROWS;
+ }
+ }
+ FX_LPCBYTE src_scan = m_pSource->GetScanline(m_CurRow);
+ FX_LPBYTE dest_scan = m_pInterBuf + (m_CurRow - m_SrcClip.top) * m_InterPitch;
+ FX_LPCBYTE src_scan_mask = NULL;
+ FX_LPBYTE dest_scan_mask = NULL;
+ if (m_pExtraAlphaBuf) {
+ src_scan_mask = m_pSource->m_pAlphaMask->GetScanline(m_CurRow);
+ dest_scan_mask = m_pExtraAlphaBuf + (m_CurRow - m_SrcClip.top) * m_ExtraMaskPitch;
+ }
+ switch (m_TransMethod) {
+ case 1:
+ case 2: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
+ int dest_a = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ if (src_scan[j / 8] & (1 << (7 - j % 8))) {
+ dest_a += pixel_weight * 255;
+ }
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
+ }
+ *dest_scan++ = (FX_BYTE)(dest_a >> 16);
+ }
+ break;
+ }
+ case 3: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
+ int dest_a = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ dest_a += pixel_weight * src_scan[j];
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
+ }
+ *dest_scan++ = (FX_BYTE)(dest_a >> 16);
+ }
+ break;
+ }
+ case 4: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
+ int dest_a = 0, dest_r = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ pixel_weight = pixel_weight * src_scan_mask[j] / 255;
+ dest_r += pixel_weight * src_scan[j];
+ dest_a += pixel_weight;
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_r = dest_r < 0 ? 0 : dest_r > 16711680 ? 16711680 : dest_r;
+ dest_a = dest_a < 0 ? 0 : dest_a > 65536 ? 65536 : dest_a;
+ }
+ *dest_scan++ = (FX_BYTE)(dest_r >> 16);
+ *dest_scan_mask++ = (FX_BYTE)((dest_a * 255) >> 16);
+ }
+ break;
+ }
+ case 5: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
+ int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0, dest_k = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ unsigned long argb_cmyk = m_pSrcPalette[src_scan[j]];
+ if (m_DestFormat == FXDIB_Rgb) {
+ dest_r_y += pixel_weight * (FX_BYTE)(argb_cmyk >> 16);
+ dest_g_m += pixel_weight * (FX_BYTE)(argb_cmyk >> 8);
+ dest_b_c += pixel_weight * (FX_BYTE)argb_cmyk;
+ } else {
+ dest_b_c += pixel_weight * (FX_BYTE)(argb_cmyk >> 24);
+ dest_g_m += pixel_weight * (FX_BYTE)(argb_cmyk >> 16);
+ dest_r_y += pixel_weight * (FX_BYTE)(argb_cmyk >> 8);
+ }
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_r_y = dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y;
+ dest_g_m = dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m;
+ dest_b_c = dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c;
+ }
+ *dest_scan++ = (FX_BYTE)(dest_b_c >> 16);
+ *dest_scan++ = (FX_BYTE)(dest_g_m >> 16);
+ *dest_scan++ = (FX_BYTE)(dest_r_y >> 16);
+ }
+ break;
+ }
+ case 6: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
+ int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0, dest_k = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ pixel_weight = pixel_weight * src_scan_mask[j] / 255;
+ unsigned long argb_cmyk = m_pSrcPalette[src_scan[j]];
+ if (m_DestFormat == FXDIB_Rgba) {
+ dest_r_y += pixel_weight * (FX_BYTE)(argb_cmyk >> 16);
+ dest_g_m += pixel_weight * (FX_BYTE)(argb_cmyk >> 8);
+ dest_b_c += pixel_weight * (FX_BYTE)argb_cmyk;
+ } else {
+ dest_b_c += pixel_weight * (FX_BYTE)(argb_cmyk >> 24);
+ dest_g_m += pixel_weight * (FX_BYTE)(argb_cmyk >> 16);
+ dest_r_y += pixel_weight * (FX_BYTE)(argb_cmyk >> 8);
+ }
+ dest_a += pixel_weight;
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_k = dest_k < 0 ? 0 : dest_k > 16711680 ? 16711680 : dest_k;
+ dest_b_c = dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c;
+ dest_g_m = dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m;
+ dest_r_y = dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y;
+ dest_a = dest_a < 0 ? 0 : dest_a > 65536 ? 65536 : dest_a;
+ }
+ *dest_scan++ = (FX_BYTE)(dest_b_c >> 16);
+ *dest_scan++ = (FX_BYTE)(dest_g_m >> 16);
+ *dest_scan++ = (FX_BYTE)(dest_r_y >> 16);
+ *dest_scan_mask++ = (FX_BYTE)((dest_a * 255) >> 16);
+ }
+ break;
+ }
+ case 7: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
+ int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0, dest_k = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ FX_LPCBYTE src_pixel = src_scan + j * Bpp;
+ dest_b_c += pixel_weight * (*src_pixel++);
+ dest_g_m += pixel_weight * (*src_pixel++);
+ dest_r_y += pixel_weight * (*src_pixel);
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_b_c = dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c;
+ dest_g_m = dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m;
+ dest_r_y = dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y;
+ }
+ *dest_scan++ = (FX_BYTE)((dest_b_c) >> 16);
+ *dest_scan++ = (FX_BYTE)((dest_g_m) >> 16);
+ *dest_scan++ = (FX_BYTE)((dest_r_y) >> 16);
+ dest_scan += Bpp - 3;
+ }
+ break;
+ }
+ case 8: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
+ int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0, dest_k = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ FX_LPCBYTE src_pixel = src_scan + j * Bpp;
+ if (m_DestFormat == FXDIB_Argb) {
+ pixel_weight = pixel_weight * src_pixel[3] / 255;
+ } else {
+ pixel_weight = pixel_weight * src_scan_mask[j] / 255;
+ }
+ dest_b_c += pixel_weight * (*src_pixel++);
+ dest_g_m += pixel_weight * (*src_pixel++);
+ dest_r_y += pixel_weight * (*src_pixel);
+ dest_a += pixel_weight;
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_r_y = dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y;
+ dest_g_m = dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m;
+ dest_b_c = dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c;
+ dest_a = dest_a < 0 ? 0 : dest_a > 65536 ? 65536 : dest_a;
+ }
+ *dest_scan++ = (FX_BYTE)((dest_b_c) >> 16);
+ *dest_scan++ = (FX_BYTE)((dest_g_m) >> 16);
+ *dest_scan++ = (FX_BYTE)((dest_r_y) >> 16);
+ if (m_DestFormat == FXDIB_Argb) {
+ *dest_scan = (FX_BYTE)((dest_a * 255) >> 16);
+ }
+ if (dest_scan_mask) {
+ *dest_scan_mask++ = (FX_BYTE)((dest_a * 255) >> 16);
+ }
+ dest_scan += Bpp - 3;
+ }
+ break;
+ }
+ }
+ rows_to_go --;
+ }
+ return FALSE;
+}
+void CStretchEngine::StretchVert()
+{
+ if (m_DestHeight == 0) {
+ return;
+ }
+ CWeightTable table;
+ table.Calc(m_DestHeight, m_DestClip.top, m_DestClip.bottom, m_SrcHeight, m_SrcClip.top, m_SrcClip.bottom, m_Flags);
+ if (table.m_pWeightTables == NULL) {
+ return;
+ }
+ int DestBpp = m_DestBpp / 8;
+ for (int row = m_DestClip.top; row < m_DestClip.bottom; row ++) {
+ unsigned char* dest_scan = m_pDestScanline;
+ unsigned char* dest_sacn_mask = m_pDestMaskScanline;
+ PixelWeight* pPixelWeights = table.GetPixelWeight(row);
+ switch(m_TransMethod) {
+ case 1:
+ case 2:
+ case 3: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ unsigned char* src_scan = m_pInterBuf + (col - m_DestClip.left) * DestBpp;
+ int dest_a = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ dest_a += pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch];
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
+ }
+ *dest_scan = (FX_BYTE)(dest_a >> 16);
+ dest_scan += DestBpp;
+ }
+ break;
+ }
+ case 4: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ unsigned char* src_scan = m_pInterBuf + (col - m_DestClip.left) * DestBpp;
+ unsigned char* src_scan_mask = m_pExtraAlphaBuf + (col - m_DestClip.left);
+ int dest_a = 0, dest_k = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ dest_k += pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch];
+ dest_a += pixel_weight * src_scan_mask[(j - m_SrcClip.top) * m_ExtraMaskPitch];
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_k = dest_k < 0 ? 0 : dest_k > 16711680 ? 16711680 : dest_k;
+ dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
+ }
+ *dest_scan = (FX_BYTE)(dest_k >> 16);
+ dest_scan += DestBpp;
+ *dest_sacn_mask++ = (FX_BYTE)(dest_a >> 16);
+ }
+ break;
+ }
+ case 5:
+ case 7: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ unsigned char* src_scan = m_pInterBuf + (col - m_DestClip.left) * DestBpp;
+ int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0, dest_k = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ FX_LPCBYTE src_pixel = src_scan + (j - m_SrcClip.top) * m_InterPitch;
+ dest_b_c += pixel_weight * (*src_pixel++);
+ dest_g_m += pixel_weight * (*src_pixel++);
+ dest_r_y += pixel_weight * (*src_pixel);
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_r_y = dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y;
+ dest_g_m = dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m;
+ dest_b_c = dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c;
+ }
+ dest_scan[0] = (FX_BYTE)((dest_b_c) >> 16);
+ dest_scan[1] = (FX_BYTE)((dest_g_m) >> 16);
+ dest_scan[2] = (FX_BYTE)((dest_r_y) >> 16);
+ dest_scan += DestBpp;
+ }
+ break;
+ }
+ case 6:
+ case 8: {
+ for (int col = m_DestClip.left; col < m_DestClip.right; col ++) {
+ unsigned char* src_scan = m_pInterBuf + (col - m_DestClip.left) * DestBpp;
+ unsigned char* src_scan_mask = NULL;
+ if (m_DestFormat != FXDIB_Argb) {
+ src_scan_mask = m_pExtraAlphaBuf + (col - m_DestClip.left);
+ }
+ int dest_a = 0, dest_k = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0;
+ for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; j ++) {
+ int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
+ FX_LPCBYTE src_pixel = src_scan + (j - m_SrcClip.top) * m_InterPitch;
+ int mask_v = 255;
+ if (src_scan_mask) {
+ mask_v = src_scan_mask[(j - m_SrcClip.top) * m_ExtraMaskPitch];
+ }
+ dest_b_c += pixel_weight * (*src_pixel++);
+ dest_g_m += pixel_weight * (*src_pixel++);
+ dest_r_y += pixel_weight * (*src_pixel);
+ if (m_DestFormat == FXDIB_Argb) {
+ dest_a += pixel_weight * (*(src_pixel + 1));
+ } else {
+ dest_a += pixel_weight * mask_v;
+ }
+ }
+ if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ dest_r_y = dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y;
+ dest_g_m = dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m;
+ dest_b_c = dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c;
+ dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
+ }
+ if (dest_a) {
+ int r = ((FX_DWORD)dest_r_y) * 255 / dest_a;
+ int g = ((FX_DWORD)dest_g_m) * 255 / dest_a;
+ int b = ((FX_DWORD)dest_b_c) * 255 / dest_a;
+ dest_scan[0] = b > 255 ? 255 : b < 0 ? 0 : b;
+ dest_scan[1] = g > 255 ? 255 : g < 0 ? 0 : g;
+ dest_scan[2] = r > 255 ? 255 : r < 0 ? 0 : r;
+ }
+ if (m_DestFormat == FXDIB_Argb) {
+ dest_scan[3] = (FX_BYTE)((dest_a) >> 16);
+ } else {
+ *dest_sacn_mask = (FX_BYTE)((dest_a) >> 16);
+ }
+ dest_scan += DestBpp;
+ if (dest_sacn_mask) {
+ dest_sacn_mask++;
+ }
+ }
+ break;
+ }
+ }
+ m_pDestBitmap->ComposeScanline(row - m_DestClip.top, m_pDestScanline, m_pDestMaskScanline);
+ }
+}
+CFX_ImageStretcher::CFX_ImageStretcher()
+{
+ m_pScanline = NULL;
+ m_pStretchEngine = NULL;
+ m_pMaskScanline = NULL;
+}
+CFX_ImageStretcher::~CFX_ImageStretcher()
+{
+ if (m_pScanline) {
+ FX_Free(m_pScanline);
+ }
+ if (m_pStretchEngine) {
+ delete m_pStretchEngine;
+ }
+ if (m_pMaskScanline) {
+ FX_Free(m_pMaskScanline);
+ }
+}
+FXDIB_Format _GetStretchedFormat(const CFX_DIBSource* pSrc)
+{
+ FXDIB_Format format = pSrc->GetFormat();
+ if (format == FXDIB_1bppMask) {
+ format = FXDIB_8bppMask;
+ } else if (format == FXDIB_1bppRgb) {
+ format = FXDIB_8bppRgb;
+ } else if (format == FXDIB_8bppRgb) {
+ if (pSrc->GetPalette()) {
+ format = FXDIB_Rgb;
+ }
+ }
+ return format;
+}
+FX_BOOL CFX_ImageStretcher::Start(IFX_ScanlineComposer* pDest,
+ const CFX_DIBSource* pSource, int dest_width, int dest_height,
+ const FX_RECT& rect, FX_DWORD flags)
+{
+ m_DestFormat = _GetStretchedFormat(pSource);
+ m_DestBPP = m_DestFormat & 0xff;
+ m_pDest = pDest;
+ m_pSource = pSource;
+ m_DestWidth = dest_width;
+ m_DestHeight = dest_height;
+ m_ClipRect = rect;
+ m_Flags = flags;
+ if (pSource->GetFormat() == FXDIB_1bppRgb && pSource->GetPalette()) {
+ FX_ARGB pal[256];
+ int a0, r0, g0, b0, a1, r1, g1, b1;
+ ArgbDecode(pSource->GetPaletteEntry(0), a0, r0, g0, b0);
+ ArgbDecode(pSource->GetPaletteEntry(1), a1, r1, g1, b1);
+ for (int i = 0; i < 256; i ++) {
+ int a = a0 + (a1 - a0) * i / 255;
+ int r = r0 + (r1 - r0) * i / 255;
+ int g = g0 + (g1 - g0) * i / 255;
+ int b = b0 + (b1 - b0) * i / 255;
+ pal[i] = ArgbEncode(a, r, g, b);
+ }
+ if (!pDest->SetInfo(rect.Width(), rect.Height(), m_DestFormat, pal)) {
+ return FALSE;
+ }
+ } else if (pSource->GetFormat() == FXDIB_1bppCmyk && pSource->GetPalette()) {
+ FX_CMYK pal[256];
+ int c0, m0, y0, k0, c1, m1, y1, k1;
+ CmykDecode(pSource->GetPaletteEntry(0), c0, m0, y0, k0);
+ CmykDecode(pSource->GetPaletteEntry(1), c1, m1, y1, k1);
+ for (int i = 0; i < 256; i ++) {
+ int c = c0 + (c1 - c0) * i / 255;
+ int m = m0 + (m1 - m0) * i / 255;
+ int y = y0 + (y1 - y0) * i / 255;
+ int k = k0 + (k1 - k0) * i / 255;
+ pal[i] = CmykEncode(c, m, y, k);
+ }
+ if (!pDest->SetInfo(rect.Width(), rect.Height(), m_DestFormat, pal)) {
+ return FALSE;
+ }
+ } else if (!pDest->SetInfo(rect.Width(), rect.Height(), m_DestFormat, NULL)) {
+ return FALSE;
+ }
+ if (flags & FXDIB_DOWNSAMPLE) {
+ return StartQuickStretch();
+ } else {
+ return StartStretch();
+ }
+}
+FX_BOOL CFX_ImageStretcher::Continue(IFX_Pause* pPause)
+{
+ if (m_Flags & FXDIB_DOWNSAMPLE) {
+ return ContinueQuickStretch(pPause);
+ } else {
+ return ContinueStretch(pPause);
+ }
+}
+#ifndef _FPDFAPI_MINI_
+#define MAX_PROGRESSIVE_STRETCH_PIXELS 1000000
+#else
+#define MAX_PROGRESSIVE_STRETCH_PIXELS 100000
+#endif
+FX_BOOL CFX_ImageStretcher::StartStretch()
+{
+ m_pStretchEngine = FX_NEW CStretchEngine(m_pDest, m_DestFormat, m_DestWidth, m_DestHeight, m_ClipRect, m_pSource, m_Flags);
+ if (!m_pStretchEngine) {
+ return FALSE;
+ }
+ m_pStretchEngine->StartStretchHorz();
+ if (m_pSource->GetWidth() * m_pSource->GetHeight() < MAX_PROGRESSIVE_STRETCH_PIXELS) {
+ m_pStretchEngine->Continue(NULL);
+ return FALSE;
+ }
+ return TRUE;
+}
+FX_BOOL CFX_ImageStretcher::ContinueStretch(IFX_Pause* pPause)
+{
+ if (m_pStretchEngine == NULL) {
+ return FALSE;
+ }
+ return m_pStretchEngine->Continue(pPause);
+}
+FX_BOOL CFX_ImageStretcher::StartQuickStretch()
+{
+#ifdef _FPDFAPI_MINI_
+ m_pSource->SetDownSampleSize(m_DestWidth, m_DestHeight);
+#endif
+ m_bFlipX = FALSE;
+ m_bFlipY = FALSE;
+ if (m_DestWidth < 0) {
+ m_bFlipX = TRUE;
+ m_DestWidth = -m_DestWidth;
+ }
+ if (m_DestHeight < 0) {
+ m_bFlipY = TRUE;
+ m_DestHeight = -m_DestHeight;
+ }
+ m_LineIndex = 0;
+ FX_DWORD size = m_ClipRect.Width();
+ if (size && m_DestBPP > (int)(INT_MAX / size)) {
+ return FALSE;
+ }
+ size *= m_DestBPP;
+ m_pScanline = FX_Alloc(FX_BYTE, (size / 8 + 3) / 4 * 4);
+ if (!m_pScanline) {
+ return FALSE;
+ }
+ if (m_pSource->m_pAlphaMask) {
+ m_pMaskScanline = FX_Alloc(FX_BYTE, (m_ClipRect.Width() + 3) / 4 * 4);
+ if (!m_pMaskScanline) {
+ return FALSE;
+ }
+ }
+ if (m_pSource->GetWidth() * m_pSource->GetHeight() < MAX_PROGRESSIVE_STRETCH_PIXELS) {
+ ContinueQuickStretch(NULL);
+ return FALSE;
+ }
+ return TRUE;
+}
+FX_BOOL CFX_ImageStretcher::ContinueQuickStretch(IFX_Pause* pPause)
+{
+ if (m_pScanline == NULL) {
+ return FALSE;
+ }
+ int result_width = m_ClipRect.Width(), result_height = m_ClipRect.Height();
+ int src_width = m_pSource->GetWidth(), src_height = m_pSource->GetHeight();
+ for (; m_LineIndex < result_height; m_LineIndex ++) {
+ int dest_y, src_y;
+ if (m_bFlipY) {
+ dest_y = result_height - m_LineIndex - 1;
+ src_y = (m_DestHeight - (dest_y + m_ClipRect.top) - 1) * src_height / m_DestHeight;
+ } else {
+ dest_y = m_LineIndex;
+ src_y = (dest_y + m_ClipRect.top) * src_height / m_DestHeight;
+ }
+ if (src_y >= src_height) {
+ src_y = src_height - 1;
+ }
+ if (src_y < 0) {
+ src_y = 0;
+ }
+ if (m_pSource->SkipToScanline(src_y, pPause)) {
+ return TRUE;
+ }
+ m_pSource->DownSampleScanline(src_y, m_pScanline, m_DestBPP, m_DestWidth, m_bFlipX, m_ClipRect.left, result_width);
+ FX_LPBYTE scan_extra_alpha = NULL;
+ if (m_pMaskScanline) {
+ m_pSource->m_pAlphaMask->DownSampleScanline(src_y, m_pMaskScanline, 1, m_DestWidth, m_bFlipX, m_ClipRect.left, result_width);
+ }
+ m_pDest->ComposeScanline(dest_y, m_pScanline, m_pMaskScanline);
+ }
+ return FALSE;
+}
diff --git a/core/src/fxge/dib/fx_dib_main.cpp b/core/src/fxge/dib/fx_dib_main.cpp new file mode 100644 index 0000000000..0953f2d2e5 --- /dev/null +++ b/core/src/fxge/dib/fx_dib_main.cpp @@ -0,0 +1,1734 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../../include/fxge/fx_dib.h"
+#include "../../../include/fxge/fx_ge.h"
+#include "../../../include/fxcodec/fx_codec.h"
+#include "dib_int.h"
+#include <limits.h>
+FX_BOOL ConvertBuffer(FXDIB_Format dest_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD*& pal, void* pIccTransform);
+void CmykDecode(FX_DWORD cmyk, int& c, int& m, int& y, int& k)
+{
+ c = FXSYS_GetCValue(cmyk);
+ m = FXSYS_GetMValue(cmyk);
+ y = FXSYS_GetYValue(cmyk);
+ k = FXSYS_GetKValue(cmyk);
+}
+void ArgbDecode(FX_DWORD argb, int& a, int& r, int& g, int& b)
+{
+ a = FXARGB_A(argb);
+ r = FXARGB_R(argb);
+ g = FXARGB_G(argb);
+ b = FXARGB_B(argb);
+}
+void ArgbDecode(FX_DWORD argb, int& a, FX_COLORREF& rgb)
+{
+ a = FXARGB_A(argb);
+ rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb));
+}
+FX_DWORD ArgbEncode(int a, FX_COLORREF rgb)
+{
+ return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb), FXSYS_GetBValue(rgb));
+}
+CFX_DIBSource::CFX_DIBSource()
+{
+ m_bpp = 0;
+ m_AlphaFlag = 0;
+ m_Width = m_Height = 0;
+ m_Pitch = 0;
+ m_pPalette = NULL;
+ m_pAlphaMask = NULL;
+}
+CFX_DIBSource::~CFX_DIBSource()
+{
+ if (m_pPalette) {
+ FX_Free(m_pPalette);
+ }
+ if (m_pAlphaMask) {
+ delete m_pAlphaMask;
+ }
+}
+CFX_DIBitmap::CFX_DIBitmap()
+{
+ m_bExtBuf = FALSE;
+ m_pBuffer = NULL;
+ m_pPalette = NULL;
+}
+#define _MAX_OOM_LIMIT_ 12000000
+FX_BOOL CFX_DIBitmap::Create(int width, int height, FXDIB_Format format, FX_LPBYTE pBuffer, int pitch)
+{
+ m_pBuffer = NULL;
+ m_bpp = (FX_BYTE)format;
+ m_AlphaFlag = (FX_BYTE)(format >> 8);
+ m_Width = m_Height = m_Pitch = 0;
+ if (width <= 0 || height <= 0 || pitch < 0) {
+ return FALSE;
+ }
+ if ((INT_MAX - 31) / width < (format & 0xff)) {
+ return FALSE;
+ }
+ if (!pitch) {
+ pitch = (width * (format & 0xff) + 31) / 32 * 4;
+ }
+ if ((1 << 30) / pitch < height) {
+ return FALSE;
+ }
+ if (pBuffer) {
+ m_pBuffer = pBuffer;
+ m_bExtBuf = TRUE;
+ } else {
+ int size = pitch * height + 4;
+ int oomlimit = _MAX_OOM_LIMIT_;
+ if (oomlimit >= 0 && size >= oomlimit) {
+ m_pBuffer = FX_AllocNL(FX_BYTE, size);
+ } else {
+ m_pBuffer = FX_Alloc(FX_BYTE, size);
+ }
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ FXSYS_memset32(m_pBuffer, 0, sizeof (FX_BYTE) * size);
+ }
+ m_Width = width;
+ m_Height = height;
+ m_Pitch = pitch;
+ if (HasAlpha() && format != FXDIB_Argb) {
+ FX_BOOL ret = TRUE;
+ ret = BuildAlphaMask();
+ if (!ret) {
+ if (!m_bExtBuf && m_pBuffer) {
+ FX_Free(m_pBuffer);
+ m_pBuffer = NULL;
+ m_Width = m_Height = m_Pitch = 0;
+ return FALSE;
+ }
+ }
+ }
+ return TRUE;
+}
+FX_BOOL CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc)
+{
+ if (m_pBuffer) {
+ return FALSE;
+ }
+ if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat())) {
+ return FALSE;
+ }
+ CopyPalette(pSrc->GetPalette());
+ CopyAlphaMask(pSrc->m_pAlphaMask);
+ for (int row = 0; row < pSrc->GetHeight(); row ++) {
+ FXSYS_memcpy32(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch);
+ }
+ return TRUE;
+}
+CFX_DIBitmap::~CFX_DIBitmap()
+{
+ if (m_pBuffer && !m_bExtBuf) {
+ FX_Free(m_pBuffer);
+ }
+ m_pBuffer = NULL;
+}
+void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap)
+{
+ if (m_pBuffer && !m_bExtBuf) {
+ FX_Free(m_pBuffer);
+ }
+ if (m_pPalette) {
+ FX_Free(m_pPalette);
+ }
+ if (m_pAlphaMask) {
+ delete m_pAlphaMask;
+ }
+ m_pBuffer = pSrcBitmap->m_pBuffer;
+ m_pPalette = pSrcBitmap->m_pPalette;
+ m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
+ pSrcBitmap->m_pBuffer = NULL;
+ pSrcBitmap->m_pPalette = NULL;
+ pSrcBitmap->m_pAlphaMask = NULL;
+ m_bpp = pSrcBitmap->m_bpp;
+ m_bExtBuf = pSrcBitmap->m_bExtBuf;
+ m_AlphaFlag = pSrcBitmap->m_AlphaFlag;
+ m_Width = pSrcBitmap->m_Width;
+ m_Height = pSrcBitmap->m_Height;
+ m_Pitch = pSrcBitmap->m_Pitch;
+}
+CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const
+{
+ FX_RECT rect(0, 0, m_Width, m_Height);
+ if (pClip) {
+ rect.Intersect(*pClip);
+ if (rect.IsEmpty()) {
+ return NULL;
+ }
+ }
+ CFX_DIBitmap* pNewBitmap = FX_NEW CFX_DIBitmap;
+ if (!pNewBitmap) {
+ return NULL;
+ }
+ if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat())) {
+ delete pNewBitmap;
+ return NULL;
+ }
+ pNewBitmap->CopyPalette(m_pPalette);
+ pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip);
+ if (GetBPP() == 1 && rect.left % 8 != 0) {
+ int left_shift = rect.left % 32;
+ int right_shift = 32 - left_shift;
+ int dword_count = pNewBitmap->m_Pitch / 4;
+ for (int row = rect.top; row < rect.bottom; row ++) {
+ FX_DWORD* src_scan = (FX_DWORD*)GetScanline(row) + rect.left / 32;
+ FX_DWORD* dest_scan = (FX_DWORD*)pNewBitmap->GetScanline(row - rect.top);
+ for (int i = 0; i < dword_count; i ++) {
+ dest_scan[i] = (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift);
+ }
+ }
+ } else {
+ int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8;
+ if (m_Pitch < (FX_DWORD)copy_len) {
+ copy_len = m_Pitch;
+ }
+ for (int row = rect.top; row < rect.bottom; row ++) {
+ FX_LPCBYTE src_scan = GetScanline(row) + rect.left * m_bpp / 8;
+ FX_LPBYTE dest_scan = (FX_LPBYTE)pNewBitmap->GetScanline(row - rect.top);
+ FXSYS_memcpy32(dest_scan, src_scan, copy_len);
+ }
+ }
+ return pNewBitmap;
+}
+void CFX_DIBSource::BuildPalette()
+{
+ if (m_pPalette) {
+ return;
+ }
+ if (GetBPP() == 1) {
+ m_pPalette = FX_Alloc(FX_DWORD, 2);
+ if (!m_pPalette) {
+ return;
+ }
+ if(IsCmykImage()) {
+ m_pPalette[0] = 0xff;
+ m_pPalette[1] = 0;
+ } else {
+ m_pPalette[0] = 0xff000000;
+ m_pPalette[1] = 0xffffffff;
+ }
+ } else if (GetBPP() == 8) {
+ m_pPalette = FX_Alloc(FX_DWORD, 256);
+ if (!m_pPalette) {
+ return;
+ }
+ if(IsCmykImage()) {
+ for (int i = 0; i < 256; i ++) {
+ m_pPalette[i] = 0xff - i;
+ }
+ } else {
+ for (int i = 0; i < 256; i ++) {
+ m_pPalette[i] = 0xff000000 | (i * 0x10101);
+ }
+ }
+ }
+}
+FX_BOOL CFX_DIBSource::BuildAlphaMask()
+{
+ if (m_pAlphaMask) {
+ return TRUE;
+ }
+ m_pAlphaMask = FX_NEW CFX_DIBitmap;
+ if (!m_pAlphaMask) {
+ return FALSE;
+ }
+ if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete m_pAlphaMask;
+ m_pAlphaMask = NULL;
+ return FALSE;
+ }
+ FXSYS_memset8(m_pAlphaMask->GetBuffer(), 0xff, m_pAlphaMask->GetHeight()*m_pAlphaMask->GetPitch());
+ return TRUE;
+}
+FX_DWORD CFX_DIBSource::GetPaletteEntry(int index) const
+{
+ ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
+ if (m_pPalette) {
+ return m_pPalette[index];
+ }
+ if (IsCmykImage()) {
+ if (GetBPP() == 1) {
+ return index ? 0 : 0xff;
+ }
+ return 0xff - index;
+ }
+ if (GetBPP() == 1) {
+ return index ? 0xffffffff : 0xff000000;
+ }
+ return index * 0x10101 | 0xff000000;
+}
+void CFX_DIBSource::SetPaletteEntry(int index, FX_DWORD color)
+{
+ ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
+ if (m_pPalette == NULL) {
+ BuildPalette();
+ }
+ m_pPalette[index] = color;
+}
+int CFX_DIBSource::FindPalette(FX_DWORD color) const
+{
+ ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
+ if (m_pPalette == NULL) {
+ if (IsCmykImage()) {
+ if (GetBPP() == 1) {
+ return ((FX_BYTE)color == 0xff) ? 0 : 1;
+ }
+ return 0xff - (FX_BYTE)color;
+ }
+ if (GetBPP() == 1) {
+ return ((FX_BYTE)color == 0xff) ? 1 : 0;
+ }
+ return (FX_BYTE)color;
+ }
+ int palsize = (1 << GetBPP());
+ for (int i = 0; i < palsize; i ++)
+ if (m_pPalette[i] == color) {
+ return i;
+ }
+ return -1;
+}
+void CFX_DIBitmap::Clear(FX_DWORD color)
+{
+ if (m_pBuffer == NULL) {
+ return;
+ }
+ switch (GetFormat()) {
+ case FXDIB_1bppMask:
+ FXSYS_memset8(m_pBuffer, (color & 0xff000000) ? 0xff : 0, m_Pitch * m_Height);
+ break;
+ case FXDIB_1bppRgb: {
+ int index = FindPalette(color);
+ FXSYS_memset8(m_pBuffer, index ? 0xff : 0, m_Pitch * m_Height);
+ break;
+ }
+ case FXDIB_8bppMask:
+ FXSYS_memset8(m_pBuffer, color >> 24, m_Pitch * m_Height);
+ break;
+ case FXDIB_8bppRgb: {
+ int index = FindPalette(color);
+ FXSYS_memset8(m_pBuffer, index, m_Pitch * m_Height);
+ break;
+ }
+ case FXDIB_Rgb:
+ case FXDIB_Rgba: {
+ int a, r, g, b;
+ ArgbDecode(color, a, r, g, b);
+ if (r == g && g == b) {
+ FXSYS_memset8(m_pBuffer, r, m_Pitch * m_Height);
+ } else {
+ int byte_pos = 0;
+ for (int col = 0; col < m_Width; col ++) {
+ m_pBuffer[byte_pos++] = b;
+ m_pBuffer[byte_pos++] = g;
+ m_pBuffer[byte_pos++] = r;
+ }
+ for (int row = 1; row < m_Height; row ++) {
+ FXSYS_memcpy32(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch);
+ }
+ }
+ break;
+ }
+ case FXDIB_Rgb32:
+ case FXDIB_Argb: {
+ color = IsCmykImage() ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
+ for (int i = 0; i < m_Width; i ++) {
+ ((FX_DWORD*)m_pBuffer)[i] = color;
+ }
+ for (int row = 1; row < m_Height; row ++) {
+ FXSYS_memcpy32(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+void CFX_DIBSource::GetOverlapRect(int& dest_left, int& dest_top, int& width, int& height,
+ int src_width, int src_height, int& src_left, int& src_top,
+ const CFX_ClipRgn* pClipRgn)
+{
+ if (width == 0 || height == 0) {
+ return;
+ }
+ ASSERT(width > 0 && height > 0);
+ if (dest_left > m_Width || dest_top > m_Height) {
+ width = 0;
+ height = 0;
+ return;
+ }
+ int x_offset = dest_left - src_left;
+ int y_offset = dest_top - src_top;
+ FX_RECT src_rect(src_left, src_top, src_left + width, src_top + height);
+ FX_RECT src_bound(0, 0, src_width, src_height);
+ src_rect.Intersect(src_bound);
+ FX_RECT dest_rect(src_rect.left + x_offset, src_rect.top + y_offset,
+ src_rect.right + x_offset, src_rect.bottom + y_offset);
+ FX_RECT dest_bound(0, 0, m_Width, m_Height);
+ dest_rect.Intersect(dest_bound);
+ if (pClipRgn) {
+ dest_rect.Intersect(pClipRgn->GetBox());
+ }
+ dest_left = dest_rect.left;
+ dest_top = dest_rect.top;
+ src_left = dest_left - x_offset;
+ src_top = dest_top - y_offset;
+ width = dest_rect.right - dest_rect.left;
+ height = dest_rect.bottom - dest_rect.top;
+}
+FX_BOOL CFX_DIBitmap::TransferBitmap(int dest_left, int dest_top, int width, int height,
+ const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), src_left, src_top, NULL);
+ if (width == 0 || height == 0) {
+ return TRUE;
+ }
+ FXDIB_Format dest_format = GetFormat();
+ FXDIB_Format src_format = pSrcBitmap->GetFormat();
+ if (dest_format == src_format && pIccTransform == NULL) {
+ if (GetBPP() == 1) {
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + (dest_top + row) * m_Pitch;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = 0; col < width; col ++) {
+ if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
+ dest_scan[(dest_left + col) / 8] |= 1 << (7 - (dest_left + col) % 8);
+ } else {
+ dest_scan[(dest_left + col) / 8] &= ~(1 << (7 - (dest_left + col) % 8));
+ }
+ }
+ }
+ } else {
+ int Bpp = GetBPP() / 8;
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp;
+ FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
+ FXSYS_memcpy32(dest_scan, src_scan, width * Bpp);
+ }
+ }
+ } else {
+ if (m_pPalette) {
+ return FALSE;
+ }
+ if (m_bpp == 8) {
+ dest_format = FXDIB_8bppMask;
+ }
+ FX_LPBYTE dest_buf = m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8;
+ FX_DWORD* d_plt = NULL;
+ if(!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height, pSrcBitmap, src_left, src_top, d_plt, pIccTransform)) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+#ifndef _FPDFAPI_MINI_
+FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, int dest_top, int width, int height,
+ const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top, int alpha_flag, void* pIccTransform)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ ASSERT(HasAlpha() && (m_bpp >= 24));
+ ASSERT(pMask->IsAlphaMask());
+ if (!HasAlpha() || !pMask->IsAlphaMask() || m_bpp < 24) {
+ return FALSE;
+ }
+ GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(), pMask->GetHeight(), src_left, src_top, NULL);
+ if (width == 0 || height == 0) {
+ return TRUE;
+ }
+ int src_pitch = pMask->GetPitch();
+ int src_bpp = pMask->GetBPP();
+ int alpha;
+ FX_DWORD dst_color;
+ if (alpha_flag >> 8) {
+ alpha = alpha_flag & 0xff;
+ dst_color = FXCMYK_TODIB(color);
+ } else {
+ alpha = FXARGB_A(color);
+ dst_color = FXARGB_TODIB(color);
+ }
+ FX_LPBYTE color_p = (FX_LPBYTE)&dst_color;
+ if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() && CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
+ ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1);
+ } else {
+ if (alpha_flag >> 8 && !IsCmykImage())
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), FXSYS_GetYValue(color), FXSYS_GetKValue(color),
+ color_p[2], color_p[1], color_p[0]);
+ else if (!(alpha_flag >> 8) && IsCmykImage()) {
+ return FALSE;
+ }
+ }
+ if(!IsCmykImage()) {
+ color_p[3] = (FX_BYTE)alpha;
+ }
+ if (GetFormat() == FXDIB_Argb) {
+ for (int row = 0; row < height; row ++) {
+ FX_DWORD* dest_pos = (FX_DWORD*)(m_pBuffer + (dest_top + row) * m_Pitch + dest_left * 4);
+ FX_LPCBYTE src_scan = pMask->GetScanline(src_top + row);
+ if (src_bpp == 1) {
+ for (int col = 0; col < width; col ++) {
+ int src_bitpos = src_left + col;
+ if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8))) {
+ *dest_pos = dst_color;
+ } else {
+ *dest_pos = 0;
+ }
+ dest_pos ++;
+ }
+ } else {
+ src_scan += src_left;
+ dst_color = FXARGB_TODIB(dst_color);
+ dst_color &= 0xffffff;
+ for (int col = 0; col < width; col ++) {
+ FXARGB_SETDIB(dest_pos++, dst_color | ((alpha * (*src_scan++) / 255) << 24));
+ }
+ }
+ }
+ } else {
+ int comps = m_bpp / 8;
+ for (int row = 0; row < height; row ++) {
+ FX_LPBYTE dest_color_pos = m_pBuffer + (dest_top + row) * m_Pitch + dest_left * comps;
+ FX_LPBYTE dest_alpha_pos = (FX_LPBYTE)m_pAlphaMask->GetScanline(dest_top + row) + dest_left;
+ FX_LPCBYTE src_scan = pMask->GetScanline(src_top + row);
+ if (src_bpp == 1) {
+ for (int col = 0; col < width; col ++) {
+ int src_bitpos = src_left + col;
+ if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8))) {
+ FXSYS_memcpy32(dest_color_pos, color_p, comps);
+ *dest_alpha_pos = 0xff;
+ } else {
+ FXSYS_memset32(dest_color_pos, 0, comps);
+ *dest_alpha_pos = 0;
+ }
+ dest_color_pos += comps;
+ dest_alpha_pos ++;
+ }
+ } else {
+ src_scan += src_left;
+ for (int col = 0; col < width; col ++) {
+ FXSYS_memcpy32(dest_color_pos, color_p, comps);
+ dest_color_pos += comps;
+ *dest_alpha_pos++ = (alpha * (*src_scan++) / 255);
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+#endif
+void CFX_DIBSource::CopyPalette(const FX_DWORD* pSrc, FX_DWORD size)
+{
+ if (pSrc == NULL || GetBPP() > 8) {
+ if (m_pPalette) {
+ FX_Free(m_pPalette);
+ }
+ m_pPalette = NULL;
+ } else {
+ FX_DWORD pal_size = 1 << GetBPP();
+ if (m_pPalette == NULL) {
+ m_pPalette = FX_Alloc(FX_DWORD, pal_size);
+ }
+ if (!m_pPalette) {
+ return;
+ }
+ if (pal_size > size) {
+ pal_size = size;
+ }
+ FXSYS_memcpy32(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD));
+ }
+}
+void CFX_DIBSource::GetPalette(FX_DWORD* pal, int alpha) const
+{
+ ASSERT(GetBPP() <= 8 && !IsCmykImage());
+ if (GetBPP() == 1) {
+ pal[0] = ((m_pPalette ? m_pPalette[0] : 0xff000000) & 0xffffff) | (alpha << 24);
+ pal[1] = ((m_pPalette ? m_pPalette[1] : 0xffffffff) & 0xffffff) | (alpha << 24);
+ return;
+ }
+ if (m_pPalette) {
+ for (int i = 0; i < 256; i ++) {
+ pal[i] = (m_pPalette[i] & 0x00ffffff) | (alpha << 24);
+ }
+ } else {
+ for (int i = 0; i < 256; i ++) {
+ pal[i] = (i * 0x10101) | (alpha << 24);
+ }
+ }
+}
+CFX_DIBitmap* CFX_DIBSource::GetAlphaMask(const FX_RECT* pClip) const
+{
+ ASSERT(GetFormat() == FXDIB_Argb);
+ FX_RECT rect(0, 0, m_Width, m_Height);
+ if (pClip) {
+ rect.Intersect(*pClip);
+ if (rect.IsEmpty()) {
+ return NULL;
+ }
+ }
+ CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap;
+ if (!pMask) {
+ return NULL;
+ }
+ if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask)) {
+ delete pMask;
+ return NULL;
+ }
+ for (int row = rect.top; row < rect.bottom; row ++) {
+ FX_LPCBYTE src_scan = GetScanline(row) + rect.left * 4 + 3;
+ FX_LPBYTE dest_scan = (FX_LPBYTE)pMask->GetScanline(row - rect.top);
+ for (int col = rect.left; col < rect.right; col ++) {
+ *dest_scan ++ = *src_scan;
+ src_scan += 4;
+ }
+ }
+ return pMask;
+}
+FX_BOOL CFX_DIBSource::CopyAlphaMask(const CFX_DIBSource* pAlphaMask, const FX_RECT* pClip)
+{
+ if (!HasAlpha() || GetFormat() == FXDIB_Argb) {
+ return FALSE;
+ }
+ if (pAlphaMask) {
+ FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height);
+ if (pClip) {
+ rect.Intersect(*pClip);
+ if (rect.IsEmpty() || rect.Width() != m_Width || rect.Height() != m_Height) {
+ return FALSE;
+ }
+ } else {
+ if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height) {
+ return FALSE;
+ }
+ }
+ for (int row = 0; row < m_Height; row ++)
+ FXSYS_memcpy32((void*)m_pAlphaMask->GetScanline(row),
+ pAlphaMask->GetScanline(row + rect.top) + rect.left, m_pAlphaMask->m_Pitch);
+ } else {
+ m_pAlphaMask->Clear(0xff000000);
+ }
+ return TRUE;
+}
+const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
+FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, const CFX_DIBSource* pSrcBitmap, FXDIB_Channel srcChannel)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap;
+ CFX_DIBitmap* pDst = this;
+ int destOffset, srcOffset;
+ if (srcChannel == FXDIB_Alpha) {
+ if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) {
+ return FALSE;
+ }
+ if (pSrcBitmap->GetBPP() == 1) {
+ pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask);
+ if (pSrcClone == NULL) {
+ return FALSE;
+ }
+ }
+ if(pSrcBitmap->GetFormat() == FXDIB_Argb) {
+ srcOffset = 3;
+ } else {
+ srcOffset = 0;
+ }
+ } else {
+ if (pSrcBitmap->IsAlphaMask()) {
+ return FALSE;
+ }
+ if (pSrcBitmap->GetBPP() < 24) {
+ if (pSrcBitmap->IsCmykImage()) {
+ pSrcClone = pSrcBitmap->CloneConvert((FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20));
+ } else {
+ pSrcClone = pSrcBitmap->CloneConvert((FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18));
+ }
+ if (pSrcClone == NULL) {
+ return FALSE;
+ }
+ }
+ srcOffset = g_ChannelOffset[srcChannel];
+ }
+ if (destChannel == FXDIB_Alpha) {
+ if (IsAlphaMask()) {
+ if(!ConvertFormat(FXDIB_8bppMask)) {
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return FALSE;
+ }
+ destOffset = 0;
+ } else {
+ destOffset = 0;
+ if(!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return FALSE;
+ }
+ if (GetFormat() == FXDIB_Argb) {
+ destOffset = 3;
+ }
+ }
+ } else {
+ if (IsAlphaMask()) {
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return FALSE;
+ }
+ if (GetBPP() < 24) {
+ if (HasAlpha()) {
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return FALSE;
+ }
+ } else
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
+#else
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
+#endif
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return FALSE;
+ }
+ }
+ destOffset = g_ChannelOffset[destChannel];
+ }
+ if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
+ CFX_DIBitmap* pAlphaMask = pSrcClone->m_pAlphaMask;
+ if (pSrcClone->GetWidth() != m_Width || pSrcClone->GetHeight() != m_Height) {
+ if (pAlphaMask) {
+ pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height);
+ if (pAlphaMask == NULL) {
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return FALSE;
+ }
+ }
+ }
+ if (pSrcClone != pSrcBitmap) {
+ pSrcClone->m_pAlphaMask = NULL;
+ delete pSrcClone;
+ }
+ pSrcClone = pAlphaMask;
+ srcOffset = 0;
+ } else if (pSrcClone->GetWidth() != m_Width || pSrcClone->GetHeight() != m_Height) {
+ CFX_DIBitmap* pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height);
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ if (pSrcMatched == NULL) {
+ return FALSE;
+ }
+ pSrcClone = pSrcMatched;
+ }
+ if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
+ pDst = m_pAlphaMask;
+ destOffset = 0;
+ }
+ int srcBytes = pSrcClone->GetBPP() / 8;
+ int destBytes = pDst->GetBPP() / 8;
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE dest_pos = (FX_LPBYTE)pDst->GetScanline(row) + destOffset;
+ FX_LPCBYTE src_pos = pSrcClone->GetScanline(row) + srcOffset;
+ for (int col = 0; col < m_Width; col ++) {
+ *dest_pos = *src_pos;
+ dest_pos += destBytes;
+ src_pos += srcBytes;
+ }
+ }
+ if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) {
+ delete pSrcClone;
+ }
+ return TRUE;
+}
+FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ int destOffset;
+ if (destChannel == FXDIB_Alpha) {
+ if (IsAlphaMask()) {
+ if(!ConvertFormat(FXDIB_8bppMask)) {
+ return FALSE;
+ }
+ destOffset = 0;
+ } else {
+ destOffset = 0;
+ if(!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
+ return FALSE;
+ }
+ if (GetFormat() == FXDIB_Argb) {
+ destOffset = 3;
+ }
+ }
+ } else {
+ if (IsAlphaMask()) {
+ return FALSE;
+ }
+ if (GetBPP() < 24) {
+ if (HasAlpha()) {
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
+ return FALSE;
+ }
+ } else
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
+ return FALSE;
+ }
+#else
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
+ return FALSE;
+ }
+#endif
+ }
+ destOffset = g_ChannelOffset[destChannel];
+ }
+ int Bpp = GetBPP() / 8;
+ if (Bpp == 1) {
+ FXSYS_memset8(m_pBuffer, value, m_Height * m_Pitch);
+ return TRUE;
+ }
+ if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
+ FXSYS_memset8(m_pAlphaMask->GetBuffer(), value, m_pAlphaMask->GetHeight()*m_pAlphaMask->GetPitch());
+ return TRUE;
+ }
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE scan_line = m_pBuffer + row * m_Pitch + destOffset;
+ for (int col = 0; col < m_Width; col ++) {
+ *scan_line = value;
+ scan_line += Bpp;
+ }
+ }
+ return TRUE;
+}
+FX_BOOL CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ ASSERT(pSrcBitmap->IsAlphaMask());
+ if (!pSrcBitmap->IsAlphaMask()) {
+ return FALSE;
+ }
+ if (!IsAlphaMask() && !HasAlpha()) {
+ return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
+ }
+ CFX_DIBitmap* pSrcClone = (CFX_DIBitmap*)pSrcBitmap;
+ if (pSrcBitmap->GetWidth() != m_Width || pSrcBitmap->GetHeight() != m_Height) {
+ pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
+ ASSERT(pSrcClone != NULL);
+ if (pSrcClone == NULL) {
+ return FALSE;
+ }
+ }
+ if (IsAlphaMask()) {
+ if(!ConvertFormat(FXDIB_8bppMask)) {
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return FALSE;
+ }
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + m_Pitch * row;
+ FX_LPBYTE src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
+ if (pSrcClone->GetBPP() == 1) {
+ for (int col = 0; col < m_Width; col ++) {
+ if (!((1 << (7 - col % 8)) & src_scan[col / 8])) {
+ dest_scan[col] = 0;
+ }
+ }
+ } else {
+ for (int col = 0; col < m_Width; col ++) {
+ *dest_scan = (*dest_scan) * src_scan[col] / 255;
+ dest_scan ++;
+ }
+ }
+ }
+ } else {
+ if(GetFormat() == FXDIB_Argb) {
+ if (pSrcClone->GetBPP() == 1) {
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return FALSE;
+ }
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE dest_scan = m_pBuffer + m_Pitch * row + 3;
+ FX_LPBYTE src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
+ for (int col = 0; col < m_Width; col ++) {
+ *dest_scan = (*dest_scan) * src_scan[col] / 255;
+ dest_scan += 4;
+ }
+ }
+ } else {
+ m_pAlphaMask->MultiplyAlpha(pSrcClone);
+ }
+ }
+ if (pSrcClone != pSrcBitmap) {
+ delete pSrcClone;
+ }
+ return TRUE;
+}
+FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ switch (GetFormat()) {
+ case FXDIB_1bppRgb: {
+ if (m_pPalette == NULL) {
+ return FALSE;
+ }
+ FX_BYTE gray[2];
+ for (int i = 0; i < 2; i ++) {
+ int r = (FX_BYTE)(m_pPalette[i] >> 16);
+ int g = (FX_BYTE)(m_pPalette[i] >> 8);
+ int b = (FX_BYTE)m_pPalette[i];
+ gray[i] = (FX_BYTE)FXRGB2GRAY(r, g, b);
+ }
+ CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap;
+ if (!pMask) {
+ return FALSE;
+ }
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
+ return FALSE;
+ }
+ FXSYS_memset8(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height);
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch;
+ FX_LPBYTE dest_pos = (FX_LPBYTE)pMask->GetScanline(row);
+ for (int col = 0; col < m_Width; col ++) {
+ if (src_pos[col / 8] & (1 << (7 - col % 8))) {
+ *dest_pos = gray[1];
+ }
+ dest_pos ++;
+ }
+ }
+ TakeOver(pMask);
+ delete pMask;
+ break;
+ }
+ case FXDIB_8bppRgb: {
+ if (m_pPalette == NULL) {
+ return FALSE;
+ }
+ FX_BYTE gray[256];
+ for (int i = 0; i < 256; i ++) {
+ int r = (FX_BYTE)(m_pPalette[i] >> 16);
+ int g = (FX_BYTE)(m_pPalette[i] >> 8);
+ int b = (FX_BYTE)m_pPalette[i];
+ gray[i] = (FX_BYTE)FXRGB2GRAY(r, g, b);
+ }
+ CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap;
+ if (!pMask) {
+ return FALSE;
+ }
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
+ return FALSE;
+ }
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
+ FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch;
+ for (int col = 0; col < m_Width; col ++) {
+ *dest_pos ++ = gray[*src_pos ++];
+ }
+ }
+ TakeOver(pMask);
+ delete pMask;
+ break;
+ }
+ case FXDIB_Rgb: {
+ CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap;
+ if (!pMask) {
+ return FALSE;
+ }
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
+ return FALSE;
+ }
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch;
+ FX_LPBYTE dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
+ for (int col = 0; col < m_Width; col ++) {
+ *dest_pos ++ = FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos);
+ src_pos += 3;
+ }
+ }
+ TakeOver(pMask);
+ delete pMask;
+ break;
+ }
+ case FXDIB_Rgb32: {
+ CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap;
+ if (!pMask) {
+ return FALSE;
+ }
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
+ return FALSE;
+ }
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch;
+ FX_LPBYTE dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
+ for (int col = 0; col < m_Width; col ++) {
+ *dest_pos ++ = FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos);
+ src_pos += 4;
+ }
+ }
+ TakeOver(pMask);
+ delete pMask;
+ break;
+ }
+ default:
+ return FALSE;
+ }
+ return TRUE;
+}
+FX_BOOL CFX_DIBitmap::MultiplyAlpha(int alpha)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ switch (GetFormat()) {
+ case FXDIB_1bppMask:
+ if (!ConvertFormat(FXDIB_8bppMask)) {
+ return FALSE;
+ }
+ MultiplyAlpha(alpha);
+ break;
+ case FXDIB_8bppMask: {
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE scan_line = m_pBuffer + row * m_Pitch;
+ for (int col = 0; col < m_Width; col ++) {
+ scan_line[col] = scan_line[col] * alpha / 255;
+ }
+ }
+ break;
+ }
+ case FXDIB_Argb: {
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE scan_line = m_pBuffer + row * m_Pitch + 3;
+ for (int col = 0; col < m_Width; col ++) {
+ *scan_line = (*scan_line) * alpha / 255;
+ scan_line += 4;
+ }
+ }
+ break;
+ }
+ default:
+ if (HasAlpha()) {
+ m_pAlphaMask->MultiplyAlpha(alpha);
+ } else if (IsCmykImage()) {
+ if (!ConvertFormat((FXDIB_Format)(GetFormat() | 0x0200))) {
+ return FALSE;
+ }
+ m_pAlphaMask->MultiplyAlpha(alpha);
+ } else {
+ if (!ConvertFormat(FXDIB_Argb)) {
+ return FALSE;
+ }
+ MultiplyAlpha(alpha);
+ }
+ break;
+ }
+ return TRUE;
+}
+#if !defined(_FPDFAPI_MINI_) || defined(_FXCORE_FEATURE_ALL_)
+FX_DWORD CFX_DIBitmap::GetPixel(int x, int y) const
+{
+ if (m_pBuffer == NULL) {
+ return 0;
+ }
+ FX_LPBYTE pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
+ switch (GetFormat()) {
+ case FXDIB_1bppMask: {
+ if ((*pos) & (1 << (7 - x % 8))) {
+ return 0xff000000;
+ }
+ return 0;
+ }
+ case FXDIB_1bppRgb: {
+ if ((*pos) & (1 << (7 - x % 8))) {
+ return m_pPalette ? m_pPalette[1] : 0xffffffff;
+ } else {
+ return m_pPalette ? m_pPalette[0] : 0xff000000;
+ }
+ break;
+ }
+ case FXDIB_8bppMask:
+ return (*pos) << 24;
+ case FXDIB_8bppRgb:
+ return m_pPalette ? m_pPalette[*pos] : (0xff000000 | ((*pos) * 0x10101));
+ case FXDIB_Rgb:
+ case FXDIB_Rgba:
+ case FXDIB_Rgb32:
+ return FXARGB_GETDIB(pos) | 0xff000000;
+ case FXDIB_Argb:
+ return FXARGB_GETDIB(pos);
+ default:
+ break;
+ }
+ return 0;
+}
+#endif
+void CFX_DIBitmap::SetPixel(int x, int y, FX_DWORD color)
+{
+ if (m_pBuffer == NULL) {
+ return;
+ }
+ if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) {
+ return;
+ }
+ FX_LPBYTE pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
+ switch (GetFormat()) {
+ case FXDIB_1bppMask:
+ if (color >> 24) {
+ *pos |= 1 << (7 - x % 8);
+ } else {
+ *pos &= ~(1 << (7 - x % 8));
+ }
+ break;
+ case FXDIB_1bppRgb:
+ if (m_pPalette) {
+ if (color == m_pPalette[1]) {
+ *pos |= 1 << (7 - x % 8);
+ } else {
+ *pos &= ~(1 << (7 - x % 8));
+ }
+ } else {
+ if (color == 0xffffffff) {
+ *pos |= 1 << (7 - x % 8);
+ } else {
+ *pos &= ~(1 << (7 - x % 8));
+ }
+ }
+ break;
+ case FXDIB_8bppMask:
+ *pos = (FX_BYTE)(color >> 24);
+ break;
+ case FXDIB_8bppRgb: {
+ if (m_pPalette) {
+ for (int i = 0; i < 256; i ++) {
+ if (m_pPalette[i] == color) {
+ *pos = (FX_BYTE)i;
+ return;
+ }
+ }
+ *pos = 0;
+ } else {
+ *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color));
+ }
+ break;
+ }
+ case FXDIB_Rgb:
+ case FXDIB_Rgb32: {
+ int alpha = FXARGB_A(color);
+ pos[0] = (FXARGB_B(color) * alpha + pos[0] * (255 - alpha)) / 255;
+ pos[1] = (FXARGB_G(color) * alpha + pos[1] * (255 - alpha)) / 255;
+ pos[2] = (FXARGB_R(color) * alpha + pos[2] * (255 - alpha)) / 255;
+ break;
+ }
+ case FXDIB_Rgba: {
+ pos[0] = FXARGB_B(color);
+ pos[1] = FXARGB_G(color);
+ pos[2] = FXARGB_R(color);
+ break;
+ }
+ case FXDIB_Argb:
+ FXARGB_SETDIB(pos, color);
+ break;
+ default:
+ break;
+ }
+}
+void CFX_DIBitmap::DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_bpp,
+ int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const
+{
+ if (m_pBuffer == NULL) {
+ return;
+ }
+ int src_Bpp = m_bpp / 8;
+ FX_LPBYTE scanline = m_pBuffer + line * m_Pitch;
+ if (src_Bpp == 0) {
+ for (int i = 0; i < clip_width; i ++) {
+ FX_DWORD dest_x = clip_left + i;
+ FX_DWORD src_x = dest_x * m_Width / dest_width;
+ if (bFlipX) {
+ src_x = m_Width - src_x - 1;
+ }
+#ifdef FOXIT_CHROME_BUILD
+ src_x %= m_Width;
+#endif
+ dest_scan[i] = (scanline[src_x / 8] & (1 << (7 - src_x % 8))) ? 255 : 0;
+ }
+ } else if (src_Bpp == 1) {
+ for (int i = 0; i < clip_width; i ++) {
+ FX_DWORD dest_x = clip_left + i;
+ FX_DWORD src_x = dest_x * m_Width / dest_width;
+ if (bFlipX) {
+ src_x = m_Width - src_x - 1;
+ }
+#ifdef FOXIT_CHROME_BUILD
+ src_x %= m_Width;
+#endif
+ int dest_pos = i;
+ if (m_pPalette) {
+ if (!IsCmykImage()) {
+ dest_pos *= 3;
+ FX_ARGB argb = m_pPalette[scanline[src_x]];
+ dest_scan[dest_pos] = FXARGB_B(argb);
+ dest_scan[dest_pos + 1] = FXARGB_G(argb);
+ dest_scan[dest_pos + 2] = FXARGB_R(argb);
+ } else {
+ dest_pos *= 4;
+ FX_CMYK cmyk = m_pPalette[scanline[src_x]];
+ dest_scan[dest_pos] = FXSYS_GetCValue(cmyk);
+ dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk);
+ dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk);
+ dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk);
+ }
+ } else {
+ dest_scan[dest_pos] = scanline[src_x];
+ }
+ }
+ } else {
+ for (int i = 0; i < clip_width; i ++) {
+ FX_DWORD dest_x = clip_left + i;
+ FX_DWORD src_x = bFlipX ? (m_Width - dest_x * m_Width / dest_width - 1) * src_Bpp : (dest_x * m_Width / dest_width) * src_Bpp;
+#ifdef FOXIT_CHROME_BUILD
+ src_x %= m_Width * src_Bpp;
+#endif
+ int dest_pos = i * src_Bpp;
+ for (int b = 0; b < src_Bpp; b ++) {
+ dest_scan[dest_pos + b] = scanline[src_x + b];
+ }
+ }
+ }
+}
+FX_BOOL CFX_DIBitmap::ConvertColorScale(FX_DWORD forecolor, FX_DWORD backcolor)
+{
+ ASSERT(!IsAlphaMask());
+ if (m_pBuffer == NULL || IsAlphaMask()) {
+ return FALSE;
+ }
+ int fc, fm, fy, fk, bc, bm, by, bk;
+ int fr, fg, fb, br, bg, bb;
+ FX_BOOL isCmykImage = IsCmykImage();
+ if (isCmykImage) {
+ fc = FXSYS_GetCValue(forecolor);
+ fm = FXSYS_GetMValue(forecolor);
+ fy = FXSYS_GetYValue(forecolor);
+ fk = FXSYS_GetKValue(forecolor);
+ bc = FXSYS_GetCValue(backcolor);
+ bm = FXSYS_GetMValue(backcolor);
+ by = FXSYS_GetYValue(backcolor);
+ bk = FXSYS_GetKValue(backcolor);
+ } else {
+ fr = FXSYS_GetRValue(forecolor);
+ fg = FXSYS_GetGValue(forecolor);
+ fb = FXSYS_GetBValue(forecolor);
+ br = FXSYS_GetRValue(backcolor);
+ bg = FXSYS_GetGValue(backcolor);
+ bb = FXSYS_GetBValue(backcolor);
+ }
+ if (m_bpp <= 8) {
+ if (isCmykImage) {
+ if (forecolor == 0xff && backcolor == 0 && m_pPalette == NULL) {
+ return TRUE;
+ }
+ } else if (forecolor == 0 && backcolor == 0xffffff && m_pPalette == NULL) {
+ return TRUE;
+ }
+ if (m_pPalette == NULL) {
+ BuildPalette();
+ }
+ int size = 1 << m_bpp;
+ if (isCmykImage) {
+ for (int i = 0; i < size; i ++) {
+ FX_BYTE b, g, r;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]), FXSYS_GetMValue(m_pPalette[i]), FXSYS_GetYValue(m_pPalette[i]), FXSYS_GetKValue(m_pPalette[i]),
+ r, g, b);
+ int gray = 255 - FXRGB2GRAY(r, g, b);
+ m_pPalette[i] = CmykEncode(bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255,
+ by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255);
+ }
+ } else
+ for (int i = 0; i < size; i ++) {
+ int gray = FXRGB2GRAY(FXARGB_R(m_pPalette[i]), FXARGB_G(m_pPalette[i]), FXARGB_B(m_pPalette[i]));
+ m_pPalette[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, bg + (fg - bg) * gray / 255,
+ bb + (fb - bb) * gray / 255);
+ }
+ return TRUE;
+ }
+ if (isCmykImage) {
+ if (forecolor == 0xff && backcolor == 0x00) {
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE scanline = m_pBuffer + row * m_Pitch;
+ for (int col = 0; col < m_Width; col ++) {
+ FX_BYTE b, g, r;
+ AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3],
+ r, g, b);
+ *scanline ++ = 0;
+ *scanline ++ = 0;
+ *scanline ++ = 0;
+ *scanline ++ = 255 - FXRGB2GRAY(r, g, b);
+ }
+ }
+ return TRUE;
+ }
+ } else if (forecolor == 0 && backcolor == 0xffffff) {
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE scanline = m_pBuffer + row * m_Pitch;
+ int gap = m_bpp / 8 - 2;
+ for (int col = 0; col < m_Width; col ++) {
+ int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
+ *scanline ++ = gray;
+ *scanline ++ = gray;
+ *scanline = gray;
+ scanline += gap;
+ }
+ }
+ return TRUE;
+ }
+ if (isCmykImage) {
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE scanline = m_pBuffer + row * m_Pitch;
+ for (int col = 0; col < m_Width; col ++) {
+ FX_BYTE b, g, r;
+ AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3],
+ r, g, b);
+ int gray = 255 - FXRGB2GRAY(r, g, b);
+ *scanline ++ = bc + (fc - bc) * gray / 255;
+ *scanline ++ = bm + (fm - bm) * gray / 255;
+ *scanline ++ = by + (fy - by) * gray / 255;
+ *scanline ++ = bk + (fk - bk) * gray / 255;
+ }
+ }
+ } else
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPBYTE scanline = m_pBuffer + row * m_Pitch;
+ int gap = m_bpp / 8 - 2;
+ for (int col = 0; col < m_Width; col ++) {
+ int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
+ *scanline ++ = bb + (fb - bb) * gray / 255;
+ *scanline ++ = bg + (fg - bg) * gray / 255;
+ *scanline = br + (fr - br) * gray / 255;
+ scanline += gap;
+ }
+ }
+ return TRUE;
+}
+FX_BOOL CFX_DIBitmap::DitherFS(const FX_DWORD* pPalette, int pal_size, const FX_RECT* pRect)
+{
+ if (m_pBuffer == NULL) {
+ return FALSE;
+ }
+ if (m_bpp != 8 && m_pPalette != NULL && m_AlphaFlag != 0) {
+ return FALSE;
+ }
+ if (m_Width < 4 && m_Height < 4) {
+ return FALSE;
+ }
+ FX_RECT rect(0, 0, m_Width, m_Height);
+ if (pRect) {
+ rect.Intersect(*pRect);
+ }
+ FX_BYTE translate[256];
+ for (int i = 0; i < 256; i ++) {
+ int err2 = 65536;
+ for (int j = 0; j < pal_size; j ++) {
+ FX_BYTE entry = (FX_BYTE)pPalette[j];
+ int err = (int)entry - i;
+ if (err * err < err2) {
+ err2 = err * err;
+ translate[i] = entry;
+ }
+ }
+ }
+ for (int row = rect.top; row < rect.bottom; row ++) {
+ FX_LPBYTE scan = m_pBuffer + row * m_Pitch;
+ FX_LPBYTE next_scan = m_pBuffer + (row + 1) * m_Pitch;
+ for (int col = rect.left; col < rect.right; col ++) {
+ int src_pixel = scan[col];
+ int dest_pixel = translate[src_pixel];
+ scan[col] = (FX_BYTE)dest_pixel;
+ int error = -dest_pixel + src_pixel;
+ if (col < rect.right - 1) {
+ int src = scan[col + 1];
+ src += error * 7 / 16;
+ if (src > 255) {
+ scan[col + 1] = 255;
+ } else if (src < 0) {
+ scan[col + 1] = 0;
+ } else {
+ scan[col + 1] = src;
+ }
+ }
+ if (col < rect.right - 1 && row < rect.bottom - 1) {
+ int src = next_scan[col + 1];
+ src += error * 1 / 16;
+ if (src > 255) {
+ next_scan[col + 1] = 255;
+ } else if (src < 0) {
+ next_scan[col + 1] = 0;
+ } else {
+ next_scan[col + 1] = src;
+ }
+ }
+ if (row < rect.bottom - 1) {
+ int src = next_scan[col];
+ src += error * 5 / 16;
+ if (src > 255) {
+ next_scan[col] = 255;
+ } else if (src < 0) {
+ next_scan[col] = 0;
+ } else {
+ next_scan[col] = src;
+ }
+ }
+ if (col > rect.left && row < rect.bottom - 1) {
+ int src = next_scan[col - 1];
+ src += error * 3 / 16;
+ if (src > 255) {
+ next_scan[col - 1] = 255;
+ } else if (src < 0) {
+ next_scan[col - 1] = 0;
+ } else {
+ next_scan[col - 1] = src;
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+CFX_DIBitmap* CFX_DIBSource::FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const
+{
+ CFX_DIBitmap* pFlipped = FX_NEW CFX_DIBitmap;
+ if (!pFlipped) {
+ return NULL;
+ }
+ if (!pFlipped->Create(m_Width, m_Height, GetFormat())) {
+ delete pFlipped;
+ return NULL;
+ }
+ pFlipped->CopyPalette(m_pPalette);
+ FX_LPBYTE pDestBuffer = pFlipped->GetBuffer();
+ int Bpp = m_bpp / 8;
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPCBYTE src_scan = GetScanline(row);
+ FX_LPBYTE dest_scan = pDestBuffer + m_Pitch * (bYFlip ? (m_Height - row - 1) : row);
+ if (!bXFlip) {
+ FXSYS_memcpy32(dest_scan, src_scan, m_Pitch);
+ continue;
+ }
+ if (m_bpp == 1) {
+ FXSYS_memset32(dest_scan, 0, m_Pitch);
+ for (int col = 0; col < m_Width; col ++)
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ int dest_col = m_Width - col - 1;
+ dest_scan[dest_col / 8] |= (1 << (7 - dest_col % 8));
+ }
+ } else {
+ dest_scan += (m_Width - 1) * Bpp;
+ if (Bpp == 1) {
+ for (int col = 0; col < m_Width; col ++) {
+ *dest_scan = *src_scan;
+ dest_scan --;
+ src_scan ++;
+ }
+ } else if (Bpp == 3) {
+ for (int col = 0; col < m_Width; col ++) {
+ dest_scan[0] = src_scan[0];
+ dest_scan[1] = src_scan[1];
+ dest_scan[2] = src_scan[2];
+ dest_scan -= 3;
+ src_scan += 3;
+ }
+ } else {
+ ASSERT(Bpp == 4);
+ for (int col = 0; col < m_Width; col ++) {
+ *(FX_DWORD*)dest_scan = *(FX_DWORD*)src_scan;
+ dest_scan -= 4;
+ src_scan += 4;
+ }
+ }
+ }
+ }
+ if (m_pAlphaMask) {
+ pDestBuffer = pFlipped->m_pAlphaMask->GetBuffer();
+ FX_DWORD dest_pitch = pFlipped->m_pAlphaMask->GetPitch();
+ for (int row = 0; row < m_Height; row ++) {
+ FX_LPCBYTE src_scan = m_pAlphaMask->GetScanline(row);
+ FX_LPBYTE dest_scan = pDestBuffer + dest_pitch * (bYFlip ? (m_Height - row - 1) : row);
+ if (!bXFlip) {
+ FXSYS_memcpy32(dest_scan, src_scan, dest_pitch);
+ continue;
+ }
+ dest_scan += (m_Width - 1);
+ for (int col = 0; col < m_Width; col ++) {
+ *dest_scan = *src_scan;
+ dest_scan --;
+ src_scan ++;
+ }
+ }
+ }
+ return pFlipped;
+}
+CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc)
+{
+ m_pBitmap = NULL;
+ if (pSrc->GetBuffer() == NULL) {
+ m_pBitmap = pSrc->Clone();
+ } else {
+ m_pBitmap = FX_NEW CFX_DIBitmap;
+ if (!m_pBitmap) {
+ return;
+ }
+ if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat(), pSrc->GetBuffer())) {
+ delete m_pBitmap;
+ m_pBitmap = NULL;
+ return;
+ }
+ m_pBitmap->CopyPalette(pSrc->GetPalette());
+ m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask);
+ }
+}
+CFX_DIBExtractor::~CFX_DIBExtractor()
+{
+ if (m_pBitmap) {
+ delete m_pBitmap;
+ }
+}
+CFX_FilteredDIB::CFX_FilteredDIB()
+{
+ m_pScanline = NULL;
+ m_pSrc = NULL;
+}
+CFX_FilteredDIB::~CFX_FilteredDIB()
+{
+ if (m_pSrc && m_bAutoDropSrc) {
+ delete m_pSrc;
+ }
+ if (m_pScanline) {
+ FX_Free(m_pScanline);
+ }
+}
+void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc)
+{
+ m_pSrc = pSrc;
+ m_bAutoDropSrc = bAutoDropSrc;
+ m_Width = pSrc->GetWidth();
+ m_Height = pSrc->GetHeight();
+ FXDIB_Format format = GetDestFormat();
+ m_bpp = (FX_BYTE)format;
+ m_AlphaFlag = (FX_BYTE)(format >> 8);
+ m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4;
+ m_pPalette = GetDestPalette();
+ m_pScanline = FX_Alloc(FX_BYTE, m_Pitch);
+}
+FX_LPCBYTE CFX_FilteredDIB::GetScanline(int line) const
+{
+ TranslateScanline(m_pScanline, m_pSrc->GetScanline(line));
+ return m_pScanline;
+}
+void CFX_FilteredDIB::DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_bpp,
+ int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const
+{
+ m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, clip_left, clip_width);
+ TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp);
+}
+CFX_ImageRenderer::CFX_ImageRenderer()
+{
+ m_Status = 0;
+ m_pTransformer = NULL;
+ m_bRgbByteOrder = FALSE;
+ m_BlendType = FXDIB_BLEND_NORMAL;
+}
+CFX_ImageRenderer::~CFX_ImageRenderer()
+{
+ if (m_pTransformer) {
+ delete m_pTransformer;
+ }
+}
+extern FX_RECT _FXDIB_SwapClipBox(FX_RECT& clip, int width, int height, FX_BOOL bFlipX, FX_BOOL bFlipY);
+FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClipRgn,
+ const CFX_DIBSource* pSource, int bitmap_alpha,
+ FX_DWORD mask_color, const CFX_AffineMatrix* pMatrix,
+ FX_DWORD dib_flags, FX_BOOL bRgbByteOrder,
+ int alpha_flag, void* pIccTransform, int blend_type)
+{
+ m_Matrix = *pMatrix;
+ CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect();
+ FX_RECT image_rect = image_rect_f.GetOutterRect();
+ m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(), pDevice->GetHeight());
+ m_ClipBox.Intersect(image_rect);
+ if (m_ClipBox.IsEmpty()) {
+ return FALSE;
+ }
+ m_pDevice = pDevice;
+ m_pClipRgn = pClipRgn;
+ m_MaskColor = mask_color;
+ m_BitmapAlpha = bitmap_alpha;
+ m_Matrix = *pMatrix;
+ m_Flags = dib_flags;
+ m_AlphaFlag = alpha_flag;
+ m_pIccTransform = pIccTransform;
+ m_bRgbByteOrder = bRgbByteOrder;
+ m_BlendType = blend_type;
+ FX_BOOL ret = TRUE;
+ if ((FXSYS_fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) ||
+ (FXSYS_fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0) ) {
+ if (FXSYS_fabs(m_Matrix.a) < FXSYS_fabs(m_Matrix.b) / 20 && FXSYS_fabs(m_Matrix.d) < FXSYS_fabs(m_Matrix.c) / 20 &&
+ FXSYS_fabs(m_Matrix.a) < 0.5f && FXSYS_fabs(m_Matrix.d) < 0.5f) {
+ int dest_width = image_rect.Width();
+ int dest_height = image_rect.Height();
+ FX_RECT bitmap_clip = m_ClipBox;
+ bitmap_clip.Offset(-image_rect.left, -image_rect.top);
+ bitmap_clip = _FXDIB_SwapClipBox(bitmap_clip, dest_width, dest_height, m_Matrix.c > 0, m_Matrix.b < 0);
+ m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox, TRUE,
+ m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder, alpha_flag, pIccTransform, m_BlendType);
+ if (!m_Stretcher.Start(&m_Composer, pSource, dest_height, dest_width, bitmap_clip, dib_flags)) {
+ return FALSE;
+ }
+ m_Status = 1;
+ return TRUE;
+ }
+ m_Status = 2;
+ m_pTransformer = FX_NEW CFX_ImageTransformer;
+ if (!m_pTransformer) {
+ return FALSE;
+ }
+ m_pTransformer->Start(pSource, &m_Matrix, dib_flags, &m_ClipBox);
+ return TRUE;
+ }
+ int dest_width = image_rect.Width();
+ if (m_Matrix.a < 0) {
+ dest_width = -dest_width;
+ }
+ int dest_height = image_rect.Height();
+ if (m_Matrix.d > 0) {
+ dest_height = -dest_height;
+ }
+ if (dest_width == 0 || dest_height == 0) {
+ return FALSE;
+ }
+ FX_RECT bitmap_clip = m_ClipBox;
+ bitmap_clip.Offset(-image_rect.left, -image_rect.top);
+ m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color,
+ m_ClipBox, FALSE, FALSE, FALSE, m_bRgbByteOrder, alpha_flag, pIccTransform, m_BlendType);
+ m_Status = 1;
+ ret = m_Stretcher.Start(&m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags);
+ return ret;
+}
+FX_BOOL CFX_ImageRenderer::Continue(IFX_Pause* pPause)
+{
+ if (m_Status == 1) {
+ return m_Stretcher.Continue(pPause);
+ } else if (m_Status == 2) {
+ if (m_pTransformer->Continue(pPause)) {
+ return TRUE;
+ }
+ CFX_DIBitmap* pBitmap = m_pTransformer->m_Storer.Detach();
+ if (pBitmap == NULL) {
+ return FALSE;
+ }
+ if (pBitmap->GetBuffer() == NULL) {
+ delete pBitmap;
+ return FALSE;
+ }
+ if (pBitmap->IsAlphaMask()) {
+ if (m_BitmapAlpha != 255) {
+ if (m_AlphaFlag >> 8) {
+ m_AlphaFlag = (((FX_BYTE)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) | ((m_AlphaFlag >> 8) << 8));
+ } else {
+ m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha);
+ }
+ }
+ m_pDevice->CompositeMask(m_pTransformer->m_ResultLeft, m_pTransformer->m_ResultTop,
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor,
+ 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag, m_pIccTransform);
+ } else {
+ if (m_BitmapAlpha != 255) {
+ pBitmap->MultiplyAlpha(m_BitmapAlpha);
+ }
+ m_pDevice->CompositeBitmap(m_pTransformer->m_ResultLeft, m_pTransformer->m_ResultTop,
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
+ }
+ delete pBitmap;
+ return FALSE;
+ }
+ return FALSE;
+}
+CFX_BitmapStorer::CFX_BitmapStorer()
+{
+ m_pBitmap = NULL;
+}
+CFX_BitmapStorer::~CFX_BitmapStorer()
+{
+ if (m_pBitmap) {
+ delete m_pBitmap;
+ }
+}
+CFX_DIBitmap* CFX_BitmapStorer::Detach()
+{
+ CFX_DIBitmap* pBitmap = m_pBitmap;
+ m_pBitmap = NULL;
+ return pBitmap;
+}
+void CFX_BitmapStorer::Replace(CFX_DIBitmap* pBitmap)
+{
+ if (m_pBitmap) {
+ delete m_pBitmap;
+ }
+ m_pBitmap = pBitmap;
+}
+void CFX_BitmapStorer::ComposeScanline(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha)
+{
+ FX_LPBYTE dest_buf = (FX_LPBYTE)m_pBitmap->GetScanline(line);
+ FX_LPBYTE dest_alpha_buf = m_pBitmap->m_pAlphaMask ?
+ (FX_LPBYTE)m_pBitmap->m_pAlphaMask->GetScanline(line) : NULL;
+ if (dest_buf) {
+ FXSYS_memcpy32(dest_buf, scanline, m_pBitmap->GetPitch());
+ }
+ if (dest_alpha_buf) {
+ FXSYS_memcpy32(dest_alpha_buf, scan_extra_alpha, m_pBitmap->m_pAlphaMask->GetPitch());
+ }
+}
+FX_BOOL CFX_BitmapStorer::SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette)
+{
+ m_pBitmap = FX_NEW CFX_DIBitmap;
+ if (!m_pBitmap) {
+ return FALSE;
+ }
+ if (!m_pBitmap->Create(width, height, src_format)) {
+ delete m_pBitmap;
+ m_pBitmap = NULL;
+ return FALSE;
+ }
+ if (pSrcPalette) {
+ m_pBitmap->CopyPalette(pSrcPalette);
+ }
+ return TRUE;
+}
diff --git a/core/src/fxge/dib/fx_dib_transform.cpp b/core/src/fxge/dib/fx_dib_transform.cpp new file mode 100644 index 0000000000..4d83005161 --- /dev/null +++ b/core/src/fxge/dib/fx_dib_transform.cpp @@ -0,0 +1,797 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../../include/fxge/fx_dib.h"
+#include "dib_int.h"
+int SDP_Table[513] = {
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255, 254, 254, 254, 254,
+ 253, 253, 253, 252, 252, 252, 251, 251, 251, 250, 250, 249, 249, 249, 248, 248, 247, 247, 246,
+ 246, 245, 244, 244, 243, 243, 242, 242, 241, 240, 240, 239, 238, 238, 237, 236, 236, 235, 234,
+ 233, 233, 232, 231, 230, 230, 229, 228, 227, 226, 226, 225, 224, 223, 222, 221, 220, 219, 218,
+ 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200,
+ 199, 198, 196, 195, 194, 193, 192, 191, 190, 189, 188, 186, 185, 184, 183, 182, 181, 179, 178,
+ 177, 176, 175, 173, 172, 171, 170, 169, 167, 166, 165, 164, 162, 161, 160, 159, 157, 156, 155,
+ 154, 152, 151, 150, 149, 147, 146, 145, 143, 142, 141, 140, 138, 137, 136, 134, 133, 132, 130,
+ 129, 128, 126, 125, 124, 122, 121, 120, 119, 117, 116, 115, 113, 112, 111, 109, 108, 107, 105,
+ 104, 103, 101, 100, 99, 97, 96, 95, 93, 92, 91, 89, 88, 87, 85, 84, 83, 81, 80, 79, 77, 76, 75,
+ 73, 72, 71, 69, 68, 67, 66, 64, 63, 62, 60, 59, 58, 57, 55, 54, 53, 52, 50, 49, 48, 47, 45, 44,
+ 43, 42, 40, 39, 38, 37, 36, 34, 33, 32, 31, 30, 28, 27, 26, 25, 24, 23, 21, 20, 19, 18, 17, 16,
+ 15, 14, 13, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, -1, -2, -3, -4, -5, -6, -7, -7, -8, -9, -10,
+ -11, -12, -12, -13, -14, -15, -15, -16, -17, -17, -18, -19, -19, -20, -21, -21, -22, -22, -23, -24,
+ -24, -25, -25, -26, -26, -27, -27, -27, -28, -28, -29, -29, -30, -30, -30, -31, -31, -31, -32, -32,
+ -32, -33, -33, -33, -33, -34, -34, -34, -34, -35, -35, -35, -35, -35, -36, -36, -36, -36, -36, -36,
+ -36, -36, -36, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
+ -37, -37, -37, -37, -36, -36, -36, -36, -36, -36, -36, -36, -36, -35, -35, -35, -35, -35, -35, -34,
+ -34, -34, -34, -34, -33, -33, -33, -33, -33, -32, -32, -32, -32, -31, -31, -31, -31, -30, -30, -30,
+ -30, -29, -29, -29, -29, -28, -28, -28, -27, -27, -27, -27, -26, -26, -26, -25, -25, -25, -24, -24,
+ -24, -23, -23, -23, -22, -22, -22, -22, -21, -21, -21, -20, -20, -20, -19, -19, -19, -18, -18, -18,
+ -17, -17, -17, -16, -16, -16, -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -12, -11, -11,
+ -11, -10, -10, -10, -9, -9, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6, -6, -6, -6, -5, -5, -5, -5, -4,
+ -4, -4, -4, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+class CFX_BilinearMatrix : public CPDF_FixedMatrix
+{
+public:
+ CFX_BilinearMatrix(const CFX_AffineMatrix& src, int bits): CPDF_FixedMatrix(src, bits)
+ {}
+ inline void Transform(int x, int y, int& x1, int& y1, int&res_x, int&res_y)
+ {
+ x1 = a * x + c * y + e + base / 2;
+ y1 = b * x + d * y + f + base / 2;
+ res_x = x1 % base;
+ res_y = y1 % base;
+ if (res_x < 0 && res_x > -base) {
+ res_x = base + res_x;
+ }
+ if (res_y < 0 && res_x > -base) {
+ res_y = base + res_y;
+ }
+ x1 /= base;
+ y1 /= base;
+ }
+};
+CFX_DIBitmap* CFX_DIBSource::SwapXY(FX_BOOL bXFlip, FX_BOOL bYFlip, const FX_RECT* pDestClip) const
+{
+ FX_RECT dest_clip(0, 0, m_Height, m_Width);
+ if (pDestClip) {
+ dest_clip.Intersect(*pDestClip);
+ }
+ if (dest_clip.IsEmpty()) {
+ return NULL;
+ }
+ CFX_DIBitmap* pTransBitmap = FX_NEW CFX_DIBitmap;
+ if (!pTransBitmap) {
+ return NULL;
+ }
+ int result_height = dest_clip.Height(), result_width = dest_clip.Width();
+ if (!pTransBitmap->Create(result_width, result_height, GetFormat())) {
+ delete pTransBitmap;
+ return NULL;
+ }
+ pTransBitmap->CopyPalette(m_pPalette);
+ int src_pitch = m_Pitch;
+ int dest_pitch = pTransBitmap->GetPitch();
+ FX_LPBYTE dest_buf = pTransBitmap->GetBuffer();
+ int row_start = bXFlip ? m_Height - dest_clip.right : dest_clip.left;
+ int row_end = bXFlip ? m_Height - dest_clip.left : dest_clip.right;
+ int col_start = bYFlip ? m_Width - dest_clip.bottom : dest_clip.top;
+ int col_end = bYFlip ? m_Width - dest_clip.top : dest_clip.bottom;
+ if (GetBPP() == 1) {
+ FXSYS_memset8(dest_buf, 0xff, dest_pitch * result_height);
+ for (int row = row_start; row < row_end; row ++) {
+ FX_LPCBYTE src_scan = GetScanline(row);
+ int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) - dest_clip.left;
+ FX_LPBYTE dest_scan = dest_buf;
+ if (bYFlip) {
+ dest_scan += (result_height - 1) * dest_pitch;
+ }
+ int dest_step = bYFlip ? -dest_pitch : dest_pitch;
+ for (int col = col_start; col < col_end; col ++) {
+ if (!(src_scan[col / 8] & (1 << (7 - col % 8)))) {
+ dest_scan[dest_col / 8] &= ~(1 << (7 - dest_col % 8));
+ }
+ dest_scan += dest_step;
+ }
+ }
+ } else {
+ int nBytes = GetBPP() / 8;
+ int dest_step = bYFlip ? -dest_pitch : dest_pitch;
+ if (nBytes == 3) {
+ dest_step -= 2;
+ }
+ for (int row = row_start; row < row_end; row ++) {
+ int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) - dest_clip.left;
+ FX_LPBYTE dest_scan = dest_buf + dest_col * nBytes;
+ if (bYFlip) {
+ dest_scan += (result_height - 1) * dest_pitch;
+ }
+ if (nBytes == 4) {
+ FX_DWORD* src_scan = (FX_DWORD*)GetScanline(row) + col_start;
+ for (int col = col_start; col < col_end; col ++) {
+ *(FX_DWORD*)dest_scan = *src_scan++;
+ dest_scan += dest_step;
+ }
+ } else {
+ FX_LPCBYTE src_scan = GetScanline(row) + col_start * nBytes;
+ if (nBytes == 1)
+ for (int col = col_start; col < col_end; col ++) {
+ *dest_scan = *src_scan++;
+ dest_scan += dest_step;
+ }
+ else
+ for (int col = col_start; col < col_end; col ++) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan = *src_scan++;
+ dest_scan += dest_step;
+ }
+ }
+ }
+ }
+ if (m_pAlphaMask) {
+ src_pitch = m_pAlphaMask->m_Pitch;
+ dest_pitch = pTransBitmap->m_pAlphaMask->GetPitch();
+ dest_buf = pTransBitmap->m_pAlphaMask->GetBuffer();
+ int dest_step = bYFlip ? -dest_pitch : dest_pitch;
+ for (int row = row_start; row < row_end; row ++) {
+ int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) - dest_clip.left;
+ FX_LPBYTE dest_scan = dest_buf + dest_col;
+ if (bYFlip) {
+ dest_scan += (result_height - 1) * dest_pitch;
+ }
+ FX_LPCBYTE src_scan = m_pAlphaMask->GetScanline(row) + col_start;
+ for (int col = col_start; col < col_end; col ++) {
+ *dest_scan = *src_scan++;
+ dest_scan += dest_step;
+ }
+ }
+ }
+ return pTransBitmap;
+}
+#define FIX16_005 0.05f
+FX_RECT _FXDIB_SwapClipBox(FX_RECT& clip, int width, int height, FX_BOOL bFlipX, FX_BOOL bFlipY)
+{
+ FX_RECT rect;
+ if (bFlipY) {
+ rect.left = height - clip.top;
+ rect.right = height - clip.bottom;
+ } else {
+ rect.left = clip.top;
+ rect.right = clip.bottom;
+ }
+ if (bFlipX) {
+ rect.top = width - clip.left;
+ rect.bottom = width - clip.right;
+ } else {
+ rect.top = clip.left;
+ rect.bottom = clip.right;
+ }
+ rect.Normalize();
+ return rect;
+}
+CFX_DIBitmap* CFX_DIBSource::TransformTo(const CFX_AffineMatrix* pDestMatrix, int& result_left, int& result_top,
+ FX_DWORD flags, const FX_RECT* pDestClip) const
+{
+ CFX_ImageTransformer transformer;
+ transformer.Start(this, pDestMatrix, flags, pDestClip);
+ transformer.Continue(NULL);
+ result_left = transformer.m_ResultLeft;
+ result_top = transformer.m_ResultTop;
+ CFX_DIBitmap* pTransformed = transformer.m_Storer.Detach();
+ return pTransformed;
+}
+CFX_DIBitmap* CFX_DIBSource::StretchTo(int dest_width, int dest_height, FX_DWORD flags, const FX_RECT* pClip) const
+{
+ FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height));
+ if (pClip) {
+ clip_rect.Intersect(*pClip);
+ }
+ if (clip_rect.IsEmpty()) {
+ return NULL;
+ }
+ if (dest_width == m_Width && dest_height == m_Height) {
+ return Clone(&clip_rect);
+ }
+ CFX_ImageStretcher stretcher;
+ CFX_BitmapStorer storer;
+ if (stretcher.Start(&storer, this, dest_width, dest_height, clip_rect, flags)) {
+ stretcher.Continue(NULL);
+ }
+ return storer.Detach();
+}
+CFX_ImageTransformer::CFX_ImageTransformer()
+{
+ m_Status = 0;
+ m_pMatrix = NULL;
+}
+CFX_ImageTransformer::~CFX_ImageTransformer()
+{
+}
+FX_BOOL CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, const CFX_AffineMatrix* pDestMatrix, int flags, const FX_RECT* pDestClip)
+{
+ m_pMatrix = (CFX_AffineMatrix*)pDestMatrix;
+ CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect();
+ FX_RECT result_rect = unit_rect.GetClosestRect();
+ FX_RECT result_clip = result_rect;
+ if (pDestClip) {
+ result_clip.Intersect(*pDestClip);
+ }
+ if (result_clip.IsEmpty()) {
+ return FALSE;
+ }
+ m_ResultLeft = result_clip.left;
+ m_ResultTop = result_clip.top;
+ m_ResultWidth = result_clip.Width();
+ m_ResultHeight = result_clip.Height();
+ m_Flags = flags;
+ if (FXSYS_fabs(pDestMatrix->a) < FXSYS_fabs(pDestMatrix->b) / 20 &&
+ FXSYS_fabs(pDestMatrix->d) < FXSYS_fabs(pDestMatrix->c) / 20 &&
+ FXSYS_fabs(pDestMatrix->a) < 0.5f && FXSYS_fabs(pDestMatrix->d) < 0.5f) {
+ int dest_width = result_rect.Width();
+ int dest_height = result_rect.Height();
+ result_clip.Offset(-result_rect.left, -result_rect.top);
+ result_clip = _FXDIB_SwapClipBox(result_clip, dest_width, dest_height, pDestMatrix->c > 0, pDestMatrix->b < 0);
+ m_Stretcher.Start(&m_Storer, pSrc, dest_height, dest_width, result_clip, flags);
+ m_Status = 1;
+ return TRUE;
+ }
+ if (FXSYS_fabs(pDestMatrix->b) < FIX16_005 && FXSYS_fabs(pDestMatrix->c) < FIX16_005) {
+ int dest_width = pDestMatrix->a > 0 ? (int)FXSYS_ceil(pDestMatrix->a) : (int)FXSYS_floor(pDestMatrix->a);
+ int dest_height = pDestMatrix->d > 0 ? (int) - FXSYS_ceil(pDestMatrix->d) : (int) - FXSYS_floor(pDestMatrix->d);
+ result_clip.Offset(-result_rect.left, -result_rect.top);
+ m_Stretcher.Start(&m_Storer, pSrc, dest_width, dest_height, result_clip, flags);
+ m_Status = 2;
+ return TRUE;
+ }
+ int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix->b));
+ int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix->d));
+ CFX_AffineMatrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, (FX_FLOAT)(stretch_height));
+ stretch2dest.Concat(pDestMatrix->a / stretch_width, pDestMatrix->b / stretch_width,
+ pDestMatrix->c / stretch_height, pDestMatrix->d / stretch_height, pDestMatrix->e, pDestMatrix->f);
+ m_dest2stretch.SetReverse(stretch2dest);
+ CFX_FloatRect clip_rect_f(result_clip);
+ clip_rect_f.Transform(&m_dest2stretch);
+ m_StretchClip = clip_rect_f.GetOutterRect();
+ m_StretchClip.Intersect(0, 0, stretch_width, stretch_height);
+ m_Stretcher.Start(&m_Storer, pSrc, stretch_width, stretch_height, m_StretchClip, flags);
+ m_Status = 3;
+ return TRUE;
+}
+FX_BYTE _bilinear_interpol(FX_LPCBYTE buf, int row_offset_l, int row_offset_r,
+ int src_col_l, int src_col_r, int res_x, int res_y,
+ int bpp, int c_offset)
+{
+ int i_resx = 255 - res_x;
+ int col_bpp_l = src_col_l * bpp;
+ int col_bpp_r = src_col_r * bpp;
+ FX_LPCBYTE buf_u = buf + row_offset_l + c_offset;
+ FX_LPCBYTE buf_d = buf + row_offset_r + c_offset;
+ FX_LPCBYTE src_pos0 = buf_u + col_bpp_l;
+ FX_LPCBYTE src_pos1 = buf_u + col_bpp_r;
+ FX_LPCBYTE src_pos2 = buf_d + col_bpp_l;
+ FX_LPCBYTE src_pos3 = buf_d + col_bpp_r;
+ FX_BYTE r_pos_0 = (*src_pos0 * i_resx + *src_pos1 * res_x) >> 8;
+ FX_BYTE r_pos_1 = (*src_pos2 * i_resx + *src_pos3 * res_x) >> 8;
+ return (r_pos_0 * (255 - res_y) + r_pos_1 * res_y) >> 8;
+}
+FX_BYTE _bicubic_interpol(FX_LPCBYTE buf, int pitch, int pos_pixel[], int u_w[], int v_w[], int res_x, int res_y,
+ int bpp, int c_offset)
+{
+ int s_result = 0;
+ for (int i = 0; i < 4; i ++) {
+ int a_result = 0;
+ for (int j = 0; j < 4; j ++) {
+ a_result += u_w[j] * (*(FX_BYTE*)(buf + pos_pixel[i + 4] * pitch + pos_pixel[j] * bpp + c_offset));
+ }
+ s_result += a_result * v_w[i];
+ }
+ s_result >>= 16;
+ return (FX_BYTE)(s_result < 0 ? 0 : s_result > 255 ? 255 : s_result);
+}
+void _bicubic_get_pos_weight(int pos_pixel[], int u_w[], int v_w[], int src_col_l, int src_row_l,
+ int res_x, int res_y, int stretch_width, int stretch_height)
+{
+ pos_pixel[0] = src_col_l - 1;
+ pos_pixel[1] = src_col_l;
+ pos_pixel[2] = src_col_l + 1;
+ pos_pixel[3] = src_col_l + 2;
+ pos_pixel[4] = src_row_l - 1;
+ pos_pixel[5] = src_row_l;
+ pos_pixel[6] = src_row_l + 1;
+ pos_pixel[7] = src_row_l + 2;
+ for (int i = 0 ; i < 4; i ++) {
+ if (pos_pixel[i] < 0) {
+ pos_pixel[i] = 0;
+ }
+ if (pos_pixel[i] >= stretch_width) {
+ pos_pixel[i] = stretch_width - 1;
+ }
+ if (pos_pixel[i + 4] < 0) {
+ pos_pixel[i + 4] = 0;
+ }
+ if (pos_pixel[i + 4] >= stretch_height) {
+ pos_pixel[i + 4] = stretch_height - 1;
+ }
+ }
+ u_w[0] = SDP_Table[256 + res_x];
+ u_w[1] = SDP_Table[res_x];
+ u_w[2] = SDP_Table[256 - res_x];
+ u_w[3] = SDP_Table[512 - res_x];
+ v_w[0] = SDP_Table[256 + res_y];
+ v_w[1] = SDP_Table[res_y];
+ v_w[2] = SDP_Table[256 - res_y];
+ v_w[3] = SDP_Table[512 - res_y];
+}
+FXDIB_Format _GetTransformedFormat(const CFX_DIBSource* pDrc)
+{
+ FXDIB_Format format = pDrc->GetFormat();
+ if (pDrc->IsAlphaMask()) {
+ format = FXDIB_8bppMask;
+ } else if (format >= 1025) {
+ format = FXDIB_Cmyka;
+ } else if (format <= 32 || format == FXDIB_Argb) {
+ format = FXDIB_Argb;
+ } else {
+ format = FXDIB_Rgba;
+ }
+ return format;
+}
+FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause)
+{
+ if (m_Status == 1) {
+ if (m_Stretcher.Continue(pPause)) {
+ return TRUE;
+ }
+ if (m_Storer.GetBitmap()) {
+ m_Storer.Replace(m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pMatrix->b < 0));
+ }
+ return FALSE;
+ } else if (m_Status == 2) {
+ return m_Stretcher.Continue(pPause);
+ } else if (m_Status != 3) {
+ return FALSE;
+ }
+ if (m_Stretcher.Continue(pPause)) {
+ return TRUE;
+ }
+ int stretch_width = m_StretchClip.Width();
+ int stretch_height = m_StretchClip.Height();
+ if (m_Storer.GetBitmap() == NULL) {
+ return FALSE;
+ }
+ FX_LPCBYTE stretch_buf = m_Storer.GetBitmap()->GetBuffer();
+ FX_LPCBYTE stretch_buf_mask = NULL;
+ if (m_Storer.GetBitmap()->m_pAlphaMask) {
+ stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer();
+ }
+ int stretch_pitch = m_Storer.GetBitmap()->GetPitch();
+ CFX_DIBitmap* pTransformed = FX_NEW CFX_DIBitmap;
+ if (!pTransformed) {
+ return FALSE;
+ }
+ FXDIB_Format transformF = _GetTransformedFormat(m_Stretcher.m_pSource);
+ if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) {
+ delete pTransformed;
+ return FALSE;
+ }
+ pTransformed->Clear(0);
+ if (pTransformed->m_pAlphaMask) {
+ pTransformed->m_pAlphaMask->Clear(0);
+ }
+ CFX_AffineMatrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_ResultLeft), (FX_FLOAT)(m_ResultTop));
+ result2stretch.Concat(m_dest2stretch);
+ result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top);
+ if (stretch_buf_mask == NULL && pTransformed->m_pAlphaMask) {
+ pTransformed->m_pAlphaMask->Clear(0xff000000);
+ } else if (pTransformed->m_pAlphaMask) {
+ int stretch_pitch_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetPitch();
+ if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) {
+ CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos_mask = (FX_BYTE*)pTransformed->m_pAlphaMask->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col_l, src_row_l, res_x, res_y;
+ result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y);
+ if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) {
+ if (src_col_l == stretch_width) {
+ src_col_l--;
+ }
+ if (src_row_l == stretch_height) {
+ src_row_l--;
+ }
+ int src_col_r = src_col_l + 1;
+ int src_row_r = src_row_l + 1;
+ if (src_col_r == stretch_width) {
+ src_col_r--;
+ }
+ if (src_row_r == stretch_height) {
+ src_row_r--;
+ }
+ int row_offset_l = src_row_l * stretch_pitch_mask;
+ int row_offset_r = src_row_r * stretch_pitch_mask;
+ *dest_pos_mask = _bilinear_interpol(stretch_buf_mask, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, 1, 0);
+ }
+ dest_pos_mask++;
+ }
+ }
+ } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
+ int pos_pixel[8];
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos_mask = (FX_BYTE*)pTransformed->m_pAlphaMask->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col_l, src_row_l, res_x, res_y;
+ result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y);
+ if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) {
+ int u_w[4], v_w[4];
+ if (src_col_l == stretch_width) {
+ src_col_l--;
+ }
+ if (src_row_l == stretch_height) {
+ src_row_l--;
+ }
+ _bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l, res_x, res_y, stretch_width, stretch_height);
+ *dest_pos_mask = _bicubic_interpol(stretch_buf_mask, stretch_pitch_mask, pos_pixel, u_w, v_w, res_x, res_y, 1, 0);
+ }
+ dest_pos_mask++;
+ }
+ }
+ } else {
+ CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos_mask = (FX_BYTE*)pTransformed->m_pAlphaMask->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col, src_row;
+ result2stretch_fix.Transform(col, row, src_col, src_row);
+ if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && src_row <= stretch_height) {
+ if (src_col == stretch_width) {
+ src_col --;
+ }
+ if (src_row == stretch_height) {
+ src_row --;
+ }
+ *dest_pos_mask = stretch_buf_mask[src_row * stretch_pitch_mask + src_col];
+ }
+ dest_pos_mask++;
+ }
+ }
+ }
+ }
+ if (m_Storer.GetBitmap()->IsAlphaMask()) {
+ if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) {
+ CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_LPBYTE dest_scan = (FX_LPBYTE)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col_l, src_row_l, res_x, res_y;
+ result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y);
+ if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) {
+ if (src_col_l == stretch_width) {
+ src_col_l--;
+ }
+ if (src_row_l == stretch_height) {
+ src_row_l--;
+ }
+ int src_col_r = src_col_l + 1;
+ int src_row_r = src_row_l + 1;
+ if (src_col_r == stretch_width) {
+ src_col_r--;
+ }
+ if (src_row_r == stretch_height) {
+ src_row_r--;
+ }
+ int row_offset_l = src_row_l * stretch_pitch;
+ int row_offset_r = src_row_r * stretch_pitch;
+ *dest_scan = _bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, 1, 0);
+ }
+ dest_scan ++;
+ }
+ }
+ } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
+ int pos_pixel[8];
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_LPBYTE dest_scan = (FX_LPBYTE)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col_l, src_row_l, res_x, res_y;
+ result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y);
+ if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) {
+ int u_w[4], v_w[4];
+ if (src_col_l == stretch_width) {
+ src_col_l--;
+ }
+ if (src_row_l == stretch_height) {
+ src_row_l--;
+ }
+ _bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l, res_x, res_y, stretch_width, stretch_height);
+ *dest_scan = _bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, 1, 0);
+ }
+ dest_scan ++;
+ }
+ }
+ } else {
+ CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_LPBYTE dest_scan = (FX_LPBYTE)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col, src_row;
+ result2stretch_fix.Transform(col, row, src_col, src_row);
+ if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && src_row <= stretch_height) {
+ if (src_col == stretch_width) {
+ src_col --;
+ }
+ if (src_row == stretch_height) {
+ src_row --;
+ }
+ FX_LPCBYTE src_pixel = stretch_buf + stretch_pitch * src_row + src_col;
+ *dest_scan = *src_pixel;
+ }
+ dest_scan ++;
+ }
+ }
+ }
+ } else {
+ int Bpp = m_Storer.GetBitmap()->GetBPP() / 8;
+ int destBpp = pTransformed->GetBPP() / 8;
+ if (Bpp == 1) {
+ FX_BOOL bHasAlpha = m_Storer.GetBitmap()->HasAlpha();
+ FX_DWORD argb[256];
+ FX_ARGB* pPal = m_Storer.GetBitmap()->GetPalette();
+ if (pPal) {
+ for (int i = 0; i < 256; i ++) {
+ argb[i] = pPal[i];
+ }
+ } else {
+ if (m_Storer.GetBitmap()->IsCmykImage())
+ for (int i = 0; i < 256; i ++) {
+ argb[i] = 255 - i;
+ }
+ else
+ for (int i = 0; i < 256; i ++) {
+ argb[i] = 0xff000000 | (i * 0x010101);
+ }
+ }
+ if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) {
+ CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos = (FX_BYTE*)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col_l, src_row_l, res_x, res_y;
+ result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y);
+ if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) {
+ if (src_col_l == stretch_width) {
+ src_col_l--;
+ }
+ if (src_row_l == stretch_height) {
+ src_row_l--;
+ }
+ int src_col_r = src_col_l + 1;
+ int src_row_r = src_row_l + 1;
+ if (src_col_r == stretch_width) {
+ src_col_r--;
+ }
+ if (src_row_r == stretch_height) {
+ src_row_r--;
+ }
+ int row_offset_l = src_row_l * stretch_pitch;
+ int row_offset_r = src_row_r * stretch_pitch;
+ FX_DWORD r_bgra_cmyk = argb[_bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, 1, 0)];
+ if (transformF == FXDIB_Rgba) {
+ dest_pos[0] = (FX_BYTE)(r_bgra_cmyk >> 24);
+ dest_pos[1] = (FX_BYTE)(r_bgra_cmyk >> 16);
+ dest_pos[2] = (FX_BYTE)(r_bgra_cmyk >> 8);
+ } else {
+ *(FX_DWORD*)dest_pos = r_bgra_cmyk;
+ }
+ }
+ dest_pos += destBpp;
+ }
+ }
+ } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
+ int pos_pixel[8];
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos = (FX_BYTE*)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col_l, src_row_l, res_x, res_y;
+ result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y);
+ if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) {
+ int u_w[4], v_w[4];
+ if (src_col_l == stretch_width) {
+ src_col_l--;
+ }
+ if (src_row_l == stretch_height) {
+ src_row_l--;
+ }
+ _bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l, res_x, res_y, stretch_width, stretch_height);
+ FX_DWORD r_bgra_cmyk = argb[_bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, 1, 0)];
+ if (transformF == FXDIB_Rgba) {
+ dest_pos[0] = (FX_BYTE)(r_bgra_cmyk >> 24);
+ dest_pos[1] = (FX_BYTE)(r_bgra_cmyk >> 16);
+ dest_pos[2] = (FX_BYTE)(r_bgra_cmyk >> 8);
+ } else {
+ *(FX_DWORD*)dest_pos = r_bgra_cmyk;
+ }
+ }
+ dest_pos += destBpp;
+ }
+ }
+ } else {
+ CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos = (FX_BYTE*)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col, src_row;
+ result2stretch_fix.Transform(col, row, src_col, src_row);
+ if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && src_row <= stretch_height) {
+ if (src_col == stretch_width) {
+ src_col --;
+ }
+ if (src_row == stretch_height) {
+ src_row --;
+ }
+ FX_DWORD r_bgra_cmyk = argb[stretch_buf[src_row * stretch_pitch + src_col]];
+ if (transformF == FXDIB_Rgba) {
+ dest_pos[0] = (FX_BYTE)(r_bgra_cmyk >> 24);
+ dest_pos[1] = (FX_BYTE)(r_bgra_cmyk >> 16);
+ dest_pos[2] = (FX_BYTE)(r_bgra_cmyk >> 8);
+ } else {
+ *(FX_DWORD*)dest_pos = r_bgra_cmyk;
+ }
+ }
+ dest_pos += destBpp;
+ }
+ }
+ }
+ } else {
+ FX_BOOL bHasAlpha = m_Storer.GetBitmap()->HasAlpha();
+ int destBpp = pTransformed->GetBPP() / 8;
+ if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) {
+ CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos = (FX_BYTE*)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0;
+ result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y);
+ if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) {
+ if (src_col_l == stretch_width) {
+ src_col_l--;
+ }
+ if (src_row_l == stretch_height) {
+ src_row_l--;
+ }
+ int src_col_r = src_col_l + 1;
+ int src_row_r = src_row_l + 1;
+ if (src_col_r == stretch_width) {
+ src_col_r--;
+ }
+ if (src_row_r == stretch_height) {
+ src_row_r--;
+ }
+ int row_offset_l = src_row_l * stretch_pitch;
+ int row_offset_r = src_row_r * stretch_pitch;
+ FX_BYTE r_pos_red_y_r = _bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, Bpp, 2);
+ FX_BYTE r_pos_green_m_r = _bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, Bpp, 1);
+ FX_BYTE r_pos_blue_c_r = _bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, Bpp, 0);
+ if (bHasAlpha) {
+ if (transformF != FXDIB_Argb) {
+ if (transformF == FXDIB_Rgba) {
+ dest_pos[0] = r_pos_blue_c_r;
+ dest_pos[1] = r_pos_green_m_r;
+ dest_pos[2] = r_pos_red_y_r;
+ } else {
+ r_pos_k_r = _bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, Bpp, 3);
+ *(FX_DWORD*)dest_pos = FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, r_pos_red_y_r, r_pos_k_r));
+ }
+ } else {
+ FX_BYTE r_pos_a_r = _bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, Bpp, 3);
+ *(FX_DWORD*)dest_pos = FXARGB_TODIB(FXARGB_MAKE(r_pos_a_r, r_pos_red_y_r, r_pos_green_m_r, r_pos_blue_c_r));
+ }
+ } else {
+ r_pos_k_r = 0xff;
+ if (transformF == FXDIB_Cmyka) {
+ r_pos_k_r = _bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, Bpp, 3);
+ *(FX_DWORD*)dest_pos = FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, r_pos_red_y_r, r_pos_k_r));
+ } else {
+ *(FX_DWORD*)dest_pos = FXARGB_TODIB(FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r, r_pos_blue_c_r));
+ }
+ }
+ }
+ dest_pos += destBpp;
+ }
+ }
+ } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
+ CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
+ int pos_pixel[8];
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos = (FX_BYTE*)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0;
+ result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y);
+ if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) {
+ int u_w[4], v_w[4];
+ if (src_col_l == stretch_width) {
+ src_col_l--;
+ }
+ if (src_row_l == stretch_height) {
+ src_row_l--;
+ }
+ _bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l, res_x, res_y, stretch_width, stretch_height);
+ FX_BYTE r_pos_red_y_r = _bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, Bpp, 2);
+ FX_BYTE r_pos_green_m_r = _bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, Bpp, 1);
+ FX_BYTE r_pos_blue_c_r = _bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, Bpp, 0);
+ if (bHasAlpha) {
+ if (transformF != FXDIB_Argb) {
+ if (transformF == FXDIB_Rgba) {
+ dest_pos[0] = r_pos_blue_c_r;
+ dest_pos[1] = r_pos_green_m_r;
+ dest_pos[2] = r_pos_red_y_r;
+ } else {
+ r_pos_k_r = _bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, Bpp, 3);
+ *(FX_DWORD*)dest_pos = FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, r_pos_red_y_r, r_pos_k_r));
+ }
+ } else {
+ FX_BYTE r_pos_a_r = _bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, Bpp, 3);
+ *(FX_DWORD*)dest_pos = FXARGB_TODIB(FXARGB_MAKE(r_pos_a_r, r_pos_red_y_r, r_pos_green_m_r, r_pos_blue_c_r));
+ }
+ } else {
+ r_pos_k_r = 0xff;
+ if (transformF == FXDIB_Cmyka) {
+ r_pos_k_r = _bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, Bpp, 3);
+ *(FX_DWORD*)dest_pos = FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, r_pos_red_y_r, r_pos_k_r));
+ } else {
+ *(FX_DWORD*)dest_pos = FXARGB_TODIB(FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r, r_pos_blue_c_r));
+ }
+ }
+ }
+ dest_pos += destBpp;
+ }
+ }
+ } else {
+ CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
+ for (int row = 0; row < m_ResultHeight; row ++) {
+ FX_BYTE* dest_pos = (FX_BYTE*)pTransformed->GetScanline(row);
+ for (int col = 0; col < m_ResultWidth; col ++) {
+ int src_col, src_row;
+ result2stretch_fix.Transform(col, row, src_col, src_row);
+ if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && src_row <= stretch_height) {
+ if (src_col == stretch_width) {
+ src_col --;
+ }
+ if (src_row == stretch_height) {
+ src_row --;
+ }
+ FX_LPCBYTE src_pos = stretch_buf + src_row * stretch_pitch + src_col * Bpp;
+ if (bHasAlpha) {
+ if (transformF != FXDIB_Argb) {
+ if (transformF == FXDIB_Rgba) {
+ dest_pos[0] = src_pos[0];
+ dest_pos[1] = src_pos[1];
+ dest_pos[2] = src_pos[2];
+ } else {
+ *(FX_DWORD*)dest_pos = FXCMYK_TODIB(CmykEncode(src_pos[0], src_pos[1], src_pos[2], src_pos[3]));
+ }
+ } else {
+ *(FX_DWORD*)dest_pos = FXARGB_TODIB(FXARGB_MAKE(src_pos[3], src_pos[2], src_pos[1], src_pos[0]));
+ }
+ } else {
+ if (transformF == FXDIB_Cmyka) {
+ *(FX_DWORD*)dest_pos = FXCMYK_TODIB(CmykEncode(src_pos[0], src_pos[1], src_pos[2], src_pos[3]));
+ } else {
+ *(FX_DWORD*)dest_pos = FXARGB_TODIB(FXARGB_MAKE(0xff, src_pos[2], src_pos[1], src_pos[0]));
+ }
+ }
+ }
+ dest_pos += destBpp;
+ }
+ }
+ }
+ }
+ }
+ m_Storer.Replace(pTransformed);
+ return FALSE;
+}
|