Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: core/src/fxge/dib/fx_dib_composite.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #include "../../../include/fxcodec/fx_codec.h" 8 #include "../../../include/fxcodec/fx_codec.h"
9 #include "dib_int.h" 9 #include "dib_int.h"
10 const uint8_t _color_sqrt[256] = { 10 const uint8_t _color_sqrt[256] = {
11 0x00, 0x03, 0x07, 0x0B, 0x0F, 0x12, 0x16, 0x19, 0x1D, 0x20, 0x23, 0x26, 0x29 , 0x2C, 0x2F, 0x32, 11 0x00, 0x03, 0x07, 0x0B, 0x0F, 0x12, 0x16, 0x19, 0x1D, 0x20, 0x23, 0x26,
12 0x35, 0x37, 0x3A, 0x3C, 0x3F, 0x41, 0x43, 0x46, 0x48, 0x4A, 0x4C, 0x4E, 0x50 , 0x52, 0x54, 0x56, 12 0x29, 0x2C, 0x2F, 0x32, 0x35, 0x37, 0x3A, 0x3C, 0x3F, 0x41, 0x43, 0x46,
13 0x57, 0x59, 0x5B, 0x5C, 0x5E, 0x60, 0x61, 0x63, 0x64, 0x65, 0x67, 0x68, 0x69 , 0x6B, 0x6C, 0x6D, 13 0x48, 0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56, 0x57, 0x59, 0x5B, 0x5C,
14 0x6E, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B , 0x7C, 0x7D, 0x7E, 14 0x5E, 0x60, 0x61, 0x63, 0x64, 0x65, 0x67, 0x68, 0x69, 0x6B, 0x6C, 0x6D,
15 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x87, 0x88, 0x89, 0x8A, 0x8B , 0x8C, 0x8D, 0x8E, 15 0x6E, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,
16 0x8F, 0x90, 0x91, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x97, 0x98, 0x99 , 0x9A, 0x9B, 0x9C, 16 0x7B, 0x7C, 0x7D, 0x7E, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
17 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA4, 0xA5, 0xA6 , 0xA7, 0xA7, 0xA8, 17 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x91,
18 0xA9, 0xAA, 0xAA, 0xAB, 0xAC, 0xAD, 0xAD, 0xAE, 0xAF, 0xB0, 0xB0, 0xB1, 0xB2 , 0xB3, 0xB3, 0xB4, 18 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C,
19 0xB5, 0xB5, 0xB6, 0xB7, 0xB7, 0xB8, 0xB9, 0xBA, 0xBA, 0xBB, 0xBC, 0xBC, 0xBD , 0xBE, 0xBE, 0xBF, 19 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA4, 0xA5,
20 0xC0, 0xC0, 0xC1, 0xC2, 0xC2, 0xC3, 0xC4, 0xC4, 0xC5, 0xC6, 0xC6, 0xC7, 0xC7 , 0xC8, 0xC9, 0xC9, 20 0xA6, 0xA7, 0xA7, 0xA8, 0xA9, 0xAA, 0xAA, 0xAB, 0xAC, 0xAD, 0xAD, 0xAE,
21 0xCA, 0xCB, 0xCB, 0xCC, 0xCC, 0xCD, 0xCE, 0xCE, 0xCF, 0xD0, 0xD0, 0xD1, 0xD1 , 0xD2, 0xD3, 0xD3, 21 0xAF, 0xB0, 0xB0, 0xB1, 0xB2, 0xB3, 0xB3, 0xB4, 0xB5, 0xB5, 0xB6, 0xB7,
22 0xD4, 0xD4, 0xD5, 0xD6, 0xD6, 0xD7, 0xD7, 0xD8, 0xD9, 0xD9, 0xDA, 0xDA, 0xDB , 0xDC, 0xDC, 0xDD, 22 0xB7, 0xB8, 0xB9, 0xBA, 0xBA, 0xBB, 0xBC, 0xBC, 0xBD, 0xBE, 0xBE, 0xBF,
23 0xDD, 0xDE, 0xDE, 0xDF, 0xE0, 0xE0, 0xE1, 0xE1, 0xE2, 0xE2, 0xE3, 0xE4, 0xE4 , 0xE5, 0xE5, 0xE6, 23 0xC0, 0xC0, 0xC1, 0xC2, 0xC2, 0xC3, 0xC4, 0xC4, 0xC5, 0xC6, 0xC6, 0xC7,
24 0xE6, 0xE7, 0xE7, 0xE8, 0xE9, 0xE9, 0xEA, 0xEA, 0xEB, 0xEB, 0xEC, 0xEC, 0xED , 0xED, 0xEE, 0xEE, 24 0xC7, 0xC8, 0xC9, 0xC9, 0xCA, 0xCB, 0xCB, 0xCC, 0xCC, 0xCD, 0xCE, 0xCE,
25 0xEF, 0xF0, 0xF0, 0xF1, 0xF1, 0xF2, 0xF2, 0xF3, 0xF3, 0xF4, 0xF4, 0xF5, 0xF5 , 0xF6, 0xF6, 0xF7, 25 0xCF, 0xD0, 0xD0, 0xD1, 0xD1, 0xD2, 0xD3, 0xD3, 0xD4, 0xD4, 0xD5, 0xD6,
26 0xF7, 0xF8, 0xF8, 0xF9, 0xF9, 0xFA, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC, 0xFD, 0xFD , 0xFE, 0xFE, 0xFF 26 0xD6, 0xD7, 0xD7, 0xD8, 0xD9, 0xD9, 0xDA, 0xDA, 0xDB, 0xDC, 0xDC, 0xDD,
27 0xDD, 0xDE, 0xDE, 0xDF, 0xE0, 0xE0, 0xE1, 0xE1, 0xE2, 0xE2, 0xE3, 0xE4,
28 0xE4, 0xE5, 0xE5, 0xE6, 0xE6, 0xE7, 0xE7, 0xE8, 0xE9, 0xE9, 0xEA, 0xEA,
29 0xEB, 0xEB, 0xEC, 0xEC, 0xED, 0xED, 0xEE, 0xEE, 0xEF, 0xF0, 0xF0, 0xF1,
30 0xF1, 0xF2, 0xF2, 0xF3, 0xF3, 0xF4, 0xF4, 0xF5, 0xF5, 0xF6, 0xF6, 0xF7,
31 0xF7, 0xF8, 0xF8, 0xF9, 0xF9, 0xFA, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC, 0xFD,
32 0xFD, 0xFE, 0xFE, 0xFF};
33 int _BLEND(int blend_mode, int back_color, int src_color) {
34 switch (blend_mode) {
35 case FXDIB_BLEND_NORMAL:
36 return src_color;
37 case FXDIB_BLEND_MULTIPLY:
38 return src_color * back_color / 255;
39 case FXDIB_BLEND_SCREEN:
40 return src_color + back_color - src_color * back_color / 255;
41 case FXDIB_BLEND_OVERLAY:
42 return _BLEND(FXDIB_BLEND_HARDLIGHT, src_color, back_color);
43 case FXDIB_BLEND_DARKEN:
44 return src_color < back_color ? src_color : back_color;
45 case FXDIB_BLEND_LIGHTEN:
46 return src_color > back_color ? src_color : back_color;
47 case FXDIB_BLEND_COLORDODGE: {
48 if (src_color == 255) {
49 return src_color;
50 }
51 int result = back_color * 255 / (255 - src_color);
52 if (result > 255) {
53 return 255;
54 }
55 return result;
56 }
57 case FXDIB_BLEND_COLORBURN: {
58 if (src_color == 0) {
59 return src_color;
60 }
61 int result = (255 - back_color) * 255 / src_color;
62 if (result > 255) {
63 result = 255;
64 }
65 return 255 - result;
66 }
67 case FXDIB_BLEND_HARDLIGHT:
68 if (src_color < 128) {
69 return (src_color * back_color * 2) / 255;
70 }
71 return _BLEND(FXDIB_BLEND_SCREEN, back_color, 2 * src_color - 255);
72 case FXDIB_BLEND_SOFTLIGHT: {
73 if (src_color < 128) {
74 return back_color -
75 (255 - 2 * src_color) * back_color * (255 - back_color) / 255 /
76 255;
77 }
78 return back_color +
79 (2 * src_color - 255) * (_color_sqrt[back_color] - back_color) /
80 255;
81 }
82 case FXDIB_BLEND_DIFFERENCE:
83 return back_color < src_color ? src_color - back_color
84 : back_color - src_color;
85 case FXDIB_BLEND_EXCLUSION:
86 return back_color + src_color - 2 * back_color * src_color / 255;
87 }
88 return src_color;
89 }
90 struct _RGB {
91 int red;
92 int green;
93 int blue;
27 }; 94 };
28 int _BLEND(int blend_mode, int back_color, int src_color) 95 static inline int _Lum(_RGB color) {
29 { 96 return (color.red * 30 + color.green * 59 + color.blue * 11) / 100;
30 switch (blend_mode) { 97 }
31 case FXDIB_BLEND_NORMAL: 98 static _RGB _ClipColor(_RGB color) {
32 return src_color; 99 int l = _Lum(color);
33 case FXDIB_BLEND_MULTIPLY: 100 int n = color.red;
34 return src_color * back_color / 255; 101 if (color.green < n) {
35 case FXDIB_BLEND_SCREEN: 102 n = color.green;
36 return src_color + back_color - src_color * back_color / 255; 103 }
37 case FXDIB_BLEND_OVERLAY: 104 if (color.blue < n) {
38 return _BLEND(FXDIB_BLEND_HARDLIGHT, src_color, back_color); 105 n = color.blue;
39 case FXDIB_BLEND_DARKEN: 106 }
40 return src_color < back_color ? src_color : back_color; 107 int x = color.red;
41 case FXDIB_BLEND_LIGHTEN: 108 if (color.green > x) {
42 return src_color > back_color ? src_color : back_color; 109 x = color.green;
43 case FXDIB_BLEND_COLORDODGE: { 110 }
44 if (src_color == 255) { 111 if (color.blue > x) {
45 return src_color; 112 x = color.blue;
46 } 113 }
47 int result = back_color * 255 / (255 - src_color); 114 if (n < 0) {
48 if (result > 255) { 115 color.red = l + ((color.red - l) * l / (l - n));
49 return 255; 116 color.green = l + ((color.green - l) * l / (l - n));
50 } 117 color.blue = l + ((color.blue - l) * l / (l - n));
51 return result; 118 }
119 if (x > 255) {
120 color.red = l + ((color.red - l) * (255 - l) / (x - l));
121 color.green = l + ((color.green - l) * (255 - l) / (x - l));
122 color.blue = l + ((color.blue - l) * (255 - l) / (x - l));
123 }
124 return color;
125 }
126 static _RGB _SetLum(_RGB color, int l) {
127 int d = l - _Lum(color);
128 color.red += d;
129 color.green += d;
130 color.blue += d;
131 return _ClipColor(color);
132 }
133 static int _Sat(_RGB color) {
134 int n = color.red;
135 if (color.green < n) {
136 n = color.green;
137 }
138 if (color.blue < n) {
139 n = color.blue;
140 }
141 int x = color.red;
142 if (color.green > x) {
143 x = color.green;
144 }
145 if (color.blue > x) {
146 x = color.blue;
147 }
148 return x - n;
149 }
150 static _RGB _SetSat(_RGB color, int s) {
151 int* max = &color.red;
152 int* mid = &color.red;
153 int* min = &color.red;
154 if (color.green > *max) {
155 max = &color.green;
156 }
157 if (color.blue > *max) {
158 max = &color.blue;
159 }
160 if (color.green < *min) {
161 min = &color.green;
162 }
163 if (color.blue < *min) {
164 min = &color.blue;
165 }
166 if (*max == *min) {
167 color.red = 0;
168 color.green = 0;
169 color.blue = 0;
170 return color;
171 }
172 if (max == &color.red) {
173 if (min == &color.green) {
174 mid = &color.blue;
175 } else {
176 mid = &color.green;
177 }
178 } else if (max == &color.green) {
179 if (min == &color.red) {
180 mid = &color.blue;
181 } else {
182 mid = &color.red;
183 }
184 } else {
185 if (min == &color.green) {
186 mid = &color.red;
187 } else {
188 mid = &color.green;
189 }
190 }
191 if (*max > *min) {
192 *mid = (*mid - *min) * s / (*max - *min);
193 *max = s;
194 *min = 0;
195 }
196 return color;
197 }
198 void _RGB_Blend(int blend_mode,
199 const uint8_t* src_scan,
200 uint8_t* dest_scan,
201 int results[3]) {
202 _RGB src, back, result;
203 src.red = src_scan[2];
204 src.green = src_scan[1];
205 src.blue = src_scan[0];
206 back.red = dest_scan[2];
207 back.green = dest_scan[1];
208 back.blue = dest_scan[0];
209 switch (blend_mode) {
210 case FXDIB_BLEND_HUE:
211 result = _SetLum(_SetSat(src, _Sat(back)), _Lum(back));
212 break;
213 case FXDIB_BLEND_SATURATION:
214 result = _SetLum(_SetSat(back, _Sat(src)), _Lum(back));
215 break;
216 case FXDIB_BLEND_COLOR:
217 result = _SetLum(src, _Lum(back));
218 break;
219 case FXDIB_BLEND_LUMINOSITY:
220 result = _SetLum(back, _Lum(src));
221 break;
222 }
223 results[0] = result.blue;
224 results[1] = result.green;
225 results[2] = result.red;
226 }
227 inline void _CompositeRow_Argb2Mask(uint8_t* dest_scan,
228 const uint8_t* src_scan,
229 int pixel_count,
230 const uint8_t* clip_scan) {
231 src_scan += 3;
232 for (int col = 0; col < pixel_count; col++) {
233 int src_alpha = *src_scan;
234 if (clip_scan) {
235 src_alpha = clip_scan[col] * src_alpha / 255;
236 }
237 uint8_t back_alpha = *dest_scan;
238 if (!back_alpha) {
239 *dest_scan = src_alpha;
240 } else if (src_alpha) {
241 *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
242 }
243 dest_scan++;
244 src_scan += 4;
245 }
246 }
247 void _CompositeRow_Rgba2Mask(uint8_t* dest_scan,
248 const uint8_t* src_alpha_scan,
249 int pixel_count,
250 const uint8_t* clip_scan) {
251 for (int col = 0; col < pixel_count; col++) {
252 int src_alpha = *src_alpha_scan++;
253 if (clip_scan) {
254 src_alpha = clip_scan[col] * src_alpha / 255;
255 }
256 uint8_t back_alpha = *dest_scan;
257 if (!back_alpha) {
258 *dest_scan = src_alpha;
259 } else if (src_alpha) {
260 *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
261 }
262 dest_scan++;
263 }
264 }
265 void _CompositeRow_Rgb2Mask(uint8_t* dest_scan,
266 const uint8_t* src_scan,
267 int width,
268 const uint8_t* clip_scan) {
269 if (clip_scan) {
270 for (int i = 0; i < width; i++) {
271 *dest_scan = FXDIB_ALPHA_UNION(*dest_scan, *clip_scan);
272 dest_scan++;
273 clip_scan++;
274 }
275 } else {
276 FXSYS_memset(dest_scan, 0xff, width);
277 }
278 }
279 void _CompositeRow_Argb2Graya(uint8_t* dest_scan,
280 const uint8_t* src_scan,
281 int pixel_count,
282 int blend_type,
283 const uint8_t* clip_scan,
284 const uint8_t* src_alpha_scan,
285 uint8_t* dst_alpha_scan,
286 void* pIccTransform) {
287 ICodec_IccModule* pIccModule = NULL;
288 if (pIccTransform) {
289 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
290 }
291 if (blend_type) {
292 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
293 int blended_color;
294 if (src_alpha_scan) {
295 for (int col = 0; col < pixel_count; col++) {
296 uint8_t back_alpha = *dst_alpha_scan;
297 if (back_alpha == 0) {
298 int src_alpha = *src_alpha_scan++;
299 if (clip_scan) {
300 src_alpha = clip_scan[col] * src_alpha / 255;
301 }
302 if (src_alpha) {
303 if (pIccTransform) {
304 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
305 1);
306 } else {
307 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
52 } 308 }
53 case FXDIB_BLEND_COLORBURN: { 309 *dst_alpha_scan = src_alpha;
54 if (src_color == 0) { 310 }
55 return src_color; 311 dest_scan++;
56 } 312 dst_alpha_scan++;
57 int result = (255 - back_color) * 255 / src_color; 313 src_scan += 3;
58 if (result > 255) { 314 continue;
59 result = 255; 315 }
60 } 316 uint8_t src_alpha = *src_alpha_scan++;
61 return 255 - result; 317 if (clip_scan) {
318 src_alpha = clip_scan[col] * src_alpha / 255;
319 }
320 if (src_alpha == 0) {
321 dest_scan++;
322 dst_alpha_scan++;
323 src_scan += 3;
324 continue;
325 }
326 *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
327 int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
328 uint8_t gray;
329 if (pIccTransform) {
330 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
331 } else {
332 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
333 }
334 if (bNonseparableBlend) {
335 blended_color =
336 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
337 }
338 gray = bNonseparableBlend ? blended_color
339 : _BLEND(blend_type, *dest_scan, gray);
340 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
341 dest_scan++;
342 dst_alpha_scan++;
343 src_scan += 3;
344 }
345 } else
346 for (int col = 0; col < pixel_count; col++) {
347 uint8_t back_alpha = *dst_alpha_scan;
348 if (back_alpha == 0) {
349 int src_alpha = src_scan[3];
350 if (clip_scan) {
351 src_alpha = clip_scan[col] * src_alpha / 255;
352 }
353 if (src_alpha) {
354 if (pIccTransform) {
355 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
356 1);
357 } else {
358 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
62 } 359 }
63 case FXDIB_BLEND_HARDLIGHT: 360 *dst_alpha_scan = src_alpha;
64 if (src_color < 128) { 361 }
65 return (src_color * back_color * 2) / 255; 362 dest_scan++;
66 } 363 dst_alpha_scan++;
67 return _BLEND(FXDIB_BLEND_SCREEN, back_color, 2 * src_color - 255); 364 src_scan += 4;
68 case FXDIB_BLEND_SOFTLIGHT: { 365 continue;
69 if (src_color < 128) { 366 }
70 return back_color - (255 - 2 * src_color) * back_color * (25 5 - back_color) / 255 / 255; 367 uint8_t src_alpha = src_scan[3];
71 } 368 if (clip_scan) {
72 return back_color + (2 * src_color - 255) * (_color_sqrt[back_co lor] - back_color) / 255; 369 src_alpha = clip_scan[col] * src_alpha / 255;
73 } 370 }
74 case FXDIB_BLEND_DIFFERENCE: 371 if (src_alpha == 0) {
75 return back_color < src_color ? src_color - back_color : back_color - src_color; 372 dest_scan++;
76 case FXDIB_BLEND_EXCLUSION: 373 dst_alpha_scan++;
77 return back_color + src_color - 2 * back_color * src_color / 255; 374 src_scan += 4;
78 } 375 continue;
79 return src_color; 376 }
80 } 377 *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
81 struct _RGB { 378 int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
82 int red; 379 uint8_t gray;
83 int green; 380 if (pIccTransform) {
84 int blue; 381 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
85 };
86 static inline int _Lum(_RGB color)
87 {
88 return (color.red * 30 + color.green * 59 + color.blue * 11) / 100;
89 }
90 static _RGB _ClipColor(_RGB color)
91 {
92 int l = _Lum(color);
93 int n = color.red;
94 if (color.green < n) {
95 n = color.green;
96 }
97 if (color.blue < n) {
98 n = color.blue;
99 }
100 int x = color.red;
101 if (color.green > x) {
102 x = color.green;
103 }
104 if (color.blue > x) {
105 x = color.blue;
106 }
107 if (n < 0) {
108 color.red = l + ((color.red - l) * l / (l - n));
109 color.green = l + ((color.green - l) * l / (l - n));
110 color.blue = l + ((color.blue - l) * l / (l - n));
111 }
112 if (x > 255) {
113 color.red = l + ((color.red - l) * (255 - l) / (x - l));
114 color.green = l + ((color.green - l) * (255 - l) / (x - l));
115 color.blue = l + ((color.blue - l) * (255 - l) / (x - l));
116 }
117 return color;
118 }
119 static _RGB _SetLum(_RGB color, int l)
120 {
121 int d = l - _Lum(color);
122 color.red += d;
123 color.green += d;
124 color.blue += d;
125 return _ClipColor(color);
126 }
127 static int _Sat(_RGB color)
128 {
129 int n = color.red;
130 if (color.green < n) {
131 n = color.green;
132 }
133 if (color.blue < n) {
134 n = color.blue;
135 }
136 int x = color.red;
137 if (color.green > x) {
138 x = color.green;
139 }
140 if (color.blue > x) {
141 x = color.blue;
142 }
143 return x - n;
144 }
145 static _RGB _SetSat(_RGB color, int s)
146 {
147 int* max = &color.red;
148 int* mid = &color.red;
149 int* min = &color.red;
150 if (color.green > *max) {
151 max = &color.green;
152 }
153 if (color.blue > *max) {
154 max = &color.blue;
155 }
156 if (color.green < *min) {
157 min = &color.green;
158 }
159 if (color.blue < *min) {
160 min = &color.blue;
161 }
162 if (*max == *min) {
163 color.red = 0;
164 color.green = 0;
165 color.blue = 0;
166 return color;
167 }
168 if (max == &color.red) {
169 if (min == &color.green) {
170 mid = &color.blue;
171 } else { 382 } else {
172 mid = &color.green; 383 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
173 } 384 }
174 } else if (max == &color.green) { 385 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
175 if (min == &color.red) { 386 dest_scan++;
176 mid = &color.blue; 387 dst_alpha_scan++;
177 } else {
178 mid = &color.red;
179 }
180 } else {
181 if (min == &color.green) {
182 mid = &color.red;
183 } else {
184 mid = &color.green;
185 }
186 }
187 if (*max > *min) {
188 *mid = (*mid - *min) * s / (*max - *min);
189 *max = s;
190 *min = 0;
191 }
192 return color;
193 }
194 void _RGB_Blend(int blend_mode, const uint8_t* src_scan, uint8_t* dest_scan, int results[3])
195 {
196 _RGB src, back, result;
197 src.red = src_scan[2];
198 src.green = src_scan[1];
199 src.blue = src_scan[0];
200 back.red = dest_scan[2];
201 back.green = dest_scan[1];
202 back.blue = dest_scan[0];
203 switch (blend_mode) {
204 case FXDIB_BLEND_HUE:
205 result = _SetLum(_SetSat(src, _Sat(back)), _Lum(back));
206 break;
207 case FXDIB_BLEND_SATURATION:
208 result = _SetLum(_SetSat(back, _Sat(src)), _Lum(back));
209 break;
210 case FXDIB_BLEND_COLOR:
211 result = _SetLum(src, _Lum(back));
212 break;
213 case FXDIB_BLEND_LUMINOSITY:
214 result = _SetLum(back, _Lum(src));
215 break;
216 }
217 results[0] = result.blue;
218 results[1] = result.green;
219 results[2] = result.red;
220 }
221 inline void _CompositeRow_Argb2Mask(uint8_t* dest_scan, const uint8_t* src_scan, int pixel_count, const uint8_t* clip_scan)
222 {
223 src_scan += 3;
224 for (int col = 0; col < pixel_count; col ++) {
225 int src_alpha = *src_scan;
226 if (clip_scan) {
227 src_alpha = clip_scan[col] * src_alpha / 255;
228 }
229 uint8_t back_alpha = *dest_scan;
230 if (!back_alpha) {
231 *dest_scan = src_alpha;
232 } else if (src_alpha) {
233 *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
234 }
235 dest_scan ++;
236 src_scan += 4; 388 src_scan += 4;
237 } 389 }
238 } 390 return;
239 void _CompositeRow_Rgba2Mask(uint8_t* dest_scan, const uint8_t* src_alpha_scan, int pixel_count, const uint8_t* clip_scan) 391 }
240 { 392 if (src_alpha_scan) {
241 for (int col = 0; col < pixel_count; col ++) { 393 for (int col = 0; col < pixel_count; col++) {
394 uint8_t back_alpha = *dst_alpha_scan;
395 if (back_alpha == 0) {
242 int src_alpha = *src_alpha_scan++; 396 int src_alpha = *src_alpha_scan++;
243 if (clip_scan) { 397 if (clip_scan) {
244 src_alpha = clip_scan[col] * src_alpha / 255; 398 src_alpha = clip_scan[col] * src_alpha / 255;
245 } 399 }
246 uint8_t back_alpha = *dest_scan; 400 if (src_alpha) {
247 if (!back_alpha) { 401 if (pIccTransform) {
248 *dest_scan = src_alpha; 402 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
249 } else if (src_alpha) { 403 1);
250 *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255; 404 } else {
251 } 405 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
252 dest_scan ++; 406 }
253 } 407 *dst_alpha_scan = src_alpha;
254 } 408 }
255 void _CompositeRow_Rgb2Mask(uint8_t* dest_scan, const uint8_t* src_scan, int wid th, const uint8_t* clip_scan) 409 dest_scan++;
256 { 410 dst_alpha_scan++;
411 src_scan += 3;
412 continue;
413 }
414 uint8_t src_alpha = *src_alpha_scan++;
415 if (clip_scan) {
416 src_alpha = clip_scan[col] * src_alpha / 255;
417 }
418 if (src_alpha == 0) {
419 dest_scan++;
420 dst_alpha_scan++;
421 src_scan += 3;
422 continue;
423 }
424 *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
425 int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
426 uint8_t gray;
427 if (pIccTransform) {
428 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
429 } else {
430 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
431 }
432 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
433 dest_scan++;
434 dst_alpha_scan++;
435 src_scan += 3;
436 }
437 } else
438 for (int col = 0; col < pixel_count; col++) {
439 uint8_t back_alpha = *dst_alpha_scan;
440 if (back_alpha == 0) {
441 int src_alpha = src_scan[3];
442 if (clip_scan) {
443 src_alpha = clip_scan[col] * src_alpha / 255;
444 }
445 if (src_alpha) {
446 if (pIccTransform) {
447 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
448 1);
449 } else {
450 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
451 }
452 *dst_alpha_scan = src_alpha;
453 }
454 dest_scan++;
455 dst_alpha_scan++;
456 src_scan += 4;
457 continue;
458 }
459 uint8_t src_alpha = src_scan[3];
460 if (clip_scan) {
461 src_alpha = clip_scan[col] * src_alpha / 255;
462 }
463 if (src_alpha == 0) {
464 dest_scan++;
465 dst_alpha_scan++;
466 src_scan += 4;
467 continue;
468 }
469 *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
470 int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
471 uint8_t gray;
472 if (pIccTransform) {
473 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
474 } else {
475 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
476 }
477 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
478 dest_scan++;
479 dst_alpha_scan++;
480 src_scan += 4;
481 }
482 }
483 inline void _CompositeRow_Argb2Gray(uint8_t* dest_scan,
484 const uint8_t* src_scan,
485 int pixel_count,
486 int blend_type,
487 const uint8_t* clip_scan,
488 const uint8_t* src_alpha_scan,
489 void* pIccTransform) {
490 ICodec_IccModule* pIccModule = NULL;
491 uint8_t gray;
492 if (pIccTransform) {
493 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
494 }
495 if (blend_type) {
496 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
497 int blended_color;
498 if (src_alpha_scan) {
499 for (int col = 0; col < pixel_count; col++) {
500 int src_alpha = *src_alpha_scan++;
501 if (clip_scan) {
502 src_alpha = clip_scan[col] * src_alpha / 255;
503 }
504 if (src_alpha) {
505 if (pIccTransform) {
506 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
507 } else {
508 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
509 }
510 if (bNonseparableBlend) {
511 blended_color =
512 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
513 }
514 gray = bNonseparableBlend ? blended_color
515 : _BLEND(blend_type, *dest_scan, gray);
516 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
517 }
518 dest_scan++;
519 src_scan += 3;
520 }
521 } else
522 for (int col = 0; col < pixel_count; col++) {
523 int src_alpha = src_scan[3];
524 if (clip_scan) {
525 src_alpha = clip_scan[col] * src_alpha / 255;
526 }
527 if (src_alpha) {
528 if (pIccTransform) {
529 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
530 } else {
531 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
532 }
533 if (bNonseparableBlend) {
534 blended_color =
535 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
536 }
537 gray = bNonseparableBlend ? blended_color
538 : _BLEND(blend_type, *dest_scan, gray);
539 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
540 }
541 dest_scan++;
542 src_scan += 4;
543 }
544 return;
545 }
546 if (src_alpha_scan) {
547 for (int col = 0; col < pixel_count; col++) {
548 int src_alpha = *src_alpha_scan++;
549 if (clip_scan) {
550 src_alpha = clip_scan[col] * src_alpha / 255;
551 }
552 if (src_alpha) {
553 if (pIccTransform) {
554 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
555 } else {
556 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
557 }
558 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
559 }
560 dest_scan++;
561 src_scan += 3;
562 }
563 } else
564 for (int col = 0; col < pixel_count; col++) {
565 int src_alpha = src_scan[3];
566 if (clip_scan) {
567 src_alpha = clip_scan[col] * src_alpha / 255;
568 }
569 if (src_alpha) {
570 if (pIccTransform) {
571 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
572 } else {
573 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
574 }
575 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
576 }
577 dest_scan++;
578 src_scan += 4;
579 }
580 }
581 inline void _CompositeRow_Rgb2Gray(uint8_t* dest_scan,
582 const uint8_t* src_scan,
583 int src_Bpp,
584 int pixel_count,
585 int blend_type,
586 const uint8_t* clip_scan,
587 void* pIccTransform) {
588 ICodec_IccModule* pIccModule = NULL;
589 uint8_t gray;
590 if (pIccTransform) {
591 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
592 }
593 if (blend_type) {
594 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
595 int blended_color;
596 for (int col = 0; col < pixel_count; col++) {
597 if (pIccTransform) {
598 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
599 } else {
600 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
601 }
602 if (bNonseparableBlend) {
603 blended_color =
604 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
605 }
606 gray = bNonseparableBlend ? blended_color
607 : _BLEND(blend_type, *dest_scan, gray);
608 if (clip_scan && clip_scan[col] < 255) {
609 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
610 } else {
611 *dest_scan = gray;
612 }
613 dest_scan++;
614 src_scan += src_Bpp;
615 }
616 return;
617 }
618 for (int col = 0; col < pixel_count; col++) {
619 if (pIccTransform) {
620 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
621 } else {
622 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
623 }
624 if (clip_scan && clip_scan[col] < 255) {
625 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
626 } else {
627 *dest_scan = gray;
628 }
629 dest_scan++;
630 src_scan += src_Bpp;
631 }
632 }
633 void _CompositeRow_Rgb2Graya(uint8_t* dest_scan,
634 const uint8_t* src_scan,
635 int src_Bpp,
636 int pixel_count,
637 int blend_type,
638 const uint8_t* clip_scan,
639 uint8_t* dest_alpha_scan,
640 void* pIccTransform) {
641 ICodec_IccModule* pIccModule = NULL;
642 if (pIccTransform) {
643 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
644 }
645 if (blend_type) {
646 int blended_color;
647 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
648 for (int col = 0; col < pixel_count; col++) {
649 int back_alpha = *dest_alpha_scan;
650 if (back_alpha == 0) {
651 if (pIccTransform) {
652 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
653 } else {
654 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
655 }
656 dest_scan++;
657 dest_alpha_scan++;
658 src_scan += src_Bpp;
659 continue;
660 }
661 int src_alpha = 255;
662 if (clip_scan) {
663 src_alpha = clip_scan[col];
664 }
665 if (src_alpha == 0) {
666 dest_scan++;
667 dest_alpha_scan++;
668 src_scan += src_Bpp;
669 continue;
670 }
671 uint8_t dest_alpha =
672 back_alpha + src_alpha - back_alpha * src_alpha / 255;
673 *dest_alpha_scan++ = dest_alpha;
674 int alpha_ratio = src_alpha * 255 / dest_alpha;
675 uint8_t gray;
676 if (pIccTransform) {
677 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
678 } else {
679 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
680 }
681 if (bNonseparableBlend) {
682 blended_color =
683 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
684 }
685 gray = bNonseparableBlend ? blended_color
686 : _BLEND(blend_type, *dest_scan, gray);
687 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
688 dest_scan++;
689 src_scan += src_Bpp;
690 }
691 return;
692 }
693 for (int col = 0; col < pixel_count; col++) {
694 int src_alpha = 255;
257 if (clip_scan) { 695 if (clip_scan) {
258 for (int i = 0; i < width; i ++) { 696 src_alpha = clip_scan[col];
259 *dest_scan = FXDIB_ALPHA_UNION(*dest_scan, *clip_scan); 697 }
260 dest_scan ++; 698 if (src_alpha == 255) {
261 clip_scan ++; 699 if (pIccTransform) {
262 } 700 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
263 } else { 701 } else {
264 FXSYS_memset(dest_scan, 0xff, width); 702 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
265 } 703 }
266 } 704 dest_scan++;
267 void _CompositeRow_Argb2Graya(uint8_t* dest_scan, const uint8_t* src_scan, int p ixel_count, int blend_type, const uint8_t* clip_scan, 705 *dest_alpha_scan++ = 255;
268 const uint8_t* src_alpha_scan, uint8_t* dst_alpha_ scan, void* pIccTransform) 706 src_scan += src_Bpp;
269 { 707 continue;
270 ICodec_IccModule* pIccModule = NULL; 708 }
271 if (pIccTransform) { 709 if (src_alpha == 0) {
272 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); 710 dest_scan++;
273 } 711 dest_alpha_scan++;
274 if (blend_type) { 712 src_scan += src_Bpp;
275 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; 713 continue;
276 int blended_color; 714 }
277 if (src_alpha_scan) { 715 int back_alpha = *dest_alpha_scan;
278 for (int col = 0; col < pixel_count; col ++) { 716 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
279 uint8_t back_alpha = *dst_alpha_scan; 717 *dest_alpha_scan++ = dest_alpha;
280 if (back_alpha == 0) { 718 int alpha_ratio = src_alpha * 255 / dest_alpha;
281 int src_alpha = *src_alpha_scan++;
282 if (clip_scan) {
283 src_alpha = clip_scan[col] * src_alpha / 255;
284 }
285 if (src_alpha) {
286 if (pIccTransform) {
287 pIccModule->TranslateScanline(pIccTransform, dest_sc an, src_scan, 1);
288 } else {
289 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], * src_scan);
290 }
291 *dst_alpha_scan = src_alpha;
292 }
293 dest_scan ++;
294 dst_alpha_scan ++;
295 src_scan += 3;
296 continue;
297 }
298 uint8_t src_alpha = *src_alpha_scan++;
299 if (clip_scan) {
300 src_alpha = clip_scan[col] * src_alpha / 255;
301 }
302 if (src_alpha == 0) {
303 dest_scan ++;
304 dst_alpha_scan ++;
305 src_scan += 3;
306 continue;
307 }
308 *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
309 int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
310 uint8_t gray;
311 if (pIccTransform) {
312 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan , 1);
313 } else {
314 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
315 }
316 if (bNonseparableBlend) {
317 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
318 }
319 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, * dest_scan, gray);
320 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
321 dest_scan ++;
322 dst_alpha_scan++;
323 src_scan += 3;
324 }
325 } else
326 for (int col = 0; col < pixel_count; col ++) {
327 uint8_t back_alpha = *dst_alpha_scan;
328 if (back_alpha == 0) {
329 int src_alpha = src_scan[3];
330 if (clip_scan) {
331 src_alpha = clip_scan[col] * src_alpha / 255;
332 }
333 if (src_alpha) {
334 if (pIccTransform) {
335 pIccModule->TranslateScanline(pIccTransform, dest_sc an, src_scan, 1);
336 } else {
337 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], * src_scan);
338 }
339 *dst_alpha_scan = src_alpha;
340 }
341 dest_scan ++;
342 dst_alpha_scan ++;
343 src_scan += 4;
344 continue;
345 }
346 uint8_t src_alpha = src_scan[3];
347 if (clip_scan) {
348 src_alpha = clip_scan[col] * src_alpha / 255;
349 }
350 if (src_alpha == 0) {
351 dest_scan ++;
352 dst_alpha_scan ++;
353 src_scan += 4;
354 continue;
355 }
356 *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
357 int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
358 uint8_t gray;
359 if (pIccTransform) {
360 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan , 1);
361 } else {
362 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
363 }
364 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
365 dest_scan ++;
366 dst_alpha_scan++;
367 src_scan += 4;
368 }
369 return;
370 }
371 if (src_alpha_scan) {
372 for (int col = 0; col < pixel_count; col ++) {
373 uint8_t back_alpha = *dst_alpha_scan;
374 if (back_alpha == 0) {
375 int src_alpha = *src_alpha_scan++;
376 if (clip_scan) {
377 src_alpha = clip_scan[col] * src_alpha / 255;
378 }
379 if (src_alpha) {
380 if (pIccTransform) {
381 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
382 } else {
383 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_ scan);
384 }
385 *dst_alpha_scan = src_alpha;
386 }
387 dest_scan ++;
388 dst_alpha_scan ++;
389 src_scan += 3;
390 continue;
391 }
392 uint8_t src_alpha = *src_alpha_scan++;
393 if (clip_scan) {
394 src_alpha = clip_scan[col] * src_alpha / 255;
395 }
396 if (src_alpha == 0) {
397 dest_scan ++;
398 dst_alpha_scan ++;
399 src_scan += 3;
400 continue;
401 }
402 *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
403 int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
404 uint8_t gray;
405 if (pIccTransform) {
406 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1) ;
407 } else {
408 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
409 }
410 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
411 dest_scan ++;
412 dst_alpha_scan++;
413 src_scan += 3;
414 }
415 } else
416 for (int col = 0; col < pixel_count; col ++) {
417 uint8_t back_alpha = *dst_alpha_scan;
418 if (back_alpha == 0) {
419 int src_alpha = src_scan[3];
420 if (clip_scan) {
421 src_alpha = clip_scan[col] * src_alpha / 255;
422 }
423 if (src_alpha) {
424 if (pIccTransform) {
425 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
426 } else {
427 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_ scan);
428 }
429 *dst_alpha_scan = src_alpha;
430 }
431 dest_scan ++;
432 dst_alpha_scan ++;
433 src_scan += 4;
434 continue;
435 }
436 uint8_t src_alpha = src_scan[3];
437 if (clip_scan) {
438 src_alpha = clip_scan[col] * src_alpha / 255;
439 }
440 if (src_alpha == 0) {
441 dest_scan ++;
442 dst_alpha_scan ++;
443 src_scan += 4;
444 continue;
445 }
446 *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
447 int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
448 uint8_t gray;
449 if (pIccTransform) {
450 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1) ;
451 } else {
452 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
453 }
454 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
455 dest_scan ++;
456 dst_alpha_scan++;
457 src_scan += 4;
458 }
459 }
460 inline void _CompositeRow_Argb2Gray(uint8_t* dest_scan, const uint8_t* src_scan, int pixel_count,
461 int blend_type, const uint8_t* clip_scan,
462 const uint8_t* src_alpha_scan, void* pIccTra nsform)
463 {
464 ICodec_IccModule* pIccModule = NULL;
465 uint8_t gray; 719 uint8_t gray;
466 if (pIccTransform) { 720 if (pIccTransform) {
467 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); 721 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
468 } 722 } else {
469 if (blend_type) { 723 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
470 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; 724 }
471 int blended_color; 725 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
472 if (src_alpha_scan) { 726 dest_scan++;
473 for (int col = 0; col < pixel_count; col ++) { 727 src_scan += src_Bpp;
474 int src_alpha = *src_alpha_scan++; 728 }
475 if (clip_scan) { 729 }
476 src_alpha = clip_scan[col] * src_alpha / 255; 730 void _CompositeRow_Argb2Argb(uint8_t* dest_scan,
477 } 731 const uint8_t* src_scan,
478 if (src_alpha) { 732 int pixel_count,
479 if (pIccTransform) { 733 int blend_type,
480 pIccModule->TranslateScanline(pIccTransform, &gray, src_ scan, 1); 734 const uint8_t* clip_scan,
481 } else { 735 uint8_t* dest_alpha_scan,
482 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan); 736 const uint8_t* src_alpha_scan) {
483 } 737 int blended_colors[3];
484 if (bNonseparableBlend) { 738 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
485 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? g ray : *dest_scan; 739 if (dest_alpha_scan == NULL) {
486 } 740 if (src_alpha_scan == NULL) {
487 gray = bNonseparableBlend ? blended_color : _BLEND(blend_typ e, *dest_scan, gray); 741 uint8_t back_alpha = 0;
488 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha); 742 for (int col = 0; col < pixel_count; col++) {
489 } 743 back_alpha = dest_scan[3];
490 dest_scan ++; 744 if (back_alpha == 0) {
491 src_scan += 3; 745 if (clip_scan) {
492 } 746 int src_alpha = clip_scan[col] * src_scan[3] / 255;
493 } else 747 FXARGB_SETDIB(dest_scan, (FXARGB_GETDIB(src_scan) & 0xffffff) |
494 for (int col = 0; col < pixel_count; col ++) { 748 (src_alpha << 24));
495 int src_alpha = src_scan[3]; 749 } else {
496 if (clip_scan) { 750 FXARGB_COPY(dest_scan, src_scan);
497 src_alpha = clip_scan[col] * src_alpha / 255; 751 }
498 } 752 dest_scan += 4;
499 if (src_alpha) { 753 src_scan += 4;
500 if (pIccTransform) { 754 continue;
501 pIccModule->TranslateScanline(pIccTransform, &gray, src_ scan, 1); 755 }
502 } else { 756 uint8_t src_alpha;
503 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan); 757 if (clip_scan == NULL) {
504 } 758 src_alpha = src_scan[3];
505 if (bNonseparableBlend) { 759 } else {
506 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? g ray : *dest_scan; 760 src_alpha = clip_scan[col] * src_scan[3] / 255;
507 } 761 }
508 gray = bNonseparableBlend ? blended_color : _BLEND(blend_typ e, *dest_scan, gray); 762 if (src_alpha == 0) {
509 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha); 763 dest_scan += 4;
510 } 764 src_scan += 4;
511 dest_scan ++; 765 continue;
512 src_scan += 4; 766 }
513 } 767 uint8_t dest_alpha =
514 return; 768 back_alpha + src_alpha - back_alpha * src_alpha / 255;
515 } 769 dest_scan[3] = dest_alpha;
770 int alpha_ratio = src_alpha * 255 / dest_alpha;
771 if (bNonseparableBlend) {
772 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
773 }
774 for (int color = 0; color < 3; color++) {
775 if (blend_type) {
776 int blended = bNonseparableBlend
777 ? blended_colors[color]
778 : _BLEND(blend_type, *dest_scan, *src_scan);
779 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
780 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
781 } else {
782 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
783 }
784 dest_scan++;
785 src_scan++;
786 }
787 dest_scan++;
788 src_scan++;
789 }
790 } else {
791 for (int col = 0; col < pixel_count; col++) {
792 uint8_t back_alpha = dest_scan[3];
793 if (back_alpha == 0) {
794 if (clip_scan) {
795 int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
796 FXARGB_SETDIB(dest_scan, FXARGB_MAKE((src_alpha << 24), src_scan[2],
797 src_scan[1], *src_scan));
798 } else {
799 FXARGB_SETDIB(dest_scan,
800 FXARGB_MAKE((*src_alpha_scan << 24), src_scan[2],
801 src_scan[1], *src_scan));
802 }
803 dest_scan += 4;
804 src_scan += 3;
805 src_alpha_scan++;
806 continue;
807 }
808 uint8_t src_alpha;
809 if (clip_scan == NULL) {
810 src_alpha = *src_alpha_scan++;
811 } else {
812 src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
813 }
814 if (src_alpha == 0) {
815 dest_scan += 4;
816 src_scan += 3;
817 continue;
818 }
819 uint8_t dest_alpha =
820 back_alpha + src_alpha - back_alpha * src_alpha / 255;
821 dest_scan[3] = dest_alpha;
822 int alpha_ratio = src_alpha * 255 / dest_alpha;
823 if (bNonseparableBlend) {
824 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
825 }
826 for (int color = 0; color < 3; color++) {
827 if (blend_type) {
828 int blended = bNonseparableBlend
829 ? blended_colors[color]
830 : _BLEND(blend_type, *dest_scan, *src_scan);
831 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
832 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
833 } else {
834 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
835 }
836 dest_scan++;
837 src_scan++;
838 }
839 dest_scan++;
840 }
841 }
842 } else {
516 if (src_alpha_scan) { 843 if (src_alpha_scan) {
517 for (int col = 0; col < pixel_count; col ++) { 844 for (int col = 0; col < pixel_count; col++) {
518 int src_alpha = *src_alpha_scan++; 845 uint8_t back_alpha = *dest_alpha_scan;
519 if (clip_scan) { 846 if (back_alpha == 0) {
520 src_alpha = clip_scan[col] * src_alpha / 255; 847 if (clip_scan) {
521 } 848 int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
522 if (src_alpha) { 849 *dest_alpha_scan = src_alpha;
523 if (pIccTransform) {
524 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan , 1);
525 } else {
526 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
527 }
528 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
529 }
530 dest_scan ++;
531 src_scan += 3;
532 }
533 } else
534 for (int col = 0; col < pixel_count; col ++) {
535 int src_alpha = src_scan[3];
536 if (clip_scan) {
537 src_alpha = clip_scan[col] * src_alpha / 255;
538 }
539 if (src_alpha) {
540 if (pIccTransform) {
541 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan , 1);
542 } else {
543 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
544 }
545 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
546 }
547 dest_scan ++;
548 src_scan += 4;
549 }
550 }
551 inline void _CompositeRow_Rgb2Gray(uint8_t* dest_scan, const uint8_t* src_scan, int src_Bpp, int pixel_count,
552 int blend_type, const uint8_t* clip_scan,
553 void* pIccTransform)
554 {
555 ICodec_IccModule* pIccModule = NULL;
556 uint8_t gray;
557 if (pIccTransform) {
558 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
559 }
560 if (blend_type) {
561 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
562 int blended_color;
563 for (int col = 0; col < pixel_count; col ++) {
564 if (pIccTransform) {
565 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1) ;
566 } else {
567 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
568 }
569 if (bNonseparableBlend) {
570 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *d est_scan;
571 }
572 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest _scan, gray);
573 if (clip_scan && clip_scan[col] < 255) {
574 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]) ;
575 } else {
576 *dest_scan = gray;
577 }
578 dest_scan ++;
579 src_scan += src_Bpp;
580 }
581 return;
582 }
583 for (int col = 0; col < pixel_count; col ++) {
584 if (pIccTransform) {
585 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
586 } else {
587 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
588 }
589 if (clip_scan && clip_scan[col] < 255) {
590 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
591 } else {
592 *dest_scan = gray;
593 }
594 dest_scan ++;
595 src_scan += src_Bpp;
596 }
597 }
598 void _CompositeRow_Rgb2Graya(uint8_t* dest_scan, const uint8_t* src_scan, int sr c_Bpp, int pixel_count,
599 int blend_type, const uint8_t* clip_scan,
600 uint8_t* dest_alpha_scan, void* pIccTransform)
601 {
602 ICodec_IccModule* pIccModule = NULL;
603 if (pIccTransform) {
604 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
605 }
606 if (blend_type) {
607 int blended_color;
608 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
609 for (int col = 0; col < pixel_count; col ++) {
610 int back_alpha = *dest_alpha_scan;
611 if (back_alpha == 0) {
612 if (pIccTransform) {
613 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_ scan, 1);
614 } else {
615 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan) ;
616 }
617 dest_scan ++;
618 dest_alpha_scan++;
619 src_scan += src_Bpp;
620 continue;
621 }
622 int src_alpha = 255;
623 if (clip_scan) {
624 src_alpha = clip_scan[col];
625 }
626 if (src_alpha == 0) {
627 dest_scan ++;
628 dest_alpha_scan ++;
629 src_scan += src_Bpp;
630 continue;
631 }
632 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
633 *dest_alpha_scan++ = dest_alpha;
634 int alpha_ratio = src_alpha * 255 / dest_alpha;
635 uint8_t gray;
636 if (pIccTransform) {
637 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1) ;
638 } else {
639 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
640 }
641 if (bNonseparableBlend) {
642 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *d est_scan;
643 }
644 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest _scan, gray);
645 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
646 dest_scan ++;
647 src_scan += src_Bpp;
648 }
649 return;
650 }
651 for (int col = 0; col < pixel_count; col ++) {
652 int src_alpha = 255;
653 if (clip_scan) {
654 src_alpha = clip_scan[col];
655 }
656 if (src_alpha == 255) {
657 if (pIccTransform) {
658 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan , 1);
659 } else {
660 *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
661 }
662 dest_scan ++;
663 *dest_alpha_scan++ = 255;
664 src_scan += src_Bpp;
665 continue;
666 }
667 if (src_alpha == 0) {
668 dest_scan ++;
669 dest_alpha_scan ++;
670 src_scan += src_Bpp;
671 continue;
672 }
673 int back_alpha = *dest_alpha_scan;
674 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
675 *dest_alpha_scan++ = dest_alpha;
676 int alpha_ratio = src_alpha * 255 / dest_alpha;
677 uint8_t gray;
678 if (pIccTransform) {
679 pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
680 } else {
681 gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
682 }
683 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
684 dest_scan ++;
685 src_scan += src_Bpp;
686 }
687 }
688 void _CompositeRow_Argb2Argb(uint8_t* dest_scan, const uint8_t* src_scan, int pi xel_count, int blend_type, const uint8_t* clip_scan,
689 uint8_t* dest_alpha_scan, const uint8_t* src_alpha_ scan)
690 {
691 int blended_colors[3];
692 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
693 if (dest_alpha_scan == NULL) {
694 if (src_alpha_scan == NULL) {
695 uint8_t back_alpha = 0;
696 for (int col = 0; col < pixel_count; col ++) {
697 back_alpha = dest_scan[3];
698 if (back_alpha == 0) {
699 if (clip_scan) {
700 int src_alpha = clip_scan[col] * src_scan[3] / 255;
701 FXARGB_SETDIB(dest_scan, (FXARGB_GETDIB(src_scan) & 0xff ffff) | (src_alpha << 24));
702 } else {
703 FXARGB_COPY(dest_scan, src_scan);
704 }
705 dest_scan += 4;
706 src_scan += 4;
707 continue;
708 }
709 uint8_t src_alpha;
710 if (clip_scan == NULL) {
711 src_alpha = src_scan[3];
712 } else {
713 src_alpha = clip_scan[col] * src_scan[3] / 255;
714 }
715 if (src_alpha == 0) {
716 dest_scan += 4;
717 src_scan += 4;
718 continue;
719 }
720 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_a lpha / 255;
721 dest_scan[3] = dest_alpha;
722 int alpha_ratio = src_alpha * 255 / dest_alpha;
723 if (bNonseparableBlend) {
724 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
725 }
726 for (int color = 0; color < 3; color ++) {
727 if (blend_type) {
728 int blended = bNonseparableBlend ? blended_colors[color] :
729 _BLEND(blend_type, *dest_scan, *src_scan);
730 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alp ha);
731 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alph a_ratio);
732 } else {
733 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, al pha_ratio);
734 }
735 dest_scan ++;
736 src_scan ++;
737 }
738 dest_scan ++;
739 src_scan ++;
740 }
741 } else {
742 for (int col = 0; col < pixel_count; col ++) {
743 uint8_t back_alpha = dest_scan[3];
744 if (back_alpha == 0) {
745 if (clip_scan) {
746 int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255 ;
747 FXARGB_SETDIB(dest_scan, FXARGB_MAKE((src_alpha << 24), src_scan[2], src_scan[1], *src_scan));
748 } else {
749 FXARGB_SETDIB(dest_scan, FXARGB_MAKE((*src_alpha_scan << 24), src_scan[2], src_scan[1], *src_scan));
750 }
751 dest_scan += 4;
752 src_scan += 3;
753 src_alpha_scan ++;
754 continue;
755 }
756 uint8_t src_alpha;
757 if (clip_scan == NULL) {
758 src_alpha = *src_alpha_scan ++;
759 } else {
760 src_alpha = clip_scan[col] * (*src_alpha_scan ++) / 255;
761 }
762 if (src_alpha == 0) {
763 dest_scan += 4;
764 src_scan += 3;
765 continue;
766 }
767 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_a lpha / 255;
768 dest_scan[3] = dest_alpha;
769 int alpha_ratio = src_alpha * 255 / dest_alpha;
770 if (bNonseparableBlend) {
771 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
772 }
773 for (int color = 0; color < 3; color ++) {
774 if (blend_type) {
775 int blended = bNonseparableBlend ? blended_colors[color] :
776 _BLEND(blend_type, *dest_scan, *src_scan);
777 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alp ha);
778 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alph a_ratio);
779 } else {
780 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, al pha_ratio);
781 }
782 dest_scan ++;
783 src_scan ++;
784 }
785 dest_scan ++;
786 }
787 }
788 } else {
789 if (src_alpha_scan) {
790 for (int col = 0; col < pixel_count; col ++) {
791 uint8_t back_alpha = *dest_alpha_scan;
792 if (back_alpha == 0) {
793 if (clip_scan) {
794 int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255 ;
795 *dest_alpha_scan = src_alpha;
796 *dest_scan++ = *src_scan++;
797 *dest_scan++ = *src_scan++;
798 *dest_scan++ = *src_scan++;
799 } else {
800 *dest_alpha_scan = *src_alpha_scan;
801 *dest_scan++ = *src_scan++;
802 *dest_scan++ = *src_scan++;
803 *dest_scan++ = *src_scan++;
804 }
805 dest_alpha_scan ++;
806 src_alpha_scan ++;
807 continue;
808 }
809 uint8_t src_alpha;
810 if (clip_scan == NULL) {
811 src_alpha = *src_alpha_scan ++;
812 } else {
813 src_alpha = clip_scan[col] * (*src_alpha_scan ++) / 255;
814 }
815 if (src_alpha == 0) {
816 dest_scan += 3;
817 src_scan += 3;
818 dest_alpha_scan ++;
819 continue;
820 }
821 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_a lpha / 255;
822 *dest_alpha_scan ++ = dest_alpha;
823 int alpha_ratio = src_alpha * 255 / dest_alpha;
824 if (bNonseparableBlend) {
825 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
826 }
827 for (int color = 0; color < 3; color ++) {
828 if (blend_type) {
829 int blended = bNonseparableBlend ? blended_colors[color] :
830 _BLEND(blend_type, *dest_scan, *src_scan);
831 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alp ha);
832 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alph a_ratio);
833 } else {
834 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, al pha_ratio);
835 }
836 dest_scan ++;
837 src_scan ++;
838 }
839 }
840 } else {
841 for (int col = 0; col < pixel_count; col ++) {
842 uint8_t back_alpha = *dest_alpha_scan;
843 if (back_alpha == 0) {
844 if (clip_scan) {
845 int src_alpha = clip_scan[col] * src_scan[3] / 255;
846 *dest_alpha_scan = src_alpha;
847 *dest_scan++ = *src_scan++;
848 *dest_scan++ = *src_scan++;
849 *dest_scan++ = *src_scan++;
850 } else {
851 *dest_alpha_scan = src_scan[3];
852 *dest_scan++ = *src_scan++;
853 *dest_scan++ = *src_scan++;
854 *dest_scan++ = *src_scan++;
855 }
856 dest_alpha_scan ++;
857 src_scan ++;
858 continue;
859 }
860 uint8_t src_alpha;
861 if (clip_scan == NULL) {
862 src_alpha = src_scan[3];
863 } else {
864 src_alpha = clip_scan[col] * src_scan[3] / 255;
865 }
866 if (src_alpha == 0) {
867 dest_scan += 3;
868 src_scan += 4;
869 dest_alpha_scan ++;
870 continue;
871 }
872 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_a lpha / 255;
873 *dest_alpha_scan++ = dest_alpha;
874 int alpha_ratio = src_alpha * 255 / dest_alpha;
875 if (bNonseparableBlend) {
876 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
877 }
878 for (int color = 0; color < 3; color ++) {
879 if (blend_type) {
880 int blended = bNonseparableBlend ? blended_colors[color] :
881 _BLEND(blend_type, *dest_scan, *src_scan);
882 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alp ha);
883 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alph a_ratio);
884 } else {
885 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, al pha_ratio);
886 }
887 dest_scan ++;
888 src_scan ++;
889 }
890 src_scan ++;
891 }
892 }
893 }
894 }
895 void _CompositeRow_Rgb2Argb_Blend_NoClip(uint8_t* dest_scan, const uint8_t* src_ scan, int width, int blend_type, int src_Bpp,
896 uint8_t* dest_alpha_scan)
897 {
898 int blended_colors[3];
899 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
900 int src_gap = src_Bpp - 3;
901 if (dest_alpha_scan == NULL) {
902 for (int col = 0; col < width; col ++) {
903 uint8_t back_alpha = dest_scan[3];
904 if (back_alpha == 0) {
905 if (src_Bpp == 4) {
906 FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan ));
907 } else {
908 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_ scan[1], src_scan[0]));
909 }
910 dest_scan += 4;
911 src_scan += src_Bpp;
912 continue;
913 }
914 dest_scan[3] = 0xff;
915 if (bNonseparableBlend) {
916 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
917 }
918 for (int color = 0; color < 3; color ++) {
919 int src_color = *src_scan;
920 int blended = bNonseparableBlend ? blended_colors[color] :
921 _BLEND(blend_type, *dest_scan, src_color);
922 *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
923 dest_scan ++;
924 src_scan ++;
925 }
926 dest_scan ++;
927 src_scan += src_gap;
928 }
929 } else {
930 for (int col = 0; col < width; col ++) {
931 uint8_t back_alpha = *dest_alpha_scan;
932 if (back_alpha == 0) {
933 *dest_scan++ = *src_scan++;
934 *dest_scan++ = *src_scan++;
935 *dest_scan++ = *src_scan++;
936 *dest_alpha_scan++ = 0xff;
937 src_scan += src_gap;
938 continue;
939 }
940 *dest_alpha_scan++ = 0xff;
941 if (bNonseparableBlend) {
942 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
943 }
944 for (int color = 0; color < 3; color ++) {
945 int src_color = *src_scan;
946 int blended = bNonseparableBlend ? blended_colors[color] :
947 _BLEND(blend_type, *dest_scan, src_color);
948 *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
949 dest_scan ++;
950 src_scan ++;
951 }
952 src_scan += src_gap;
953 }
954 }
955 }
956 inline void _CompositeRow_Rgb2Argb_Blend_Clip(uint8_t* dest_scan, const uint8_t* src_scan, int width, int blend_type, int src_Bpp, const uint8_t* clip_scan,
957 uint8_t* dest_alpha_scan)
958 {
959 int blended_colors[3];
960 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
961 int src_gap = src_Bpp - 3;
962 if (dest_alpha_scan == NULL) {
963 for (int col = 0; col < width; col ++) {
964 int src_alpha = *clip_scan ++;
965 uint8_t back_alpha = dest_scan[3];
966 if (back_alpha == 0) {
967 *dest_scan++ = *src_scan++;
968 *dest_scan++ = *src_scan++;
969 *dest_scan++ = *src_scan++;
970 src_scan += src_gap;
971 dest_scan ++;
972 continue;
973 }
974 if (src_alpha == 0) {
975 dest_scan += 4;
976 src_scan += src_Bpp;
977 continue;
978 }
979 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
980 dest_scan[3] = dest_alpha;
981 int alpha_ratio = src_alpha * 255 / dest_alpha;
982 if (bNonseparableBlend) {
983 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
984 }
985 for (int color = 0; color < 3; color ++) {
986 int src_color = *src_scan;
987 int blended = bNonseparableBlend ? blended_colors[color] :
988 _BLEND(blend_type, *dest_scan, src_color);
989 blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
990 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio) ;
991 dest_scan ++;
992 src_scan ++;
993 }
994 dest_scan ++;
995 src_scan += src_gap;
996 }
997 } else {
998 for (int col = 0; col < width; col ++) {
999 int src_alpha = *clip_scan ++;
1000 uint8_t back_alpha = *dest_alpha_scan;
1001 if (back_alpha == 0) {
1002 *dest_scan++ = *src_scan++;
1003 *dest_scan++ = *src_scan++;
1004 *dest_scan++ = *src_scan++;
1005 src_scan += src_gap;
1006 dest_alpha_scan++;
1007 continue;
1008 }
1009 if (src_alpha == 0) {
1010 dest_scan += 3;
1011 dest_alpha_scan++;
1012 src_scan += src_Bpp;
1013 continue;
1014 }
1015 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
1016 *dest_alpha_scan++ = dest_alpha;
1017 int alpha_ratio = src_alpha * 255 / dest_alpha;
1018 if (bNonseparableBlend) {
1019 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
1020 }
1021 for (int color = 0; color < 3; color ++) {
1022 int src_color = *src_scan;
1023 int blended = bNonseparableBlend ? blended_colors[color] :
1024 _BLEND(blend_type, *dest_scan, src_color);
1025 blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
1026 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio) ;
1027 dest_scan ++;
1028 src_scan ++;
1029 }
1030 src_scan += src_gap;
1031 }
1032 }
1033 }
1034 inline void _CompositeRow_Rgb2Argb_NoBlend_Clip(uint8_t* dest_scan, const uint8_ t* src_scan, int width, int src_Bpp, const uint8_t* clip_scan,
1035 uint8_t* dest_alpha_scan)
1036 {
1037 int src_gap = src_Bpp - 3;
1038 if (dest_alpha_scan == NULL) {
1039 for (int col = 0; col < width; col ++) {
1040 int src_alpha = clip_scan[col];
1041 if (src_alpha == 255) {
1042 *dest_scan++ = *src_scan++;
1043 *dest_scan++ = *src_scan++;
1044 *dest_scan++ = *src_scan++;
1045 *dest_scan++ = 255;
1046 src_scan += src_gap;
1047 continue;
1048 }
1049 if (src_alpha == 0) {
1050 dest_scan += 4;
1051 src_scan += src_Bpp;
1052 continue;
1053 }
1054 int back_alpha = dest_scan[3];
1055 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
1056 dest_scan[3] = dest_alpha;
1057 int alpha_ratio = src_alpha * 255 / dest_alpha;
1058 for (int color = 0; color < 3; color ++) {
1059 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_rati o);
1060 dest_scan ++;
1061 src_scan ++;
1062 }
1063 dest_scan ++;
1064 src_scan += src_gap;
1065 }
1066 } else {
1067 for (int col = 0; col < width; col ++) {
1068 int src_alpha = clip_scan[col];
1069 if (src_alpha == 255) {
1070 *dest_scan++ = *src_scan++;
1071 *dest_scan++ = *src_scan++;
1072 *dest_scan++ = *src_scan++;
1073 *dest_alpha_scan++ = 255;
1074 src_scan += src_gap;
1075 continue;
1076 }
1077 if (src_alpha == 0) {
1078 dest_scan += 3;
1079 dest_alpha_scan ++;
1080 src_scan += src_Bpp;
1081 continue;
1082 }
1083 int back_alpha = *dest_alpha_scan;
1084 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
1085 *dest_alpha_scan ++ = dest_alpha;
1086 int alpha_ratio = src_alpha * 255 / dest_alpha;
1087 for (int color = 0; color < 3; color ++) {
1088 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_rati o);
1089 dest_scan ++;
1090 src_scan ++;
1091 }
1092 src_scan += src_gap;
1093 }
1094 }
1095 }
1096 inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip(uint8_t* dest_scan, const uint 8_t* src_scan, int width, int src_Bpp,
1097 uint8_t* dest_alpha_scan)
1098 {
1099 if (dest_alpha_scan == NULL) {
1100 for (int col = 0; col < width; col ++) {
1101 if (src_Bpp == 4) {
1102 FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
1103 } else {
1104 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_scan [1], src_scan[0]));
1105 }
1106 dest_scan += 4;
1107 src_scan += src_Bpp;
1108 }
1109 } else {
1110 int src_gap = src_Bpp - 3;
1111 for (int col = 0; col < width; col ++) {
1112 *dest_scan++ = *src_scan++; 850 *dest_scan++ = *src_scan++;
1113 *dest_scan++ = *src_scan++; 851 *dest_scan++ = *src_scan++;
1114 *dest_scan++ = *src_scan++; 852 *dest_scan++ = *src_scan++;
1115 *dest_alpha_scan++ = 0xff; 853 } else {
1116 src_scan += src_gap; 854 *dest_alpha_scan = *src_alpha_scan;
1117 } 855 *dest_scan++ = *src_scan++;
1118 } 856 *dest_scan++ = *src_scan++;
1119 } 857 *dest_scan++ = *src_scan++;
1120 inline void _CompositeRow_Argb2Rgb_Blend(uint8_t* dest_scan, const uint8_t* src_ scan, int width, int blend_type, int dest_Bpp, const uint8_t* clip_scan, 858 }
1121 const uint8_t* src_alpha_scan) 859 dest_alpha_scan++;
1122 { 860 src_alpha_scan++;
861 continue;
862 }
863 uint8_t src_alpha;
864 if (clip_scan == NULL) {
865 src_alpha = *src_alpha_scan++;
866 } else {
867 src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
868 }
869 if (src_alpha == 0) {
870 dest_scan += 3;
871 src_scan += 3;
872 dest_alpha_scan++;
873 continue;
874 }
875 uint8_t dest_alpha =
876 back_alpha + src_alpha - back_alpha * src_alpha / 255;
877 *dest_alpha_scan++ = dest_alpha;
878 int alpha_ratio = src_alpha * 255 / dest_alpha;
879 if (bNonseparableBlend) {
880 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
881 }
882 for (int color = 0; color < 3; color++) {
883 if (blend_type) {
884 int blended = bNonseparableBlend
885 ? blended_colors[color]
886 : _BLEND(blend_type, *dest_scan, *src_scan);
887 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
888 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
889 } else {
890 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
891 }
892 dest_scan++;
893 src_scan++;
894 }
895 }
896 } else {
897 for (int col = 0; col < pixel_count; col++) {
898 uint8_t back_alpha = *dest_alpha_scan;
899 if (back_alpha == 0) {
900 if (clip_scan) {
901 int src_alpha = clip_scan[col] * src_scan[3] / 255;
902 *dest_alpha_scan = src_alpha;
903 *dest_scan++ = *src_scan++;
904 *dest_scan++ = *src_scan++;
905 *dest_scan++ = *src_scan++;
906 } else {
907 *dest_alpha_scan = src_scan[3];
908 *dest_scan++ = *src_scan++;
909 *dest_scan++ = *src_scan++;
910 *dest_scan++ = *src_scan++;
911 }
912 dest_alpha_scan++;
913 src_scan++;
914 continue;
915 }
916 uint8_t src_alpha;
917 if (clip_scan == NULL) {
918 src_alpha = src_scan[3];
919 } else {
920 src_alpha = clip_scan[col] * src_scan[3] / 255;
921 }
922 if (src_alpha == 0) {
923 dest_scan += 3;
924 src_scan += 4;
925 dest_alpha_scan++;
926 continue;
927 }
928 uint8_t dest_alpha =
929 back_alpha + src_alpha - back_alpha * src_alpha / 255;
930 *dest_alpha_scan++ = dest_alpha;
931 int alpha_ratio = src_alpha * 255 / dest_alpha;
932 if (bNonseparableBlend) {
933 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
934 }
935 for (int color = 0; color < 3; color++) {
936 if (blend_type) {
937 int blended = bNonseparableBlend
938 ? blended_colors[color]
939 : _BLEND(blend_type, *dest_scan, *src_scan);
940 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
941 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
942 } else {
943 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
944 }
945 dest_scan++;
946 src_scan++;
947 }
948 src_scan++;
949 }
950 }
951 }
952 }
953 void _CompositeRow_Rgb2Argb_Blend_NoClip(uint8_t* dest_scan,
954 const uint8_t* src_scan,
955 int width,
956 int blend_type,
957 int src_Bpp,
958 uint8_t* dest_alpha_scan) {
959 int blended_colors[3];
960 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
961 int src_gap = src_Bpp - 3;
962 if (dest_alpha_scan == NULL) {
963 for (int col = 0; col < width; col++) {
964 uint8_t back_alpha = dest_scan[3];
965 if (back_alpha == 0) {
966 if (src_Bpp == 4) {
967 FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
968 } else {
969 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_scan[1],
970 src_scan[0]));
971 }
972 dest_scan += 4;
973 src_scan += src_Bpp;
974 continue;
975 }
976 dest_scan[3] = 0xff;
977 if (bNonseparableBlend) {
978 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
979 }
980 for (int color = 0; color < 3; color++) {
981 int src_color = *src_scan;
982 int blended = bNonseparableBlend
983 ? blended_colors[color]
984 : _BLEND(blend_type, *dest_scan, src_color);
985 *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
986 dest_scan++;
987 src_scan++;
988 }
989 dest_scan++;
990 src_scan += src_gap;
991 }
992 } else {
993 for (int col = 0; col < width; col++) {
994 uint8_t back_alpha = *dest_alpha_scan;
995 if (back_alpha == 0) {
996 *dest_scan++ = *src_scan++;
997 *dest_scan++ = *src_scan++;
998 *dest_scan++ = *src_scan++;
999 *dest_alpha_scan++ = 0xff;
1000 src_scan += src_gap;
1001 continue;
1002 }
1003 *dest_alpha_scan++ = 0xff;
1004 if (bNonseparableBlend) {
1005 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
1006 }
1007 for (int color = 0; color < 3; color++) {
1008 int src_color = *src_scan;
1009 int blended = bNonseparableBlend
1010 ? blended_colors[color]
1011 : _BLEND(blend_type, *dest_scan, src_color);
1012 *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
1013 dest_scan++;
1014 src_scan++;
1015 }
1016 src_scan += src_gap;
1017 }
1018 }
1019 }
1020 inline void _CompositeRow_Rgb2Argb_Blend_Clip(uint8_t* dest_scan,
1021 const uint8_t* src_scan,
1022 int width,
1023 int blend_type,
1024 int src_Bpp,
1025 const uint8_t* clip_scan,
1026 uint8_t* dest_alpha_scan) {
1027 int blended_colors[3];
1028 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1029 int src_gap = src_Bpp - 3;
1030 if (dest_alpha_scan == NULL) {
1031 for (int col = 0; col < width; col++) {
1032 int src_alpha = *clip_scan++;
1033 uint8_t back_alpha = dest_scan[3];
1034 if (back_alpha == 0) {
1035 *dest_scan++ = *src_scan++;
1036 *dest_scan++ = *src_scan++;
1037 *dest_scan++ = *src_scan++;
1038 src_scan += src_gap;
1039 dest_scan++;
1040 continue;
1041 }
1042 if (src_alpha == 0) {
1043 dest_scan += 4;
1044 src_scan += src_Bpp;
1045 continue;
1046 }
1047 uint8_t dest_alpha =
1048 back_alpha + src_alpha - back_alpha * src_alpha / 255;
1049 dest_scan[3] = dest_alpha;
1050 int alpha_ratio = src_alpha * 255 / dest_alpha;
1051 if (bNonseparableBlend) {
1052 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
1053 }
1054 for (int color = 0; color < 3; color++) {
1055 int src_color = *src_scan;
1056 int blended = bNonseparableBlend
1057 ? blended_colors[color]
1058 : _BLEND(blend_type, *dest_scan, src_color);
1059 blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
1060 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
1061 dest_scan++;
1062 src_scan++;
1063 }
1064 dest_scan++;
1065 src_scan += src_gap;
1066 }
1067 } else {
1068 for (int col = 0; col < width; col++) {
1069 int src_alpha = *clip_scan++;
1070 uint8_t back_alpha = *dest_alpha_scan;
1071 if (back_alpha == 0) {
1072 *dest_scan++ = *src_scan++;
1073 *dest_scan++ = *src_scan++;
1074 *dest_scan++ = *src_scan++;
1075 src_scan += src_gap;
1076 dest_alpha_scan++;
1077 continue;
1078 }
1079 if (src_alpha == 0) {
1080 dest_scan += 3;
1081 dest_alpha_scan++;
1082 src_scan += src_Bpp;
1083 continue;
1084 }
1085 uint8_t dest_alpha =
1086 back_alpha + src_alpha - back_alpha * src_alpha / 255;
1087 *dest_alpha_scan++ = dest_alpha;
1088 int alpha_ratio = src_alpha * 255 / dest_alpha;
1089 if (bNonseparableBlend) {
1090 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
1091 }
1092 for (int color = 0; color < 3; color++) {
1093 int src_color = *src_scan;
1094 int blended = bNonseparableBlend
1095 ? blended_colors[color]
1096 : _BLEND(blend_type, *dest_scan, src_color);
1097 blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
1098 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
1099 dest_scan++;
1100 src_scan++;
1101 }
1102 src_scan += src_gap;
1103 }
1104 }
1105 }
1106 inline void _CompositeRow_Rgb2Argb_NoBlend_Clip(uint8_t* dest_scan,
1107 const uint8_t* src_scan,
1108 int width,
1109 int src_Bpp,
1110 const uint8_t* clip_scan,
1111 uint8_t* dest_alpha_scan) {
1112 int src_gap = src_Bpp - 3;
1113 if (dest_alpha_scan == NULL) {
1114 for (int col = 0; col < width; col++) {
1115 int src_alpha = clip_scan[col];
1116 if (src_alpha == 255) {
1117 *dest_scan++ = *src_scan++;
1118 *dest_scan++ = *src_scan++;
1119 *dest_scan++ = *src_scan++;
1120 *dest_scan++ = 255;
1121 src_scan += src_gap;
1122 continue;
1123 }
1124 if (src_alpha == 0) {
1125 dest_scan += 4;
1126 src_scan += src_Bpp;
1127 continue;
1128 }
1129 int back_alpha = dest_scan[3];
1130 uint8_t dest_alpha =
1131 back_alpha + src_alpha - back_alpha * src_alpha / 255;
1132 dest_scan[3] = dest_alpha;
1133 int alpha_ratio = src_alpha * 255 / dest_alpha;
1134 for (int color = 0; color < 3; color++) {
1135 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
1136 dest_scan++;
1137 src_scan++;
1138 }
1139 dest_scan++;
1140 src_scan += src_gap;
1141 }
1142 } else {
1143 for (int col = 0; col < width; col++) {
1144 int src_alpha = clip_scan[col];
1145 if (src_alpha == 255) {
1146 *dest_scan++ = *src_scan++;
1147 *dest_scan++ = *src_scan++;
1148 *dest_scan++ = *src_scan++;
1149 *dest_alpha_scan++ = 255;
1150 src_scan += src_gap;
1151 continue;
1152 }
1153 if (src_alpha == 0) {
1154 dest_scan += 3;
1155 dest_alpha_scan++;
1156 src_scan += src_Bpp;
1157 continue;
1158 }
1159 int back_alpha = *dest_alpha_scan;
1160 uint8_t dest_alpha =
1161 back_alpha + src_alpha - back_alpha * src_alpha / 255;
1162 *dest_alpha_scan++ = dest_alpha;
1163 int alpha_ratio = src_alpha * 255 / dest_alpha;
1164 for (int color = 0; color < 3; color++) {
1165 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
1166 dest_scan++;
1167 src_scan++;
1168 }
1169 src_scan += src_gap;
1170 }
1171 }
1172 }
1173 inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip(uint8_t* dest_scan,
1174 const uint8_t* src_scan,
1175 int width,
1176 int src_Bpp,
1177 uint8_t* dest_alpha_scan) {
1178 if (dest_alpha_scan == NULL) {
1179 for (int col = 0; col < width; col++) {
1180 if (src_Bpp == 4) {
1181 FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
1182 } else {
1183 FXARGB_SETDIB(dest_scan,
1184 FXARGB_MAKE(0xff, src_scan[2], src_scan[1], src_scan[0]));
1185 }
1186 dest_scan += 4;
1187 src_scan += src_Bpp;
1188 }
1189 } else {
1190 int src_gap = src_Bpp - 3;
1191 for (int col = 0; col < width; col++) {
1192 *dest_scan++ = *src_scan++;
1193 *dest_scan++ = *src_scan++;
1194 *dest_scan++ = *src_scan++;
1195 *dest_alpha_scan++ = 0xff;
1196 src_scan += src_gap;
1197 }
1198 }
1199 }
1200 inline void _CompositeRow_Argb2Rgb_Blend(uint8_t* dest_scan,
1201 const uint8_t* src_scan,
1202 int width,
1203 int blend_type,
1204 int dest_Bpp,
1205 const uint8_t* clip_scan,
1206 const uint8_t* src_alpha_scan) {
1207 int blended_colors[3];
1208 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1209 int dest_gap = dest_Bpp - 3;
1210 if (src_alpha_scan == NULL) {
1211 for (int col = 0; col < width; col++) {
1212 uint8_t src_alpha;
1213 if (clip_scan) {
1214 src_alpha = src_scan[3] * (*clip_scan++) / 255;
1215 } else {
1216 src_alpha = src_scan[3];
1217 }
1218 if (src_alpha == 0) {
1219 dest_scan += dest_Bpp;
1220 src_scan += 4;
1221 continue;
1222 }
1223 if (bNonseparableBlend) {
1224 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
1225 }
1226 for (int color = 0; color < 3; color++) {
1227 int back_color = *dest_scan;
1228 int blended = bNonseparableBlend
1229 ? blended_colors[color]
1230 : _BLEND(blend_type, back_color, *src_scan);
1231 *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
1232 dest_scan++;
1233 src_scan++;
1234 }
1235 dest_scan += dest_gap;
1236 src_scan++;
1237 }
1238 } else {
1239 for (int col = 0; col < width; col++) {
1240 uint8_t src_alpha;
1241 if (clip_scan) {
1242 src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
1243 } else {
1244 src_alpha = *src_alpha_scan++;
1245 }
1246 if (src_alpha == 0) {
1247 dest_scan += dest_Bpp;
1248 src_scan += 3;
1249 continue;
1250 }
1251 if (bNonseparableBlend) {
1252 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
1253 }
1254 for (int color = 0; color < 3; color++) {
1255 int back_color = *dest_scan;
1256 int blended = bNonseparableBlend
1257 ? blended_colors[color]
1258 : _BLEND(blend_type, back_color, *src_scan);
1259 *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
1260 dest_scan++;
1261 src_scan++;
1262 }
1263 dest_scan += dest_gap;
1264 }
1265 }
1266 }
1267 inline void _CompositeRow_Argb2Rgb_NoBlend(uint8_t* dest_scan,
1268 const uint8_t* src_scan,
1269 int width,
1270 int dest_Bpp,
1271 const uint8_t* clip_scan,
1272 const uint8_t* src_alpha_scan) {
1273 int dest_gap = dest_Bpp - 3;
1274 if (src_alpha_scan == NULL) {
1275 for (int col = 0; col < width; col++) {
1276 uint8_t src_alpha;
1277 if (clip_scan) {
1278 src_alpha = src_scan[3] * (*clip_scan++) / 255;
1279 } else {
1280 src_alpha = src_scan[3];
1281 }
1282 if (src_alpha == 255) {
1283 *dest_scan++ = *src_scan++;
1284 *dest_scan++ = *src_scan++;
1285 *dest_scan++ = *src_scan++;
1286 dest_scan += dest_gap;
1287 src_scan++;
1288 continue;
1289 }
1290 if (src_alpha == 0) {
1291 dest_scan += dest_Bpp;
1292 src_scan += 4;
1293 continue;
1294 }
1295 for (int color = 0; color < 3; color++) {
1296 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
1297 dest_scan++;
1298 src_scan++;
1299 }
1300 dest_scan += dest_gap;
1301 src_scan++;
1302 }
1303 } else {
1304 for (int col = 0; col < width; col++) {
1305 uint8_t src_alpha;
1306 if (clip_scan) {
1307 src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
1308 } else {
1309 src_alpha = *src_alpha_scan++;
1310 }
1311 if (src_alpha == 255) {
1312 *dest_scan++ = *src_scan++;
1313 *dest_scan++ = *src_scan++;
1314 *dest_scan++ = *src_scan++;
1315 dest_scan += dest_gap;
1316 continue;
1317 }
1318 if (src_alpha == 0) {
1319 dest_scan += dest_Bpp;
1320 src_scan += 3;
1321 continue;
1322 }
1323 for (int color = 0; color < 3; color++) {
1324 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
1325 dest_scan++;
1326 src_scan++;
1327 }
1328 dest_scan += dest_gap;
1329 }
1330 }
1331 }
1332 inline void _CompositeRow_Rgb2Rgb_Blend_NoClip(uint8_t* dest_scan,
1333 const uint8_t* src_scan,
1334 int width,
1335 int blend_type,
1336 int dest_Bpp,
1337 int src_Bpp) {
1338 int blended_colors[3];
1339 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1340 int dest_gap = dest_Bpp - 3;
1341 int src_gap = src_Bpp - 3;
1342 for (int col = 0; col < width; col++) {
1343 if (bNonseparableBlend) {
1344 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
1345 }
1346 for (int color = 0; color < 3; color++) {
1347 int back_color = *dest_scan;
1348 int src_color = *src_scan;
1349 int blended = bNonseparableBlend
1350 ? blended_colors[color]
1351 : _BLEND(blend_type, back_color, src_color);
1352 *dest_scan = blended;
1353 dest_scan++;
1354 src_scan++;
1355 }
1356 dest_scan += dest_gap;
1357 src_scan += src_gap;
1358 }
1359 }
1360 inline void _CompositeRow_Rgb2Rgb_Blend_Clip(uint8_t* dest_scan,
1361 const uint8_t* src_scan,
1362 int width,
1363 int blend_type,
1364 int dest_Bpp,
1365 int src_Bpp,
1366 const uint8_t* clip_scan) {
1367 int blended_colors[3];
1368 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1369 int dest_gap = dest_Bpp - 3;
1370 int src_gap = src_Bpp - 3;
1371 for (int col = 0; col < width; col++) {
1372 uint8_t src_alpha = *clip_scan++;
1373 if (src_alpha == 0) {
1374 dest_scan += dest_Bpp;
1375 src_scan += src_Bpp;
1376 continue;
1377 }
1378 if (bNonseparableBlend) {
1379 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
1380 }
1381 for (int color = 0; color < 3; color++) {
1382 int src_color = *src_scan;
1383 int back_color = *dest_scan;
1384 int blended = bNonseparableBlend
1385 ? blended_colors[color]
1386 : _BLEND(blend_type, back_color, src_color);
1387 *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
1388 dest_scan++;
1389 src_scan++;
1390 }
1391 dest_scan += dest_gap;
1392 src_scan += src_gap;
1393 }
1394 }
1395 inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip(uint8_t* dest_scan,
1396 const uint8_t* src_scan,
1397 int width,
1398 int dest_Bpp,
1399 int src_Bpp) {
1400 if (dest_Bpp == src_Bpp) {
1401 FXSYS_memcpy(dest_scan, src_scan, width * dest_Bpp);
1402 return;
1403 }
1404 for (int col = 0; col < width; col++) {
1405 dest_scan[0] = src_scan[0];
1406 dest_scan[1] = src_scan[1];
1407 dest_scan[2] = src_scan[2];
1408 dest_scan += dest_Bpp;
1409 src_scan += src_Bpp;
1410 }
1411 }
1412 inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip(uint8_t* dest_scan,
1413 const uint8_t* src_scan,
1414 int width,
1415 int dest_Bpp,
1416 int src_Bpp,
1417 const uint8_t* clip_scan) {
1418 for (int col = 0; col < width; col++) {
1419 int src_alpha = clip_scan[col];
1420 if (src_alpha == 255) {
1421 dest_scan[0] = src_scan[0];
1422 dest_scan[1] = src_scan[1];
1423 dest_scan[2] = src_scan[2];
1424 } else if (src_alpha) {
1425 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
1426 dest_scan++;
1427 src_scan++;
1428 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
1429 dest_scan++;
1430 src_scan++;
1431 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
1432 dest_scan += dest_Bpp - 2;
1433 src_scan += src_Bpp - 2;
1434 continue;
1435 }
1436 dest_scan += dest_Bpp;
1437 src_scan += src_Bpp;
1438 }
1439 }
1440 void _CompositeRow_Argb2Argb_Transform(uint8_t* dest_scan,
1441 const uint8_t* src_scan,
1442 int pixel_count,
1443 int blend_type,
1444 const uint8_t* clip_scan,
1445 uint8_t* dest_alpha_scan,
1446 const uint8_t* src_alpha_scan,
1447 uint8_t* src_cache_scan,
1448 void* pIccTransform) {
1449 uint8_t* dp = src_cache_scan;
1450 ICodec_IccModule* pIccModule =
1451 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1452 if (src_alpha_scan) {
1453 if (dest_alpha_scan == NULL) {
1454 for (int col = 0; col < pixel_count; col++) {
1455 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1456 dp[3] = *src_alpha_scan++;
1457 src_scan += 3;
1458 dp += 4;
1459 }
1460 src_alpha_scan = NULL;
1461 } else {
1462 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, pixel_count);
1463 }
1464 } else {
1465 if (dest_alpha_scan == NULL) {
1466 for (int col = 0; col < pixel_count; col++) {
1467 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1468 dp[3] = src_scan[3];
1469 src_scan += 4;
1470 dp += 4;
1471 }
1472 } else {
1473 int blended_colors[3];
1474 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1475 for (int col = 0; col < pixel_count; col++) {
1476 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1477 1);
1478 uint8_t back_alpha = *dest_alpha_scan;
1479 if (back_alpha == 0) {
1480 if (clip_scan) {
1481 int src_alpha = clip_scan[col] * src_scan[3] / 255;
1482 *dest_alpha_scan = src_alpha;
1483 *dest_scan++ = *src_cache_scan++;
1484 *dest_scan++ = *src_cache_scan++;
1485 *dest_scan++ = *src_cache_scan++;
1486 } else {
1487 *dest_alpha_scan = src_scan[3];
1488 *dest_scan++ = *src_cache_scan++;
1489 *dest_scan++ = *src_cache_scan++;
1490 *dest_scan++ = *src_cache_scan++;
1491 }
1492 dest_alpha_scan++;
1493 src_scan += 4;
1494 continue;
1495 }
1496 uint8_t src_alpha;
1497 if (clip_scan == NULL) {
1498 src_alpha = src_scan[3];
1499 } else {
1500 src_alpha = clip_scan[col] * src_scan[3] / 255;
1501 }
1502 src_scan += 4;
1503 if (src_alpha == 0) {
1504 dest_scan += 3;
1505 src_cache_scan += 3;
1506 dest_alpha_scan++;
1507 continue;
1508 }
1509 uint8_t dest_alpha =
1510 back_alpha + src_alpha - back_alpha * src_alpha / 255;
1511 *dest_alpha_scan++ = dest_alpha;
1512 int alpha_ratio = src_alpha * 255 / dest_alpha;
1513 if (bNonseparableBlend) {
1514 _RGB_Blend(blend_type, src_cache_scan, dest_scan, blended_colors);
1515 }
1516 for (int color = 0; color < 3; color++) {
1517 if (blend_type) {
1518 int blended = bNonseparableBlend
1519 ? blended_colors[color]
1520 : _BLEND(blend_type, *dest_scan, *src_cache_scan);
1521 blended = FXDIB_ALPHA_MERGE(*src_cache_scan, blended, back_alpha);
1522 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
1523 } else {
1524 *dest_scan =
1525 FXDIB_ALPHA_MERGE(*dest_scan, *src_cache_scan, alpha_ratio);
1526 }
1527 dest_scan++;
1528 src_cache_scan++;
1529 }
1530 }
1531 return;
1532 }
1533 }
1534 _CompositeRow_Argb2Argb(dest_scan, src_cache_scan, pixel_count, blend_type,
1535 clip_scan, dest_alpha_scan, src_alpha_scan);
1536 }
1537 void _CompositeRow_Rgb2Argb_Blend_NoClip_Transform(uint8_t* dest_scan,
1538 const uint8_t* src_scan,
1539 int width,
1540 int blend_type,
1541 int src_Bpp,
1542 uint8_t* dest_alpha_scan,
1543 uint8_t* src_cache_scan,
1544 void* pIccTransform) {
1545 ICodec_IccModule* pIccModule =
1546 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1547 if (src_Bpp == 3) {
1548 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1549 width);
1550 } else {
1551 uint8_t* dp = src_cache_scan;
1552 for (int col = 0; col < width; col++) {
1553 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1554 src_scan += 4;
1555 dp += 3;
1556 }
1557 }
1558 _CompositeRow_Rgb2Argb_Blend_NoClip(dest_scan, src_cache_scan, width,
1559 blend_type, 3, dest_alpha_scan);
1560 }
1561 inline void _CompositeRow_Rgb2Argb_Blend_Clip_Transform(
1562 uint8_t* dest_scan,
1563 const uint8_t* src_scan,
1564 int width,
1565 int blend_type,
1566 int src_Bpp,
1567 const uint8_t* clip_scan,
1568 uint8_t* dest_alpha_scan,
1569 uint8_t* src_cache_scan,
1570 void* pIccTransform) {
1571 ICodec_IccModule* pIccModule =
1572 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1573 if (src_Bpp == 3) {
1574 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1575 width);
1576 } else {
1577 uint8_t* dp = src_cache_scan;
1578 for (int col = 0; col < width; col++) {
1579 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1580 src_scan += 4;
1581 dp += 3;
1582 }
1583 }
1584 _CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_cache_scan, width,
1585 blend_type, 3, clip_scan, dest_alpha_scan);
1586 }
1587 inline void _CompositeRow_Rgb2Argb_NoBlend_Clip_Transform(
1588 uint8_t* dest_scan,
1589 const uint8_t* src_scan,
1590 int width,
1591 int src_Bpp,
1592 const uint8_t* clip_scan,
1593 uint8_t* dest_alpha_scan,
1594 uint8_t* src_cache_scan,
1595 void* pIccTransform) {
1596 ICodec_IccModule* pIccModule =
1597 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1598 if (src_Bpp == 3) {
1599 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1600 width);
1601 } else {
1602 uint8_t* dp = src_cache_scan;
1603 for (int col = 0; col < width; col++) {
1604 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1605 src_scan += 4;
1606 dp += 3;
1607 }
1608 }
1609 _CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_cache_scan, width, 3,
1610 clip_scan, dest_alpha_scan);
1611 }
1612 inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip_Transform(
1613 uint8_t* dest_scan,
1614 const uint8_t* src_scan,
1615 int width,
1616 int src_Bpp,
1617 uint8_t* dest_alpha_scan,
1618 uint8_t* src_cache_scan,
1619 void* pIccTransform) {
1620 ICodec_IccModule* pIccModule =
1621 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1622 if (src_Bpp == 3) {
1623 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1624 width);
1625 } else {
1626 uint8_t* dp = src_cache_scan;
1627 for (int col = 0; col < width; col++) {
1628 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1629 src_scan += 4;
1630 dp += 3;
1631 }
1632 }
1633 _CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_cache_scan, width, 3,
1634 dest_alpha_scan);
1635 }
1636 inline void _CompositeRow_Argb2Rgb_Blend_Transform(
1637 uint8_t* dest_scan,
1638 const uint8_t* src_scan,
1639 int width,
1640 int blend_type,
1641 int dest_Bpp,
1642 const uint8_t* clip_scan,
1643 const uint8_t* src_alpha_scan,
1644 uint8_t* src_cache_scan,
1645 void* pIccTransform) {
1646 ICodec_IccModule* pIccModule =
1647 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1648 if (src_alpha_scan) {
1649 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1650 width);
1651 } else {
1123 int blended_colors[3]; 1652 int blended_colors[3];
1124 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; 1653 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1125 int dest_gap = dest_Bpp - 3; 1654 int dest_gap = dest_Bpp - 3;
1126 if (src_alpha_scan == NULL) { 1655 for (int col = 0; col < width; col++) {
1127 for (int col = 0; col < width; col ++) { 1656 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, 1);
1128 uint8_t src_alpha; 1657 uint8_t src_alpha;
1129 if (clip_scan) { 1658 if (clip_scan) {
1130 src_alpha = src_scan[3] * (*clip_scan++) / 255; 1659 src_alpha = src_scan[3] * (*clip_scan++) / 255;
1131 } else { 1660 } else {
1132 src_alpha = src_scan[3]; 1661 src_alpha = src_scan[3];
1133 } 1662 }
1134 if (src_alpha == 0) { 1663 src_scan += 4;
1135 dest_scan += dest_Bpp; 1664 if (src_alpha == 0) {
1136 src_scan += 4; 1665 dest_scan += dest_Bpp;
1137 continue; 1666 src_cache_scan += 3;
1138 } 1667 continue;
1139 if (bNonseparableBlend) { 1668 }
1140 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); 1669 if (bNonseparableBlend) {
1141 } 1670 _RGB_Blend(blend_type, src_cache_scan, dest_scan, blended_colors);
1142 for (int color = 0; color < 3; color ++) { 1671 }
1143 int back_color = *dest_scan; 1672 for (int color = 0; color < 3; color++) {
1144 int blended = bNonseparableBlend ? blended_colors[color] : 1673 int back_color = *dest_scan;
1145 _BLEND(blend_type, back_color, *src_scan); 1674 int blended = bNonseparableBlend
1146 *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha); 1675 ? blended_colors[color]
1147 dest_scan ++; 1676 : _BLEND(blend_type, back_color, *src_cache_scan);
1148 src_scan ++; 1677 *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
1149 } 1678 dest_scan++;
1150 dest_scan += dest_gap; 1679 src_cache_scan++;
1151 src_scan ++; 1680 }
1152 } 1681 dest_scan += dest_gap;
1153 } else { 1682 }
1154 for (int col = 0; col < width; col ++) { 1683 return;
1155 uint8_t src_alpha; 1684 }
1156 if (clip_scan) { 1685 _CompositeRow_Argb2Rgb_Blend(dest_scan, src_cache_scan, width, blend_type,
1157 src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255; 1686 dest_Bpp, clip_scan, src_alpha_scan);
1158 } else { 1687 }
1159 src_alpha = *src_alpha_scan++; 1688 inline void _CompositeRow_Argb2Rgb_NoBlend_Transform(
1160 } 1689 uint8_t* dest_scan,
1161 if (src_alpha == 0) { 1690 const uint8_t* src_scan,
1162 dest_scan += dest_Bpp; 1691 int width,
1163 src_scan += 3; 1692 int dest_Bpp,
1164 continue; 1693 const uint8_t* clip_scan,
1165 } 1694 const uint8_t* src_alpha_scan,
1166 if (bNonseparableBlend) { 1695 uint8_t* src_cache_scan,
1167 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); 1696 void* pIccTransform) {
1168 } 1697 ICodec_IccModule* pIccModule =
1169 for (int color = 0; color < 3; color ++) { 1698 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1170 int back_color = *dest_scan; 1699 if (src_alpha_scan) {
1171 int blended = bNonseparableBlend ? blended_colors[color] : 1700 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1172 _BLEND(blend_type, back_color, *src_scan); 1701 width);
1173 *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha); 1702 } else {
1174 dest_scan ++;
1175 src_scan ++;
1176 }
1177 dest_scan += dest_gap;
1178 }
1179 }
1180 }
1181 inline void _CompositeRow_Argb2Rgb_NoBlend(uint8_t* dest_scan, const uint8_t* sr c_scan, int width, int dest_Bpp, const uint8_t* clip_scan,
1182 const uint8_t* src_alpha_scan)
1183 {
1184 int dest_gap = dest_Bpp - 3; 1703 int dest_gap = dest_Bpp - 3;
1185 if (src_alpha_scan == NULL) { 1704 for (int col = 0; col < width; col++) {
1186 for (int col = 0; col < width; col ++) { 1705 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, 1);
1187 uint8_t src_alpha; 1706 uint8_t src_alpha;
1188 if (clip_scan) { 1707 if (clip_scan) {
1189 src_alpha = src_scan[3] * (*clip_scan++) / 255; 1708 src_alpha = src_scan[3] * (*clip_scan++) / 255;
1190 } else { 1709 } else {
1191 src_alpha = src_scan[3]; 1710 src_alpha = src_scan[3];
1192 } 1711 }
1193 if (src_alpha == 255) { 1712 src_scan += 4;
1194 *dest_scan++ = *src_scan++; 1713 if (src_alpha == 255) {
1195 *dest_scan++ = *src_scan++; 1714 *dest_scan++ = *src_cache_scan++;
1196 *dest_scan++ = *src_scan++; 1715 *dest_scan++ = *src_cache_scan++;
1197 dest_scan += dest_gap; 1716 *dest_scan++ = *src_cache_scan++;
1198 src_scan ++; 1717 dest_scan += dest_gap;
1199 continue; 1718 continue;
1200 } 1719 }
1201 if (src_alpha == 0) { 1720 if (src_alpha == 0) {
1202 dest_scan += dest_Bpp; 1721 dest_scan += dest_Bpp;
1203 src_scan += 4; 1722 src_cache_scan += 3;
1204 continue; 1723 continue;
1205 } 1724 }
1206 for (int color = 0; color < 3; color ++) { 1725 for (int color = 0; color < 3; color++) {
1207 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha) ; 1726 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_cache_scan, src_alpha);
1208 dest_scan ++; 1727 dest_scan++;
1209 src_scan ++; 1728 src_cache_scan++;
1210 } 1729 }
1211 dest_scan += dest_gap; 1730 dest_scan += dest_gap;
1212 src_scan ++; 1731 }
1213 } 1732 return;
1214 } else { 1733 }
1215 for (int col = 0; col < width; col ++) { 1734 _CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_cache_scan, width, dest_Bpp,
1216 uint8_t src_alpha; 1735 clip_scan, src_alpha_scan);
1217 if (clip_scan) { 1736 }
1218 src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255; 1737 inline void _CompositeRow_Rgb2Rgb_Blend_NoClip_Transform(
1219 } else { 1738 uint8_t* dest_scan,
1220 src_alpha = *src_alpha_scan++; 1739 const uint8_t* src_scan,
1221 } 1740 int width,
1222 if (src_alpha == 255) { 1741 int blend_type,
1223 *dest_scan++ = *src_scan++; 1742 int dest_Bpp,
1224 *dest_scan++ = *src_scan++; 1743 int src_Bpp,
1225 *dest_scan++ = *src_scan++; 1744 uint8_t* src_cache_scan,
1226 dest_scan += dest_gap; 1745 void* pIccTransform) {
1227 continue; 1746 ICodec_IccModule* pIccModule =
1228 } 1747 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1229 if (src_alpha == 0) { 1748 if (src_Bpp == 3) {
1230 dest_scan += dest_Bpp; 1749 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1231 src_scan += 3; 1750 width);
1232 continue; 1751 } else {
1233 } 1752 uint8_t* dp = src_cache_scan;
1234 for (int color = 0; color < 3; color ++) { 1753 for (int col = 0; col < width; col++) {
1235 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha) ; 1754 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1236 dest_scan ++; 1755 src_scan += 4;
1237 src_scan ++; 1756 dp += 3;
1238 } 1757 }
1239 dest_scan += dest_gap; 1758 }
1240 } 1759 _CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_cache_scan, width,
1241 } 1760 blend_type, dest_Bpp, 3);
1242 } 1761 }
1243 inline void _CompositeRow_Rgb2Rgb_Blend_NoClip(uint8_t* dest_scan, const uint8_t * src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp) 1762 inline void _CompositeRow_Rgb2Rgb_Blend_Clip_Transform(uint8_t* dest_scan,
1244 { 1763 const uint8_t* src_scan,
1245 int blended_colors[3]; 1764 int width,
1246 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; 1765 int blend_type,
1247 int dest_gap = dest_Bpp - 3; 1766 int dest_Bpp,
1248 int src_gap = src_Bpp - 3; 1767 int src_Bpp,
1249 for (int col = 0; col < width; col ++) { 1768 const uint8_t* clip_scan,
1769 uint8_t* src_cache_scan,
1770 void* pIccTransform) {
1771 ICodec_IccModule* pIccModule =
1772 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1773 if (src_Bpp == 3) {
1774 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1775 width);
1776 } else {
1777 uint8_t* dp = src_cache_scan;
1778 for (int col = 0; col < width; col++) {
1779 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1780 src_scan += 4;
1781 dp += 3;
1782 }
1783 }
1784 _CompositeRow_Rgb2Rgb_Blend_Clip(dest_scan, src_cache_scan, width, blend_type,
1785 dest_Bpp, 3, clip_scan);
1786 }
1787 inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip_Transform(
1788 uint8_t* dest_scan,
1789 const uint8_t* src_scan,
1790 int width,
1791 int dest_Bpp,
1792 int src_Bpp,
1793 uint8_t* src_cache_scan,
1794 void* pIccTransform) {
1795 ICodec_IccModule* pIccModule =
1796 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1797 if (src_Bpp == 3) {
1798 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1799 width);
1800 } else {
1801 uint8_t* dp = src_cache_scan;
1802 for (int col = 0; col < width; col++) {
1803 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1804 src_scan += 4;
1805 dp += 3;
1806 }
1807 }
1808 _CompositeRow_Rgb2Rgb_NoBlend_NoClip(dest_scan, src_cache_scan, width,
1809 dest_Bpp, 3);
1810 }
1811 inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip_Transform(
1812 uint8_t* dest_scan,
1813 const uint8_t* src_scan,
1814 int width,
1815 int dest_Bpp,
1816 int src_Bpp,
1817 const uint8_t* clip_scan,
1818 uint8_t* src_cache_scan,
1819 void* pIccTransform) {
1820 ICodec_IccModule* pIccModule =
1821 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1822 if (src_Bpp == 3) {
1823 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
1824 width);
1825 } else {
1826 uint8_t* dp = src_cache_scan;
1827 for (int col = 0; col < width; col++) {
1828 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1829 src_scan += 4;
1830 dp += 3;
1831 }
1832 }
1833 _CompositeRow_Rgb2Rgb_NoBlend_Clip(dest_scan, src_cache_scan, width, dest_Bpp,
1834 3, clip_scan);
1835 }
1836 inline void _CompositeRow_8bppPal2Gray(uint8_t* dest_scan,
1837 const uint8_t* src_scan,
1838 const uint8_t* pPalette,
1839 int pixel_count,
1840 int blend_type,
1841 const uint8_t* clip_scan,
1842 const uint8_t* src_alpha_scan) {
1843 if (src_alpha_scan) {
1844 if (blend_type) {
1845 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1846 int blended_color;
1847 for (int col = 0; col < pixel_count; col++) {
1848 uint8_t gray = pPalette[*src_scan];
1849 int src_alpha = *src_alpha_scan++;
1850 if (clip_scan) {
1851 src_alpha = clip_scan[col] * src_alpha / 255;
1852 }
1250 if (bNonseparableBlend) { 1853 if (bNonseparableBlend) {
1251 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); 1854 blended_color =
1252 } 1855 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
1253 for (int color = 0; color < 3; color ++) { 1856 }
1254 int back_color = *dest_scan; 1857 gray = bNonseparableBlend ? blended_color
1255 int src_color = *src_scan; 1858 : _BLEND(blend_type, *dest_scan, gray);
1256 int blended = bNonseparableBlend ? blended_colors[color] : 1859 if (src_alpha) {
1257 _BLEND(blend_type, back_color, src_color); 1860 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
1258 *dest_scan = blended; 1861 } else {
1259 dest_scan ++; 1862 *dest_scan = gray;
1260 src_scan ++; 1863 }
1261 } 1864 dest_scan++;
1262 dest_scan += dest_gap; 1865 src_scan++;
1263 src_scan += src_gap; 1866 }
1264 } 1867 return;
1265 } 1868 }
1266 inline void _CompositeRow_Rgb2Rgb_Blend_Clip(uint8_t* dest_scan, const uint8_t* src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp, const uint8_t* c lip_scan) 1869 for (int col = 0; col < pixel_count; col++) {
1267 { 1870 uint8_t gray = pPalette[*src_scan];
1268 int blended_colors[3]; 1871 int src_alpha = *src_alpha_scan++;
1269 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; 1872 if (clip_scan) {
1270 int dest_gap = dest_Bpp - 3; 1873 src_alpha = clip_scan[col] * src_alpha / 255;
1271 int src_gap = src_Bpp - 3; 1874 }
1272 for (int col = 0; col < width; col ++) { 1875 if (src_alpha) {
1273 uint8_t src_alpha = *clip_scan ++; 1876 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
1877 } else {
1878 *dest_scan = gray;
1879 }
1880 dest_scan++;
1881 src_scan++;
1882 }
1883 } else {
1884 if (blend_type) {
1885 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1886 int blended_color;
1887 for (int col = 0; col < pixel_count; col++) {
1888 uint8_t gray = pPalette[*src_scan];
1889 if (bNonseparableBlend) {
1890 blended_color =
1891 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
1892 }
1893 gray = bNonseparableBlend ? blended_color
1894 : _BLEND(blend_type, *dest_scan, gray);
1895 if (clip_scan && clip_scan[col] < 255) {
1896 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
1897 } else {
1898 *dest_scan = gray;
1899 }
1900 dest_scan++;
1901 src_scan++;
1902 }
1903 return;
1904 }
1905 for (int col = 0; col < pixel_count; col++) {
1906 uint8_t gray = pPalette[*src_scan];
1907 if (clip_scan && clip_scan[col] < 255) {
1908 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
1909 } else {
1910 *dest_scan = gray;
1911 }
1912 dest_scan++;
1913 src_scan++;
1914 }
1915 }
1916 }
1917 inline void _CompositeRow_8bppPal2Graya(uint8_t* dest_scan,
1918 const uint8_t* src_scan,
1919 const uint8_t* pPalette,
1920 int pixel_count,
1921 int blend_type,
1922 const uint8_t* clip_scan,
1923 uint8_t* dest_alpha_scan,
1924 const uint8_t* src_alpha_scan) {
1925 if (src_alpha_scan) {
1926 if (blend_type) {
1927 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1928 int blended_color;
1929 for (int col = 0; col < pixel_count; col++) {
1930 uint8_t gray = pPalette[*src_scan];
1931 src_scan++;
1932 uint8_t back_alpha = *dest_alpha_scan;
1933 if (back_alpha == 0) {
1934 int src_alpha = *src_alpha_scan++;
1935 if (clip_scan) {
1936 src_alpha = clip_scan[col] * src_alpha / 255;
1937 }
1938 if (src_alpha) {
1939 *dest_scan = gray;
1940 *dest_alpha_scan = src_alpha;
1941 }
1942 dest_scan++;
1943 dest_alpha_scan++;
1944 continue;
1945 }
1946 uint8_t src_alpha = *src_alpha_scan++;
1947 if (clip_scan) {
1948 src_alpha = clip_scan[col] * src_alpha / 255;
1949 }
1274 if (src_alpha == 0) { 1950 if (src_alpha == 0) {
1275 dest_scan += dest_Bpp; 1951 dest_scan++;
1276 src_scan += src_Bpp; 1952 dest_alpha_scan++;
1277 continue; 1953 continue;
1278 } 1954 }
1955 *dest_alpha_scan =
1956 back_alpha + src_alpha - back_alpha * src_alpha / 255;
1957 int alpha_ratio = src_alpha * 255 / (*dest_alpha_scan);
1279 if (bNonseparableBlend) { 1958 if (bNonseparableBlend) {
1280 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); 1959 blended_color =
1281 } 1960 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
1282 for (int color = 0; color < 3; color ++) { 1961 }
1283 int src_color = *src_scan; 1962 gray = bNonseparableBlend ? blended_color
1284 int back_color = *dest_scan; 1963 : _BLEND(blend_type, *dest_scan, gray);
1285 int blended = bNonseparableBlend ? blended_colors[color] : 1964 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1286 _BLEND(blend_type, back_color, src_color); 1965 dest_alpha_scan++;
1287 *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha); 1966 dest_scan++;
1288 dest_scan ++; 1967 }
1289 src_scan ++; 1968 return;
1290 } 1969 }
1291 dest_scan += dest_gap; 1970 for (int col = 0; col < pixel_count; col++) {
1292 src_scan += src_gap; 1971 uint8_t gray = pPalette[*src_scan];
1293 } 1972 src_scan++;
1294 } 1973 uint8_t back_alpha = *dest_alpha_scan;
1295 inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip(uint8_t* dest_scan, const uint8 _t* src_scan, int width, int dest_Bpp, int src_Bpp) 1974 if (back_alpha == 0) {
1296 { 1975 int src_alpha = *src_alpha_scan++;
1297 if (dest_Bpp == src_Bpp) { 1976 if (clip_scan) {
1298 FXSYS_memcpy(dest_scan, src_scan, width * dest_Bpp); 1977 src_alpha = clip_scan[col] * src_alpha / 255;
1299 return; 1978 }
1300 } 1979 if (src_alpha) {
1301 for (int col = 0; col < width; col ++) { 1980 *dest_scan = gray;
1302 dest_scan[0] = src_scan[0]; 1981 *dest_alpha_scan = src_alpha;
1303 dest_scan[1] = src_scan[1]; 1982 }
1304 dest_scan[2] = src_scan[2]; 1983 dest_scan++;
1305 dest_scan += dest_Bpp; 1984 dest_alpha_scan++;
1306 src_scan += src_Bpp; 1985 continue;
1307 } 1986 }
1308 } 1987 uint8_t src_alpha = *src_alpha_scan++;
1309 inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip(uint8_t* dest_scan, const uint8_t * src_scan, int width, int dest_Bpp, int src_Bpp, const uint8_t* clip_scan) 1988 if (clip_scan) {
1310 { 1989 src_alpha = clip_scan[col] * src_alpha / 255;
1311 for (int col = 0; col < width; col ++) { 1990 }
1312 int src_alpha = clip_scan[col]; 1991 if (src_alpha == 0) {
1313 if (src_alpha == 255) { 1992 dest_scan++;
1314 dest_scan[0] = src_scan[0]; 1993 dest_alpha_scan++;
1315 dest_scan[1] = src_scan[1]; 1994 continue;
1316 dest_scan[2] = src_scan[2]; 1995 }
1317 } else if (src_alpha) { 1996 *dest_alpha_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
1318 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha); 1997 int alpha_ratio = src_alpha * 255 / (*dest_alpha_scan);
1319 dest_scan ++; 1998 dest_alpha_scan++;
1320 src_scan ++; 1999 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1321 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha); 2000 dest_scan++;
1322 dest_scan ++; 2001 }
1323 src_scan ++; 2002 } else {
1324 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
1325 dest_scan += dest_Bpp - 2;
1326 src_scan += src_Bpp - 2;
1327 continue;
1328 }
1329 dest_scan += dest_Bpp;
1330 src_scan += src_Bpp;
1331 }
1332 }
1333 void _CompositeRow_Argb2Argb_Transform(uint8_t* dest_scan, const uint8_t* src_sc an, int pixel_count, int blend_type, const uint8_t* clip_scan,
1334 uint8_t* dest_alpha_scan, const uint8_t* src_alpha_scan, uint8_t* src_cache_scan, void* pIccTransform)
1335 {
1336 uint8_t* dp = src_cache_scan;
1337 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1338 if (src_alpha_scan) {
1339 if (dest_alpha_scan == NULL) {
1340 for (int col = 0; col < pixel_count; col ++) {
1341 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1342 dp[3] = *src_alpha_scan++;
1343 src_scan += 3;
1344 dp += 4;
1345 }
1346 src_alpha_scan = NULL;
1347 } else {
1348 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, pixel_cou nt);
1349 }
1350 } else {
1351 if (dest_alpha_scan == NULL) {
1352 for (int col = 0; col < pixel_count; col ++) {
1353 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1354 dp[3] = src_scan[3];
1355 src_scan += 4;
1356 dp += 4;
1357 }
1358 } else {
1359 int blended_colors[3];
1360 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1361 for (int col = 0; col < pixel_count; col ++) {
1362 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src _scan, 1);
1363 uint8_t back_alpha = *dest_alpha_scan;
1364 if (back_alpha == 0) {
1365 if (clip_scan) {
1366 int src_alpha = clip_scan[col] * src_scan[3] / 255;
1367 *dest_alpha_scan = src_alpha;
1368 *dest_scan++ = *src_cache_scan++;
1369 *dest_scan++ = *src_cache_scan++;
1370 *dest_scan++ = *src_cache_scan++;
1371 } else {
1372 *dest_alpha_scan = src_scan[3];
1373 *dest_scan++ = *src_cache_scan++;
1374 *dest_scan++ = *src_cache_scan++;
1375 *dest_scan++ = *src_cache_scan++;
1376 }
1377 dest_alpha_scan ++;
1378 src_scan += 4;
1379 continue;
1380 }
1381 uint8_t src_alpha;
1382 if (clip_scan == NULL) {
1383 src_alpha = src_scan[3];
1384 } else {
1385 src_alpha = clip_scan[col] * src_scan[3] / 255;
1386 }
1387 src_scan += 4;
1388 if (src_alpha == 0) {
1389 dest_scan += 3;
1390 src_cache_scan += 3;
1391 dest_alpha_scan ++;
1392 continue;
1393 }
1394 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_a lpha / 255;
1395 *dest_alpha_scan ++ = dest_alpha;
1396 int alpha_ratio = src_alpha * 255 / dest_alpha;
1397 if (bNonseparableBlend) {
1398 _RGB_Blend(blend_type, src_cache_scan, dest_scan, blended_co lors);
1399 }
1400 for (int color = 0; color < 3; color ++) {
1401 if (blend_type) {
1402 int blended = bNonseparableBlend ? blended_colors[color] :
1403 _BLEND(blend_type, *dest_scan, *src_cache_ scan);
1404 blended = FXDIB_ALPHA_MERGE(*src_cache_scan, blended, ba ck_alpha);
1405 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alph a_ratio);
1406 } else {
1407 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_cache_sc an, alpha_ratio);
1408 }
1409 dest_scan ++;
1410 src_cache_scan ++;
1411 }
1412 }
1413 return;
1414 }
1415 }
1416 _CompositeRow_Argb2Argb(dest_scan, src_cache_scan, pixel_count, blend_type, clip_scan, dest_alpha_scan, src_alpha_scan);
1417 }
1418 void _CompositeRow_Rgb2Argb_Blend_NoClip_Transform(uint8_t* dest_scan, const uin t8_t* src_scan, int width, int blend_type, int src_Bpp,
1419 uint8_t* dest_alpha_scan, uint8_t* src_cache_scan, void* pIccTransform)
1420 {
1421 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1422 if (src_Bpp == 3) {
1423 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1424 } else {
1425 uint8_t* dp = src_cache_scan;
1426 for (int col = 0; col < width; col ++) {
1427 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1428 src_scan += 4;
1429 dp += 3;
1430 }
1431 }
1432 _CompositeRow_Rgb2Argb_Blend_NoClip(dest_scan, src_cache_scan, width, blend_ type, 3, dest_alpha_scan);
1433 }
1434 inline void _CompositeRow_Rgb2Argb_Blend_Clip_Transform(uint8_t* dest_scan, cons t uint8_t* src_scan, int width, int blend_type, int src_Bpp, const uint8_t* clip _scan,
1435 uint8_t* dest_alpha_scan, uint8_t* src_cache_scan, void* pIccTransform)
1436 {
1437 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1438 if (src_Bpp == 3) {
1439 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1440 } else {
1441 uint8_t* dp = src_cache_scan;
1442 for (int col = 0; col < width; col ++) {
1443 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1444 src_scan += 4;
1445 dp += 3;
1446 }
1447 }
1448 _CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_cache_scan, width, blend_ty pe, 3, clip_scan, dest_alpha_scan);
1449 }
1450 inline void _CompositeRow_Rgb2Argb_NoBlend_Clip_Transform(uint8_t* dest_scan, co nst uint8_t* src_scan, int width, int src_Bpp, const uint8_t* clip_scan,
1451 uint8_t* dest_alpha_scan, uint8_t* src_cache_scan, void* pIccTransform)
1452 {
1453 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1454 if (src_Bpp == 3) {
1455 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1456 } else {
1457 uint8_t* dp = src_cache_scan;
1458 for (int col = 0; col < width; col ++) {
1459 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1460 src_scan += 4;
1461 dp += 3;
1462 }
1463 }
1464 _CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_cache_scan, width, 3, cli p_scan, dest_alpha_scan);
1465 }
1466 inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip_Transform(uint8_t* dest_scan, const uint8_t* src_scan, int width, int src_Bpp,
1467 uint8_t* dest_alpha_scan, uint8_t* src_cache_scan, void* pIccTransform)
1468 {
1469 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1470 if (src_Bpp == 3) {
1471 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1472 } else {
1473 uint8_t* dp = src_cache_scan;
1474 for (int col = 0; col < width; col ++) {
1475 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1476 src_scan += 4;
1477 dp += 3;
1478 }
1479 }
1480 _CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_cache_scan, width, 3, d est_alpha_scan);
1481 }
1482 inline void _CompositeRow_Argb2Rgb_Blend_Transform(uint8_t* dest_scan, const uin t8_t* src_scan, int width, int blend_type, int dest_Bpp, const uint8_t* clip_sca n,
1483 const uint8_t* src_alpha_scan, uint8_t* src_cache_scan, void* pIccTransf orm)
1484 {
1485 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1486 if (src_alpha_scan) {
1487 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1488 } else {
1489 int blended_colors[3];
1490 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1491 int dest_gap = dest_Bpp - 3;
1492 for (int col = 0; col < width; col ++) {
1493 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_sca n, 1);
1494 uint8_t src_alpha;
1495 if (clip_scan) {
1496 src_alpha = src_scan[3] * (*clip_scan++) / 255;
1497 } else {
1498 src_alpha = src_scan[3];
1499 }
1500 src_scan += 4;
1501 if (src_alpha == 0) {
1502 dest_scan += dest_Bpp;
1503 src_cache_scan += 3;
1504 continue;
1505 }
1506 if (bNonseparableBlend) {
1507 _RGB_Blend(blend_type, src_cache_scan, dest_scan, blended_colors );
1508 }
1509 for (int color = 0; color < 3; color ++) {
1510 int back_color = *dest_scan;
1511 int blended = bNonseparableBlend ? blended_colors[color] :
1512 _BLEND(blend_type, back_color, *src_cache_scan);
1513 *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
1514 dest_scan ++;
1515 src_cache_scan ++;
1516 }
1517 dest_scan += dest_gap;
1518 }
1519 return;
1520 }
1521 _CompositeRow_Argb2Rgb_Blend(dest_scan, src_cache_scan, width, blend_type, d est_Bpp, clip_scan, src_alpha_scan);
1522 }
1523 inline void _CompositeRow_Argb2Rgb_NoBlend_Transform(uint8_t* dest_scan, const u int8_t* src_scan, int width, int dest_Bpp, const uint8_t* clip_scan,
1524 const uint8_t* src_alpha_scan, uint8_t* src_cache_scan, void* pIccTransf orm)
1525 {
1526 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1527 if (src_alpha_scan) {
1528 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1529 } else {
1530 int dest_gap = dest_Bpp - 3;
1531 for (int col = 0; col < width; col ++) {
1532 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_sca n, 1);
1533 uint8_t src_alpha;
1534 if (clip_scan) {
1535 src_alpha = src_scan[3] * (*clip_scan++) / 255;
1536 } else {
1537 src_alpha = src_scan[3];
1538 }
1539 src_scan += 4;
1540 if (src_alpha == 255) {
1541 *dest_scan++ = *src_cache_scan++;
1542 *dest_scan++ = *src_cache_scan++;
1543 *dest_scan++ = *src_cache_scan++;
1544 dest_scan += dest_gap;
1545 continue;
1546 }
1547 if (src_alpha == 0) {
1548 dest_scan += dest_Bpp;
1549 src_cache_scan += 3;
1550 continue;
1551 }
1552 for (int color = 0; color < 3; color ++) {
1553 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_cache_scan, src_ alpha);
1554 dest_scan ++;
1555 src_cache_scan ++;
1556 }
1557 dest_scan += dest_gap;
1558 }
1559 return;
1560 }
1561 _CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_cache_scan, width, dest_Bpp, c lip_scan, src_alpha_scan);
1562 }
1563 inline void _CompositeRow_Rgb2Rgb_Blend_NoClip_Transform(uint8_t* dest_scan, con st uint8_t* src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp,
1564 uint8_t* src_cache_scan, void* pIccTransform)
1565 {
1566 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1567 if (src_Bpp == 3) {
1568 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1569 } else {
1570 uint8_t* dp = src_cache_scan;
1571 for (int col = 0; col < width; col ++) {
1572 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1573 src_scan += 4;
1574 dp += 3;
1575 }
1576 }
1577 _CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_cache_scan, width, blend_t ype, dest_Bpp, 3);
1578 }
1579 inline void _CompositeRow_Rgb2Rgb_Blend_Clip_Transform(uint8_t* dest_scan, const uint8_t* src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp, const uint8_t* clip_scan,
1580 uint8_t* src_cache_scan, void* pIccTransform)
1581 {
1582 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1583 if (src_Bpp == 3) {
1584 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1585 } else {
1586 uint8_t* dp = src_cache_scan;
1587 for (int col = 0; col < width; col ++) {
1588 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1589 src_scan += 4;
1590 dp += 3;
1591 }
1592 }
1593 _CompositeRow_Rgb2Rgb_Blend_Clip(dest_scan, src_cache_scan, width, blend_typ e, dest_Bpp, 3, clip_scan);
1594 }
1595 inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip_Transform(uint8_t* dest_scan, c onst uint8_t* src_scan, int width, int dest_Bpp, int src_Bpp,
1596 uint8_t* src_cache_scan, void* pIccTransform)
1597 {
1598 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1599 if (src_Bpp == 3) {
1600 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1601 } else {
1602 uint8_t* dp = src_cache_scan;
1603 for (int col = 0; col < width; col ++) {
1604 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1605 src_scan += 4;
1606 dp += 3;
1607 }
1608 }
1609 _CompositeRow_Rgb2Rgb_NoBlend_NoClip(dest_scan, src_cache_scan, width, dest_ Bpp, 3);
1610 }
1611 inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip_Transform(uint8_t* dest_scan, con st uint8_t* src_scan, int width, int dest_Bpp, int src_Bpp, const uint8_t* clip_ scan,
1612 uint8_t* src_cache_scan, void* pIccTransform)
1613 {
1614 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIcc Module();
1615 if (src_Bpp == 3) {
1616 pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, w idth);
1617 } else {
1618 uint8_t* dp = src_cache_scan;
1619 for (int col = 0; col < width; col ++) {
1620 pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
1621 src_scan += 4;
1622 dp += 3;
1623 }
1624 }
1625 _CompositeRow_Rgb2Rgb_NoBlend_Clip(dest_scan, src_cache_scan, width, dest_Bp p, 3, clip_scan);
1626 }
1627 inline void _CompositeRow_8bppPal2Gray(uint8_t* dest_scan, const uint8_t* src_sc an, const uint8_t* pPalette, int pixel_count,
1628 int blend_type, const uint8_t* clip_scan,
1629 const uint8_t* src_alpha_scan)
1630 {
1631 if (src_alpha_scan) {
1632 if (blend_type) {
1633 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1634 int blended_color;
1635 for (int col = 0; col < pixel_count; col ++) {
1636 uint8_t gray = pPalette[*src_scan];
1637 int src_alpha = *src_alpha_scan++;
1638 if (clip_scan) {
1639 src_alpha = clip_scan[col] * src_alpha / 255;
1640 }
1641 if (bNonseparableBlend) {
1642 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
1643 }
1644 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, * dest_scan, gray);
1645 if (src_alpha) {
1646 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
1647 } else {
1648 *dest_scan = gray;
1649 }
1650 dest_scan ++;
1651 src_scan ++;
1652 }
1653 return;
1654 }
1655 for (int col = 0; col < pixel_count; col ++) {
1656 uint8_t gray = pPalette[*src_scan];
1657 int src_alpha = *src_alpha_scan++;
1658 if (clip_scan) {
1659 src_alpha = clip_scan[col] * src_alpha / 255;
1660 }
1661 if (src_alpha) {
1662 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
1663 } else {
1664 *dest_scan = gray;
1665 }
1666 dest_scan ++;
1667 src_scan ++;
1668 }
1669 } else {
1670 if (blend_type) {
1671 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1672 int blended_color;
1673 for (int col = 0; col < pixel_count; col ++) {
1674 uint8_t gray = pPalette[*src_scan];
1675 if (bNonseparableBlend) {
1676 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
1677 }
1678 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, * dest_scan, gray);
1679 if (clip_scan && clip_scan[col] < 255) {
1680 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[c ol]);
1681 } else {
1682 *dest_scan = gray;
1683 }
1684 dest_scan ++;
1685 src_scan ++;
1686 }
1687 return;
1688 }
1689 for (int col = 0; col < pixel_count; col ++) {
1690 uint8_t gray = pPalette[*src_scan];
1691 if (clip_scan && clip_scan[col] < 255) {
1692 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]) ;
1693 } else {
1694 *dest_scan = gray;
1695 }
1696 dest_scan ++;
1697 src_scan ++;
1698 }
1699 }
1700 }
1701 inline void _CompositeRow_8bppPal2Graya(uint8_t* dest_scan, const uint8_t* src_s can, const uint8_t* pPalette, int pixel_count,
1702 int blend_type, const uint8_t* clip_scan ,
1703 uint8_t* dest_alpha_scan, const uint8_t* src_alpha_scan)
1704 {
1705 if (src_alpha_scan) {
1706 if (blend_type) {
1707 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1708 int blended_color;
1709 for (int col = 0; col < pixel_count; col ++) {
1710 uint8_t gray = pPalette[*src_scan];
1711 src_scan ++;
1712 uint8_t back_alpha = *dest_alpha_scan;
1713 if (back_alpha == 0) {
1714 int src_alpha = *src_alpha_scan ++;
1715 if (clip_scan) {
1716 src_alpha = clip_scan[col] * src_alpha / 255;
1717 }
1718 if (src_alpha) {
1719 *dest_scan = gray;
1720 *dest_alpha_scan = src_alpha;
1721 }
1722 dest_scan ++;
1723 dest_alpha_scan ++;
1724 continue;
1725 }
1726 uint8_t src_alpha = *src_alpha_scan++;
1727 if (clip_scan) {
1728 src_alpha = clip_scan[col] * src_alpha / 255;
1729 }
1730 if (src_alpha == 0) {
1731 dest_scan ++;
1732 dest_alpha_scan ++;
1733 continue;
1734 }
1735 *dest_alpha_scan = back_alpha + src_alpha - back_alpha * src_alp ha / 255;
1736 int alpha_ratio = src_alpha * 255 / (*dest_alpha_scan);
1737 if (bNonseparableBlend) {
1738 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
1739 }
1740 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, * dest_scan, gray);
1741 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1742 dest_alpha_scan ++;
1743 dest_scan ++;
1744 }
1745 return;
1746 }
1747 for (int col = 0; col < pixel_count; col ++) {
1748 uint8_t gray = pPalette[*src_scan];
1749 src_scan ++;
1750 uint8_t back_alpha = *dest_alpha_scan;
1751 if (back_alpha == 0) {
1752 int src_alpha = *src_alpha_scan ++;
1753 if (clip_scan) {
1754 src_alpha = clip_scan[col] * src_alpha / 255;
1755 }
1756 if (src_alpha) {
1757 *dest_scan = gray;
1758 *dest_alpha_scan = src_alpha;
1759 }
1760 dest_scan ++;
1761 dest_alpha_scan ++;
1762 continue;
1763 }
1764 uint8_t src_alpha = *src_alpha_scan++;
1765 if (clip_scan) {
1766 src_alpha = clip_scan[col] * src_alpha / 255;
1767 }
1768 if (src_alpha == 0) {
1769 dest_scan ++;
1770 dest_alpha_scan ++;
1771 continue;
1772 }
1773 *dest_alpha_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
1774 int alpha_ratio = src_alpha * 255 / (*dest_alpha_scan);
1775 dest_alpha_scan ++;
1776 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1777 dest_scan ++;
1778 }
1779 } else {
1780 if (blend_type) {
1781 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1782 int blended_color;
1783 for (int col = 0; col < pixel_count; col ++) {
1784 uint8_t gray = pPalette[*src_scan];
1785 src_scan ++;
1786 if (clip_scan == NULL || clip_scan[col] == 255) {
1787 *dest_scan++ = gray;
1788 *dest_alpha_scan++ = 255;
1789 continue;
1790 }
1791 int src_alpha = clip_scan[col];
1792 if (src_alpha == 0) {
1793 dest_scan ++;
1794 dest_alpha_scan ++;
1795 continue;
1796 }
1797 int back_alpha = *dest_alpha_scan;
1798 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_a lpha / 255;
1799 *dest_alpha_scan ++ = dest_alpha;
1800 int alpha_ratio = src_alpha * 255 / dest_alpha;
1801 if (bNonseparableBlend) {
1802 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
1803 }
1804 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, * dest_scan, gray);
1805 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1806 dest_scan ++;
1807 }
1808 return;
1809 }
1810 for (int col = 0; col < pixel_count; col ++) {
1811 uint8_t gray = pPalette[*src_scan];
1812 src_scan ++;
1813 if (clip_scan == NULL || clip_scan[col] == 255) {
1814 *dest_scan++ = gray;
1815 *dest_alpha_scan++ = 255;
1816 continue;
1817 }
1818 int src_alpha = clip_scan[col];
1819 if (src_alpha == 0) {
1820 dest_scan ++;
1821 dest_alpha_scan ++;
1822 continue;
1823 }
1824 int back_alpha = *dest_alpha_scan;
1825 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
1826 *dest_alpha_scan ++ = dest_alpha;
1827 int alpha_ratio = src_alpha * 255 / dest_alpha;
1828 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1829 dest_scan ++;
1830 }
1831 }
1832 }
1833 inline void _CompositeRow_1bppPal2Gray(uint8_t* dest_scan, const uint8_t* src_sc an, int src_left,
1834 const uint8_t* pPalette, int pixel_count, int blend_type, const uint8_t* clip_scan)
1835 {
1836 int reset_gray = pPalette[0];
1837 int set_gray = pPalette[1];
1838 if (blend_type) { 2003 if (blend_type) {
1839 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; 2004 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1840 int blended_color; 2005 int blended_color;
1841 for (int col = 0; col < pixel_count; col ++) { 2006 for (int col = 0; col < pixel_count; col++) {
1842 uint8_t gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + s rc_left) % 8))) ? set_gray : reset_gray; 2007 uint8_t gray = pPalette[*src_scan];
1843 if (bNonseparableBlend) { 2008 src_scan++;
1844 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *d est_scan;
1845 }
1846 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest _scan, gray);
1847 if (clip_scan && clip_scan[col] < 255) {
1848 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]) ;
1849 } else {
1850 *dest_scan = gray;
1851 }
1852 dest_scan ++;
1853 }
1854 return;
1855 }
1856 for (int col = 0; col < pixel_count; col ++) {
1857 uint8_t gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_l eft) % 8))) ? set_gray : reset_gray;
1858 if (clip_scan && clip_scan[col] < 255) {
1859 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
1860 } else {
1861 *dest_scan = gray;
1862 }
1863 dest_scan ++;
1864 }
1865 }
1866 inline void _CompositeRow_1bppPal2Graya(uint8_t* dest_scan, const uint8_t* src_s can, int src_left,
1867 const uint8_t* pPalette, int pixel_count , int blend_type, const uint8_t* clip_scan,
1868 uint8_t* dest_alpha_scan)
1869 {
1870 int reset_gray = pPalette[0];
1871 int set_gray = pPalette[1];
1872 if (blend_type) {
1873 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1874 int blended_color;
1875 for (int col = 0; col < pixel_count; col ++) {
1876 uint8_t gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + s rc_left) % 8))) ? set_gray : reset_gray;
1877 if (clip_scan == NULL || clip_scan[col] == 255) {
1878 *dest_scan++ = gray;
1879 *dest_alpha_scan ++ = 255;
1880 continue;
1881 }
1882 int src_alpha = clip_scan[col];
1883 if (src_alpha == 0) {
1884 dest_scan ++;
1885 dest_alpha_scan ++;
1886 continue;
1887 }
1888 int back_alpha = *dest_alpha_scan;
1889 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
1890 *dest_alpha_scan ++ = dest_alpha;
1891 int alpha_ratio = src_alpha * 255 / dest_alpha;
1892 if (bNonseparableBlend) {
1893 blended_color = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *d est_scan;
1894 }
1895 gray = bNonseparableBlend ? blended_color : _BLEND(blend_type, *dest _scan, gray);
1896 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1897 dest_scan ++;
1898 }
1899 return;
1900 }
1901 for (int col = 0; col < pixel_count; col ++) {
1902 uint8_t gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_l eft) % 8))) ? set_gray : reset_gray;
1903 if (clip_scan == NULL || clip_scan[col] == 255) { 2009 if (clip_scan == NULL || clip_scan[col] == 255) {
1904 *dest_scan++ = gray; 2010 *dest_scan++ = gray;
1905 *dest_alpha_scan ++ = 255; 2011 *dest_alpha_scan++ = 255;
1906 continue; 2012 continue;
1907 } 2013 }
1908 int src_alpha = clip_scan[col]; 2014 int src_alpha = clip_scan[col];
1909 if (src_alpha == 0) { 2015 if (src_alpha == 0) {
1910 dest_scan ++; 2016 dest_scan++;
1911 dest_alpha_scan ++; 2017 dest_alpha_scan++;
1912 continue; 2018 continue;
1913 } 2019 }
1914 int back_alpha = *dest_alpha_scan; 2020 int back_alpha = *dest_alpha_scan;
1915 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55; 2021 uint8_t dest_alpha =
1916 *dest_alpha_scan ++ = dest_alpha; 2022 back_alpha + src_alpha - back_alpha * src_alpha / 255;
2023 *dest_alpha_scan++ = dest_alpha;
1917 int alpha_ratio = src_alpha * 255 / dest_alpha; 2024 int alpha_ratio = src_alpha * 255 / dest_alpha;
2025 if (bNonseparableBlend) {
2026 blended_color =
2027 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
2028 }
2029 gray = bNonseparableBlend ? blended_color
2030 : _BLEND(blend_type, *dest_scan, gray);
1918 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio); 2031 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1919 dest_scan ++; 2032 dest_scan++;
1920 } 2033 }
1921 } 2034 return;
1922 inline void _CompositeRow_8bppRgb2Rgb_NoBlend(uint8_t* dest_scan, const uint8_t* src_scan, FX_DWORD* pPalette, int pixel_count, 2035 }
1923 int DestBpp, const uint8_t* clip_scan, 2036 for (int col = 0; col < pixel_count; col++) {
1924 const uint8_t* src_alpha_scan) 2037 uint8_t gray = pPalette[*src_scan];
1925 { 2038 src_scan++;
1926 if (src_alpha_scan) { 2039 if (clip_scan == NULL || clip_scan[col] == 255) {
1927 int dest_gap = DestBpp - 3; 2040 *dest_scan++ = gray;
1928 FX_ARGB argb = 0; 2041 *dest_alpha_scan++ = 255;
1929 for (int col = 0; col < pixel_count; col ++) { 2042 continue;
1930 argb = pPalette[*src_scan]; 2043 }
1931 int src_r = FXARGB_R(argb); 2044 int src_alpha = clip_scan[col];
1932 int src_g = FXARGB_G(argb); 2045 if (src_alpha == 0) {
1933 int src_b = FXARGB_B(argb); 2046 dest_scan++;
1934 src_scan ++; 2047 dest_alpha_scan++;
1935 uint8_t src_alpha = 0; 2048 continue;
1936 if (clip_scan) { 2049 }
1937 src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255; 2050 int back_alpha = *dest_alpha_scan;
1938 } else { 2051 uint8_t dest_alpha =
1939 src_alpha = *src_alpha_scan++; 2052 back_alpha + src_alpha - back_alpha * src_alpha / 255;
1940 } 2053 *dest_alpha_scan++ = dest_alpha;
1941 if (src_alpha == 255) { 2054 int alpha_ratio = src_alpha * 255 / dest_alpha;
1942 *dest_scan++ = src_b; 2055 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
1943 *dest_scan++ = src_g; 2056 dest_scan++;
1944 *dest_scan++ = src_r; 2057 }
1945 dest_scan += dest_gap; 2058 }
1946 continue; 2059 }
1947 } 2060 inline void _CompositeRow_1bppPal2Gray(uint8_t* dest_scan,
1948 if (src_alpha == 0) { 2061 const uint8_t* src_scan,
1949 dest_scan += DestBpp; 2062 int src_left,
1950 continue; 2063 const uint8_t* pPalette,
1951 } 2064 int pixel_count,
1952 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha); 2065 int blend_type,
1953 dest_scan ++; 2066 const uint8_t* clip_scan) {
1954 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha); 2067 int reset_gray = pPalette[0];
1955 dest_scan ++; 2068 int set_gray = pPalette[1];
1956 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha); 2069 if (blend_type) {
1957 dest_scan ++; 2070 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
1958 dest_scan += dest_gap; 2071 int blended_color;
1959 } 2072 for (int col = 0; col < pixel_count; col++) {
1960 } else { 2073 uint8_t gray =
1961 FX_ARGB argb = 0; 2074 (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8)))
1962 for (int col = 0; col < pixel_count; col ++) { 2075 ? set_gray
1963 argb = pPalette[*src_scan]; 2076 : reset_gray;
1964 int src_r = FXARGB_R(argb); 2077 if (bNonseparableBlend) {
1965 int src_g = FXARGB_G(argb); 2078 blended_color =
1966 int src_b = FXARGB_B(argb); 2079 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
1967 if (clip_scan && clip_scan[col] < 255) { 2080 }
1968 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, clip_scan[col] ); 2081 gray = bNonseparableBlend ? blended_color
1969 dest_scan ++; 2082 : _BLEND(blend_type, *dest_scan, gray);
1970 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, clip_scan[col] ); 2083 if (clip_scan && clip_scan[col] < 255) {
1971 dest_scan ++; 2084 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
1972 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, clip_scan[col] ); 2085 } else {
1973 dest_scan ++; 2086 *dest_scan = gray;
1974 } else { 2087 }
1975 *dest_scan++ = src_b; 2088 dest_scan++;
1976 *dest_scan++ = src_g; 2089 }
1977 *dest_scan++ = src_r; 2090 return;
1978 } 2091 }
1979 if (DestBpp == 4) { 2092 for (int col = 0; col < pixel_count; col++) {
1980 dest_scan++; 2093 uint8_t gray =
1981 } 2094 (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8)))
1982 src_scan ++; 2095 ? set_gray
1983 } 2096 : reset_gray;
1984 } 2097 if (clip_scan && clip_scan[col] < 255) {
1985 } 2098 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
1986 inline void _CompositeRow_1bppRgb2Rgb_NoBlend(uint8_t* dest_scan, const uint8_t* src_scan, int src_left, 2099 } else {
1987 FX_DWORD* pPalette, int pixel_count, int DestBpp, const uint8_t* clip_sc an) 2100 *dest_scan = gray;
1988 { 2101 }
1989 int reset_r, reset_g, reset_b; 2102 dest_scan++;
1990 int set_r, set_g, set_b; 2103 }
2104 }
2105 inline void _CompositeRow_1bppPal2Graya(uint8_t* dest_scan,
2106 const uint8_t* src_scan,
2107 int src_left,
2108 const uint8_t* pPalette,
2109 int pixel_count,
2110 int blend_type,
2111 const uint8_t* clip_scan,
2112 uint8_t* dest_alpha_scan) {
2113 int reset_gray = pPalette[0];
2114 int set_gray = pPalette[1];
2115 if (blend_type) {
2116 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
2117 int blended_color;
2118 for (int col = 0; col < pixel_count; col++) {
2119 uint8_t gray =
2120 (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8)))
2121 ? set_gray
2122 : reset_gray;
2123 if (clip_scan == NULL || clip_scan[col] == 255) {
2124 *dest_scan++ = gray;
2125 *dest_alpha_scan++ = 255;
2126 continue;
2127 }
2128 int src_alpha = clip_scan[col];
2129 if (src_alpha == 0) {
2130 dest_scan++;
2131 dest_alpha_scan++;
2132 continue;
2133 }
2134 int back_alpha = *dest_alpha_scan;
2135 uint8_t dest_alpha =
2136 back_alpha + src_alpha - back_alpha * src_alpha / 255;
2137 *dest_alpha_scan++ = dest_alpha;
2138 int alpha_ratio = src_alpha * 255 / dest_alpha;
2139 if (bNonseparableBlend) {
2140 blended_color =
2141 blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
2142 }
2143 gray = bNonseparableBlend ? blended_color
2144 : _BLEND(blend_type, *dest_scan, gray);
2145 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
2146 dest_scan++;
2147 }
2148 return;
2149 }
2150 for (int col = 0; col < pixel_count; col++) {
2151 uint8_t gray =
2152 (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8)))
2153 ? set_gray
2154 : reset_gray;
2155 if (clip_scan == NULL || clip_scan[col] == 255) {
2156 *dest_scan++ = gray;
2157 *dest_alpha_scan++ = 255;
2158 continue;
2159 }
2160 int src_alpha = clip_scan[col];
2161 if (src_alpha == 0) {
2162 dest_scan++;
2163 dest_alpha_scan++;
2164 continue;
2165 }
2166 int back_alpha = *dest_alpha_scan;
2167 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2168 *dest_alpha_scan++ = dest_alpha;
2169 int alpha_ratio = src_alpha * 255 / dest_alpha;
2170 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
2171 dest_scan++;
2172 }
2173 }
2174 inline void _CompositeRow_8bppRgb2Rgb_NoBlend(uint8_t* dest_scan,
2175 const uint8_t* src_scan,
2176 FX_DWORD* pPalette,
2177 int pixel_count,
2178 int DestBpp,
2179 const uint8_t* clip_scan,
2180 const uint8_t* src_alpha_scan) {
2181 if (src_alpha_scan) {
2182 int dest_gap = DestBpp - 3;
2183 FX_ARGB argb = 0;
2184 for (int col = 0; col < pixel_count; col++) {
2185 argb = pPalette[*src_scan];
2186 int src_r = FXARGB_R(argb);
2187 int src_g = FXARGB_G(argb);
2188 int src_b = FXARGB_B(argb);
2189 src_scan++;
2190 uint8_t src_alpha = 0;
2191 if (clip_scan) {
2192 src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
2193 } else {
2194 src_alpha = *src_alpha_scan++;
2195 }
2196 if (src_alpha == 255) {
2197 *dest_scan++ = src_b;
2198 *dest_scan++ = src_g;
2199 *dest_scan++ = src_r;
2200 dest_scan += dest_gap;
2201 continue;
2202 }
2203 if (src_alpha == 0) {
2204 dest_scan += DestBpp;
2205 continue;
2206 }
2207 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
2208 dest_scan++;
2209 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
2210 dest_scan++;
2211 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
2212 dest_scan++;
2213 dest_scan += dest_gap;
2214 }
2215 } else {
2216 FX_ARGB argb = 0;
2217 for (int col = 0; col < pixel_count; col++) {
2218 argb = pPalette[*src_scan];
2219 int src_r = FXARGB_R(argb);
2220 int src_g = FXARGB_G(argb);
2221 int src_b = FXARGB_B(argb);
2222 if (clip_scan && clip_scan[col] < 255) {
2223 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, clip_scan[col]);
2224 dest_scan++;
2225 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, clip_scan[col]);
2226 dest_scan++;
2227 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, clip_scan[col]);
2228 dest_scan++;
2229 } else {
2230 *dest_scan++ = src_b;
2231 *dest_scan++ = src_g;
2232 *dest_scan++ = src_r;
2233 }
2234 if (DestBpp == 4) {
2235 dest_scan++;
2236 }
2237 src_scan++;
2238 }
2239 }
2240 }
2241 inline void _CompositeRow_1bppRgb2Rgb_NoBlend(uint8_t* dest_scan,
2242 const uint8_t* src_scan,
2243 int src_left,
2244 FX_DWORD* pPalette,
2245 int pixel_count,
2246 int DestBpp,
2247 const uint8_t* clip_scan) {
2248 int reset_r, reset_g, reset_b;
2249 int set_r, set_g, set_b;
2250 reset_r = FXARGB_R(pPalette[0]);
2251 reset_g = FXARGB_G(pPalette[0]);
2252 reset_b = FXARGB_B(pPalette[0]);
2253 set_r = FXARGB_R(pPalette[1]);
2254 set_g = FXARGB_G(pPalette[1]);
2255 set_b = FXARGB_B(pPalette[1]);
2256 for (int col = 0; col < pixel_count; col++) {
2257 int src_r, src_g, src_b;
2258 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
2259 src_r = set_r;
2260 src_g = set_g;
2261 src_b = set_b;
2262 } else {
2263 src_r = reset_r;
2264 src_g = reset_g;
2265 src_b = reset_b;
2266 }
2267 if (clip_scan && clip_scan[col] < 255) {
2268 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, clip_scan[col]);
2269 dest_scan++;
2270 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, clip_scan[col]);
2271 dest_scan++;
2272 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, clip_scan[col]);
2273 dest_scan++;
2274 } else {
2275 *dest_scan++ = src_b;
2276 *dest_scan++ = src_g;
2277 *dest_scan++ = src_r;
2278 }
2279 if (DestBpp == 4) {
2280 dest_scan++;
2281 }
2282 }
2283 }
2284 inline void _CompositeRow_8bppRgb2Argb_NoBlend(uint8_t* dest_scan,
2285 const uint8_t* src_scan,
2286 int width,
2287 FX_DWORD* pPalette,
2288 const uint8_t* clip_scan,
2289 const uint8_t* src_alpha_scan) {
2290 if (src_alpha_scan) {
2291 for (int col = 0; col < width; col++) {
2292 FX_ARGB argb = pPalette[*src_scan];
2293 src_scan++;
2294 int src_r = FXARGB_R(argb);
2295 int src_g = FXARGB_G(argb);
2296 int src_b = FXARGB_B(argb);
2297 uint8_t back_alpha = dest_scan[3];
2298 if (back_alpha == 0) {
2299 if (clip_scan) {
2300 int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
2301 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
2302 } else {
2303 FXARGB_SETDIB(dest_scan,
2304 FXARGB_MAKE(*src_alpha_scan, src_r, src_g, src_b));
2305 }
2306 dest_scan += 4;
2307 src_alpha_scan++;
2308 continue;
2309 }
2310 uint8_t src_alpha;
2311 if (clip_scan == NULL) {
2312 src_alpha = *src_alpha_scan++;
2313 } else {
2314 src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
2315 }
2316 if (src_alpha == 0) {
2317 dest_scan += 4;
2318 continue;
2319 }
2320 uint8_t dest_alpha =
2321 back_alpha + src_alpha - back_alpha * src_alpha / 255;
2322 dest_scan[3] = dest_alpha;
2323 int alpha_ratio = src_alpha * 255 / dest_alpha;
2324 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2325 dest_scan++;
2326 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2327 dest_scan++;
2328 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2329 dest_scan++;
2330 dest_scan++;
2331 }
2332 } else
2333 for (int col = 0; col < width; col++) {
2334 FX_ARGB argb = pPalette[*src_scan];
2335 int src_r = FXARGB_R(argb);
2336 int src_g = FXARGB_G(argb);
2337 int src_b = FXARGB_B(argb);
2338 if (clip_scan == NULL || clip_scan[col] == 255) {
2339 *dest_scan++ = src_b;
2340 *dest_scan++ = src_g;
2341 *dest_scan++ = src_r;
2342 *dest_scan++ = 255;
2343 src_scan++;
2344 continue;
2345 }
2346 int src_alpha = clip_scan[col];
2347 if (src_alpha == 0) {
2348 dest_scan += 4;
2349 src_scan++;
2350 continue;
2351 }
2352 int back_alpha = dest_scan[3];
2353 uint8_t dest_alpha =
2354 back_alpha + src_alpha - back_alpha * src_alpha / 255;
2355 dest_scan[3] = dest_alpha;
2356 int alpha_ratio = src_alpha * 255 / dest_alpha;
2357 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2358 dest_scan++;
2359 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2360 dest_scan++;
2361 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2362 dest_scan++;
2363 dest_scan++;
2364 src_scan++;
2365 }
2366 }
2367 void _CompositeRow_8bppRgb2Rgba_NoBlend(uint8_t* dest_scan,
2368 const uint8_t* src_scan,
2369 int width,
2370 FX_DWORD* pPalette,
2371 const uint8_t* clip_scan,
2372 uint8_t* dest_alpha_scan,
2373 const uint8_t* src_alpha_scan) {
2374 if (src_alpha_scan) {
2375 for (int col = 0; col < width; col++) {
2376 FX_ARGB argb = pPalette[*src_scan];
2377 src_scan++;
2378 int src_r = FXARGB_R(argb);
2379 int src_g = FXARGB_G(argb);
2380 int src_b = FXARGB_B(argb);
2381 uint8_t back_alpha = *dest_alpha_scan;
2382 if (back_alpha == 0) {
2383 if (clip_scan) {
2384 int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
2385 *dest_alpha_scan++ = src_alpha;
2386 } else {
2387 *dest_alpha_scan++ = *src_alpha_scan;
2388 }
2389 *dest_scan++ = src_b;
2390 *dest_scan++ = src_g;
2391 *dest_scan++ = src_r;
2392 src_alpha_scan++;
2393 continue;
2394 }
2395 uint8_t src_alpha;
2396 if (clip_scan == NULL) {
2397 src_alpha = *src_alpha_scan++;
2398 } else {
2399 src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
2400 }
2401 if (src_alpha == 0) {
2402 dest_scan += 3;
2403 dest_alpha_scan++;
2404 continue;
2405 }
2406 uint8_t dest_alpha =
2407 back_alpha + src_alpha - back_alpha * src_alpha / 255;
2408 *dest_alpha_scan++ = dest_alpha;
2409 int alpha_ratio = src_alpha * 255 / dest_alpha;
2410 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2411 dest_scan++;
2412 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2413 dest_scan++;
2414 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2415 dest_scan++;
2416 }
2417 } else
2418 for (int col = 0; col < width; col++) {
2419 FX_ARGB argb = pPalette[*src_scan];
2420 int src_r = FXARGB_R(argb);
2421 int src_g = FXARGB_G(argb);
2422 int src_b = FXARGB_B(argb);
2423 if (clip_scan == NULL || clip_scan[col] == 255) {
2424 *dest_scan++ = src_b;
2425 *dest_scan++ = src_g;
2426 *dest_scan++ = src_r;
2427 *dest_alpha_scan++ = 255;
2428 src_scan++;
2429 continue;
2430 }
2431 int src_alpha = clip_scan[col];
2432 if (src_alpha == 0) {
2433 dest_scan += 3;
2434 dest_alpha_scan++;
2435 src_scan++;
2436 continue;
2437 }
2438 int back_alpha = *dest_alpha_scan;
2439 uint8_t dest_alpha =
2440 back_alpha + src_alpha - back_alpha * src_alpha / 255;
2441 *dest_alpha_scan++ = dest_alpha;
2442 int alpha_ratio = src_alpha * 255 / dest_alpha;
2443 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2444 dest_scan++;
2445 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2446 dest_scan++;
2447 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2448 dest_scan++;
2449 src_scan++;
2450 }
2451 }
2452 inline void _CompositeRow_1bppRgb2Argb_NoBlend(uint8_t* dest_scan,
2453 const uint8_t* src_scan,
2454 int src_left,
2455 int width,
2456 FX_DWORD* pPalette,
2457 const uint8_t* clip_scan) {
2458 int reset_r, reset_g, reset_b;
2459 int set_r, set_g, set_b;
2460 reset_r = FXARGB_R(pPalette[0]);
2461 reset_g = FXARGB_G(pPalette[0]);
2462 reset_b = FXARGB_B(pPalette[0]);
2463 set_r = FXARGB_R(pPalette[1]);
2464 set_g = FXARGB_G(pPalette[1]);
2465 set_b = FXARGB_B(pPalette[1]);
2466 for (int col = 0; col < width; col++) {
2467 int src_r, src_g, src_b;
2468 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
2469 src_r = set_r;
2470 src_g = set_g;
2471 src_b = set_b;
2472 } else {
2473 src_r = reset_r;
2474 src_g = reset_g;
2475 src_b = reset_b;
2476 }
2477 if (clip_scan == NULL || clip_scan[col] == 255) {
2478 *dest_scan++ = src_b;
2479 *dest_scan++ = src_g;
2480 *dest_scan++ = src_r;
2481 *dest_scan++ = 255;
2482 continue;
2483 }
2484 int src_alpha = clip_scan[col];
2485 if (src_alpha == 0) {
2486 dest_scan += 4;
2487 continue;
2488 }
2489 int back_alpha = dest_scan[3];
2490 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2491 dest_scan[3] = dest_alpha;
2492 int alpha_ratio = src_alpha * 255 / dest_alpha;
2493 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2494 dest_scan++;
2495 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2496 dest_scan++;
2497 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2498 dest_scan++;
2499 dest_scan++;
2500 }
2501 }
2502 void _CompositeRow_1bppRgb2Rgba_NoBlend(uint8_t* dest_scan,
2503 const uint8_t* src_scan,
2504 int src_left,
2505 int width,
2506 FX_DWORD* pPalette,
2507 const uint8_t* clip_scan,
2508 uint8_t* dest_alpha_scan) {
2509 int reset_r, reset_g, reset_b;
2510 int set_r, set_g, set_b;
2511 reset_r = FXARGB_R(pPalette[0]);
2512 reset_g = FXARGB_G(pPalette[0]);
2513 reset_b = FXARGB_B(pPalette[0]);
2514 set_r = FXARGB_R(pPalette[1]);
2515 set_g = FXARGB_G(pPalette[1]);
2516 set_b = FXARGB_B(pPalette[1]);
2517 for (int col = 0; col < width; col++) {
2518 int src_r, src_g, src_b;
2519 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
2520 src_r = set_r;
2521 src_g = set_g;
2522 src_b = set_b;
2523 } else {
2524 src_r = reset_r;
2525 src_g = reset_g;
2526 src_b = reset_b;
2527 }
2528 if (clip_scan == NULL || clip_scan[col] == 255) {
2529 *dest_scan++ = src_b;
2530 *dest_scan++ = src_g;
2531 *dest_scan++ = src_r;
2532 *dest_alpha_scan++ = 255;
2533 continue;
2534 }
2535 int src_alpha = clip_scan[col];
2536 if (src_alpha == 0) {
2537 dest_scan += 3;
2538 dest_alpha_scan++;
2539 continue;
2540 }
2541 int back_alpha = *dest_alpha_scan;
2542 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2543 *dest_alpha_scan++ = dest_alpha;
2544 int alpha_ratio = src_alpha * 255 / dest_alpha;
2545 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2546 dest_scan++;
2547 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2548 dest_scan++;
2549 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2550 dest_scan++;
2551 }
2552 }
2553 void _CompositeRow_ByteMask2Argb(uint8_t* dest_scan,
2554 const uint8_t* src_scan,
2555 int mask_alpha,
2556 int src_r,
2557 int src_g,
2558 int src_b,
2559 int pixel_count,
2560 int blend_type,
2561 const uint8_t* clip_scan) {
2562 for (int col = 0; col < pixel_count; col++) {
2563 int src_alpha;
2564 if (clip_scan) {
2565 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2566 } else {
2567 src_alpha = mask_alpha * src_scan[col] / 255;
2568 }
2569 uint8_t back_alpha = dest_scan[3];
2570 if (back_alpha == 0) {
2571 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
2572 dest_scan += 4;
2573 continue;
2574 }
2575 if (src_alpha == 0) {
2576 dest_scan += 4;
2577 continue;
2578 }
2579 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2580 dest_scan[3] = dest_alpha;
2581 int alpha_ratio = src_alpha * 255 / dest_alpha;
2582 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2583 int blended_colors[3];
2584 uint8_t src_scan[3];
2585 src_scan[0] = src_b;
2586 src_scan[1] = src_g;
2587 src_scan[2] = src_r;
2588 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2589 *dest_scan =
2590 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio);
2591 dest_scan++;
2592 *dest_scan =
2593 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ratio);
2594 dest_scan++;
2595 *dest_scan =
2596 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ratio);
2597 } else if (blend_type) {
2598 int blended = _BLEND(blend_type, *dest_scan, src_b);
2599 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
2600 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2601 dest_scan++;
2602 blended = _BLEND(blend_type, *dest_scan, src_g);
2603 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
2604 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2605 dest_scan++;
2606 blended = _BLEND(blend_type, *dest_scan, src_r);
2607 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
2608 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2609 } else {
2610 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2611 dest_scan++;
2612 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2613 dest_scan++;
2614 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2615 }
2616 dest_scan += 2;
2617 }
2618 }
2619 void _CompositeRow_ByteMask2Rgba(uint8_t* dest_scan,
2620 const uint8_t* src_scan,
2621 int mask_alpha,
2622 int src_r,
2623 int src_g,
2624 int src_b,
2625 int pixel_count,
2626 int blend_type,
2627 const uint8_t* clip_scan,
2628 uint8_t* dest_alpha_scan) {
2629 for (int col = 0; col < pixel_count; col++) {
2630 int src_alpha;
2631 if (clip_scan) {
2632 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2633 } else {
2634 src_alpha = mask_alpha * src_scan[col] / 255;
2635 }
2636 uint8_t back_alpha = *dest_alpha_scan;
2637 if (back_alpha == 0) {
2638 *dest_scan++ = src_b;
2639 *dest_scan++ = src_g;
2640 *dest_scan++ = src_r;
2641 *dest_alpha_scan++ = src_alpha;
2642 continue;
2643 }
2644 if (src_alpha == 0) {
2645 dest_scan += 3;
2646 dest_alpha_scan++;
2647 continue;
2648 }
2649 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2650 *dest_alpha_scan++ = dest_alpha;
2651 int alpha_ratio = src_alpha * 255 / dest_alpha;
2652 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2653 int blended_colors[3];
2654 uint8_t src_scan[3];
2655 src_scan[0] = src_b;
2656 src_scan[1] = src_g;
2657 src_scan[2] = src_r;
2658 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2659 *dest_scan =
2660 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio);
2661 dest_scan++;
2662 *dest_scan =
2663 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ratio);
2664 dest_scan++;
2665 *dest_scan =
2666 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ratio);
2667 dest_scan++;
2668 } else if (blend_type) {
2669 int blended = _BLEND(blend_type, *dest_scan, src_b);
2670 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
2671 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2672 dest_scan++;
2673 blended = _BLEND(blend_type, *dest_scan, src_g);
2674 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
2675 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2676 dest_scan++;
2677 blended = _BLEND(blend_type, *dest_scan, src_r);
2678 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
2679 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2680 dest_scan++;
2681 } else {
2682 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2683 dest_scan++;
2684 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2685 dest_scan++;
2686 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2687 dest_scan++;
2688 }
2689 }
2690 }
2691 void _CompositeRow_ByteMask2Rgb(uint8_t* dest_scan,
2692 const uint8_t* src_scan,
2693 int mask_alpha,
2694 int src_r,
2695 int src_g,
2696 int src_b,
2697 int pixel_count,
2698 int blend_type,
2699 int Bpp,
2700 const uint8_t* clip_scan) {
2701 for (int col = 0; col < pixel_count; col++) {
2702 int src_alpha;
2703 if (clip_scan) {
2704 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2705 } else {
2706 src_alpha = mask_alpha * src_scan[col] / 255;
2707 }
2708 if (src_alpha == 0) {
2709 dest_scan += Bpp;
2710 continue;
2711 }
2712 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2713 int blended_colors[3];
2714 uint8_t src_scan[3];
2715 src_scan[0] = src_b;
2716 src_scan[1] = src_g;
2717 src_scan[2] = src_r;
2718 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2719 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], src_alpha);
2720 dest_scan++;
2721 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], src_alpha);
2722 dest_scan++;
2723 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], src_alpha);
2724 } else if (blend_type) {
2725 int blended = _BLEND(blend_type, *dest_scan, src_b);
2726 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2727 dest_scan++;
2728 blended = _BLEND(blend_type, *dest_scan, src_g);
2729 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2730 dest_scan++;
2731 blended = _BLEND(blend_type, *dest_scan, src_r);
2732 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2733 } else {
2734 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
2735 dest_scan++;
2736 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
2737 dest_scan++;
2738 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
2739 }
2740 dest_scan += Bpp - 2;
2741 }
2742 }
2743 void _CompositeRow_ByteMask2Mask(uint8_t* dest_scan,
2744 const uint8_t* src_scan,
2745 int mask_alpha,
2746 int pixel_count,
2747 const uint8_t* clip_scan) {
2748 for (int col = 0; col < pixel_count; col++) {
2749 int src_alpha;
2750 if (clip_scan) {
2751 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2752 } else {
2753 src_alpha = mask_alpha * src_scan[col] / 255;
2754 }
2755 uint8_t back_alpha = *dest_scan;
2756 if (!back_alpha) {
2757 *dest_scan = src_alpha;
2758 } else if (src_alpha) {
2759 *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2760 }
2761 dest_scan++;
2762 }
2763 }
2764 void _CompositeRow_ByteMask2Gray(uint8_t* dest_scan,
2765 const uint8_t* src_scan,
2766 int mask_alpha,
2767 int src_gray,
2768 int pixel_count,
2769 const uint8_t* clip_scan) {
2770 for (int col = 0; col < pixel_count; col++) {
2771 int src_alpha;
2772 if (clip_scan) {
2773 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2774 } else {
2775 src_alpha = mask_alpha * src_scan[col] / 255;
2776 }
2777 if (src_alpha) {
2778 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, src_alpha);
2779 }
2780 dest_scan++;
2781 }
2782 }
2783 void _CompositeRow_ByteMask2Graya(uint8_t* dest_scan,
2784 const uint8_t* src_scan,
2785 int mask_alpha,
2786 int src_gray,
2787 int pixel_count,
2788 const uint8_t* clip_scan,
2789 uint8_t* dest_alpha_scan) {
2790 for (int col = 0; col < pixel_count; col++) {
2791 int src_alpha;
2792 if (clip_scan) {
2793 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2794 } else {
2795 src_alpha = mask_alpha * src_scan[col] / 255;
2796 }
2797 uint8_t back_alpha = *dest_alpha_scan;
2798 if (back_alpha == 0) {
2799 *dest_scan++ = src_gray;
2800 *dest_alpha_scan++ = src_alpha;
2801 continue;
2802 }
2803 if (src_alpha == 0) {
2804 dest_scan++;
2805 dest_alpha_scan++;
2806 continue;
2807 }
2808 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2809 *dest_alpha_scan++ = dest_alpha;
2810 int alpha_ratio = src_alpha * 255 / dest_alpha;
2811 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, alpha_ratio);
2812 dest_scan++;
2813 }
2814 }
2815 void _CompositeRow_BitMask2Argb(uint8_t* dest_scan,
2816 const uint8_t* src_scan,
2817 int mask_alpha,
2818 int src_r,
2819 int src_g,
2820 int src_b,
2821 int src_left,
2822 int pixel_count,
2823 int blend_type,
2824 const uint8_t* clip_scan) {
2825 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL &&
2826 mask_alpha == 255) {
2827 FX_ARGB argb = FXARGB_MAKE(0xff, src_r, src_g, src_b);
2828 for (int col = 0; col < pixel_count; col++) {
2829 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
2830 FXARGB_SETDIB(dest_scan, argb);
2831 }
2832 dest_scan += 4;
2833 }
2834 return;
2835 }
2836 for (int col = 0; col < pixel_count; col++) {
2837 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
2838 dest_scan += 4;
2839 continue;
2840 }
2841 int src_alpha;
2842 if (clip_scan) {
2843 src_alpha = mask_alpha * clip_scan[col] / 255;
2844 } else {
2845 src_alpha = mask_alpha;
2846 }
2847 uint8_t back_alpha = dest_scan[3];
2848 if (back_alpha == 0) {
2849 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
2850 dest_scan += 4;
2851 continue;
2852 }
2853 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2854 dest_scan[3] = dest_alpha;
2855 int alpha_ratio = src_alpha * 255 / dest_alpha;
2856 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2857 int blended_colors[3];
2858 uint8_t src_scan[3];
2859 src_scan[0] = src_b;
2860 src_scan[1] = src_g;
2861 src_scan[2] = src_r;
2862 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2863 *dest_scan =
2864 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio);
2865 dest_scan++;
2866 *dest_scan =
2867 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ratio);
2868 dest_scan++;
2869 *dest_scan =
2870 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ratio);
2871 } else if (blend_type) {
2872 int blended = _BLEND(blend_type, *dest_scan, src_b);
2873 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
2874 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2875 dest_scan++;
2876 blended = _BLEND(blend_type, *dest_scan, src_g);
2877 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
2878 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2879 dest_scan++;
2880 blended = _BLEND(blend_type, *dest_scan, src_r);
2881 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
2882 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2883 } else {
2884 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2885 dest_scan++;
2886 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2887 dest_scan++;
2888 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2889 }
2890 dest_scan += 2;
2891 }
2892 }
2893 void _CompositeRow_BitMask2Rgba(uint8_t* dest_scan,
2894 const uint8_t* src_scan,
2895 int mask_alpha,
2896 int src_r,
2897 int src_g,
2898 int src_b,
2899 int src_left,
2900 int pixel_count,
2901 int blend_type,
2902 const uint8_t* clip_scan,
2903 uint8_t* dest_alpha_scan) {
2904 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL &&
2905 mask_alpha == 255) {
2906 for (int col = 0; col < pixel_count; col++) {
2907 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
2908 dest_scan[0] = src_b;
2909 dest_scan[1] = src_g;
2910 dest_scan[2] = src_r;
2911 *dest_alpha_scan = mask_alpha;
2912 }
2913 dest_scan += 3;
2914 dest_alpha_scan++;
2915 }
2916 return;
2917 }
2918 for (int col = 0; col < pixel_count; col++) {
2919 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
2920 dest_scan += 3;
2921 dest_alpha_scan++;
2922 continue;
2923 }
2924 int src_alpha;
2925 if (clip_scan) {
2926 src_alpha = mask_alpha * clip_scan[col] / 255;
2927 } else {
2928 src_alpha = mask_alpha;
2929 }
2930 uint8_t back_alpha = dest_scan[3];
2931 if (back_alpha == 0) {
2932 *dest_scan++ = src_b;
2933 *dest_scan++ = src_g;
2934 *dest_scan++ = src_r;
2935 *dest_alpha_scan++ = mask_alpha;
2936 continue;
2937 }
2938 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2939 *dest_alpha_scan++ = dest_alpha;
2940 int alpha_ratio = src_alpha * 255 / dest_alpha;
2941 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2942 int blended_colors[3];
2943 uint8_t src_scan[3];
2944 src_scan[0] = src_b;
2945 src_scan[1] = src_g;
2946 src_scan[2] = src_r;
2947 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2948 *dest_scan =
2949 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio);
2950 dest_scan++;
2951 *dest_scan =
2952 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ratio);
2953 dest_scan++;
2954 *dest_scan =
2955 FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ratio);
2956 dest_scan++;
2957 } else if (blend_type) {
2958 int blended = _BLEND(blend_type, *dest_scan, src_b);
2959 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
2960 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2961 dest_scan++;
2962 blended = _BLEND(blend_type, *dest_scan, src_g);
2963 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
2964 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2965 dest_scan++;
2966 blended = _BLEND(blend_type, *dest_scan, src_r);
2967 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
2968 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2969 dest_scan++;
2970 } else {
2971 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2972 dest_scan++;
2973 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2974 dest_scan++;
2975 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2976 dest_scan++;
2977 }
2978 }
2979 }
2980 void _CompositeRow_BitMask2Rgb(uint8_t* dest_scan,
2981 const uint8_t* src_scan,
2982 int mask_alpha,
2983 int src_r,
2984 int src_g,
2985 int src_b,
2986 int src_left,
2987 int pixel_count,
2988 int blend_type,
2989 int Bpp,
2990 const uint8_t* clip_scan) {
2991 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL &&
2992 mask_alpha == 255) {
2993 for (int col = 0; col < pixel_count; col++) {
2994 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
2995 dest_scan[2] = src_r;
2996 dest_scan[1] = src_g;
2997 dest_scan[0] = src_b;
2998 }
2999 dest_scan += Bpp;
3000 }
3001 return;
3002 }
3003 for (int col = 0; col < pixel_count; col++) {
3004 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
3005 dest_scan += Bpp;
3006 continue;
3007 }
3008 int src_alpha;
3009 if (clip_scan) {
3010 src_alpha = mask_alpha * clip_scan[col] / 255;
3011 } else {
3012 src_alpha = mask_alpha;
3013 }
3014 if (src_alpha == 0) {
3015 dest_scan += Bpp;
3016 continue;
3017 }
3018 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3019 int blended_colors[3];
3020 uint8_t src_scan[3];
3021 src_scan[0] = src_b;
3022 src_scan[1] = src_g;
3023 src_scan[2] = src_r;
3024 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
3025 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], src_alpha);
3026 dest_scan++;
3027 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], src_alpha);
3028 dest_scan++;
3029 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], src_alpha);
3030 } else if (blend_type) {
3031 int blended = _BLEND(blend_type, *dest_scan, src_b);
3032 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
3033 dest_scan++;
3034 blended = _BLEND(blend_type, *dest_scan, src_g);
3035 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
3036 dest_scan++;
3037 blended = _BLEND(blend_type, *dest_scan, src_r);
3038 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
3039 } else {
3040 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
3041 dest_scan++;
3042 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
3043 dest_scan++;
3044 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
3045 }
3046 dest_scan += Bpp - 2;
3047 }
3048 }
3049 void _CompositeRow_BitMask2Mask(uint8_t* dest_scan,
3050 const uint8_t* src_scan,
3051 int mask_alpha,
3052 int src_left,
3053 int pixel_count,
3054 const uint8_t* clip_scan) {
3055 for (int col = 0; col < pixel_count; col++) {
3056 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
3057 dest_scan++;
3058 continue;
3059 }
3060 int src_alpha;
3061 if (clip_scan) {
3062 src_alpha = mask_alpha * clip_scan[col] / 255;
3063 } else {
3064 src_alpha = mask_alpha;
3065 }
3066 uint8_t back_alpha = *dest_scan;
3067 if (!back_alpha) {
3068 *dest_scan = src_alpha;
3069 } else if (src_alpha) {
3070 *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
3071 }
3072 dest_scan++;
3073 }
3074 }
3075 void _CompositeRow_BitMask2Gray(uint8_t* dest_scan,
3076 const uint8_t* src_scan,
3077 int mask_alpha,
3078 int src_gray,
3079 int src_left,
3080 int pixel_count,
3081 const uint8_t* clip_scan) {
3082 for (int col = 0; col < pixel_count; col++) {
3083 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
3084 dest_scan++;
3085 continue;
3086 }
3087 int src_alpha;
3088 if (clip_scan) {
3089 src_alpha = mask_alpha * clip_scan[col] / 255;
3090 } else {
3091 src_alpha = mask_alpha;
3092 }
3093 if (src_alpha) {
3094 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, src_alpha);
3095 }
3096 dest_scan++;
3097 }
3098 }
3099 void _CompositeRow_BitMask2Graya(uint8_t* dest_scan,
3100 const uint8_t* src_scan,
3101 int mask_alpha,
3102 int src_gray,
3103 int src_left,
3104 int pixel_count,
3105 const uint8_t* clip_scan,
3106 uint8_t* dest_alpha_scan) {
3107 for (int col = 0; col < pixel_count; col++) {
3108 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
3109 dest_scan++;
3110 dest_alpha_scan++;
3111 continue;
3112 }
3113 int src_alpha;
3114 if (clip_scan) {
3115 src_alpha = mask_alpha * clip_scan[col] / 255;
3116 } else {
3117 src_alpha = mask_alpha;
3118 }
3119 uint8_t back_alpha = *dest_alpha_scan;
3120 if (back_alpha == 0) {
3121 *dest_scan++ = src_gray;
3122 *dest_alpha_scan++ = src_alpha;
3123 continue;
3124 }
3125 if (src_alpha == 0) {
3126 dest_scan++;
3127 dest_alpha_scan++;
3128 continue;
3129 }
3130 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
3131 *dest_alpha_scan++ = dest_alpha;
3132 int alpha_ratio = src_alpha * 255 / dest_alpha;
3133 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, alpha_ratio);
3134 dest_scan++;
3135 }
3136 }
3137 void _CompositeRow_Argb2Argb_RgbByteOrder(uint8_t* dest_scan,
3138 const uint8_t* src_scan,
3139 int pixel_count,
3140 int blend_type,
3141 const uint8_t* clip_scan) {
3142 int blended_colors[3];
3143 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
3144 for (int col = 0; col < pixel_count; col++) {
3145 uint8_t back_alpha = dest_scan[3];
3146 if (back_alpha == 0) {
3147 if (clip_scan) {
3148 int src_alpha = clip_scan[col] * src_scan[3] / 255;
3149 dest_scan[3] = src_alpha;
3150 dest_scan[0] = src_scan[2];
3151 dest_scan[1] = src_scan[1];
3152 dest_scan[2] = src_scan[0];
3153 } else {
3154 FXARGB_RGBORDERCOPY(dest_scan, src_scan);
3155 }
3156 dest_scan += 4;
3157 src_scan += 4;
3158 continue;
3159 }
3160 uint8_t src_alpha;
3161 if (clip_scan == NULL) {
3162 src_alpha = src_scan[3];
3163 } else {
3164 src_alpha = clip_scan[col] * src_scan[3] / 255;
3165 }
3166 if (src_alpha == 0) {
3167 dest_scan += 4;
3168 src_scan += 4;
3169 continue;
3170 }
3171 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
3172 dest_scan[3] = dest_alpha;
3173 int alpha_ratio = src_alpha * 255 / dest_alpha;
3174 if (bNonseparableBlend) {
3175 uint8_t dest_scan_o[3];
3176 dest_scan_o[0] = dest_scan[2];
3177 dest_scan_o[1] = dest_scan[1];
3178 dest_scan_o[2] = dest_scan[0];
3179 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3180 }
3181 for (int color = 0; color < 3; color++) {
3182 int index = 2 - color;
3183 if (blend_type) {
3184 int blended = bNonseparableBlend
3185 ? blended_colors[color]
3186 : _BLEND(blend_type, dest_scan[index], *src_scan);
3187 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
3188 dest_scan[index] =
3189 FXDIB_ALPHA_MERGE(dest_scan[index], blended, alpha_ratio);
3190 } else {
3191 dest_scan[index] =
3192 FXDIB_ALPHA_MERGE(dest_scan[index], *src_scan, alpha_ratio);
3193 }
3194 src_scan++;
3195 }
3196 dest_scan += 4;
3197 src_scan++;
3198 }
3199 }
3200 void _CompositeRow_Rgb2Argb_Blend_NoClip_RgbByteOrder(uint8_t* dest_scan,
3201 const uint8_t* src_scan,
3202 int width,
3203 int blend_type,
3204 int src_Bpp) {
3205 int blended_colors[3];
3206 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
3207 int src_gap = src_Bpp - 3;
3208 for (int col = 0; col < width; col++) {
3209 uint8_t back_alpha = dest_scan[3];
3210 if (back_alpha == 0) {
3211 if (src_Bpp == 4) {
3212 FXARGB_SETRGBORDERDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
3213 } else {
3214 FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2],
3215 src_scan[1], src_scan[0]));
3216 }
3217 dest_scan += 4;
3218 src_scan += src_Bpp;
3219 continue;
3220 }
3221 dest_scan[3] = 0xff;
3222 if (bNonseparableBlend) {
3223 uint8_t dest_scan_o[3];
3224 dest_scan_o[0] = dest_scan[2];
3225 dest_scan_o[1] = dest_scan[1];
3226 dest_scan_o[2] = dest_scan[0];
3227 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3228 }
3229 for (int color = 0; color < 3; color++) {
3230 int index = 2 - color;
3231 int src_color = FX_GAMMA(*src_scan);
3232 int blended = bNonseparableBlend
3233 ? blended_colors[color]
3234 : _BLEND(blend_type, dest_scan[index], src_color);
3235 dest_scan[index] = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
3236 src_scan++;
3237 }
3238 dest_scan += 4;
3239 src_scan += src_gap;
3240 }
3241 }
3242 inline void _CompositeRow_Argb2Rgb_Blend_RgbByteOrder(
3243 uint8_t* dest_scan,
3244 const uint8_t* src_scan,
3245 int width,
3246 int blend_type,
3247 int dest_Bpp,
3248 const uint8_t* clip_scan) {
3249 int blended_colors[3];
3250 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
3251 for (int col = 0; col < width; col++) {
3252 uint8_t src_alpha;
3253 if (clip_scan) {
3254 src_alpha = src_scan[3] * (*clip_scan++) / 255;
3255 } else {
3256 src_alpha = src_scan[3];
3257 }
3258 if (src_alpha == 0) {
3259 dest_scan += dest_Bpp;
3260 src_scan += 4;
3261 continue;
3262 }
3263 if (bNonseparableBlend) {
3264 uint8_t dest_scan_o[3];
3265 dest_scan_o[0] = dest_scan[2];
3266 dest_scan_o[1] = dest_scan[1];
3267 dest_scan_o[2] = dest_scan[0];
3268 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3269 }
3270 for (int color = 0; color < 3; color++) {
3271 int index = 2 - color;
3272 int back_color = FX_GAMMA(dest_scan[index]);
3273 int blended = bNonseparableBlend
3274 ? blended_colors[color]
3275 : _BLEND(blend_type, back_color, *src_scan);
3276 dest_scan[index] =
3277 FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
3278 src_scan++;
3279 }
3280 dest_scan += dest_Bpp;
3281 src_scan++;
3282 }
3283 }
3284 inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip_RgbByteOrder(
3285 uint8_t* dest_scan,
3286 const uint8_t* src_scan,
3287 int width,
3288 int src_Bpp) {
3289 for (int col = 0; col < width; col++) {
3290 if (src_Bpp == 4) {
3291 FXARGB_SETRGBORDERDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
3292 } else {
3293 FXARGB_SETRGBORDERDIB(
3294 dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_scan[1], src_scan[0]));
3295 }
3296 dest_scan += 4;
3297 src_scan += src_Bpp;
3298 }
3299 }
3300 inline void _CompositeRow_Rgb2Rgb_Blend_NoClip_RgbByteOrder(
3301 uint8_t* dest_scan,
3302 const uint8_t* src_scan,
3303 int width,
3304 int blend_type,
3305 int dest_Bpp,
3306 int src_Bpp) {
3307 int blended_colors[3];
3308 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
3309 int src_gap = src_Bpp - 3;
3310 for (int col = 0; col < width; col++) {
3311 if (bNonseparableBlend) {
3312 uint8_t dest_scan_o[3];
3313 dest_scan_o[0] = dest_scan[2];
3314 dest_scan_o[1] = dest_scan[1];
3315 dest_scan_o[2] = dest_scan[0];
3316 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3317 }
3318 for (int color = 0; color < 3; color++) {
3319 int index = 2 - color;
3320 int back_color = FX_GAMMA(dest_scan[index]);
3321 int src_color = FX_GAMMA(*src_scan);
3322 int blended = bNonseparableBlend
3323 ? blended_colors[color]
3324 : _BLEND(blend_type, back_color, src_color);
3325 dest_scan[index] = FX_GAMMA_INVERSE(blended);
3326 src_scan++;
3327 }
3328 dest_scan += dest_Bpp;
3329 src_scan += src_gap;
3330 }
3331 }
3332 inline void _CompositeRow_Argb2Rgb_NoBlend_RgbByteOrder(
3333 uint8_t* dest_scan,
3334 const uint8_t* src_scan,
3335 int width,
3336 int dest_Bpp,
3337 const uint8_t* clip_scan) {
3338 for (int col = 0; col < width; col++) {
3339 uint8_t src_alpha;
3340 if (clip_scan) {
3341 src_alpha = src_scan[3] * (*clip_scan++) / 255;
3342 } else {
3343 src_alpha = src_scan[3];
3344 }
3345 if (src_alpha == 255) {
3346 dest_scan[2] = FX_GAMMA_INVERSE(*src_scan++);
3347 dest_scan[1] = FX_GAMMA_INVERSE(*src_scan++);
3348 dest_scan[0] = FX_GAMMA_INVERSE(*src_scan++);
3349 dest_scan += dest_Bpp;
3350 src_scan++;
3351 continue;
3352 }
3353 if (src_alpha == 0) {
3354 dest_scan += dest_Bpp;
3355 src_scan += 4;
3356 continue;
3357 }
3358 for (int color = 0; color < 3; color++) {
3359 int index = 2 - color;
3360 dest_scan[index] = FX_GAMMA_INVERSE(
3361 FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[index]), *src_scan, src_alpha));
3362 src_scan++;
3363 }
3364 dest_scan += dest_Bpp;
3365 src_scan++;
3366 }
3367 }
3368 inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip_RgbByteOrder(
3369 uint8_t* dest_scan,
3370 const uint8_t* src_scan,
3371 int width,
3372 int dest_Bpp,
3373 int src_Bpp) {
3374 for (int col = 0; col < width; col++) {
3375 dest_scan[2] = src_scan[0];
3376 dest_scan[1] = src_scan[1];
3377 dest_scan[0] = src_scan[2];
3378 dest_scan += dest_Bpp;
3379 src_scan += src_Bpp;
3380 }
3381 }
3382 inline void _CompositeRow_Rgb2Argb_Blend_Clip_RgbByteOrder(
3383 uint8_t* dest_scan,
3384 const uint8_t* src_scan,
3385 int width,
3386 int blend_type,
3387 int src_Bpp,
3388 const uint8_t* clip_scan) {
3389 int blended_colors[3];
3390 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
3391 int src_gap = src_Bpp - 3;
3392 for (int col = 0; col < width; col++) {
3393 int src_alpha = *clip_scan++;
3394 uint8_t back_alpha = dest_scan[3];
3395 if (back_alpha == 0) {
3396 dest_scan[2] = FX_GAMMA(*src_scan++);
3397 dest_scan[1] = FX_GAMMA(*src_scan++);
3398 dest_scan[0] = FX_GAMMA(*src_scan++);
3399 src_scan += src_gap;
3400 dest_scan += 4;
3401 continue;
3402 }
3403 if (src_alpha == 0) {
3404 dest_scan += 4;
3405 src_scan += src_Bpp;
3406 continue;
3407 }
3408 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
3409 dest_scan[3] = dest_alpha;
3410 int alpha_ratio = src_alpha * 255 / dest_alpha;
3411 if (bNonseparableBlend) {
3412 uint8_t dest_scan_o[3];
3413 dest_scan_o[0] = dest_scan[2];
3414 dest_scan_o[1] = dest_scan[1];
3415 dest_scan_o[2] = dest_scan[0];
3416 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3417 }
3418 for (int color = 0; color < 3; color++) {
3419 int index = 2 - color;
3420 int src_color = FX_GAMMA(*src_scan);
3421 int blended = bNonseparableBlend
3422 ? blended_colors[color]
3423 : _BLEND(blend_type, dest_scan[index], src_color);
3424 blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
3425 dest_scan[index] =
3426 FXDIB_ALPHA_MERGE(dest_scan[index], blended, alpha_ratio);
3427 src_scan++;
3428 }
3429 dest_scan += 4;
3430 src_scan += src_gap;
3431 }
3432 }
3433 inline void _CompositeRow_Rgb2Rgb_Blend_Clip_RgbByteOrder(
3434 uint8_t* dest_scan,
3435 const uint8_t* src_scan,
3436 int width,
3437 int blend_type,
3438 int dest_Bpp,
3439 int src_Bpp,
3440 const uint8_t* clip_scan) {
3441 int blended_colors[3];
3442 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
3443 int src_gap = src_Bpp - 3;
3444 for (int col = 0; col < width; col++) {
3445 uint8_t src_alpha = *clip_scan++;
3446 if (src_alpha == 0) {
3447 dest_scan += dest_Bpp;
3448 src_scan += src_Bpp;
3449 continue;
3450 }
3451 if (bNonseparableBlend) {
3452 uint8_t dest_scan_o[3];
3453 dest_scan_o[0] = dest_scan[2];
3454 dest_scan_o[1] = dest_scan[1];
3455 dest_scan_o[2] = dest_scan[0];
3456 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3457 }
3458 for (int color = 0; color < 3; color++) {
3459 int index = 2 - color;
3460 int src_color = FX_GAMMA(*src_scan);
3461 int back_color = FX_GAMMA(dest_scan[index]);
3462 int blended = bNonseparableBlend
3463 ? blended_colors[color]
3464 : _BLEND(blend_type, back_color, src_color);
3465 dest_scan[index] =
3466 FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
3467 src_scan++;
3468 }
3469 dest_scan += dest_Bpp;
3470 src_scan += src_gap;
3471 }
3472 }
3473 inline void _CompositeRow_Rgb2Argb_NoBlend_Clip_RgbByteOrder(
3474 uint8_t* dest_scan,
3475 const uint8_t* src_scan,
3476 int width,
3477 int src_Bpp,
3478 const uint8_t* clip_scan) {
3479 int src_gap = src_Bpp - 3;
3480 for (int col = 0; col < width; col++) {
3481 int src_alpha = clip_scan[col];
3482 if (src_alpha == 255) {
3483 dest_scan[2] = FX_GAMMA(*src_scan++);
3484 dest_scan[1] = FX_GAMMA(*src_scan++);
3485 dest_scan[0] = FX_GAMMA(*src_scan++);
3486 dest_scan[3] = 255;
3487 dest_scan += 4;
3488 src_scan += src_gap;
3489 continue;
3490 }
3491 if (src_alpha == 0) {
3492 dest_scan += 4;
3493 src_scan += src_Bpp;
3494 continue;
3495 }
3496 int back_alpha = dest_scan[3];
3497 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
3498 dest_scan[3] = dest_alpha;
3499 int alpha_ratio = src_alpha * 255 / dest_alpha;
3500 for (int color = 0; color < 3; color++) {
3501 int index = 2 - color;
3502 dest_scan[index] =
3503 FXDIB_ALPHA_MERGE(dest_scan[index], FX_GAMMA(*src_scan), alpha_ratio);
3504 src_scan++;
3505 }
3506 dest_scan += 4;
3507 src_scan += src_gap;
3508 }
3509 }
3510 inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip_RgbByteOrder(
3511 uint8_t* dest_scan,
3512 const uint8_t* src_scan,
3513 int width,
3514 int dest_Bpp,
3515 int src_Bpp,
3516 const uint8_t* clip_scan) {
3517 for (int col = 0; col < width; col++) {
3518 int src_alpha = clip_scan[col];
3519 if (src_alpha == 255) {
3520 dest_scan[2] = src_scan[0];
3521 dest_scan[1] = src_scan[1];
3522 dest_scan[0] = src_scan[2];
3523 } else if (src_alpha) {
3524 dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
3525 FX_GAMMA(dest_scan[2]), FX_GAMMA(*src_scan), src_alpha));
3526 src_scan++;
3527 dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
3528 FX_GAMMA(dest_scan[1]), FX_GAMMA(*src_scan), src_alpha));
3529 src_scan++;
3530 dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
3531 FX_GAMMA(dest_scan[0]), FX_GAMMA(*src_scan), src_alpha));
3532 dest_scan += dest_Bpp;
3533 src_scan += src_Bpp - 2;
3534 continue;
3535 }
3536 dest_scan += dest_Bpp;
3537 src_scan += src_Bpp;
3538 }
3539 }
3540 inline void _CompositeRow_8bppRgb2Rgb_NoBlend_RgbByteOrder(
3541 uint8_t* dest_scan,
3542 const uint8_t* src_scan,
3543 FX_ARGB* pPalette,
3544 int pixel_count,
3545 int DestBpp,
3546 const uint8_t* clip_scan) {
3547 for (int col = 0; col < pixel_count; col++) {
3548 FX_ARGB argb = pPalette ? pPalette[*src_scan] : (*src_scan) * 0x010101;
3549 int src_r = FXARGB_R(argb);
3550 int src_g = FXARGB_G(argb);
3551 int src_b = FXARGB_B(argb);
3552 if (clip_scan && clip_scan[col] < 255) {
3553 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, clip_scan[col]);
3554 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, clip_scan[col]);
3555 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, clip_scan[col]);
3556 } else {
3557 dest_scan[2] = src_b;
3558 dest_scan[1] = src_g;
3559 dest_scan[0] = src_r;
3560 }
3561 dest_scan += DestBpp;
3562 src_scan++;
3563 }
3564 }
3565 inline void _CompositeRow_1bppRgb2Rgb_NoBlend_RgbByteOrder(
3566 uint8_t* dest_scan,
3567 const uint8_t* src_scan,
3568 int src_left,
3569 FX_ARGB* pPalette,
3570 int pixel_count,
3571 int DestBpp,
3572 const uint8_t* clip_scan) {
3573 int reset_r, reset_g, reset_b;
3574 int set_r, set_g, set_b;
3575 if (pPalette) {
1991 reset_r = FXARGB_R(pPalette[0]); 3576 reset_r = FXARGB_R(pPalette[0]);
1992 reset_g = FXARGB_G(pPalette[0]); 3577 reset_g = FXARGB_G(pPalette[0]);
1993 reset_b = FXARGB_B(pPalette[0]); 3578 reset_b = FXARGB_B(pPalette[0]);
1994 set_r = FXARGB_R(pPalette[1]); 3579 set_r = FXARGB_R(pPalette[1]);
1995 set_g = FXARGB_G(pPalette[1]); 3580 set_g = FXARGB_G(pPalette[1]);
1996 set_b = FXARGB_B(pPalette[1]); 3581 set_b = FXARGB_B(pPalette[1]);
1997 for (int col = 0; col < pixel_count; col ++) { 3582 } else {
1998 int src_r, src_g, src_b; 3583 reset_r = reset_g = reset_b = 0;
1999 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) { 3584 set_r = set_g = set_b = 255;
2000 src_r = set_r; 3585 }
2001 src_g = set_g; 3586 for (int col = 0; col < pixel_count; col++) {
2002 src_b = set_b; 3587 int src_r, src_g, src_b;
2003 } else { 3588 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
2004 src_r = reset_r; 3589 src_r = set_r;
2005 src_g = reset_g; 3590 src_g = set_g;
2006 src_b = reset_b; 3591 src_b = set_b;
2007 } 3592 } else {
2008 if (clip_scan && clip_scan[col] < 255) { 3593 src_r = reset_r;
2009 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, clip_scan[col]); 3594 src_g = reset_g;
2010 dest_scan ++; 3595 src_b = reset_b;
2011 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, clip_scan[col]); 3596 }
2012 dest_scan ++; 3597 if (clip_scan && clip_scan[col] < 255) {
2013 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, clip_scan[col]); 3598 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, clip_scan[col]);
2014 dest_scan ++; 3599 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, clip_scan[col]);
2015 } else { 3600 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, clip_scan[col]);
2016 *dest_scan++ = src_b; 3601 } else {
2017 *dest_scan++ = src_g; 3602 dest_scan[2] = src_b;
2018 *dest_scan++ = src_r; 3603 dest_scan[1] = src_g;
2019 } 3604 dest_scan[0] = src_r;
2020 if (DestBpp == 4) { 3605 }
2021 dest_scan++; 3606 dest_scan += DestBpp;
2022 } 3607 }
2023 } 3608 }
2024 } 3609 inline void _CompositeRow_8bppRgb2Argb_NoBlend_RgbByteOrder(
2025 inline void _CompositeRow_8bppRgb2Argb_NoBlend(uint8_t* dest_scan, const uint8_t * src_scan, int width, 3610 uint8_t* dest_scan,
2026 FX_DWORD* pPalette, const uint8_t* clip_scan, 3611 const uint8_t* src_scan,
2027 const uint8_t* src_alpha_scan) 3612 int width,
2028 { 3613 FX_ARGB* pPalette,
2029 if (src_alpha_scan) { 3614 const uint8_t* clip_scan) {
2030 for (int col = 0; col < width; col ++) { 3615 for (int col = 0; col < width; col++) {
2031 FX_ARGB argb = pPalette[*src_scan]; 3616 int src_r, src_g, src_b;
2032 src_scan ++; 3617 if (pPalette) {
2033 int src_r = FXARGB_R(argb); 3618 FX_ARGB argb = pPalette[*src_scan];
2034 int src_g = FXARGB_G(argb); 3619 src_r = FXARGB_R(argb);
2035 int src_b = FXARGB_B(argb); 3620 src_g = FXARGB_G(argb);
2036 uint8_t back_alpha = dest_scan[3]; 3621 src_b = FXARGB_B(argb);
2037 if (back_alpha == 0) { 3622 } else {
2038 if (clip_scan) { 3623 src_r = src_g = src_b = *src_scan;
2039 int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255; 3624 }
2040 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g , src_b)); 3625 if (clip_scan == NULL || clip_scan[col] == 255) {
2041 } else { 3626 dest_scan[2] = FX_GAMMA(src_b);
2042 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(*src_alpha_scan, src_r, src_g, src_b)); 3627 dest_scan[1] = FX_GAMMA(src_g);
2043 } 3628 dest_scan[0] = FX_GAMMA(src_r);
2044 dest_scan += 4; 3629 dest_scan[3] = 255;
2045 src_alpha_scan ++; 3630 src_scan++;
2046 continue; 3631 dest_scan += 4;
2047 } 3632 continue;
2048 uint8_t src_alpha; 3633 }
2049 if (clip_scan == NULL) { 3634 int src_alpha = clip_scan[col];
2050 src_alpha = *src_alpha_scan ++; 3635 if (src_alpha == 0) {
2051 } else { 3636 dest_scan += 4;
2052 src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255; 3637 src_scan++;
2053 } 3638 continue;
2054 if (src_alpha == 0) { 3639 }
2055 dest_scan += 4; 3640 int back_alpha = dest_scan[3];
2056 continue; 3641 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2057 } 3642 dest_scan[3] = dest_alpha;
2058 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255; 3643 int alpha_ratio = src_alpha * 255 / dest_alpha;
2059 dest_scan[3] = dest_alpha; 3644 dest_scan[2] =
2060 int alpha_ratio = src_alpha * 255 / dest_alpha; 3645 FXDIB_ALPHA_MERGE(dest_scan[2], FX_GAMMA(src_b), alpha_ratio);
2061 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio); 3646 dest_scan[1] =
2062 dest_scan ++; 3647 FXDIB_ALPHA_MERGE(dest_scan[1], FX_GAMMA(src_g), alpha_ratio);
2063 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio); 3648 dest_scan[0] =
2064 dest_scan ++; 3649 FXDIB_ALPHA_MERGE(dest_scan[0], FX_GAMMA(src_r), alpha_ratio);
2065 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio); 3650 dest_scan += 4;
2066 dest_scan ++; 3651 src_scan++;
2067 dest_scan ++; 3652 }
2068 } 3653 }
2069 } else 3654 inline void _CompositeRow_1bppRgb2Argb_NoBlend_RgbByteOrder(
2070 for (int col = 0; col < width; col ++) { 3655 uint8_t* dest_scan,
2071 FX_ARGB argb = pPalette[*src_scan]; 3656 const uint8_t* src_scan,
2072 int src_r = FXARGB_R(argb); 3657 int src_left,
2073 int src_g = FXARGB_G(argb); 3658 int width,
2074 int src_b = FXARGB_B(argb); 3659 FX_ARGB* pPalette,
2075 if (clip_scan == NULL || clip_scan[col] == 255) { 3660 const uint8_t* clip_scan) {
2076 *dest_scan++ = src_b; 3661 int reset_r, reset_g, reset_b;
2077 *dest_scan++ = src_g; 3662 int set_r, set_g, set_b;
2078 *dest_scan++ = src_r; 3663 if (pPalette) {
2079 *dest_scan++ = 255;
2080 src_scan ++;
2081 continue;
2082 }
2083 int src_alpha = clip_scan[col];
2084 if (src_alpha == 0) {
2085 dest_scan += 4;
2086 src_scan ++;
2087 continue;
2088 }
2089 int back_alpha = dest_scan[3];
2090 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2091 dest_scan[3] = dest_alpha;
2092 int alpha_ratio = src_alpha * 255 / dest_alpha;
2093 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2094 dest_scan ++;
2095 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2096 dest_scan ++;
2097 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2098 dest_scan ++;
2099 dest_scan ++;
2100 src_scan ++;
2101 }
2102 }
2103 void _CompositeRow_8bppRgb2Rgba_NoBlend(uint8_t* dest_scan, const uint8_t* src_s can, int width,
2104 FX_DWORD* pPalette, const uint8_t* clip_ scan,
2105 uint8_t* dest_alpha_scan, const uint8_t* src_alpha_scan)
2106 {
2107 if (src_alpha_scan) {
2108 for (int col = 0; col < width; col ++) {
2109 FX_ARGB argb = pPalette[*src_scan];
2110 src_scan ++;
2111 int src_r = FXARGB_R(argb);
2112 int src_g = FXARGB_G(argb);
2113 int src_b = FXARGB_B(argb);
2114 uint8_t back_alpha = *dest_alpha_scan;
2115 if (back_alpha == 0) {
2116 if (clip_scan) {
2117 int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
2118 *dest_alpha_scan ++ = src_alpha;
2119 } else {
2120 *dest_alpha_scan ++ = *src_alpha_scan;
2121 }
2122 *dest_scan ++ = src_b;
2123 *dest_scan ++ = src_g;
2124 *dest_scan ++ = src_r;
2125 src_alpha_scan ++;
2126 continue;
2127 }
2128 uint8_t src_alpha;
2129 if (clip_scan == NULL) {
2130 src_alpha = *src_alpha_scan++;
2131 } else {
2132 src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
2133 }
2134 if (src_alpha == 0) {
2135 dest_scan += 3;
2136 dest_alpha_scan ++;
2137 continue;
2138 }
2139 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2140 *dest_alpha_scan ++ = dest_alpha;
2141 int alpha_ratio = src_alpha * 255 / dest_alpha;
2142 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2143 dest_scan ++;
2144 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2145 dest_scan ++;
2146 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2147 dest_scan ++;
2148 }
2149 } else
2150 for (int col = 0; col < width; col ++) {
2151 FX_ARGB argb = pPalette[*src_scan];
2152 int src_r = FXARGB_R(argb);
2153 int src_g = FXARGB_G(argb);
2154 int src_b = FXARGB_B(argb);
2155 if (clip_scan == NULL || clip_scan[col] == 255) {
2156 *dest_scan++ = src_b;
2157 *dest_scan++ = src_g;
2158 *dest_scan++ = src_r;
2159 *dest_alpha_scan++ = 255;
2160 src_scan ++;
2161 continue;
2162 }
2163 int src_alpha = clip_scan[col];
2164 if (src_alpha == 0) {
2165 dest_scan += 3;
2166 dest_alpha_scan ++;
2167 src_scan ++;
2168 continue;
2169 }
2170 int back_alpha = *dest_alpha_scan;
2171 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2172 *dest_alpha_scan ++ = dest_alpha;
2173 int alpha_ratio = src_alpha * 255 / dest_alpha;
2174 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2175 dest_scan ++;
2176 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2177 dest_scan ++;
2178 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2179 dest_scan ++;
2180 src_scan ++;
2181 }
2182 }
2183 inline void _CompositeRow_1bppRgb2Argb_NoBlend(uint8_t* dest_scan, const uint8_t * src_scan, int src_left, int width,
2184 FX_DWORD* pPalette, const uint8_t* clip_scan)
2185 {
2186 int reset_r, reset_g, reset_b;
2187 int set_r, set_g, set_b;
2188 reset_r = FXARGB_R(pPalette[0]); 3664 reset_r = FXARGB_R(pPalette[0]);
2189 reset_g = FXARGB_G(pPalette[0]); 3665 reset_g = FXARGB_G(pPalette[0]);
2190 reset_b = FXARGB_B(pPalette[0]); 3666 reset_b = FXARGB_B(pPalette[0]);
2191 set_r = FXARGB_R(pPalette[1]); 3667 set_r = FXARGB_R(pPalette[1]);
2192 set_g = FXARGB_G(pPalette[1]); 3668 set_g = FXARGB_G(pPalette[1]);
2193 set_b = FXARGB_B(pPalette[1]); 3669 set_b = FXARGB_B(pPalette[1]);
2194 for (int col = 0; col < width; col ++) { 3670 } else {
2195 int src_r, src_g, src_b; 3671 reset_r = reset_g = reset_b = 0;
2196 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) { 3672 set_r = set_g = set_b = 255;
2197 src_r = set_r; 3673 }
2198 src_g = set_g; 3674 for (int col = 0; col < width; col++) {
2199 src_b = set_b; 3675 int src_r, src_g, src_b;
3676 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
3677 src_r = set_r;
3678 src_g = set_g;
3679 src_b = set_b;
3680 } else {
3681 src_r = reset_r;
3682 src_g = reset_g;
3683 src_b = reset_b;
3684 }
3685 if (clip_scan == NULL || clip_scan[col] == 255) {
3686 dest_scan[2] = FX_GAMMA(src_b);
3687 dest_scan[1] = FX_GAMMA(src_g);
3688 dest_scan[0] = FX_GAMMA(src_r);
3689 dest_scan[3] = 255;
3690 dest_scan += 4;
3691 continue;
3692 }
3693 int src_alpha = clip_scan[col];
3694 if (src_alpha == 0) {
3695 dest_scan += 4;
3696 continue;
3697 }
3698 int back_alpha = dest_scan[3];
3699 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
3700 dest_scan[3] = dest_alpha;
3701 int alpha_ratio = src_alpha * 255 / dest_alpha;
3702 dest_scan[2] =
3703 FXDIB_ALPHA_MERGE(dest_scan[2], FX_GAMMA(src_b), alpha_ratio);
3704 dest_scan[1] =
3705 FXDIB_ALPHA_MERGE(dest_scan[1], FX_GAMMA(src_g), alpha_ratio);
3706 dest_scan[0] =
3707 FXDIB_ALPHA_MERGE(dest_scan[0], FX_GAMMA(src_r), alpha_ratio);
3708 dest_scan += 4;
3709 }
3710 }
3711 void _CompositeRow_ByteMask2Argb_RgbByteOrder(uint8_t* dest_scan,
3712 const uint8_t* src_scan,
3713 int mask_alpha,
3714 int src_r,
3715 int src_g,
3716 int src_b,
3717 int pixel_count,
3718 int blend_type,
3719 const uint8_t* clip_scan) {
3720 for (int col = 0; col < pixel_count; col++) {
3721 int src_alpha;
3722 if (clip_scan) {
3723 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
3724 } else {
3725 src_alpha = mask_alpha * src_scan[col] / 255;
3726 }
3727 uint8_t back_alpha = dest_scan[3];
3728 if (back_alpha == 0) {
3729 FXARGB_SETRGBORDERDIB(dest_scan,
3730 FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
3731 dest_scan += 4;
3732 continue;
3733 }
3734 if (src_alpha == 0) {
3735 dest_scan += 4;
3736 continue;
3737 }
3738 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
3739 dest_scan[3] = dest_alpha;
3740 int alpha_ratio = src_alpha * 255 / dest_alpha;
3741 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3742 int blended_colors[3];
3743 uint8_t src_scan[3];
3744 uint8_t dest_scan_o[3];
3745 src_scan[0] = src_b;
3746 src_scan[1] = src_g;
3747 src_scan[2] = src_r;
3748 dest_scan_o[0] = dest_scan[2];
3749 dest_scan_o[1] = dest_scan[1];
3750 dest_scan_o[2] = dest_scan[0];
3751 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3752 dest_scan[2] =
3753 FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], alpha_ratio);
3754 dest_scan[1] =
3755 FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], alpha_ratio);
3756 dest_scan[0] =
3757 FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], alpha_ratio);
3758 } else if (blend_type) {
3759 int blended = _BLEND(blend_type, dest_scan[2], src_b);
3760 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
3761 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, alpha_ratio);
3762 blended = _BLEND(blend_type, dest_scan[1], src_g);
3763 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
3764 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, alpha_ratio);
3765 blended = _BLEND(blend_type, dest_scan[0], src_r);
3766 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
3767 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, alpha_ratio);
3768 } else {
3769 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, alpha_ratio);
3770 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, alpha_ratio);
3771 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, alpha_ratio);
3772 }
3773 dest_scan += 4;
3774 }
3775 }
3776 void _CompositeRow_ByteMask2Rgb_RgbByteOrder(uint8_t* dest_scan,
3777 const uint8_t* src_scan,
3778 int mask_alpha,
3779 int src_r,
3780 int src_g,
3781 int src_b,
3782 int pixel_count,
3783 int blend_type,
3784 int Bpp,
3785 const uint8_t* clip_scan) {
3786 for (int col = 0; col < pixel_count; col++) {
3787 int src_alpha;
3788 if (clip_scan) {
3789 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
3790 } else {
3791 src_alpha = mask_alpha * src_scan[col] / 255;
3792 }
3793 if (src_alpha == 0) {
3794 dest_scan += Bpp;
3795 continue;
3796 }
3797 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3798 int blended_colors[3];
3799 uint8_t src_scan[3];
3800 uint8_t dest_scan_o[3];
3801 src_scan[0] = src_b;
3802 src_scan[1] = src_g;
3803 src_scan[2] = src_r;
3804 dest_scan_o[0] = dest_scan[2];
3805 dest_scan_o[1] = dest_scan[1];
3806 dest_scan_o[2] = dest_scan[0];
3807 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3808 dest_scan[2] =
3809 FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], src_alpha);
3810 dest_scan[1] =
3811 FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], src_alpha);
3812 dest_scan[0] =
3813 FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], src_alpha);
3814 } else if (blend_type) {
3815 int blended = _BLEND(blend_type, dest_scan[2], src_b);
3816 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, src_alpha);
3817 blended = _BLEND(blend_type, dest_scan[1], src_g);
3818 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, src_alpha);
3819 blended = _BLEND(blend_type, dest_scan[0], src_r);
3820 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, src_alpha);
3821 } else {
3822 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, src_alpha);
3823 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, src_alpha);
3824 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, src_alpha);
3825 }
3826 dest_scan += Bpp;
3827 }
3828 }
3829 void _CompositeRow_BitMask2Argb_RgbByteOrder(uint8_t* dest_scan,
3830 const uint8_t* src_scan,
3831 int mask_alpha,
3832 int src_r,
3833 int src_g,
3834 int src_b,
3835 int src_left,
3836 int pixel_count,
3837 int blend_type,
3838 const uint8_t* clip_scan) {
3839 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL &&
3840 mask_alpha == 255) {
3841 FX_ARGB argb = FXARGB_MAKE(0xff, src_r, src_g, src_b);
3842 for (int col = 0; col < pixel_count; col++) {
3843 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
3844 FXARGB_SETRGBORDERDIB(dest_scan, argb);
3845 }
3846 dest_scan += 4;
3847 }
3848 return;
3849 }
3850 for (int col = 0; col < pixel_count; col++) {
3851 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
3852 dest_scan += 4;
3853 continue;
3854 }
3855 int src_alpha;
3856 if (clip_scan) {
3857 src_alpha = mask_alpha * clip_scan[col] / 255;
3858 } else {
3859 src_alpha = mask_alpha;
3860 }
3861 uint8_t back_alpha = dest_scan[3];
3862 if (back_alpha == 0) {
3863 FXARGB_SETRGBORDERDIB(dest_scan,
3864 FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
3865 dest_scan += 4;
3866 continue;
3867 }
3868 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
3869 dest_scan[3] = dest_alpha;
3870 int alpha_ratio = src_alpha * 255 / dest_alpha;
3871 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3872 int blended_colors[3];
3873 uint8_t src_scan[3];
3874 uint8_t dest_scan_o[3];
3875 src_scan[0] = src_b;
3876 src_scan[1] = src_g;
3877 src_scan[2] = src_r;
3878 dest_scan_o[0] = dest_scan[2];
3879 dest_scan_o[1] = dest_scan[1];
3880 dest_scan_o[2] = dest_scan[0];
3881 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3882 dest_scan[2] =
3883 FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], alpha_ratio);
3884 dest_scan[1] =
3885 FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], alpha_ratio);
3886 dest_scan[0] =
3887 FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], alpha_ratio);
3888 } else if (blend_type) {
3889 int blended = _BLEND(blend_type, dest_scan[2], src_b);
3890 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
3891 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, alpha_ratio);
3892 blended = _BLEND(blend_type, dest_scan[1], src_g);
3893 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
3894 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, alpha_ratio);
3895 blended = _BLEND(blend_type, dest_scan[0], src_r);
3896 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
3897 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, alpha_ratio);
3898 } else {
3899 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, alpha_ratio);
3900 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, alpha_ratio);
3901 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, alpha_ratio);
3902 }
3903 dest_scan += 4;
3904 }
3905 }
3906 void _CompositeRow_BitMask2Rgb_RgbByteOrder(uint8_t* dest_scan,
3907 const uint8_t* src_scan,
3908 int mask_alpha,
3909 int src_r,
3910 int src_g,
3911 int src_b,
3912 int src_left,
3913 int pixel_count,
3914 int blend_type,
3915 int Bpp,
3916 const uint8_t* clip_scan) {
3917 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL &&
3918 mask_alpha == 255) {
3919 for (int col = 0; col < pixel_count; col++) {
3920 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8))) {
3921 dest_scan[2] = src_b;
3922 dest_scan[1] = src_g;
3923 dest_scan[0] = src_r;
3924 }
3925 dest_scan += Bpp;
3926 }
3927 return;
3928 }
3929 for (int col = 0; col < pixel_count; col++) {
3930 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)))) {
3931 dest_scan += Bpp;
3932 continue;
3933 }
3934 int src_alpha;
3935 if (clip_scan) {
3936 src_alpha = mask_alpha * clip_scan[col] / 255;
3937 } else {
3938 src_alpha = mask_alpha;
3939 }
3940 if (src_alpha == 0) {
3941 dest_scan += Bpp;
3942 continue;
3943 }
3944 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3945 int blended_colors[3];
3946 uint8_t src_scan[3];
3947 uint8_t dest_scan_o[3];
3948 src_scan[0] = src_b;
3949 src_scan[1] = src_g;
3950 src_scan[2] = src_r;
3951 dest_scan_o[0] = dest_scan[2];
3952 dest_scan_o[1] = dest_scan[1];
3953 dest_scan_o[2] = dest_scan[0];
3954 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3955 dest_scan[2] =
3956 FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], src_alpha);
3957 dest_scan[1] =
3958 FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], src_alpha);
3959 dest_scan[0] =
3960 FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], src_alpha);
3961 } else if (blend_type) {
3962 int back_color = FX_GAMMA(dest_scan[2]);
3963 int blended = _BLEND(blend_type, back_color, src_b);
3964 dest_scan[2] =
3965 FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
3966 back_color = FX_GAMMA(dest_scan[1]);
3967 blended = _BLEND(blend_type, back_color, src_g);
3968 dest_scan[1] =
3969 FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
3970 back_color = FX_GAMMA(dest_scan[0]);
3971 blended = _BLEND(blend_type, back_color, src_r);
3972 dest_scan[0] =
3973 FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blended, src_alpha));
3974 } else {
3975 dest_scan[2] = FX_GAMMA_INVERSE(
3976 FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), src_b, src_alpha));
3977 dest_scan[1] = FX_GAMMA_INVERSE(
3978 FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), src_g, src_alpha));
3979 dest_scan[0] = FX_GAMMA_INVERSE(
3980 FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), src_r, src_alpha));
3981 }
3982 dest_scan += Bpp;
3983 }
3984 }
3985 inline FX_BOOL _ScanlineCompositor_InitSourceMask(FXDIB_Format dest_format,
3986 int alpha_flag,
3987 FX_DWORD mask_color,
3988 int& mask_alpha,
3989 int& mask_red,
3990 int& mask_green,
3991 int& mask_blue,
3992 int& mask_black,
3993 void* icc_module,
3994 void* pIccTransform) {
3995 ICodec_IccModule* pIccModule = (ICodec_IccModule*)icc_module;
3996 if (alpha_flag >> 8) {
3997 mask_alpha = alpha_flag & 0xff;
3998 mask_red = FXSYS_GetCValue(mask_color);
3999 mask_green = FXSYS_GetMValue(mask_color);
4000 mask_blue = FXSYS_GetYValue(mask_color);
4001 mask_black = FXSYS_GetKValue(mask_color);
4002 } else {
4003 mask_alpha = FXARGB_A(mask_color);
4004 mask_red = FXARGB_R(mask_color);
4005 mask_green = FXARGB_G(mask_color);
4006 mask_blue = FXARGB_B(mask_color);
4007 }
4008 if (dest_format == FXDIB_8bppMask) {
4009 return TRUE;
4010 }
4011 if ((dest_format & 0xff) == 8) {
4012 if (pIccTransform) {
4013 mask_color = (alpha_flag >> 8) ? FXCMYK_TODIB(mask_color)
4014 : FXARGB_TODIB(mask_color);
4015 uint8_t* gray_p = (uint8_t*)&mask_color;
4016 pIccModule->TranslateScanline(pIccTransform, gray_p, gray_p, 1);
4017 mask_red = dest_format & 0x0400 ? FX_CCOLOR(gray_p[0]) : gray_p[0];
4018 } else {
4019 if (alpha_flag >> 8) {
4020 uint8_t r, g, b;
4021 AdobeCMYK_to_sRGB1(mask_red, mask_green, mask_blue, mask_black, r, g,
4022 b);
4023 mask_red = FXRGB2GRAY(r, g, b);
4024 } else {
4025 mask_red = FXRGB2GRAY(mask_red, mask_green, mask_blue);
4026 }
4027 if (dest_format & 0x0400) {
4028 mask_red = FX_CCOLOR(mask_red);
4029 }
4030 }
4031 } else {
4032 uint8_t* mask_color_p = (uint8_t*)&mask_color;
4033 mask_color =
4034 (alpha_flag >> 8) ? FXCMYK_TODIB(mask_color) : FXARGB_TODIB(mask_color);
4035 if (pIccTransform) {
4036 pIccModule->TranslateScanline(pIccTransform, mask_color_p, mask_color_p,
4037 1);
4038 mask_red = mask_color_p[2];
4039 mask_green = mask_color_p[1];
4040 mask_blue = mask_color_p[0];
4041 } else if (alpha_flag >> 8) {
4042 AdobeCMYK_to_sRGB1(mask_color_p[0], mask_color_p[1], mask_color_p[2],
4043 mask_color_p[3], mask_color_p[2], mask_color_p[1],
4044 mask_color_p[0]);
4045 mask_red = mask_color_p[2];
4046 mask_green = mask_color_p[1];
4047 mask_blue = mask_color_p[0];
4048 }
4049 }
4050 return TRUE;
4051 }
4052 inline void _ScanlineCompositor_InitSourcePalette(FXDIB_Format src_format,
4053 FXDIB_Format dest_format,
4054 FX_DWORD*& pDestPalette,
4055 FX_DWORD* pSrcPalette,
4056 void* icc_module,
4057 void* pIccTransform) {
4058 ICodec_IccModule* pIccModule = (ICodec_IccModule*)icc_module;
4059 FX_BOOL isSrcCmyk = src_format & 0x0400 ? TRUE : FALSE;
4060 FX_BOOL isDstCmyk = dest_format & 0x0400 ? TRUE : FALSE;
4061 pDestPalette = NULL;
4062 if (pIccTransform) {
4063 if (pSrcPalette) {
4064 if ((dest_format & 0xff) == 8) {
4065 int pal_count = 1 << (src_format & 0xff);
4066 uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
4067 pDestPalette = (FX_DWORD*)gray_pal;
4068 for (int i = 0; i < pal_count; i++) {
4069 FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i])
4070 : FXARGB_TODIB(pSrcPalette[i]);
4071 pIccModule->TranslateScanline(pIccTransform, gray_pal,
4072 (const uint8_t*)&color, 1);
4073 gray_pal++;
4074 }
4075 } else {
4076 int palsize = 1 << (src_format & 0xff);
4077 pDestPalette = FX_Alloc(FX_DWORD, palsize);
4078 for (int i = 0; i < palsize; i++) {
4079 FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i])
4080 : FXARGB_TODIB(pSrcPalette[i]);
4081 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&color,
4082 (const uint8_t*)&color, 1);
4083 pDestPalette[i] =
4084 isDstCmyk ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
4085 }
4086 }
4087 } else {
4088 int pal_count = 1 << (src_format & 0xff);
4089 uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
4090 if (pal_count == 2) {
4091 gray_pal[0] = 0;
4092 gray_pal[1] = 255;
4093 } else {
4094 for (int i = 0; i < pal_count; i++) {
4095 gray_pal[i] = i;
4096 }
4097 }
4098 if ((dest_format & 0xff) == 8) {
4099 pIccModule->TranslateScanline(pIccTransform, gray_pal, gray_pal,
4100 pal_count);
4101 pDestPalette = (FX_DWORD*)gray_pal;
4102 } else {
4103 pDestPalette = FX_Alloc(FX_DWORD, pal_count);
4104 for (int i = 0; i < pal_count; i++) {
4105 pIccModule->TranslateScanline(
4106 pIccTransform, (uint8_t*)&pDestPalette[i], &gray_pal[i], 1);
4107 pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(pDestPalette[i])
4108 : FXARGB_TODIB(pDestPalette[i]);
4109 }
4110 FX_Free(gray_pal);
4111 }
4112 }
4113 } else {
4114 if (pSrcPalette) {
4115 if ((dest_format & 0xff) == 8) {
4116 int pal_count = 1 << (src_format & 0xff);
4117 uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
4118 pDestPalette = (FX_DWORD*)gray_pal;
4119 if (isSrcCmyk) {
4120 for (int i = 0; i < pal_count; i++) {
4121 FX_CMYK cmyk = pSrcPalette[i];
4122 uint8_t r, g, b;
4123 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
4124 FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r,
4125 g, b);
4126 *gray_pal++ = FXRGB2GRAY(r, g, b);
4127 }
4128 } else
4129 for (int i = 0; i < pal_count; i++) {
4130 FX_ARGB argb = pSrcPalette[i];
4131 *gray_pal++ =
4132 FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb));
4133 }
4134 } else {
4135 int palsize = 1 << (src_format & 0xff);
4136 pDestPalette = FX_Alloc(FX_DWORD, palsize);
4137 if (isDstCmyk == isSrcCmyk) {
4138 FXSYS_memcpy(pDestPalette, pSrcPalette, palsize * sizeof(FX_DWORD));
2200 } else { 4139 } else {
2201 src_r = reset_r; 4140 for (int i = 0; i < palsize; i++) {
2202 src_g = reset_g; 4141 FX_CMYK cmyk = pSrcPalette[i];
2203 src_b = reset_b; 4142 uint8_t r, g, b;
2204 } 4143 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
2205 if (clip_scan == NULL || clip_scan[col] == 255) { 4144 FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r,
2206 *dest_scan++ = src_b; 4145 g, b);
2207 *dest_scan++ = src_g; 4146 pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
2208 *dest_scan++ = src_r; 4147 }
4148 }
4149 }
4150 } else {
4151 if ((dest_format & 0xff) == 8) {
4152 int pal_count = 1 << (src_format & 0xff);
4153 uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
4154 if (pal_count == 2) {
4155 gray_pal[0] = 0;
4156 gray_pal[1] = 255;
4157 } else {
4158 for (int i = 0; i < pal_count; i++) {
4159 gray_pal[i] = i;
4160 }
4161 }
4162 pDestPalette = (FX_DWORD*)gray_pal;
4163 } else {
4164 int palsize = 1 << (src_format & 0xff);
4165 pDestPalette = FX_Alloc(FX_DWORD, palsize);
4166 if (palsize == 2) {
4167 pDestPalette[0] = isSrcCmyk ? 255 : 0xff000000;
4168 pDestPalette[1] = isSrcCmyk ? 0 : 0xffffffff;
4169 } else {
4170 for (int i = 0; i < palsize; i++) {
4171 pDestPalette[i] = isSrcCmyk ? FX_CCOLOR(i) : (i * 0x10101);
4172 }
4173 }
4174 if (isSrcCmyk != isDstCmyk) {
4175 for (int i = 0; i < palsize; i++) {
4176 FX_CMYK cmyk = pDestPalette[i];
4177 uint8_t r, g, b;
4178 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
4179 FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r,
4180 g, b);
4181 pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
4182 }
4183 }
4184 }
4185 }
4186 }
4187 }
4188 CFX_ScanlineCompositor::CFX_ScanlineCompositor() {
4189 m_pSrcPalette = NULL;
4190 m_pCacheScanline = NULL;
4191 m_CacheSize = 0;
4192 m_bRgbByteOrder = FALSE;
4193 m_BlendType = FXDIB_BLEND_NORMAL;
4194 }
4195 CFX_ScanlineCompositor::~CFX_ScanlineCompositor() {
4196 if (m_pSrcPalette) {
4197 FX_Free(m_pSrcPalette);
4198 }
4199 if (m_pCacheScanline) {
4200 FX_Free(m_pCacheScanline);
4201 }
4202 }
4203 FX_BOOL CFX_ScanlineCompositor::Init(FXDIB_Format dest_format,
4204 FXDIB_Format src_format,
4205 int32_t width,
4206 FX_DWORD* pSrcPalette,
4207 FX_DWORD mask_color,
4208 int blend_type,
4209 FX_BOOL bClip,
4210 FX_BOOL bRgbByteOrder,
4211 int alpha_flag,
4212 void* pIccTransform) {
4213 m_SrcFormat = src_format;
4214 m_DestFormat = dest_format;
4215 m_BlendType = blend_type;
4216 m_bRgbByteOrder = bRgbByteOrder;
4217 ICodec_IccModule* pIccModule = NULL;
4218 if (CFX_GEModule::Get()->GetCodecModule()) {
4219 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
4220 }
4221 if (pIccModule == NULL) {
4222 pIccTransform = NULL;
4223 }
4224 m_pIccTransform = pIccTransform;
4225 if ((dest_format & 0xff) == 1) {
4226 return FALSE;
4227 }
4228 if (m_SrcFormat == FXDIB_1bppMask || m_SrcFormat == FXDIB_8bppMask) {
4229 return _ScanlineCompositor_InitSourceMask(
4230 dest_format, alpha_flag, mask_color, m_MaskAlpha, m_MaskRed,
4231 m_MaskGreen, m_MaskBlue, m_MaskBlack, pIccModule, pIccTransform);
4232 }
4233 if (pIccTransform == NULL && (~src_format & 0x0400) &&
4234 (dest_format & 0x0400)) {
4235 return FALSE;
4236 }
4237 if ((m_SrcFormat & 0xff) <= 8) {
4238 if (dest_format == FXDIB_8bppMask) {
4239 return TRUE;
4240 }
4241 _ScanlineCompositor_InitSourcePalette(src_format, dest_format,
4242 m_pSrcPalette, pSrcPalette,
4243 pIccModule, pIccTransform);
4244 m_Transparency =
4245 (dest_format == FXDIB_Argb ? 1 : 0) + (dest_format & 0x0200 ? 2 : 0) +
4246 (dest_format & 0x0400 ? 4 : 0) + ((src_format & 0xff) == 1 ? 8 : 0);
4247 return TRUE;
4248 }
4249 m_Transparency = (src_format & 0x0200 ? 0 : 1) +
4250 (dest_format & 0x0200 ? 0 : 2) +
4251 (blend_type == FXDIB_BLEND_NORMAL ? 4 : 0) +
4252 (bClip ? 8 : 0) + (src_format & 0x0400 ? 16 : 0) +
4253 (dest_format & 0x0400 ? 32 : 0) + (pIccTransform ? 64 : 0);
4254 return TRUE;
4255 }
4256 void CFX_ScanlineCompositor::CompositeRgbBitmapLine(
4257 uint8_t* dest_scan,
4258 const uint8_t* src_scan,
4259 int width,
4260 const uint8_t* clip_scan,
4261 const uint8_t* src_extra_alpha,
4262 uint8_t* dst_extra_alpha) {
4263 int src_Bpp = (m_SrcFormat & 0xff) >> 3;
4264 int dest_Bpp = (m_DestFormat & 0xff) >> 3;
4265 if (m_bRgbByteOrder) {
4266 switch (m_Transparency) {
4267 case 0:
4268 case 4:
4269 case 8:
4270 case 12:
4271 _CompositeRow_Argb2Argb_RgbByteOrder(dest_scan, src_scan, width,
4272 m_BlendType, clip_scan);
4273 break;
4274 case 1:
4275 _CompositeRow_Rgb2Argb_Blend_NoClip_RgbByteOrder(
4276 dest_scan, src_scan, width, m_BlendType, src_Bpp);
4277 break;
4278 case 2:
4279 case 10:
4280 _CompositeRow_Argb2Rgb_Blend_RgbByteOrder(
4281 dest_scan, src_scan, width, m_BlendType, dest_Bpp, clip_scan);
4282 break;
4283 case 3:
4284 _CompositeRow_Rgb2Rgb_Blend_NoClip_RgbByteOrder(
4285 dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp);
4286 break;
4287 case 5:
4288 _CompositeRow_Rgb2Argb_NoBlend_NoClip_RgbByteOrder(dest_scan, src_scan,
4289 width, src_Bpp);
4290 break;
4291 case 6:
4292 case 14:
4293 _CompositeRow_Argb2Rgb_NoBlend_RgbByteOrder(dest_scan, src_scan, width,
4294 dest_Bpp, clip_scan);
4295 break;
4296 case 7:
4297 _CompositeRow_Rgb2Rgb_NoBlend_NoClip_RgbByteOrder(
4298 dest_scan, src_scan, width, dest_Bpp, src_Bpp);
4299 break;
4300 case 9:
4301 _CompositeRow_Rgb2Argb_Blend_Clip_RgbByteOrder(
4302 dest_scan, src_scan, width, m_BlendType, src_Bpp, clip_scan);
4303 break;
4304 case 11:
4305 _CompositeRow_Rgb2Rgb_Blend_Clip_RgbByteOrder(
4306 dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp,
4307 clip_scan);
4308 break;
4309 case 13:
4310 _CompositeRow_Rgb2Argb_NoBlend_Clip_RgbByteOrder(
4311 dest_scan, src_scan, width, src_Bpp, clip_scan);
4312 break;
4313 case 15:
4314 _CompositeRow_Rgb2Rgb_NoBlend_Clip_RgbByteOrder(
4315 dest_scan, src_scan, width, dest_Bpp, src_Bpp, clip_scan);
4316 break;
4317 }
4318 return;
4319 }
4320 if (m_DestFormat == FXDIB_8bppMask) {
4321 if (m_SrcFormat & 0x0200) {
4322 if (m_SrcFormat == FXDIB_Argb) {
4323 _CompositeRow_Argb2Mask(dest_scan, src_scan, width, clip_scan);
4324 } else {
4325 _CompositeRow_Rgba2Mask(dest_scan, src_extra_alpha, width, clip_scan);
4326 }
4327 } else {
4328 _CompositeRow_Rgb2Mask(dest_scan, src_scan, width, clip_scan);
4329 }
4330 } else if ((m_DestFormat & 0xff) == 8) {
4331 if (m_DestFormat & 0x0400) {
4332 for (int i = 0; i < width; i++) {
4333 *dest_scan = ~*dest_scan;
4334 dest_scan++;
4335 }
4336 }
4337 if (m_SrcFormat & 0x0200) {
4338 if (m_DestFormat & 0x0200) {
4339 _CompositeRow_Argb2Graya(dest_scan, src_scan, width, m_BlendType,
4340 clip_scan, src_extra_alpha, dst_extra_alpha,
4341 m_pIccTransform);
4342 } else {
4343 _CompositeRow_Argb2Gray(dest_scan, src_scan, width, m_BlendType,
4344 clip_scan, src_extra_alpha, m_pIccTransform);
4345 }
4346 } else {
4347 if (m_DestFormat & 0x0200) {
4348 _CompositeRow_Rgb2Graya(dest_scan, src_scan, src_Bpp, width,
4349 m_BlendType, clip_scan, dst_extra_alpha,
4350 m_pIccTransform);
4351 } else {
4352 _CompositeRow_Rgb2Gray(dest_scan, src_scan, src_Bpp, width, m_BlendType,
4353 clip_scan, m_pIccTransform);
4354 }
4355 }
4356 if (m_DestFormat & 0x0400) {
4357 for (int i = 0; i < width; i++) {
4358 *dest_scan = ~*dest_scan;
4359 dest_scan++;
4360 }
4361 }
4362 } else {
4363 int dest_Size = width * dest_Bpp + 4;
4364 if (dest_Size > m_CacheSize) {
4365 m_pCacheScanline = FX_Realloc(uint8_t, m_pCacheScanline, dest_Size);
4366 if (!m_pCacheScanline) {
4367 return;
4368 }
4369 m_CacheSize = dest_Size;
4370 }
4371 switch (m_Transparency) {
4372 case 0:
4373 case 4:
4374 case 8:
4375 case 4 + 8: {
4376 _CompositeRow_Argb2Argb(dest_scan, src_scan, width, m_BlendType,
4377 clip_scan, dst_extra_alpha, src_extra_alpha);
4378 } break;
4379 case 64:
4380 case 4 + 64:
4381 case 8 + 64:
4382 case 4 + 8 + 64: {
4383 _CompositeRow_Argb2Argb_Transform(
4384 dest_scan, src_scan, width, m_BlendType, clip_scan, dst_extra_alpha,
4385 src_extra_alpha, m_pCacheScanline, m_pIccTransform);
4386 } break;
4387 case 1:
4388 _CompositeRow_Rgb2Argb_Blend_NoClip(
4389 dest_scan, src_scan, width, m_BlendType, src_Bpp, dst_extra_alpha);
4390 break;
4391 case 1 + 64:
4392 _CompositeRow_Rgb2Argb_Blend_NoClip_Transform(
4393 dest_scan, src_scan, width, m_BlendType, src_Bpp, dst_extra_alpha,
4394 m_pCacheScanline, m_pIccTransform);
4395 break;
4396 case 1 + 8:
4397 _CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_scan, width,
4398 m_BlendType, src_Bpp, clip_scan,
4399 dst_extra_alpha);
4400 break;
4401 case 1 + 8 + 64:
4402 _CompositeRow_Rgb2Argb_Blend_Clip_Transform(
4403 dest_scan, src_scan, width, m_BlendType, src_Bpp, clip_scan,
4404 dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
4405 break;
4406 case 1 + 4:
4407 _CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_scan, width,
4408 src_Bpp, dst_extra_alpha);
4409 break;
4410 case 1 + 4 + 64:
4411 _CompositeRow_Rgb2Argb_NoBlend_NoClip_Transform(
4412 dest_scan, src_scan, width, src_Bpp, dst_extra_alpha,
4413 m_pCacheScanline, m_pIccTransform);
4414 break;
4415 case 1 + 4 + 8:
4416 _CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_scan, width, src_Bpp,
4417 clip_scan, dst_extra_alpha);
4418 break;
4419 case 1 + 4 + 8 + 64:
4420 _CompositeRow_Rgb2Argb_NoBlend_Clip_Transform(
4421 dest_scan, src_scan, width, src_Bpp, clip_scan, dst_extra_alpha,
4422 m_pCacheScanline, m_pIccTransform);
4423 break;
4424 case 2:
4425 case 2 + 8:
4426 _CompositeRow_Argb2Rgb_Blend(dest_scan, src_scan, width, m_BlendType,
4427 dest_Bpp, clip_scan, src_extra_alpha);
4428 break;
4429 case 2 + 64:
4430 case 2 + 8 + 64:
4431 _CompositeRow_Argb2Rgb_Blend_Transform(
4432 dest_scan, src_scan, width, m_BlendType, dest_Bpp, clip_scan,
4433 src_extra_alpha, m_pCacheScanline, m_pIccTransform);
4434 break;
4435 case 2 + 4:
4436 case 2 + 4 + 8:
4437 _CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_scan, width, dest_Bpp,
4438 clip_scan, src_extra_alpha);
4439 break;
4440 case 2 + 4 + 64:
4441 case 2 + 4 + 8 + 64:
4442 _CompositeRow_Argb2Rgb_NoBlend_Transform(
4443 dest_scan, src_scan, width, dest_Bpp, clip_scan, src_extra_alpha,
4444 m_pCacheScanline, m_pIccTransform);
4445 break;
4446 case 1 + 2:
4447 _CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_scan, width,
4448 m_BlendType, dest_Bpp, src_Bpp);
4449 break;
4450 case 1 + 2 + 64:
4451 _CompositeRow_Rgb2Rgb_Blend_NoClip_Transform(
4452 dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp,
4453 m_pCacheScanline, m_pIccTransform);
4454 break;
4455 case 1 + 2 + 8:
4456 _CompositeRow_Rgb2Rgb_Blend_Clip(dest_scan, src_scan, width,
4457 m_BlendType, dest_Bpp, src_Bpp,
4458 clip_scan);
4459 break;
4460 case 1 + 2 + 8 + 64:
4461 _CompositeRow_Rgb2Rgb_Blend_Clip_Transform(
4462 dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp,
4463 clip_scan, m_pCacheScanline, m_pIccTransform);
4464 break;
4465 case 1 + 2 + 4:
4466 _CompositeRow_Rgb2Rgb_NoBlend_NoClip(dest_scan, src_scan, width,
4467 dest_Bpp, src_Bpp);
4468 break;
4469 case 1 + 2 + 4 + 64:
4470 _CompositeRow_Rgb2Rgb_NoBlend_NoClip_Transform(
4471 dest_scan, src_scan, width, dest_Bpp, src_Bpp, m_pCacheScanline,
4472 m_pIccTransform);
4473 break;
4474 case 1 + 2 + 4 + 8:
4475 _CompositeRow_Rgb2Rgb_NoBlend_Clip(dest_scan, src_scan, width, dest_Bpp,
4476 src_Bpp, clip_scan);
4477 break;
4478 case 1 + 2 + 4 + 8 + 64:
4479 _CompositeRow_Rgb2Rgb_NoBlend_Clip_Transform(
4480 dest_scan, src_scan, width, dest_Bpp, src_Bpp, clip_scan,
4481 m_pCacheScanline, m_pIccTransform);
4482 break;
4483 }
4484 }
4485 }
4486 void CFX_ScanlineCompositor::CompositePalBitmapLine(
4487 uint8_t* dest_scan,
4488 const uint8_t* src_scan,
4489 int src_left,
4490 int width,
4491 const uint8_t* clip_scan,
4492 const uint8_t* src_extra_alpha,
4493 uint8_t* dst_extra_alpha) {
4494 if (m_bRgbByteOrder) {
4495 if (m_SrcFormat == FXDIB_1bppRgb) {
4496 if (m_DestFormat == FXDIB_8bppRgb) {
4497 return;
4498 }
4499 if (m_DestFormat == FXDIB_Argb) {
4500 _CompositeRow_1bppRgb2Argb_NoBlend_RgbByteOrder(
4501 dest_scan, src_scan, src_left, width, m_pSrcPalette, clip_scan);
4502 } else {
4503 _CompositeRow_1bppRgb2Rgb_NoBlend_RgbByteOrder(
4504 dest_scan, src_scan, src_left, m_pSrcPalette, width,
4505 (m_DestFormat & 0xff) >> 3, clip_scan);
4506 }
4507 } else {
4508 if (m_DestFormat == FXDIB_8bppRgb) {
4509 return;
4510 }
4511 if (m_DestFormat == FXDIB_Argb) {
4512 _CompositeRow_8bppRgb2Argb_NoBlend_RgbByteOrder(
4513 dest_scan, src_scan, width, m_pSrcPalette, clip_scan);
4514 } else {
4515 _CompositeRow_8bppRgb2Rgb_NoBlend_RgbByteOrder(
4516 dest_scan, src_scan, m_pSrcPalette, width,
4517 (m_DestFormat & 0xff) >> 3, clip_scan);
4518 }
4519 }
4520 return;
4521 }
4522 if (m_DestFormat == FXDIB_8bppMask) {
4523 _CompositeRow_Rgb2Mask(dest_scan, src_scan, width, clip_scan);
4524 return;
4525 }
4526 if ((m_DestFormat & 0xff) == 8) {
4527 if (m_Transparency & 8) {
4528 if (m_DestFormat & 0x0200) {
4529 _CompositeRow_1bppPal2Graya(dest_scan, src_scan, src_left,
4530 (const uint8_t*)m_pSrcPalette, width,
4531 m_BlendType, clip_scan, dst_extra_alpha);
4532 } else {
4533 _CompositeRow_1bppPal2Gray(dest_scan, src_scan, src_left,
4534 (const uint8_t*)m_pSrcPalette, width,
4535 m_BlendType, clip_scan);
4536 }
4537 } else {
4538 if (m_DestFormat & 0x0200)
4539 _CompositeRow_8bppPal2Graya(
4540 dest_scan, src_scan, (const uint8_t*)m_pSrcPalette, width,
4541 m_BlendType, clip_scan, dst_extra_alpha, src_extra_alpha);
4542 else
4543 _CompositeRow_8bppPal2Gray(dest_scan, src_scan,
4544 (const uint8_t*)m_pSrcPalette, width,
4545 m_BlendType, clip_scan, src_extra_alpha);
4546 }
4547 } else {
4548 switch (m_Transparency) {
4549 case 1 + 2:
4550 _CompositeRow_8bppRgb2Argb_NoBlend(dest_scan, src_scan, width,
4551 m_pSrcPalette, clip_scan,
4552 src_extra_alpha);
4553 break;
4554 case 1 + 2 + 8:
4555 _CompositeRow_1bppRgb2Argb_NoBlend(dest_scan, src_scan, src_left, width,
4556 m_pSrcPalette, clip_scan);
4557 break;
4558 case 0:
4559 _CompositeRow_8bppRgb2Rgb_NoBlend(dest_scan, src_scan, m_pSrcPalette,
4560 width, (m_DestFormat & 0xff) >> 3,
4561 clip_scan, src_extra_alpha);
4562 break;
4563 case 0 + 8:
4564 _CompositeRow_1bppRgb2Rgb_NoBlend(
4565 dest_scan, src_scan, src_left, m_pSrcPalette, width,
4566 (m_DestFormat & 0xff) >> 3, clip_scan);
4567 break;
4568 case 0 + 2:
4569 _CompositeRow_8bppRgb2Rgb_NoBlend(dest_scan, src_scan, m_pSrcPalette,
4570 width, (m_DestFormat & 0xff) >> 3,
4571 clip_scan, src_extra_alpha);
4572 break;
4573 case 0 + 2 + 8:
4574 _CompositeRow_1bppRgb2Rgba_NoBlend(dest_scan, src_scan, src_left, width,
4575 m_pSrcPalette, clip_scan,
4576 dst_extra_alpha);
4577 break;
4578 break;
4579 }
4580 }
4581 }
4582 void CFX_ScanlineCompositor::CompositeByteMaskLine(uint8_t* dest_scan,
4583 const uint8_t* src_scan,
4584 int width,
4585 const uint8_t* clip_scan,
4586 uint8_t* dst_extra_alpha) {
4587 if (m_DestFormat == FXDIB_8bppMask) {
4588 _CompositeRow_ByteMask2Mask(dest_scan, src_scan, m_MaskAlpha, width,
4589 clip_scan);
4590 } else if ((m_DestFormat & 0xff) == 8) {
4591 if (m_DestFormat & 0x0200) {
4592 _CompositeRow_ByteMask2Graya(dest_scan, src_scan, m_MaskAlpha, m_MaskRed,
4593 width, clip_scan, dst_extra_alpha);
4594 } else {
4595 _CompositeRow_ByteMask2Gray(dest_scan, src_scan, m_MaskAlpha, m_MaskRed,
4596 width, clip_scan);
4597 }
4598 } else if (m_bRgbByteOrder) {
4599 if (m_DestFormat == FXDIB_Argb)
4600 _CompositeRow_ByteMask2Argb_RgbByteOrder(
4601 dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4602 width, m_BlendType, clip_scan);
4603 else
4604 _CompositeRow_ByteMask2Rgb_RgbByteOrder(
4605 dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4606 width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
4607 return;
4608 } else if (m_DestFormat == FXDIB_Argb)
4609 _CompositeRow_ByteMask2Argb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed,
4610 m_MaskGreen, m_MaskBlue, width, m_BlendType,
4611 clip_scan);
4612 else if (m_DestFormat == FXDIB_Rgb || m_DestFormat == FXDIB_Rgb32)
4613 _CompositeRow_ByteMask2Rgb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed,
4614 m_MaskGreen, m_MaskBlue, width, m_BlendType,
4615 (m_DestFormat & 0xff) >> 3, clip_scan);
4616 else if (m_DestFormat == FXDIB_Rgba)
4617 _CompositeRow_ByteMask2Rgba(dest_scan, src_scan, m_MaskAlpha, m_MaskRed,
4618 m_MaskGreen, m_MaskBlue, width, m_BlendType,
4619 clip_scan, dst_extra_alpha);
4620 }
4621 void CFX_ScanlineCompositor::CompositeBitMaskLine(uint8_t* dest_scan,
4622 const uint8_t* src_scan,
4623 int src_left,
4624 int width,
4625 const uint8_t* clip_scan,
4626 uint8_t* dst_extra_alpha) {
4627 if (m_DestFormat == FXDIB_8bppMask) {
4628 _CompositeRow_BitMask2Mask(dest_scan, src_scan, m_MaskAlpha, src_left,
4629 width, clip_scan);
4630 } else if ((m_DestFormat & 0xff) == 8) {
4631 if (m_DestFormat & 0x0200)
4632 _CompositeRow_BitMask2Graya(dest_scan, src_scan, m_MaskAlpha, m_MaskRed,
4633 src_left, width, clip_scan, dst_extra_alpha);
4634 else {
4635 _CompositeRow_BitMask2Gray(dest_scan, src_scan, m_MaskAlpha, m_MaskRed,
4636 src_left, width, clip_scan);
4637 }
4638 } else if (m_bRgbByteOrder) {
4639 if (m_DestFormat == FXDIB_Argb)
4640 _CompositeRow_BitMask2Argb_RgbByteOrder(
4641 dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4642 src_left, width, m_BlendType, clip_scan);
4643 else
4644 _CompositeRow_BitMask2Rgb_RgbByteOrder(
4645 dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4646 src_left, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
4647 return;
4648 } else if (m_DestFormat == FXDIB_Argb)
4649 _CompositeRow_BitMask2Argb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed,
4650 m_MaskGreen, m_MaskBlue, src_left, width,
4651 m_BlendType, clip_scan);
4652 else if (m_DestFormat == FXDIB_Rgb || m_DestFormat == FXDIB_Rgb32)
4653 _CompositeRow_BitMask2Rgb(
4654 dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4655 src_left, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
4656 }
4657 FX_BOOL CFX_DIBitmap::CompositeBitmap(int dest_left,
4658 int dest_top,
4659 int width,
4660 int height,
4661 const CFX_DIBSource* pSrcBitmap,
4662 int src_left,
4663 int src_top,
4664 int blend_type,
4665 const CFX_ClipRgn* pClipRgn,
4666 FX_BOOL bRgbByteOrder,
4667 void* pIccTransform) {
4668 if (m_pBuffer == NULL) {
4669 return FALSE;
4670 }
4671 ASSERT(!pSrcBitmap->IsAlphaMask());
4672 ASSERT(m_bpp >= 8);
4673 if (pSrcBitmap->IsAlphaMask() || m_bpp < 8) {
4674 return FALSE;
4675 }
4676 GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(),
4677 pSrcBitmap->GetHeight(), src_left, src_top, pClipRgn);
4678 if (width == 0 || height == 0) {
4679 return TRUE;
4680 }
4681 const CFX_DIBitmap* pClipMask = NULL;
4682 FX_RECT clip_box;
4683 if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
4684 ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
4685 pClipMask = pClipRgn->GetMask();
4686 clip_box = pClipRgn->GetBox();
4687 }
4688 CFX_ScanlineCompositor compositor;
4689 if (!compositor.Init(GetFormat(), pSrcBitmap->GetFormat(), width,
4690 pSrcBitmap->GetPalette(), 0, blend_type,
4691 pClipMask != NULL, bRgbByteOrder, 0, pIccTransform)) {
4692 return FALSE;
4693 }
4694 int dest_Bpp = m_bpp / 8;
4695 int src_Bpp = pSrcBitmap->GetBPP() / 8;
4696 FX_BOOL bRgb = src_Bpp > 1 && !pSrcBitmap->IsCmykImage();
4697 CFX_DIBitmap* pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
4698 for (int row = 0; row < height; row++) {
4699 uint8_t* dest_scan =
4700 m_pBuffer + (dest_top + row) * m_Pitch + dest_left * dest_Bpp;
4701 const uint8_t* src_scan =
4702 pSrcBitmap->GetScanline(src_top + row) + src_left * src_Bpp;
4703 const uint8_t* src_scan_extra_alpha =
4704 pSrcAlphaMask ? pSrcAlphaMask->GetScanline(src_top + row) + src_left
4705 : NULL;
4706 uint8_t* dst_scan_extra_alpha =
4707 m_pAlphaMask
4708 ? (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left
4709 : NULL;
4710 const uint8_t* clip_scan = NULL;
4711 if (pClipMask) {
4712 clip_scan = pClipMask->m_pBuffer +
4713 (dest_top + row - clip_box.top) * pClipMask->m_Pitch +
4714 (dest_left - clip_box.left);
4715 }
4716 if (bRgb) {
4717 compositor.CompositeRgbBitmapLine(dest_scan, src_scan, width, clip_scan,
4718 src_scan_extra_alpha,
4719 dst_scan_extra_alpha);
4720 } else {
4721 compositor.CompositePalBitmapLine(dest_scan, src_scan, src_left, width,
4722 clip_scan, src_scan_extra_alpha,
4723 dst_scan_extra_alpha);
4724 }
4725 }
4726 return TRUE;
4727 }
4728 FX_BOOL CFX_DIBitmap::CompositeMask(int dest_left,
4729 int dest_top,
4730 int width,
4731 int height,
4732 const CFX_DIBSource* pMask,
4733 FX_DWORD color,
4734 int src_left,
4735 int src_top,
4736 int blend_type,
4737 const CFX_ClipRgn* pClipRgn,
4738 FX_BOOL bRgbByteOrder,
4739 int alpha_flag,
4740 void* pIccTransform) {
4741 if (m_pBuffer == NULL) {
4742 return FALSE;
4743 }
4744 ASSERT(pMask->IsAlphaMask());
4745 ASSERT(m_bpp >= 8);
4746 if (!pMask->IsAlphaMask() || m_bpp < 8) {
4747 return FALSE;
4748 }
4749 GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(),
4750 pMask->GetHeight(), src_left, src_top, pClipRgn);
4751 if (width == 0 || height == 0) {
4752 return TRUE;
4753 }
4754 int src_alpha =
4755 (uint8_t)(alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
4756 if (src_alpha == 0) {
4757 return TRUE;
4758 }
4759 const CFX_DIBitmap* pClipMask = NULL;
4760 FX_RECT clip_box;
4761 if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
4762 ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
4763 pClipMask = pClipRgn->GetMask();
4764 clip_box = pClipRgn->GetBox();
4765 }
4766 int src_bpp = pMask->GetBPP();
4767 int Bpp = GetBPP() / 8;
4768 CFX_ScanlineCompositor compositor;
4769 if (!compositor.Init(GetFormat(), pMask->GetFormat(), width, NULL, color,
4770 blend_type, pClipMask != NULL, bRgbByteOrder, alpha_flag,
4771 pIccTransform)) {
4772 return FALSE;
4773 }
4774 for (int row = 0; row < height; row++) {
4775 uint8_t* dest_scan =
4776 m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp;
4777 const uint8_t* src_scan = pMask->GetScanline(src_top + row);
4778 uint8_t* dst_scan_extra_alpha =
4779 m_pAlphaMask
4780 ? (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left
4781 : NULL;
4782 const uint8_t* clip_scan = NULL;
4783 if (pClipMask) {
4784 clip_scan = pClipMask->m_pBuffer +
4785 (dest_top + row - clip_box.top) * pClipMask->m_Pitch +
4786 (dest_left - clip_box.left);
4787 }
4788 if (src_bpp == 1) {
4789 compositor.CompositeBitMaskLine(dest_scan, src_scan, src_left, width,
4790 clip_scan, dst_scan_extra_alpha);
4791 } else {
4792 compositor.CompositeByteMaskLine(dest_scan, src_scan + src_left, width,
4793 clip_scan, dst_scan_extra_alpha);
4794 }
4795 }
4796 return TRUE;
4797 }
4798 FX_BOOL CFX_DIBitmap::CompositeRect(int left,
4799 int top,
4800 int width,
4801 int height,
4802 FX_DWORD color,
4803 int alpha_flag,
4804 void* pIccTransform) {
4805 if (m_pBuffer == NULL) {
4806 return FALSE;
4807 }
4808 int src_alpha = (alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
4809 if (src_alpha == 0) {
4810 return TRUE;
4811 }
4812 FX_RECT rect(left, top, left + width, top + height);
4813 rect.Intersect(0, 0, m_Width, m_Height);
4814 if (rect.IsEmpty()) {
4815 return TRUE;
4816 }
4817 width = rect.Width();
4818 FX_DWORD dst_color;
4819 if (alpha_flag >> 8) {
4820 dst_color = FXCMYK_TODIB(color);
4821 } else {
4822 dst_color = FXARGB_TODIB(color);
4823 }
4824 uint8_t* color_p = (uint8_t*)&dst_color;
4825 if (m_bpp == 8) {
4826 uint8_t gray = 255;
4827 if (!IsAlphaMask()) {
4828 if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() &&
4829 CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
4830 ICodec_IccModule* pIccModule =
4831 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
4832 pIccModule->TranslateScanline(pIccTransform, &gray, color_p, 1);
4833 } else {
4834 if (alpha_flag >> 8) {
4835 uint8_t r, g, b;
4836 AdobeCMYK_to_sRGB1(color_p[0], color_p[1], color_p[2], color_p[3], r,
4837 g, b);
4838 gray = FXRGB2GRAY(r, g, b);
4839 } else {
4840 gray = (uint8_t)FXRGB2GRAY((int)color_p[2], color_p[1], color_p[0]);
4841 }
4842 }
4843 if (IsCmykImage()) {
4844 gray = ~gray;
4845 }
4846 }
4847 for (int row = rect.top; row < rect.bottom; row++) {
4848 uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left;
4849 if (src_alpha == 255) {
4850 FXSYS_memset(dest_scan, gray, width);
4851 } else
4852 for (int col = 0; col < width; col++) {
4853 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
4854 dest_scan++;
4855 }
4856 }
4857 return TRUE;
4858 }
4859 if (m_bpp == 1) {
4860 ASSERT(!IsCmykImage() && (uint8_t)(alpha_flag >> 8) == 0);
4861 int left_shift = rect.left % 8;
4862 int right_shift = rect.right % 8;
4863 int width = rect.right / 8 - rect.left / 8;
4864 int index = 0;
4865 if (m_pPalette == NULL) {
4866 index = ((uint8_t)color == 0xff) ? 1 : 0;
4867 } else {
4868 for (int i = 0; i < 2; i++)
4869 if (m_pPalette[i] == color) {
4870 index = i;
4871 }
4872 }
4873 for (int row = rect.top; row < rect.bottom; row++) {
4874 uint8_t* dest_scan_top = (uint8_t*)GetScanline(row) + rect.left / 8;
4875 uint8_t* dest_scan_top_r = (uint8_t*)GetScanline(row) + rect.right / 8;
4876 uint8_t left_flag = *dest_scan_top & (255 << (8 - left_shift));
4877 uint8_t right_flag = *dest_scan_top_r & (255 >> right_shift);
4878 if (width) {
4879 FXSYS_memset(dest_scan_top + 1, index ? 255 : 0, width - 1);
4880 if (!index) {
4881 *dest_scan_top &= left_flag;
4882 *dest_scan_top_r &= right_flag;
4883 } else {
4884 *dest_scan_top |= ~left_flag;
4885 *dest_scan_top_r |= ~right_flag;
4886 }
4887 } else {
4888 if (!index) {
4889 *dest_scan_top &= left_flag | right_flag;
4890 } else {
4891 *dest_scan_top |= ~(left_flag | right_flag);
4892 }
4893 }
4894 }
4895 return TRUE;
4896 }
4897 ASSERT(m_bpp >= 24);
4898 if (m_bpp < 24) {
4899 return FALSE;
4900 }
4901 if (pIccTransform && CFX_GEModule::Get()->GetCodecModule()) {
4902 ICodec_IccModule* pIccModule =
4903 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
4904 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1);
4905 } else {
4906 if (alpha_flag >> 8 && !IsCmykImage())
4907 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
4908 FXSYS_GetYValue(color), FXSYS_GetKValue(color),
4909 color_p[2], color_p[1], color_p[0]);
4910 else if (!(alpha_flag >> 8) && IsCmykImage()) {
4911 return FALSE;
4912 }
4913 }
4914 if (!IsCmykImage()) {
4915 color_p[3] = (uint8_t)src_alpha;
4916 }
4917 int Bpp = m_bpp / 8;
4918 FX_BOOL bAlpha = HasAlpha();
4919 FX_BOOL bArgb = GetFormat() == FXDIB_Argb ? TRUE : FALSE;
4920 if (src_alpha == 255) {
4921 for (int row = rect.top; row < rect.bottom; row++) {
4922 uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp;
4923 uint8_t* dest_scan_alpha =
4924 m_pAlphaMask ? (uint8_t*)m_pAlphaMask->GetScanline(row) + rect.left
4925 : NULL;
4926 if (dest_scan_alpha) {
4927 FXSYS_memset(dest_scan_alpha, 0xff, width);
4928 }
4929 if (Bpp == 4) {
4930 FX_DWORD* scan = (FX_DWORD*)dest_scan;
4931 for (int col = 0; col < width; col++) {
4932 *scan++ = dst_color;
4933 }
4934 } else {
4935 for (int col = 0; col < width; col++) {
4936 *dest_scan++ = color_p[0];
4937 *dest_scan++ = color_p[1];
4938 *dest_scan++ = color_p[2];
4939 }
4940 }
4941 }
4942 return TRUE;
4943 }
4944 for (int row = rect.top; row < rect.bottom; row++) {
4945 uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp;
4946 if (bAlpha) {
4947 if (bArgb) {
4948 for (int col = 0; col < width; col++) {
4949 uint8_t back_alpha = dest_scan[3];
4950 if (back_alpha == 0) {
4951 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, color_p[2],
4952 color_p[1], color_p[0]));
4953 dest_scan += 4;
4954 continue;
4955 }
4956 uint8_t dest_alpha =
4957 back_alpha + src_alpha - back_alpha * src_alpha / 255;
4958 int alpha_ratio = src_alpha * 255 / dest_alpha;
4959 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[0], alpha_ratio);
4960 dest_scan++;
4961 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[1], alpha_ratio);
4962 dest_scan++;
4963 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[2], alpha_ratio);
4964 dest_scan++;
4965 *dest_scan++ = dest_alpha;
4966 }
4967 } else {
4968 uint8_t* dest_scan_alpha =
4969 (uint8_t*)m_pAlphaMask->GetScanline(row) + rect.left;
4970 for (int col = 0; col < width; col++) {
4971 uint8_t back_alpha = *dest_scan_alpha;
4972 if (back_alpha == 0) {
4973 *dest_scan_alpha++ = src_alpha;
4974 FXSYS_memcpy(dest_scan, color_p, Bpp);
4975 dest_scan += Bpp;
4976 continue;
4977 }
4978 uint8_t dest_alpha =
4979 back_alpha + src_alpha - back_alpha * src_alpha / 255;
4980 *dest_scan_alpha++ = dest_alpha;
4981 int alpha_ratio = src_alpha * 255 / dest_alpha;
4982 for (int comps = 0; comps < Bpp; comps++) {
4983 *dest_scan =
4984 FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], alpha_ratio);
4985 dest_scan++;
4986 }
4987 }
4988 }
4989 } else {
4990 for (int col = 0; col < width; col++) {
4991 for (int comps = 0; comps < Bpp; comps++) {
4992 if (comps == 3) {
2209 *dest_scan++ = 255; 4993 *dest_scan++ = 255;
2210 continue; 4994 continue;
2211 } 4995 }
2212 int src_alpha = clip_scan[col]; 4996 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], src_alpha);
2213 if (src_alpha == 0) { 4997 dest_scan++;
2214 dest_scan += 4; 4998 }
2215 continue; 4999 }
2216 } 5000 }
2217 int back_alpha = dest_scan[3]; 5001 }
2218 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55; 5002 return TRUE;
2219 dest_scan[3] = dest_alpha; 5003 }
2220 int alpha_ratio = src_alpha * 255 / dest_alpha; 5004 CFX_BitmapComposer::CFX_BitmapComposer() {
2221 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio); 5005 m_pScanlineV = NULL;
2222 dest_scan ++; 5006 m_pScanlineAlphaV = NULL;
2223 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio); 5007 m_pClipScanV = NULL;
2224 dest_scan ++; 5008 m_pAddClipScan = NULL;
2225 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio); 5009 m_bRgbByteOrder = FALSE;
2226 dest_scan ++; 5010 m_BlendType = FXDIB_BLEND_NORMAL;
2227 dest_scan ++; 5011 }
2228 } 5012 CFX_BitmapComposer::~CFX_BitmapComposer() {
2229 } 5013 if (m_pScanlineV) {
2230 void _CompositeRow_1bppRgb2Rgba_NoBlend(uint8_t* dest_scan, const uint8_t* src_s can, int src_left, int width, 5014 FX_Free(m_pScanlineV);
2231 FX_DWORD* pPalette, const uint8_t* clip_ scan, 5015 }
2232 uint8_t* dest_alpha_scan) 5016 if (m_pScanlineAlphaV) {
2233 { 5017 FX_Free(m_pScanlineAlphaV);
2234 int reset_r, reset_g, reset_b; 5018 }
2235 int set_r, set_g, set_b; 5019 if (m_pClipScanV) {
2236 reset_r = FXARGB_R(pPalette[0]); 5020 FX_Free(m_pClipScanV);
2237 reset_g = FXARGB_G(pPalette[0]); 5021 }
2238 reset_b = FXARGB_B(pPalette[0]); 5022 if (m_pAddClipScan) {
2239 set_r = FXARGB_R(pPalette[1]); 5023 FX_Free(m_pAddClipScan);
2240 set_g = FXARGB_G(pPalette[1]); 5024 }
2241 set_b = FXARGB_B(pPalette[1]); 5025 }
2242 for (int col = 0; col < width; col ++) { 5026 void CFX_BitmapComposer::Compose(CFX_DIBitmap* pDest,
2243 int src_r, src_g, src_b; 5027 const CFX_ClipRgn* pClipRgn,
2244 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) { 5028 int bitmap_alpha,
2245 src_r = set_r; 5029 FX_DWORD mask_color,
2246 src_g = set_g; 5030 FX_RECT& dest_rect,
2247 src_b = set_b; 5031 FX_BOOL bVertical,
2248 } else { 5032 FX_BOOL bFlipX,
2249 src_r = reset_r; 5033 FX_BOOL bFlipY,
2250 src_g = reset_g; 5034 FX_BOOL bRgbByteOrder,
2251 src_b = reset_b; 5035 int alpha_flag,
2252 } 5036 void* pIccTransform,
2253 if (clip_scan == NULL || clip_scan[col] == 255) { 5037 int blend_type) {
2254 *dest_scan++ = src_b; 5038 m_pBitmap = pDest;
2255 *dest_scan++ = src_g; 5039 m_pClipRgn = pClipRgn;
2256 *dest_scan++ = src_r; 5040 m_DestLeft = dest_rect.left;
2257 *dest_alpha_scan++ = 255; 5041 m_DestTop = dest_rect.top;
2258 continue; 5042 m_DestWidth = dest_rect.Width();
2259 } 5043 m_DestHeight = dest_rect.Height();
2260 int src_alpha = clip_scan[col]; 5044 m_BitmapAlpha = bitmap_alpha;
2261 if (src_alpha == 0) { 5045 m_MaskColor = mask_color;
2262 dest_scan += 3; 5046 m_pClipMask = NULL;
2263 dest_alpha_scan ++; 5047 if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
2264 continue; 5048 m_pClipMask = pClipRgn->GetMask();
2265 } 5049 }
2266 int back_alpha = *dest_alpha_scan; 5050 m_bVertical = bVertical;
2267 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55; 5051 m_bFlipX = bFlipX;
2268 *dest_alpha_scan ++ = dest_alpha; 5052 m_bFlipY = bFlipY;
2269 int alpha_ratio = src_alpha * 255 / dest_alpha; 5053 m_AlphaFlag = alpha_flag;
2270 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio); 5054 m_pIccTransform = pIccTransform;
2271 dest_scan ++; 5055 m_bRgbByteOrder = bRgbByteOrder;
2272 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio); 5056 m_BlendType = blend_type;
2273 dest_scan ++; 5057 }
2274 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio); 5058 FX_BOOL CFX_BitmapComposer::SetInfo(int width,
2275 dest_scan ++; 5059 int height,
2276 } 5060 FXDIB_Format src_format,
2277 } 5061 FX_DWORD* pSrcPalette) {
2278 void _CompositeRow_ByteMask2Argb(uint8_t* dest_scan, const uint8_t* src_scan, in t mask_alpha, int src_r, int src_g, int src_b, int pixel_count, 5062 m_SrcFormat = src_format;
2279 int blend_type, const uint8_t* clip_scan) 5063 if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, pSrcPalette,
2280 { 5064 m_MaskColor, FXDIB_BLEND_NORMAL,
2281 for (int col = 0; col < pixel_count; col ++) { 5065 m_pClipMask != NULL || (m_BitmapAlpha < 255),
2282 int src_alpha; 5066 m_bRgbByteOrder, m_AlphaFlag, m_pIccTransform)) {
2283 if (clip_scan) { 5067 return FALSE;
2284 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255; 5068 }
2285 } else { 5069 if (m_bVertical) {
2286 src_alpha = mask_alpha * src_scan[col] / 255; 5070 m_pScanlineV = FX_Alloc(uint8_t, m_pBitmap->GetBPP() / 8 * width + 4);
2287 } 5071 m_pClipScanV = FX_Alloc(uint8_t, m_pBitmap->GetHeight());
2288 uint8_t back_alpha = dest_scan[3]; 5072 if (m_pBitmap->m_pAlphaMask) {
2289 if (back_alpha == 0) { 5073 m_pScanlineAlphaV = FX_Alloc(uint8_t, width + 4);
2290 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b) ); 5074 }
2291 dest_scan += 4; 5075 }
2292 continue; 5076 if (m_BitmapAlpha < 255) {
2293 } 5077 m_pAddClipScan = FX_Alloc(
2294 if (src_alpha == 0) { 5078 uint8_t, m_bVertical ? m_pBitmap->GetHeight() : m_pBitmap->GetWidth());
2295 dest_scan += 4; 5079 }
2296 continue; 5080 return TRUE;
2297 } 5081 }
2298 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55; 5082 void CFX_BitmapComposer::DoCompose(uint8_t* dest_scan,
2299 dest_scan[3] = dest_alpha; 5083 const uint8_t* src_scan,
2300 int alpha_ratio = src_alpha * 255 / dest_alpha; 5084 int dest_width,
2301 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { 5085 const uint8_t* clip_scan,
2302 int blended_colors[3]; 5086 const uint8_t* src_extra_alpha,
2303 uint8_t src_scan[3]; 5087 uint8_t* dst_extra_alpha) {
2304 src_scan[0] = src_b; 5088 if (m_BitmapAlpha < 255) {
2305 src_scan[1] = src_g; 5089 if (clip_scan) {
2306 src_scan[2] = src_r; 5090 for (int i = 0; i < dest_width; i++) {
2307 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); 5091 m_pAddClipScan[i] = clip_scan[i] * m_BitmapAlpha / 255;
2308 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ ratio); 5092 }
2309 dest_scan ++; 5093 } else {
2310 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ ratio); 5094 FXSYS_memset(m_pAddClipScan, m_BitmapAlpha, dest_width);
2311 dest_scan ++; 5095 }
2312 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ ratio); 5096 clip_scan = m_pAddClipScan;
2313 } else if (blend_type) { 5097 }
2314 int blended = _BLEND(blend_type, *dest_scan, src_b); 5098 if (m_SrcFormat == FXDIB_8bppMask) {
2315 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha); 5099 m_Compositor.CompositeByteMaskLine(dest_scan, src_scan, dest_width,
2316 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio); 5100 clip_scan, dst_extra_alpha);
2317 dest_scan ++; 5101 } else if ((m_SrcFormat & 0xff) == 8) {
2318 blended = _BLEND(blend_type, *dest_scan, src_g); 5102 m_Compositor.CompositePalBitmapLine(dest_scan, src_scan, 0, dest_width,
2319 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha); 5103 clip_scan, src_extra_alpha,
2320 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2321 dest_scan ++;
2322 blended = _BLEND(blend_type, *dest_scan, src_r);
2323 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
2324 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2325 } else {
2326 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2327 dest_scan ++;
2328 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2329 dest_scan ++;
2330 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2331 }
2332 dest_scan += 2;
2333 }
2334 }
2335 void _CompositeRow_ByteMask2Rgba(uint8_t* dest_scan, const uint8_t* src_scan, in t mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
2336 int blend_type, const uint8_t* clip_scan,
2337 uint8_t* dest_alpha_scan)
2338 {
2339 for (int col = 0; col < pixel_count; col ++) {
2340 int src_alpha;
2341 if (clip_scan) {
2342 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2343 } else {
2344 src_alpha = mask_alpha * src_scan[col] / 255;
2345 }
2346 uint8_t back_alpha = *dest_alpha_scan;
2347 if (back_alpha == 0) {
2348 *dest_scan ++ = src_b;
2349 *dest_scan ++ = src_g;
2350 *dest_scan ++ = src_r;
2351 *dest_alpha_scan ++ = src_alpha;
2352 continue;
2353 }
2354 if (src_alpha == 0) {
2355 dest_scan += 3;
2356 dest_alpha_scan ++;
2357 continue;
2358 }
2359 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
2360 *dest_alpha_scan ++ = dest_alpha;
2361 int alpha_ratio = src_alpha * 255 / dest_alpha;
2362 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2363 int blended_colors[3];
2364 uint8_t src_scan[3];
2365 src_scan[0] = src_b;
2366 src_scan[1] = src_g;
2367 src_scan[2] = src_r;
2368 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2369 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ ratio);
2370 dest_scan ++;
2371 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ ratio);
2372 dest_scan ++;
2373 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ ratio);
2374 dest_scan ++;
2375 } else if (blend_type) {
2376 int blended = _BLEND(blend_type, *dest_scan, src_b);
2377 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
2378 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2379 dest_scan ++;
2380 blended = _BLEND(blend_type, *dest_scan, src_g);
2381 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
2382 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2383 dest_scan ++;
2384 blended = _BLEND(blend_type, *dest_scan, src_r);
2385 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
2386 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2387 dest_scan ++;
2388 } else {
2389 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2390 dest_scan ++;
2391 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2392 dest_scan ++;
2393 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2394 dest_scan ++;
2395 }
2396 }
2397 }
2398 void _CompositeRow_ByteMask2Rgb(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
2399 int blend_type, int Bpp, const uint8_t* clip_sca n)
2400 {
2401 for (int col = 0; col < pixel_count; col ++) {
2402 int src_alpha;
2403 if (clip_scan) {
2404 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2405 } else {
2406 src_alpha = mask_alpha * src_scan[col] / 255;
2407 }
2408 if (src_alpha == 0) {
2409 dest_scan += Bpp;
2410 continue;
2411 }
2412 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2413 int blended_colors[3];
2414 uint8_t src_scan[3];
2415 src_scan[0] = src_b;
2416 src_scan[1] = src_g;
2417 src_scan[2] = src_r;
2418 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2419 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], src_al pha);
2420 dest_scan ++;
2421 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], src_al pha);
2422 dest_scan ++;
2423 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], src_al pha);
2424 } else if (blend_type) {
2425 int blended = _BLEND(blend_type, *dest_scan, src_b);
2426 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2427 dest_scan ++;
2428 blended = _BLEND(blend_type, *dest_scan, src_g);
2429 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2430 dest_scan ++;
2431 blended = _BLEND(blend_type, *dest_scan, src_r);
2432 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2433 } else {
2434 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
2435 dest_scan ++;
2436 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
2437 dest_scan ++;
2438 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
2439 }
2440 dest_scan += Bpp - 2;
2441 }
2442 }
2443 void _CompositeRow_ByteMask2Mask(uint8_t* dest_scan, const uint8_t* src_scan, in t mask_alpha, int pixel_count,
2444 const uint8_t* clip_scan)
2445 {
2446 for (int col = 0; col < pixel_count; col ++) {
2447 int src_alpha;
2448 if (clip_scan) {
2449 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2450 } else {
2451 src_alpha = mask_alpha * src_scan[col] / 255;
2452 }
2453 uint8_t back_alpha = *dest_scan;
2454 if (!back_alpha) {
2455 *dest_scan = src_alpha;
2456 } else if (src_alpha) {
2457 *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2458 }
2459 dest_scan ++;
2460 }
2461 }
2462 void _CompositeRow_ByteMask2Gray(uint8_t* dest_scan, const uint8_t* src_scan, in t mask_alpha, int src_gray,
2463 int pixel_count, const uint8_t* clip_scan)
2464 {
2465 for (int col = 0; col < pixel_count; col ++) {
2466 int src_alpha;
2467 if (clip_scan) {
2468 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2469 } else {
2470 src_alpha = mask_alpha * src_scan[col] / 255;
2471 }
2472 if (src_alpha) {
2473 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, src_alpha);
2474 }
2475 dest_scan ++;
2476 }
2477 }
2478 void _CompositeRow_ByteMask2Graya(uint8_t* dest_scan, const uint8_t* src_scan, i nt mask_alpha, int src_gray,
2479 int pixel_count, const uint8_t* clip_scan,
2480 uint8_t* dest_alpha_scan)
2481 {
2482 for (int col = 0; col < pixel_count; col ++) {
2483 int src_alpha;
2484 if (clip_scan) {
2485 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
2486 } else {
2487 src_alpha = mask_alpha * src_scan[col] / 255;
2488 }
2489 uint8_t back_alpha = *dest_alpha_scan;
2490 if (back_alpha == 0) {
2491 *dest_scan ++ = src_gray;
2492 *dest_alpha_scan ++ = src_alpha;
2493 continue;
2494 }
2495 if (src_alpha == 0) {
2496 dest_scan ++;
2497 dest_alpha_scan ++;
2498 continue;
2499 }
2500 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
2501 *dest_alpha_scan++ = dest_alpha;
2502 int alpha_ratio = src_alpha * 255 / dest_alpha;
2503 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, alpha_ratio);
2504 dest_scan ++;
2505 }
2506 }
2507 void _CompositeRow_BitMask2Argb(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_r, int src_g, int src_b,
2508 int src_left, int pixel_count, int blend_type, c onst uint8_t* clip_scan)
2509 {
2510 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 2 55) {
2511 FX_ARGB argb = FXARGB_MAKE(0xff, src_r, src_g, src_b);
2512 for (int col = 0; col < pixel_count; col ++) {
2513 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8 ))) {
2514 FXARGB_SETDIB(dest_scan, argb);
2515 }
2516 dest_scan += 4;
2517 }
2518 return;
2519 }
2520 for (int col = 0; col < pixel_count; col ++) {
2521 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)) )) {
2522 dest_scan += 4;
2523 continue;
2524 }
2525 int src_alpha;
2526 if (clip_scan) {
2527 src_alpha = mask_alpha * clip_scan[col] / 255;
2528 } else {
2529 src_alpha = mask_alpha;
2530 }
2531 uint8_t back_alpha = dest_scan[3];
2532 if (back_alpha == 0) {
2533 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g, src_b) );
2534 dest_scan += 4;
2535 continue;
2536 }
2537 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
2538 dest_scan[3] = dest_alpha;
2539 int alpha_ratio = src_alpha * 255 / dest_alpha;
2540 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2541 int blended_colors[3];
2542 uint8_t src_scan[3];
2543 src_scan[0] = src_b;
2544 src_scan[1] = src_g;
2545 src_scan[2] = src_r;
2546 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2547 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ ratio);
2548 dest_scan ++;
2549 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ ratio);
2550 dest_scan ++;
2551 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ ratio);
2552 } else if (blend_type) {
2553 int blended = _BLEND(blend_type, *dest_scan, src_b);
2554 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
2555 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2556 dest_scan ++;
2557 blended = _BLEND(blend_type, *dest_scan, src_g);
2558 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
2559 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2560 dest_scan ++;
2561 blended = _BLEND(blend_type, *dest_scan, src_r);
2562 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
2563 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2564 } else {
2565 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2566 dest_scan ++;
2567 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2568 dest_scan ++;
2569 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2570 }
2571 dest_scan += 2;
2572 }
2573 }
2574 void _CompositeRow_BitMask2Rgba(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_r, int src_g, int src_b,
2575 int src_left, int pixel_count, int blend_type, c onst uint8_t* clip_scan,
2576 uint8_t* dest_alpha_scan)
2577 {
2578 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 2 55) {
2579 for (int col = 0; col < pixel_count; col ++) {
2580 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8 ))) {
2581 dest_scan[0] = src_b;
2582 dest_scan[1] = src_g;
2583 dest_scan[2] = src_r;
2584 *dest_alpha_scan = mask_alpha;
2585 }
2586 dest_scan += 3;
2587 dest_alpha_scan ++;
2588 }
2589 return;
2590 }
2591 for (int col = 0; col < pixel_count; col ++) {
2592 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)) )) {
2593 dest_scan += 3;
2594 dest_alpha_scan ++;
2595 continue;
2596 }
2597 int src_alpha;
2598 if (clip_scan) {
2599 src_alpha = mask_alpha * clip_scan[col] / 255;
2600 } else {
2601 src_alpha = mask_alpha;
2602 }
2603 uint8_t back_alpha = dest_scan[3];
2604 if (back_alpha == 0) {
2605 *dest_scan ++ = src_b;
2606 *dest_scan ++ = src_g;
2607 *dest_scan ++ = src_r;
2608 *dest_alpha_scan ++ = mask_alpha;
2609 continue;
2610 }
2611 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
2612 *dest_alpha_scan ++ = dest_alpha;
2613 int alpha_ratio = src_alpha * 255 / dest_alpha;
2614 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2615 int blended_colors[3];
2616 uint8_t src_scan[3];
2617 src_scan[0] = src_b;
2618 src_scan[1] = src_g;
2619 src_scan[2] = src_r;
2620 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2621 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ ratio);
2622 dest_scan ++;
2623 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], alpha_ ratio);
2624 dest_scan ++;
2625 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], alpha_ ratio);
2626 dest_scan ++;
2627 } else if (blend_type) {
2628 int blended = _BLEND(blend_type, *dest_scan, src_b);
2629 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
2630 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2631 dest_scan ++;
2632 blended = _BLEND(blend_type, *dest_scan, src_g);
2633 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
2634 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2635 dest_scan ++;
2636 blended = _BLEND(blend_type, *dest_scan, src_r);
2637 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
2638 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
2639 dest_scan ++;
2640 } else {
2641 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
2642 dest_scan ++;
2643 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
2644 dest_scan ++;
2645 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
2646 dest_scan ++;
2647 }
2648 }
2649 }
2650 void _CompositeRow_BitMask2Rgb(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_r, int src_g, int src_b,
2651 int src_left, int pixel_count, int blend_type, in t Bpp, const uint8_t* clip_scan)
2652 {
2653 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 2 55) {
2654 for (int col = 0; col < pixel_count; col ++) {
2655 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8 ))) {
2656 dest_scan[2] = src_r;
2657 dest_scan[1] = src_g;
2658 dest_scan[0] = src_b;
2659 }
2660 dest_scan += Bpp;
2661 }
2662 return;
2663 }
2664 for (int col = 0; col < pixel_count; col ++) {
2665 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)) )) {
2666 dest_scan += Bpp;
2667 continue;
2668 }
2669 int src_alpha;
2670 if (clip_scan) {
2671 src_alpha = mask_alpha * clip_scan[col] / 255;
2672 } else {
2673 src_alpha = mask_alpha;
2674 }
2675 if (src_alpha == 0) {
2676 dest_scan += Bpp;
2677 continue;
2678 }
2679 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
2680 int blended_colors[3];
2681 uint8_t src_scan[3];
2682 src_scan[0] = src_b;
2683 src_scan[1] = src_g;
2684 src_scan[2] = src_r;
2685 _RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
2686 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], src_al pha);
2687 dest_scan ++;
2688 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], src_al pha);
2689 dest_scan ++;
2690 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[2], src_al pha);
2691 } else if (blend_type) {
2692 int blended = _BLEND(blend_type, *dest_scan, src_b);
2693 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2694 dest_scan++;
2695 blended = _BLEND(blend_type, *dest_scan, src_g);
2696 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2697 dest_scan++;
2698 blended = _BLEND(blend_type, *dest_scan, src_r);
2699 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, src_alpha);
2700 } else {
2701 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
2702 dest_scan ++;
2703 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
2704 dest_scan ++;
2705 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
2706 }
2707 dest_scan += Bpp - 2;
2708 }
2709 }
2710 void _CompositeRow_BitMask2Mask(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_left,
2711 int pixel_count, const uint8_t* clip_scan)
2712 {
2713 for (int col = 0; col < pixel_count; col ++) {
2714 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)) )) {
2715 dest_scan ++;
2716 continue;
2717 }
2718 int src_alpha;
2719 if (clip_scan) {
2720 src_alpha = mask_alpha * clip_scan[col] / 255;
2721 } else {
2722 src_alpha = mask_alpha;
2723 }
2724 uint8_t back_alpha = *dest_scan;
2725 if (!back_alpha) {
2726 *dest_scan = src_alpha;
2727 } else if (src_alpha) {
2728 *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
2729 }
2730 dest_scan ++;
2731 }
2732 }
2733 void _CompositeRow_BitMask2Gray(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_gray,
2734 int src_left, int pixel_count, const uint8_t* cl ip_scan)
2735 {
2736 for (int col = 0; col < pixel_count; col ++) {
2737 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)) )) {
2738 dest_scan ++;
2739 continue;
2740 }
2741 int src_alpha;
2742 if (clip_scan) {
2743 src_alpha = mask_alpha * clip_scan[col] / 255;
2744 } else {
2745 src_alpha = mask_alpha;
2746 }
2747 if (src_alpha) {
2748 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, src_alpha);
2749 }
2750 dest_scan ++;
2751 }
2752 }
2753 void _CompositeRow_BitMask2Graya(uint8_t* dest_scan, const uint8_t* src_scan, in t mask_alpha, int src_gray,
2754 int src_left, int pixel_count, const uint8_t* c lip_scan,
2755 uint8_t* dest_alpha_scan)
2756 {
2757 for (int col = 0; col < pixel_count; col ++) {
2758 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)) )) {
2759 dest_scan ++;
2760 dest_alpha_scan ++;
2761 continue;
2762 }
2763 int src_alpha;
2764 if (clip_scan) {
2765 src_alpha = mask_alpha * clip_scan[col] / 255;
2766 } else {
2767 src_alpha = mask_alpha;
2768 }
2769 uint8_t back_alpha = *dest_alpha_scan;
2770 if (back_alpha == 0) {
2771 *dest_scan ++ = src_gray;
2772 *dest_alpha_scan ++ = src_alpha;
2773 continue;
2774 }
2775 if (src_alpha == 0) {
2776 dest_scan ++;
2777 dest_alpha_scan ++;
2778 continue;
2779 }
2780 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
2781 *dest_alpha_scan++ = dest_alpha;
2782 int alpha_ratio = src_alpha * 255 / dest_alpha;
2783 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_gray, alpha_ratio);
2784 dest_scan ++;
2785 }
2786 }
2787 void _CompositeRow_Argb2Argb_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src _scan, int pixel_count, int blend_type, const uint8_t* clip_scan)
2788 {
2789 int blended_colors[3];
2790 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
2791 for (int col = 0; col < pixel_count; col ++) {
2792 uint8_t back_alpha = dest_scan[3];
2793 if (back_alpha == 0) {
2794 if (clip_scan) {
2795 int src_alpha = clip_scan[col] * src_scan[3] / 255;
2796 dest_scan[3] = src_alpha;
2797 dest_scan[0] = src_scan[2];
2798 dest_scan[1] = src_scan[1];
2799 dest_scan[2] = src_scan[0];
2800 } else {
2801 FXARGB_RGBORDERCOPY(dest_scan, src_scan);
2802 }
2803 dest_scan += 4;
2804 src_scan += 4;
2805 continue;
2806 }
2807 uint8_t src_alpha;
2808 if (clip_scan == NULL) {
2809 src_alpha = src_scan[3];
2810 } else {
2811 src_alpha = clip_scan[col] * src_scan[3] / 255;
2812 }
2813 if (src_alpha == 0) {
2814 dest_scan += 4;
2815 src_scan += 4;
2816 continue;
2817 }
2818 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
2819 dest_scan[3] = dest_alpha;
2820 int alpha_ratio = src_alpha * 255 / dest_alpha;
2821 if (bNonseparableBlend) {
2822 uint8_t dest_scan_o[3];
2823 dest_scan_o[0] = dest_scan[2];
2824 dest_scan_o[1] = dest_scan[1];
2825 dest_scan_o[2] = dest_scan[0];
2826 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
2827 }
2828 for (int color = 0; color < 3; color ++) {
2829 int index = 2 - color;
2830 if (blend_type) {
2831 int blended = bNonseparableBlend ? blended_colors[color] :
2832 _BLEND(blend_type, dest_scan[index], *src_scan);
2833 blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
2834 dest_scan[index] = FXDIB_ALPHA_MERGE(dest_scan[index], blended, alpha_ratio);
2835 } else {
2836 dest_scan[index] = FXDIB_ALPHA_MERGE(dest_scan[index], *src_scan , alpha_ratio);
2837 }
2838 src_scan ++;
2839 }
2840 dest_scan += 4;
2841 src_scan++;
2842 }
2843 }
2844 void _CompositeRow_Rgb2Argb_Blend_NoClip_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int width, int blend_type, int src_Bpp)
2845 {
2846 int blended_colors[3];
2847 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
2848 int src_gap = src_Bpp - 3;
2849 for (int col = 0; col < width; col ++) {
2850 uint8_t back_alpha = dest_scan[3];
2851 if (back_alpha == 0) {
2852 if (src_Bpp == 4) {
2853 FXARGB_SETRGBORDERDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_ scan));
2854 } else {
2855 FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_scan[1], src_scan[0]));
2856 }
2857 dest_scan += 4;
2858 src_scan += src_Bpp;
2859 continue;
2860 }
2861 dest_scan[3] = 0xff;
2862 if (bNonseparableBlend) {
2863 uint8_t dest_scan_o[3];
2864 dest_scan_o[0] = dest_scan[2];
2865 dest_scan_o[1] = dest_scan[1];
2866 dest_scan_o[2] = dest_scan[0];
2867 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
2868 }
2869 for (int color = 0; color < 3; color ++) {
2870 int index = 2 - color;
2871 int src_color = FX_GAMMA(*src_scan);
2872 int blended = bNonseparableBlend ? blended_colors[color] :
2873 _BLEND(blend_type, dest_scan[index], src_color);
2874 dest_scan[index] = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha) ;
2875 src_scan ++;
2876 }
2877 dest_scan += 4;
2878 src_scan += src_gap;
2879 }
2880 }
2881 inline void _CompositeRow_Argb2Rgb_Blend_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int width, int blend_type, int dest_Bpp, const uint8_t* clip_ scan)
2882 {
2883 int blended_colors[3];
2884 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
2885 for (int col = 0; col < width; col ++) {
2886 uint8_t src_alpha;
2887 if (clip_scan) {
2888 src_alpha = src_scan[3] * (*clip_scan++) / 255;
2889 } else {
2890 src_alpha = src_scan[3];
2891 }
2892 if (src_alpha == 0) {
2893 dest_scan += dest_Bpp;
2894 src_scan += 4;
2895 continue;
2896 }
2897 if (bNonseparableBlend) {
2898 uint8_t dest_scan_o[3];
2899 dest_scan_o[0] = dest_scan[2];
2900 dest_scan_o[1] = dest_scan[1];
2901 dest_scan_o[2] = dest_scan[0];
2902 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
2903 }
2904 for (int color = 0; color < 3; color ++) {
2905 int index = 2 - color;
2906 int back_color = FX_GAMMA(dest_scan[index]);
2907 int blended = bNonseparableBlend ? blended_colors[color] :
2908 _BLEND(blend_type, back_color, *src_scan);
2909 dest_scan[index] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, bl ended, src_alpha));
2910 src_scan ++;
2911 }
2912 dest_scan += dest_Bpp;
2913 src_scan ++;
2914 }
2915 }
2916 inline void _CompositeRow_Rgb2Argb_NoBlend_NoClip_RgbByteOrder(uint8_t* dest_sca n, const uint8_t* src_scan, int width, int src_Bpp)
2917 {
2918 for (int col = 0; col < width; col ++) {
2919 if (src_Bpp == 4) {
2920 FXARGB_SETRGBORDERDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan ));
2921 } else {
2922 FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[2], src_ scan[1], src_scan[0]));
2923 }
2924 dest_scan += 4;
2925 src_scan += src_Bpp;
2926 }
2927 }
2928 inline void _CompositeRow_Rgb2Rgb_Blend_NoClip_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp)
2929 {
2930 int blended_colors[3];
2931 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
2932 int src_gap = src_Bpp - 3;
2933 for (int col = 0; col < width; col ++) {
2934 if (bNonseparableBlend) {
2935 uint8_t dest_scan_o[3];
2936 dest_scan_o[0] = dest_scan[2];
2937 dest_scan_o[1] = dest_scan[1];
2938 dest_scan_o[2] = dest_scan[0];
2939 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
2940 }
2941 for (int color = 0; color < 3; color ++) {
2942 int index = 2 - color;
2943 int back_color = FX_GAMMA(dest_scan[index]);
2944 int src_color = FX_GAMMA(*src_scan);
2945 int blended = bNonseparableBlend ? blended_colors[color] :
2946 _BLEND(blend_type, back_color, src_color);
2947 dest_scan[index] = FX_GAMMA_INVERSE(blended);
2948 src_scan ++;
2949 }
2950 dest_scan += dest_Bpp;
2951 src_scan += src_gap;
2952 }
2953 }
2954 inline void _CompositeRow_Argb2Rgb_NoBlend_RgbByteOrder(uint8_t* dest_scan, cons t uint8_t* src_scan, int width, int dest_Bpp, const uint8_t* clip_scan)
2955 {
2956 for (int col = 0; col < width; col ++) {
2957 uint8_t src_alpha;
2958 if (clip_scan) {
2959 src_alpha = src_scan[3] * (*clip_scan++) / 255;
2960 } else {
2961 src_alpha = src_scan[3];
2962 }
2963 if (src_alpha == 255) {
2964 dest_scan[2] = FX_GAMMA_INVERSE(*src_scan++);
2965 dest_scan[1] = FX_GAMMA_INVERSE(*src_scan++);
2966 dest_scan[0] = FX_GAMMA_INVERSE(*src_scan++);
2967 dest_scan += dest_Bpp;
2968 src_scan ++;
2969 continue;
2970 }
2971 if (src_alpha == 0) {
2972 dest_scan += dest_Bpp;
2973 src_scan += 4;
2974 continue;
2975 }
2976 for (int color = 0; color < 3; color ++) {
2977 int index = 2 - color;
2978 dest_scan[index] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_ scan[index]), *src_scan, src_alpha));
2979 src_scan ++;
2980 }
2981 dest_scan += dest_Bpp;
2982 src_scan ++;
2983 }
2984 }
2985 inline void _CompositeRow_Rgb2Rgb_NoBlend_NoClip_RgbByteOrder(uint8_t* dest_scan , const uint8_t* src_scan, int width, int dest_Bpp, int src_Bpp)
2986 {
2987 for (int col = 0; col < width; col ++) {
2988 dest_scan[2] = src_scan[0];
2989 dest_scan[1] = src_scan[1];
2990 dest_scan[0] = src_scan[2];
2991 dest_scan += dest_Bpp;
2992 src_scan += src_Bpp;
2993 }
2994 }
2995 inline void _CompositeRow_Rgb2Argb_Blend_Clip_RgbByteOrder(uint8_t* dest_scan, c onst uint8_t* src_scan, int width, int blend_type, int src_Bpp, const uint8_t* c lip_scan)
2996 {
2997 int blended_colors[3];
2998 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
2999 int src_gap = src_Bpp - 3;
3000 for (int col = 0; col < width; col ++) {
3001 int src_alpha = *clip_scan ++;
3002 uint8_t back_alpha = dest_scan[3];
3003 if (back_alpha == 0) {
3004 dest_scan[2] = FX_GAMMA(*src_scan++);
3005 dest_scan[1] = FX_GAMMA(*src_scan++);
3006 dest_scan[0] = FX_GAMMA(*src_scan++);
3007 src_scan += src_gap;
3008 dest_scan += 4;
3009 continue;
3010 }
3011 if (src_alpha == 0) {
3012 dest_scan += 4;
3013 src_scan += src_Bpp;
3014 continue;
3015 }
3016 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
3017 dest_scan[3] = dest_alpha;
3018 int alpha_ratio = src_alpha * 255 / dest_alpha;
3019 if (bNonseparableBlend) {
3020 uint8_t dest_scan_o[3];
3021 dest_scan_o[0] = dest_scan[2];
3022 dest_scan_o[1] = dest_scan[1];
3023 dest_scan_o[2] = dest_scan[0];
3024 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3025 }
3026 for (int color = 0; color < 3; color ++) {
3027 int index = 2 - color;
3028 int src_color = FX_GAMMA(*src_scan);
3029 int blended = bNonseparableBlend ? blended_colors[color] :
3030 _BLEND(blend_type, dest_scan[index], src_color);
3031 blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
3032 dest_scan[index] = FXDIB_ALPHA_MERGE(dest_scan[index], blended, alph a_ratio);
3033 src_scan ++;
3034 }
3035 dest_scan += 4;
3036 src_scan += src_gap;
3037 }
3038 }
3039 inline void _CompositeRow_Rgb2Rgb_Blend_Clip_RgbByteOrder(uint8_t* dest_scan, co nst uint8_t* src_scan, int width, int blend_type, int dest_Bpp, int src_Bpp, con st uint8_t* clip_scan)
3040 {
3041 int blended_colors[3];
3042 FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
3043 int src_gap = src_Bpp - 3;
3044 for (int col = 0; col < width; col ++) {
3045 uint8_t src_alpha = *clip_scan ++;
3046 if (src_alpha == 0) {
3047 dest_scan += dest_Bpp;
3048 src_scan += src_Bpp;
3049 continue;
3050 }
3051 if (bNonseparableBlend) {
3052 uint8_t dest_scan_o[3];
3053 dest_scan_o[0] = dest_scan[2];
3054 dest_scan_o[1] = dest_scan[1];
3055 dest_scan_o[2] = dest_scan[0];
3056 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3057 }
3058 for (int color = 0; color < 3; color ++) {
3059 int index = 2 - color;
3060 int src_color = FX_GAMMA(*src_scan);
3061 int back_color = FX_GAMMA(dest_scan[index]);
3062 int blended = bNonseparableBlend ? blended_colors[color] :
3063 _BLEND(blend_type, back_color, src_color);
3064 dest_scan[index] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, bl ended, src_alpha));
3065 src_scan ++;
3066 }
3067 dest_scan += dest_Bpp;
3068 src_scan += src_gap;
3069 }
3070 }
3071 inline void _CompositeRow_Rgb2Argb_NoBlend_Clip_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int width, int src_Bpp, const uint8_t* clip_scan)
3072 {
3073 int src_gap = src_Bpp - 3;
3074 for (int col = 0; col < width; col ++) {
3075 int src_alpha = clip_scan[col];
3076 if (src_alpha == 255) {
3077 dest_scan[2] = FX_GAMMA(*src_scan++);
3078 dest_scan[1] = FX_GAMMA(*src_scan++);
3079 dest_scan[0] = FX_GAMMA(*src_scan++);
3080 dest_scan[3] = 255;
3081 dest_scan += 4;
3082 src_scan += src_gap;
3083 continue;
3084 }
3085 if (src_alpha == 0) {
3086 dest_scan += 4;
3087 src_scan += src_Bpp;
3088 continue;
3089 }
3090 int back_alpha = dest_scan[3];
3091 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
3092 dest_scan[3] = dest_alpha;
3093 int alpha_ratio = src_alpha * 255 / dest_alpha;
3094 for (int color = 0; color < 3; color ++) {
3095 int index = 2 - color;
3096 dest_scan[index] = FXDIB_ALPHA_MERGE(dest_scan[index], FX_GAMMA(*src _scan), alpha_ratio);
3097 src_scan ++;
3098 }
3099 dest_scan += 4;
3100 src_scan += src_gap;
3101 }
3102 }
3103 inline void _CompositeRow_Rgb2Rgb_NoBlend_Clip_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int width, int dest_Bpp, int src_Bpp, const uint8_t* cl ip_scan)
3104 {
3105 for (int col = 0; col < width; col ++) {
3106 int src_alpha = clip_scan[col];
3107 if (src_alpha == 255) {
3108 dest_scan[2] = src_scan[0];
3109 dest_scan[1] = src_scan[1];
3110 dest_scan[0] = src_scan[2];
3111 } else if (src_alpha) {
3112 dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan [2]), FX_GAMMA(*src_scan), src_alpha));
3113 src_scan ++;
3114 dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan [1]), FX_GAMMA(*src_scan), src_alpha));
3115 src_scan ++;
3116 dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan [0]), FX_GAMMA(*src_scan), src_alpha));
3117 dest_scan += dest_Bpp;
3118 src_scan += src_Bpp - 2;
3119 continue;
3120 }
3121 dest_scan += dest_Bpp;
3122 src_scan += src_Bpp;
3123 }
3124 }
3125 inline void _CompositeRow_8bppRgb2Rgb_NoBlend_RgbByteOrder(uint8_t* dest_scan, c onst uint8_t* src_scan, FX_ARGB* pPalette, int pixel_count,
3126 int DestBpp, const uint8_t* clip_scan)
3127 {
3128 for (int col = 0; col < pixel_count; col ++) {
3129 FX_ARGB argb = pPalette ? pPalette[*src_scan] : (*src_scan) * 0x010101;
3130 int src_r = FXARGB_R(argb);
3131 int src_g = FXARGB_G(argb);
3132 int src_b = FXARGB_B(argb);
3133 if (clip_scan && clip_scan[col] < 255) {
3134 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, clip_scan[col] );
3135 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, clip_scan[col] );
3136 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, clip_scan[col] );
3137 } else {
3138 dest_scan[2] = src_b;
3139 dest_scan[1] = src_g;
3140 dest_scan[0] = src_r;
3141 }
3142 dest_scan += DestBpp;
3143 src_scan ++;
3144 }
3145 }
3146 inline void _CompositeRow_1bppRgb2Rgb_NoBlend_RgbByteOrder(uint8_t* dest_scan, c onst uint8_t* src_scan, int src_left,
3147 FX_ARGB* pPalette, int pixel_count, int DestBpp, const uint8_t* clip_sca n)
3148 {
3149 int reset_r, reset_g, reset_b;
3150 int set_r, set_g, set_b;
3151 if (pPalette) {
3152 reset_r = FXARGB_R(pPalette[0]);
3153 reset_g = FXARGB_G(pPalette[0]);
3154 reset_b = FXARGB_B(pPalette[0]);
3155 set_r = FXARGB_R(pPalette[1]);
3156 set_g = FXARGB_G(pPalette[1]);
3157 set_b = FXARGB_B(pPalette[1]);
3158 } else {
3159 reset_r = reset_g = reset_b = 0;
3160 set_r = set_g = set_b = 255;
3161 }
3162 for (int col = 0; col < pixel_count; col ++) {
3163 int src_r, src_g, src_b;
3164 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
3165 src_r = set_r;
3166 src_g = set_g;
3167 src_b = set_b;
3168 } else {
3169 src_r = reset_r;
3170 src_g = reset_g;
3171 src_b = reset_b;
3172 }
3173 if (clip_scan && clip_scan[col] < 255) {
3174 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, clip_scan[col] );
3175 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, clip_scan[col] );
3176 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, clip_scan[col] );
3177 } else {
3178 dest_scan[2] = src_b;
3179 dest_scan[1] = src_g;
3180 dest_scan[0] = src_r;
3181 }
3182 dest_scan += DestBpp;
3183 }
3184 }
3185 inline void _CompositeRow_8bppRgb2Argb_NoBlend_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int width,
3186 FX_ARGB* pPalette, const uint8_t* clip_scan)
3187 {
3188 for (int col = 0; col < width; col ++) {
3189 int src_r, src_g, src_b;
3190 if (pPalette) {
3191 FX_ARGB argb = pPalette[*src_scan];
3192 src_r = FXARGB_R(argb);
3193 src_g = FXARGB_G(argb);
3194 src_b = FXARGB_B(argb);
3195 } else {
3196 src_r = src_g = src_b = *src_scan;
3197 }
3198 if (clip_scan == NULL || clip_scan[col] == 255) {
3199 dest_scan[2] = FX_GAMMA(src_b);
3200 dest_scan[1] = FX_GAMMA(src_g);
3201 dest_scan[0] = FX_GAMMA(src_r);
3202 dest_scan[3] = 255;
3203 src_scan ++;
3204 dest_scan += 4;
3205 continue;
3206 }
3207 int src_alpha = clip_scan[col];
3208 if (src_alpha == 0) {
3209 dest_scan += 4;
3210 src_scan ++;
3211 continue;
3212 }
3213 int back_alpha = dest_scan[3];
3214 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
3215 dest_scan[3] = dest_alpha;
3216 int alpha_ratio = src_alpha * 255 / dest_alpha;
3217 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], FX_GAMMA(src_b), alpha_ra tio);
3218 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], FX_GAMMA(src_g), alpha_ra tio);
3219 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], FX_GAMMA(src_r), alpha_ra tio);
3220 dest_scan += 4;
3221 src_scan ++;
3222 }
3223 }
3224 inline void _CompositeRow_1bppRgb2Argb_NoBlend_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int src_left, int width,
3225 FX_ARGB* pPalette, const uint8_t* clip_scan)
3226 {
3227 int reset_r, reset_g, reset_b;
3228 int set_r, set_g, set_b;
3229 if (pPalette) {
3230 reset_r = FXARGB_R(pPalette[0]);
3231 reset_g = FXARGB_G(pPalette[0]);
3232 reset_b = FXARGB_B(pPalette[0]);
3233 set_r = FXARGB_R(pPalette[1]);
3234 set_g = FXARGB_G(pPalette[1]);
3235 set_b = FXARGB_B(pPalette[1]);
3236 } else {
3237 reset_r = reset_g = reset_b = 0;
3238 set_r = set_g = set_b = 255;
3239 }
3240 for (int col = 0; col < width; col ++) {
3241 int src_r, src_g, src_b;
3242 if (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) {
3243 src_r = set_r;
3244 src_g = set_g;
3245 src_b = set_b;
3246 } else {
3247 src_r = reset_r;
3248 src_g = reset_g;
3249 src_b = reset_b;
3250 }
3251 if (clip_scan == NULL || clip_scan[col] == 255) {
3252 dest_scan[2] = FX_GAMMA(src_b);
3253 dest_scan[1] = FX_GAMMA(src_g);
3254 dest_scan[0] = FX_GAMMA(src_r);
3255 dest_scan[3] = 255;
3256 dest_scan += 4;
3257 continue;
3258 }
3259 int src_alpha = clip_scan[col];
3260 if (src_alpha == 0) {
3261 dest_scan += 4;
3262 continue;
3263 }
3264 int back_alpha = dest_scan[3];
3265 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
3266 dest_scan[3] = dest_alpha;
3267 int alpha_ratio = src_alpha * 255 / dest_alpha;
3268 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], FX_GAMMA(src_b), alpha_ra tio);
3269 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], FX_GAMMA(src_g), alpha_ra tio);
3270 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], FX_GAMMA(src_r), alpha_ra tio);
3271 dest_scan += 4;
3272 }
3273 }
3274 void _CompositeRow_ByteMask2Argb_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
3275 int blend_type, const uint8_t* clip_scan)
3276 {
3277 for (int col = 0; col < pixel_count; col ++) {
3278 int src_alpha;
3279 if (clip_scan) {
3280 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
3281 } else {
3282 src_alpha = mask_alpha * src_scan[col] / 255;
3283 }
3284 uint8_t back_alpha = dest_scan[3];
3285 if (back_alpha == 0) {
3286 FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g , src_b));
3287 dest_scan += 4;
3288 continue;
3289 }
3290 if (src_alpha == 0) {
3291 dest_scan += 4;
3292 continue;
3293 }
3294 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
3295 dest_scan[3] = dest_alpha;
3296 int alpha_ratio = src_alpha * 255 / dest_alpha;
3297 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3298 int blended_colors[3];
3299 uint8_t src_scan[3];
3300 uint8_t dest_scan_o[3];
3301 src_scan[0] = src_b;
3302 src_scan[1] = src_g;
3303 src_scan[2] = src_r;
3304 dest_scan_o[0] = dest_scan[2];
3305 dest_scan_o[1] = dest_scan[1];
3306 dest_scan_o[2] = dest_scan[0];
3307 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3308 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], al pha_ratio);
3309 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], al pha_ratio);
3310 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], al pha_ratio);
3311 } else if (blend_type) {
3312 int blended = _BLEND(blend_type, dest_scan[2], src_b);
3313 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
3314 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, alpha_ratio) ;
3315 blended = _BLEND(blend_type, dest_scan[1], src_g);
3316 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
3317 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, alpha_ratio) ;
3318 blended = _BLEND(blend_type, dest_scan[0], src_r);
3319 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
3320 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, alpha_ratio) ;
3321 } else {
3322 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, alpha_ratio);
3323 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, alpha_ratio);
3324 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, alpha_ratio);
3325 }
3326 dest_scan += 4;
3327 }
3328 }
3329 void _CompositeRow_ByteMask2Rgb_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_r, int src_g, int src_b, int pixel_count,
3330 int blend_type, int Bpp, const uint8_t* clip_scan)
3331 {
3332 for (int col = 0; col < pixel_count; col ++) {
3333 int src_alpha;
3334 if (clip_scan) {
3335 src_alpha = mask_alpha * clip_scan[col] * src_scan[col] / 255 / 255;
3336 } else {
3337 src_alpha = mask_alpha * src_scan[col] / 255;
3338 }
3339 if (src_alpha == 0) {
3340 dest_scan += Bpp;
3341 continue;
3342 }
3343 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3344 int blended_colors[3];
3345 uint8_t src_scan[3];
3346 uint8_t dest_scan_o[3];
3347 src_scan[0] = src_b;
3348 src_scan[1] = src_g;
3349 src_scan[2] = src_r;
3350 dest_scan_o[0] = dest_scan[2];
3351 dest_scan_o[1] = dest_scan[1];
3352 dest_scan_o[2] = dest_scan[0];
3353 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3354 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], sr c_alpha);
3355 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], sr c_alpha);
3356 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], sr c_alpha);
3357 } else if (blend_type) {
3358 int blended = _BLEND(blend_type, dest_scan[2], src_b);
3359 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, src_alpha);
3360 blended = _BLEND(blend_type, dest_scan[1], src_g);
3361 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, src_alpha);
3362 blended = _BLEND(blend_type, dest_scan[0], src_r);
3363 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, src_alpha);
3364 } else {
3365 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, src_alpha);
3366 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, src_alpha);
3367 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, src_alpha);
3368 }
3369 dest_scan += Bpp;
3370 }
3371 }
3372 void _CompositeRow_BitMask2Argb_RgbByteOrder(uint8_t* dest_scan, const uint8_t* src_scan, int mask_alpha, int src_r, int src_g, int src_b,
3373 int src_left, int pixel_count, int blend_type, const uint8_t* clip_scan)
3374 {
3375 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 2 55) {
3376 FX_ARGB argb = FXARGB_MAKE(0xff, src_r, src_g, src_b);
3377 for (int col = 0; col < pixel_count; col ++) {
3378 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8 ))) {
3379 FXARGB_SETRGBORDERDIB(dest_scan, argb);
3380 }
3381 dest_scan += 4;
3382 }
3383 return;
3384 }
3385 for (int col = 0; col < pixel_count; col ++) {
3386 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)) )) {
3387 dest_scan += 4;
3388 continue;
3389 }
3390 int src_alpha;
3391 if (clip_scan) {
3392 src_alpha = mask_alpha * clip_scan[col] / 255;
3393 } else {
3394 src_alpha = mask_alpha;
3395 }
3396 uint8_t back_alpha = dest_scan[3];
3397 if (back_alpha == 0) {
3398 FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(src_alpha, src_r, src_g , src_b));
3399 dest_scan += 4;
3400 continue;
3401 }
3402 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 2 55;
3403 dest_scan[3] = dest_alpha;
3404 int alpha_ratio = src_alpha * 255 / dest_alpha;
3405 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3406 int blended_colors[3];
3407 uint8_t src_scan[3];
3408 uint8_t dest_scan_o[3];
3409 src_scan[0] = src_b;
3410 src_scan[1] = src_g;
3411 src_scan[2] = src_r;
3412 dest_scan_o[0] = dest_scan[2];
3413 dest_scan_o[1] = dest_scan[1];
3414 dest_scan_o[2] = dest_scan[0];
3415 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3416 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], al pha_ratio);
3417 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], al pha_ratio);
3418 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], al pha_ratio);
3419 } else if (blend_type) {
3420 int blended = _BLEND(blend_type, dest_scan[2], src_b);
3421 blended = FXDIB_ALPHA_MERGE(src_b, blended, back_alpha);
3422 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended, alpha_ratio) ;
3423 blended = _BLEND(blend_type, dest_scan[1], src_g);
3424 blended = FXDIB_ALPHA_MERGE(src_g, blended, back_alpha);
3425 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended, alpha_ratio) ;
3426 blended = _BLEND(blend_type, dest_scan[0], src_r);
3427 blended = FXDIB_ALPHA_MERGE(src_r, blended, back_alpha);
3428 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended, alpha_ratio) ;
3429 } else {
3430 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], src_b, alpha_ratio);
3431 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], src_g, alpha_ratio);
3432 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], src_r, alpha_ratio);
3433 }
3434 dest_scan += 4;
3435 }
3436 }
3437 void _CompositeRow_BitMask2Rgb_RgbByteOrder(uint8_t* dest_scan, const uint8_t* s rc_scan, int mask_alpha, int src_r, int src_g, int src_b,
3438 int src_left, int pixel_count, int blend_type, int Bpp, const uint8_t* c lip_scan)
3439 {
3440 if (blend_type == FXDIB_BLEND_NORMAL && clip_scan == NULL && mask_alpha == 2 55) {
3441 for (int col = 0; col < pixel_count; col ++) {
3442 if (src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8 ))) {
3443 dest_scan[2] = src_b;
3444 dest_scan[1] = src_g;
3445 dest_scan[0] = src_r;
3446 }
3447 dest_scan += Bpp;
3448 }
3449 return;
3450 }
3451 for (int col = 0; col < pixel_count; col ++) {
3452 if (!(src_scan[(src_left + col) / 8] & (1 << (7 - (src_left + col) % 8)) )) {
3453 dest_scan += Bpp;
3454 continue;
3455 }
3456 int src_alpha;
3457 if (clip_scan) {
3458 src_alpha = mask_alpha * clip_scan[col] / 255;
3459 } else {
3460 src_alpha = mask_alpha;
3461 }
3462 if (src_alpha == 0) {
3463 dest_scan += Bpp;
3464 continue;
3465 }
3466 if (blend_type >= FXDIB_BLEND_NONSEPARABLE) {
3467 int blended_colors[3];
3468 uint8_t src_scan[3];
3469 uint8_t dest_scan_o[3];
3470 src_scan[0] = src_b;
3471 src_scan[1] = src_g;
3472 src_scan[2] = src_r;
3473 dest_scan_o[0] = dest_scan[2];
3474 dest_scan_o[1] = dest_scan[1];
3475 dest_scan_o[2] = dest_scan[0];
3476 _RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors);
3477 dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], sr c_alpha);
3478 dest_scan[1] = FXDIB_ALPHA_MERGE(dest_scan[1], blended_colors[1], sr c_alpha);
3479 dest_scan[0] = FXDIB_ALPHA_MERGE(dest_scan[0], blended_colors[2], sr c_alpha);
3480 } else if (blend_type) {
3481 int back_color = FX_GAMMA(dest_scan[2]);
3482 int blended = _BLEND(blend_type, back_color, src_b);
3483 dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blende d, src_alpha));
3484 back_color = FX_GAMMA(dest_scan[1]);
3485 blended = _BLEND(blend_type, back_color, src_g);
3486 dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blende d, src_alpha));
3487 back_color = FX_GAMMA(dest_scan[0]);
3488 blended = _BLEND(blend_type, back_color, src_r);
3489 dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(back_color, blende d, src_alpha));
3490 } else {
3491 dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan [2]), src_b, src_alpha));
3492 dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan [1]), src_g, src_alpha));
3493 dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan [0]), src_r, src_alpha));
3494 }
3495 dest_scan += Bpp;
3496 }
3497 }
3498 inline FX_BOOL _ScanlineCompositor_InitSourceMask(FXDIB_Format dest_format, int alpha_flag, FX_DWORD mask_color, int& mask_alpha,
3499 int& mask_red, int& mask_green, int& mask_blue, int& mask_black,
3500 void* icc_module, void* pIccTransform)
3501 {
3502 ICodec_IccModule* pIccModule = (ICodec_IccModule*)icc_module;
3503 if (alpha_flag >> 8) {
3504 mask_alpha = alpha_flag & 0xff;
3505 mask_red = FXSYS_GetCValue(mask_color);
3506 mask_green = FXSYS_GetMValue(mask_color);
3507 mask_blue = FXSYS_GetYValue(mask_color);
3508 mask_black = FXSYS_GetKValue(mask_color);
3509 } else {
3510 mask_alpha = FXARGB_A(mask_color);
3511 mask_red = FXARGB_R(mask_color);
3512 mask_green = FXARGB_G(mask_color);
3513 mask_blue = FXARGB_B(mask_color);
3514 }
3515 if (dest_format == FXDIB_8bppMask) {
3516 return TRUE;
3517 }
3518 if ((dest_format & 0xff) == 8) {
3519 if (pIccTransform) {
3520 mask_color = (alpha_flag >> 8) ? FXCMYK_TODIB(mask_color) : FXARGB_T ODIB(mask_color);
3521 uint8_t* gray_p = (uint8_t*)&mask_color;
3522 pIccModule->TranslateScanline(pIccTransform, gray_p, gray_p, 1);
3523 mask_red = dest_format & 0x0400 ? FX_CCOLOR(gray_p[0]) : gray_p[0];
3524 } else {
3525 if (alpha_flag >> 8) {
3526 uint8_t r, g, b;
3527 AdobeCMYK_to_sRGB1(mask_red, mask_green, mask_blue, mask_black,
3528 r, g, b);
3529 mask_red = FXRGB2GRAY(r, g, b);
3530 } else {
3531 mask_red = FXRGB2GRAY(mask_red, mask_green, mask_blue);
3532 }
3533 if (dest_format & 0x0400) {
3534 mask_red = FX_CCOLOR(mask_red);
3535 }
3536 }
3537 } else {
3538 uint8_t* mask_color_p = (uint8_t*)&mask_color;
3539 mask_color = (alpha_flag >> 8) ? FXCMYK_TODIB(mask_color) : FXARGB_TODIB (mask_color);
3540 if (pIccTransform) {
3541 pIccModule->TranslateScanline(pIccTransform, mask_color_p, mask_colo r_p, 1);
3542 mask_red = mask_color_p[2];
3543 mask_green = mask_color_p[1];
3544 mask_blue = mask_color_p[0];
3545 } else if (alpha_flag >> 8) {
3546 AdobeCMYK_to_sRGB1(mask_color_p[0], mask_color_p[1], mask_color_p[2] , mask_color_p[3],
3547 mask_color_p[2], mask_color_p[1], mask_color_p[0] );
3548 mask_red = mask_color_p[2];
3549 mask_green = mask_color_p[1];
3550 mask_blue = mask_color_p[0];
3551 }
3552 }
3553 return TRUE;
3554 }
3555 inline void _ScanlineCompositor_InitSourcePalette(FXDIB_Format src_format, FXDIB _Format dest_format,
3556 FX_DWORD*& pDestPalette, FX_DWORD* pSrcPalette,
3557 void* icc_module, void* pIccTransform)
3558 {
3559 ICodec_IccModule* pIccModule = (ICodec_IccModule*)icc_module;
3560 FX_BOOL isSrcCmyk = src_format & 0x0400 ? TRUE : FALSE;
3561 FX_BOOL isDstCmyk = dest_format & 0x0400 ? TRUE : FALSE;
3562 pDestPalette = NULL;
3563 if (pIccTransform) {
3564 if (pSrcPalette) {
3565 if ((dest_format & 0xff) == 8) {
3566 int pal_count = 1 << (src_format & 0xff);
3567 uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
3568 pDestPalette = (FX_DWORD*)gray_pal;
3569 for (int i = 0; i < pal_count; i ++) {
3570 FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i]) : FXARGB_TODIB(pSrcPalette[i]);
3571 pIccModule->TranslateScanline(pIccTransform, gray_pal, (cons t uint8_t*)&color, 1);
3572 gray_pal ++;
3573 }
3574 } else {
3575 int palsize = 1 << (src_format & 0xff);
3576 pDestPalette = FX_Alloc(FX_DWORD, palsize);
3577 for (int i = 0; i < palsize; i ++) {
3578 FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i]) : FXARGB_TODIB(pSrcPalette[i]);
3579 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&colo r, (const uint8_t*)&color, 1);
3580 pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(color) : FXARGB_T ODIB(color);
3581 }
3582 }
3583 } else {
3584 int pal_count = 1 << (src_format & 0xff);
3585 uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
3586 if (pal_count == 2) {
3587 gray_pal[0] = 0;
3588 gray_pal[1] = 255;
3589 } else {
3590 for (int i = 0; i < pal_count; i++) {
3591 gray_pal[i] = i;
3592 }
3593 }
3594 if ((dest_format & 0xff) == 8) {
3595 pIccModule->TranslateScanline(pIccTransform, gray_pal, gray_pal, pal_count);
3596 pDestPalette = (FX_DWORD*)gray_pal;
3597 } else {
3598 pDestPalette = FX_Alloc(FX_DWORD, pal_count);
3599 for (int i = 0; i < pal_count; i ++) {
3600 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&pDes tPalette[i], &gray_pal[i], 1);
3601 pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(pDestPalette[i]) : FXARGB_TODIB(pDestPalette[i]);
3602 }
3603 FX_Free(gray_pal);
3604 }
3605 }
3606 } else {
3607 if (pSrcPalette) {
3608 if ((dest_format & 0xff) == 8) {
3609 int pal_count = 1 << (src_format & 0xff);
3610 uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
3611 pDestPalette = (FX_DWORD*)gray_pal;
3612 if (isSrcCmyk) {
3613 for (int i = 0; i < pal_count; i ++) {
3614 FX_CMYK cmyk = pSrcPalette[i];
3615 uint8_t r, g, b;
3616 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValu e(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk),
3617 r, g, b);
3618 *gray_pal ++ = FXRGB2GRAY(r, g, b);
3619 }
3620 } else
3621 for (int i = 0; i < pal_count; i ++) {
3622 FX_ARGB argb = pSrcPalette[i];
3623 *gray_pal ++ = FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb) , FXARGB_B(argb));
3624 }
3625 } else {
3626 int palsize = 1 << (src_format & 0xff);
3627 pDestPalette = FX_Alloc(FX_DWORD, palsize);
3628 if (isDstCmyk == isSrcCmyk) {
3629 FXSYS_memcpy(pDestPalette, pSrcPalette, palsize * sizeof(FX_ DWORD));
3630 } else {
3631 for (int i = 0; i < palsize; i ++) {
3632 FX_CMYK cmyk = pSrcPalette[i];
3633 uint8_t r, g, b;
3634 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValu e(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk),
3635 r, g, b);
3636 pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
3637 }
3638 }
3639 }
3640 } else {
3641 if ((dest_format & 0xff) == 8) {
3642 int pal_count = 1 << (src_format & 0xff);
3643 uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
3644 if (pal_count == 2) {
3645 gray_pal[0] = 0;
3646 gray_pal[1] = 255;
3647 } else {
3648 for (int i = 0; i < pal_count; i++) {
3649 gray_pal[i] = i;
3650 }
3651 }
3652 pDestPalette = (FX_DWORD*)gray_pal;
3653 } else {
3654 int palsize = 1 << (src_format & 0xff);
3655 pDestPalette = FX_Alloc(FX_DWORD, palsize);
3656 if (palsize == 2) {
3657 pDestPalette[0] = isSrcCmyk ? 255 : 0xff000000;
3658 pDestPalette[1] = isSrcCmyk ? 0 : 0xffffffff;
3659 } else {
3660 for (int i = 0; i < palsize; i++) {
3661 pDestPalette[i] = isSrcCmyk ? FX_CCOLOR(i) : (i * 0x1010 1);
3662 }
3663 }
3664 if (isSrcCmyk != isDstCmyk) {
3665 for (int i = 0; i < palsize; i ++) {
3666 FX_CMYK cmyk = pDestPalette[i];
3667 uint8_t r, g, b;
3668 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValu e(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk),
3669 r, g, b);
3670 pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
3671 }
3672 }
3673 }
3674 }
3675 }
3676 }
3677 CFX_ScanlineCompositor::CFX_ScanlineCompositor()
3678 {
3679 m_pSrcPalette = NULL;
3680 m_pCacheScanline = NULL;
3681 m_CacheSize = 0;
3682 m_bRgbByteOrder = FALSE;
3683 m_BlendType = FXDIB_BLEND_NORMAL;
3684 }
3685 CFX_ScanlineCompositor::~CFX_ScanlineCompositor()
3686 {
3687 if (m_pSrcPalette) {
3688 FX_Free(m_pSrcPalette);
3689 }
3690 if (m_pCacheScanline) {
3691 FX_Free(m_pCacheScanline);
3692 }
3693 }
3694 FX_BOOL CFX_ScanlineCompositor::Init(FXDIB_Format dest_format, FXDIB_Format src_ format, int32_t width, FX_DWORD* pSrcPalette,
3695 FX_DWORD mask_color, int blend_type, FX_BOO L bClip, FX_BOOL bRgbByteOrder, int alpha_flag, void* pIccTransform)
3696 {
3697 m_SrcFormat = src_format;
3698 m_DestFormat = dest_format;
3699 m_BlendType = blend_type;
3700 m_bRgbByteOrder = bRgbByteOrder;
3701 ICodec_IccModule* pIccModule = NULL;
3702 if (CFX_GEModule::Get()->GetCodecModule()) {
3703 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
3704 }
3705 if (pIccModule == NULL) {
3706 pIccTransform = NULL;
3707 }
3708 m_pIccTransform = pIccTransform;
3709 if ((dest_format & 0xff) == 1) {
3710 return FALSE;
3711 }
3712 if (m_SrcFormat == FXDIB_1bppMask || m_SrcFormat == FXDIB_8bppMask) {
3713 return _ScanlineCompositor_InitSourceMask(dest_format, alpha_flag, mask_ color,
3714 m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, m_MaskBlack,
3715 pIccModule, pIccTransform);
3716 }
3717 if (pIccTransform == NULL && (~src_format & 0x0400) && (dest_format & 0x0400 )) {
3718 return FALSE;
3719 }
3720 if ((m_SrcFormat & 0xff) <= 8) {
3721 if (dest_format == FXDIB_8bppMask) {
3722 return TRUE;
3723 }
3724 _ScanlineCompositor_InitSourcePalette(src_format, dest_format, m_pSrcPal ette, pSrcPalette,
3725 pIccModule, pIccTransform);
3726 m_Transparency = (dest_format == FXDIB_Argb ? 1 : 0)
3727 + (dest_format & 0x0200 ? 2 : 0)
3728 + (dest_format & 0x0400 ? 4 : 0)
3729 + ((src_format & 0xff) == 1 ? 8 : 0);
3730 return TRUE;
3731 }
3732 m_Transparency = (src_format & 0x0200 ? 0 : 1)
3733 + (dest_format & 0x0200 ? 0 : 2)
3734 + (blend_type == FXDIB_BLEND_NORMAL ? 4 : 0)
3735 + (bClip ? 8 : 0)
3736 + (src_format & 0x0400 ? 16 : 0)
3737 + (dest_format & 0x0400 ? 32 : 0)
3738 + (pIccTransform ? 64 : 0);
3739 return TRUE;
3740 }
3741 void CFX_ScanlineCompositor::CompositeRgbBitmapLine(uint8_t* dest_scan, const ui nt8_t* src_scan, int width, const uint8_t* clip_scan,
3742 const uint8_t* src_extra_alpha, uint8_t* dst_extra_alpha)
3743 {
3744 int src_Bpp = (m_SrcFormat & 0xff) >> 3;
3745 int dest_Bpp = (m_DestFormat & 0xff) >> 3;
3746 if (m_bRgbByteOrder) {
3747 switch (m_Transparency) {
3748 case 0:
3749 case 4:
3750 case 8:
3751 case 12:
3752 _CompositeRow_Argb2Argb_RgbByteOrder(dest_scan, src_scan, width, m_BlendType, clip_scan);
3753 break;
3754 case 1:
3755 _CompositeRow_Rgb2Argb_Blend_NoClip_RgbByteOrder(dest_scan, src_ scan, width, m_BlendType, src_Bpp);
3756 break;
3757 case 2:
3758 case 10:
3759 _CompositeRow_Argb2Rgb_Blend_RgbByteOrder(dest_scan, src_scan, w idth, m_BlendType, dest_Bpp, clip_scan);
3760 break;
3761 case 3:
3762 _CompositeRow_Rgb2Rgb_Blend_NoClip_RgbByteOrder(dest_scan, src_s can, width, m_BlendType, dest_Bpp, src_Bpp);
3763 break;
3764 case 5:
3765 _CompositeRow_Rgb2Argb_NoBlend_NoClip_RgbByteOrder(dest_scan, sr c_scan, width, src_Bpp);
3766 break;
3767 case 6:
3768 case 14:
3769 _CompositeRow_Argb2Rgb_NoBlend_RgbByteOrder(dest_scan, src_scan, width, dest_Bpp, clip_scan);
3770 break;
3771 case 7:
3772 _CompositeRow_Rgb2Rgb_NoBlend_NoClip_RgbByteOrder(dest_scan, src _scan, width, dest_Bpp, src_Bpp);
3773 break;
3774 case 9:
3775 _CompositeRow_Rgb2Argb_Blend_Clip_RgbByteOrder(dest_scan, src_sc an, width, m_BlendType, src_Bpp, clip_scan);
3776 break;
3777 case 11:
3778 _CompositeRow_Rgb2Rgb_Blend_Clip_RgbByteOrder(dest_scan, src_sca n, width, m_BlendType, dest_Bpp, src_Bpp, clip_scan);
3779 break;
3780 case 13:
3781 _CompositeRow_Rgb2Argb_NoBlend_Clip_RgbByteOrder(dest_scan, src_ scan, width, src_Bpp, clip_scan);
3782 break;
3783 case 15:
3784 _CompositeRow_Rgb2Rgb_NoBlend_Clip_RgbByteOrder(dest_scan, src_s can, width, dest_Bpp, src_Bpp, clip_scan);
3785 break;
3786 }
3787 return;
3788 }
3789 if (m_DestFormat == FXDIB_8bppMask) {
3790 if (m_SrcFormat & 0x0200) {
3791 if (m_SrcFormat == FXDIB_Argb) {
3792 _CompositeRow_Argb2Mask(dest_scan, src_scan, width, clip_scan);
3793 } else {
3794 _CompositeRow_Rgba2Mask(dest_scan, src_extra_alpha, width, clip_ scan);
3795 }
3796 } else {
3797 _CompositeRow_Rgb2Mask(dest_scan, src_scan, width, clip_scan);
3798 }
3799 } else if ((m_DestFormat & 0xff) == 8) {
3800 if (m_DestFormat & 0x0400) {
3801 for (int i = 0; i < width; i ++) {
3802 *dest_scan = ~*dest_scan;
3803 dest_scan++;
3804 }
3805 }
3806 if (m_SrcFormat & 0x0200) {
3807 if (m_DestFormat & 0x0200) {
3808 _CompositeRow_Argb2Graya(dest_scan, src_scan, width, m_BlendType , clip_scan, src_extra_alpha, dst_extra_alpha, m_pIccTransform);
3809 } else {
3810 _CompositeRow_Argb2Gray(dest_scan, src_scan, width, m_BlendType, clip_scan, src_extra_alpha, m_pIccTransform);
3811 }
3812 } else {
3813 if (m_DestFormat & 0x0200) {
3814 _CompositeRow_Rgb2Graya(dest_scan, src_scan, src_Bpp, width, m_B lendType, clip_scan, dst_extra_alpha, m_pIccTransform);
3815 } else {
3816 _CompositeRow_Rgb2Gray(dest_scan, src_scan, src_Bpp, width, m_Bl endType, clip_scan, m_pIccTransform);
3817 }
3818 }
3819 if (m_DestFormat & 0x0400) {
3820 for (int i = 0; i < width; i ++) {
3821 *dest_scan = ~*dest_scan;
3822 dest_scan++;
3823 }
3824 }
3825 } else {
3826 int dest_Size = width * dest_Bpp + 4;
3827 if (dest_Size > m_CacheSize) {
3828 m_pCacheScanline = FX_Realloc(uint8_t, m_pCacheScanline, dest_Size);
3829 if (!m_pCacheScanline) {
3830 return;
3831 }
3832 m_CacheSize = dest_Size;
3833 }
3834 switch (m_Transparency) {
3835 case 0:
3836 case 4:
3837 case 8:
3838 case 4+8: {
3839 _CompositeRow_Argb2Argb(dest_scan, src_scan, width, m_BlendT ype, clip_scan,
3840 dst_extra_alpha, src_extra_alpha);
3841 }
3842 break;
3843 case 64:
3844 case 4+64:
3845 case 8+64:
3846 case 4+8+64: {
3847 _CompositeRow_Argb2Argb_Transform(dest_scan, src_scan, width , m_BlendType, clip_scan,
3848 dst_extra_alpha, src_extra _alpha, m_pCacheScanline, m_pIccTransform);
3849 }
3850 break;
3851 case 1:
3852 _CompositeRow_Rgb2Argb_Blend_NoClip(dest_scan, src_scan, width, m_BlendType, src_Bpp,
3853 dst_extra_alpha);
3854 break;
3855 case 1+64:
3856 _CompositeRow_Rgb2Argb_Blend_NoClip_Transform(dest_scan, src_sca n, width, m_BlendType, src_Bpp,
3857 dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
3858 break;
3859 case 1+8:
3860 _CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_scan, width, m_ BlendType, src_Bpp, clip_scan,
3861 dst_extra_alpha);
3862 break;
3863 case 1+8+64:
3864 _CompositeRow_Rgb2Argb_Blend_Clip_Transform(dest_scan, src_scan, width, m_BlendType, src_Bpp, clip_scan,
3865 dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
3866 break;
3867 case 1+4:
3868 _CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_scan, width , src_Bpp,
3869 dst_extra_alpha);
3870 break;
3871 case 1+4+64:
3872 _CompositeRow_Rgb2Argb_NoBlend_NoClip_Transform(dest_scan, src_s can, width, src_Bpp,
3873 dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
3874 break;
3875 case 1+4+8:
3876 _CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_scan, width, src_Bpp, clip_scan,
3877 dst_extra_alpha);
3878 break;
3879 case 1+4+8+64:
3880 _CompositeRow_Rgb2Argb_NoBlend_Clip_Transform(dest_scan, src_sca n, width, src_Bpp, clip_scan,
3881 dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
3882 break;
3883 case 2:
3884 case 2+8:
3885 _CompositeRow_Argb2Rgb_Blend(dest_scan, src_scan, width, m_Blend Type, dest_Bpp, clip_scan,
3886 src_extra_alpha);
3887 break;
3888 case 2+64:
3889 case 2+8+64:
3890 _CompositeRow_Argb2Rgb_Blend_Transform(dest_scan, src_scan, widt h, m_BlendType, dest_Bpp, clip_scan,
3891 src_extra_alpha, m_pCache Scanline, m_pIccTransform);
3892 break;
3893 case 2+4:
3894 case 2+4+8:
3895 _CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_scan, width, dest_ Bpp, clip_scan,
3896 src_extra_alpha);
3897 break;
3898 case 2+4+64:
3899 case 2+4+8+64:
3900 _CompositeRow_Argb2Rgb_NoBlend_Transform(dest_scan, src_scan, wi dth, dest_Bpp, clip_scan,
3901 src_extra_alpha, m_pCacheScanline, m_pIccTransform);
3902 break;
3903 case 1+2:
3904 _CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_scan, width, m _BlendType, dest_Bpp, src_Bpp);
3905 break;
3906 case 1+2+64:
3907 _CompositeRow_Rgb2Rgb_Blend_NoClip_Transform(dest_scan, src_scan , width, m_BlendType, dest_Bpp, src_Bpp,
3908 m_pCacheScanline, m_pIccTransform);
3909 break;
3910 case 1+2+8:
3911 _CompositeRow_Rgb2Rgb_Blend_Clip(dest_scan, src_scan, width, m_B lendType, dest_Bpp, src_Bpp, clip_scan);
3912 break;
3913 case 1+2+8+64:
3914 _CompositeRow_Rgb2Rgb_Blend_Clip_Transform(dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp, clip_scan,
3915 m_pCacheScanline, m_pIccTransform);
3916 break;
3917 case 1+2+4:
3918 _CompositeRow_Rgb2Rgb_NoBlend_NoClip(dest_scan, src_scan, width, dest_Bpp, src_Bpp);
3919 break;
3920 case 1+2+4+64:
3921 _CompositeRow_Rgb2Rgb_NoBlend_NoClip_Transform(dest_scan, src_sc an, width, dest_Bpp, src_Bpp,
3922 m_pCacheScanline, m_pIccTransform);
3923 break;
3924 case 1+2+4+8:
3925 _CompositeRow_Rgb2Rgb_NoBlend_Clip(dest_scan, src_scan, width, d est_Bpp, src_Bpp, clip_scan);
3926 break;
3927 case 1+2+4+8+64:
3928 _CompositeRow_Rgb2Rgb_NoBlend_Clip_Transform(dest_scan, src_scan , width, dest_Bpp, src_Bpp, clip_scan,
3929 m_pCacheScanline, m_pIccTransform);
3930 break;
3931 }
3932 }
3933 }
3934 void CFX_ScanlineCompositor::CompositePalBitmapLine(uint8_t* dest_scan, const ui nt8_t* src_scan, int src_left, int width, const uint8_t* clip_scan,
3935 const uint8_t* src_extra_alpha, uint8_t* dst_extra_alpha)
3936 {
3937 if (m_bRgbByteOrder) {
3938 if (m_SrcFormat == FXDIB_1bppRgb) {
3939 if (m_DestFormat == FXDIB_8bppRgb) {
3940 return;
3941 }
3942 if(m_DestFormat == FXDIB_Argb) {
3943 _CompositeRow_1bppRgb2Argb_NoBlend_RgbByteOrder(dest_scan, src_s can, src_left, width, m_pSrcPalette, clip_scan);
3944 } else {
3945 _CompositeRow_1bppRgb2Rgb_NoBlend_RgbByteOrder(dest_scan, src_sc an, src_left, m_pSrcPalette, width, (m_DestFormat & 0xff) >> 3, clip_scan);
3946 }
3947 } else {
3948 if (m_DestFormat == FXDIB_8bppRgb) {
3949 return;
3950 }
3951 if (m_DestFormat == FXDIB_Argb) {
3952 _CompositeRow_8bppRgb2Argb_NoBlend_RgbByteOrder(dest_scan, src_s can, width, m_pSrcPalette, clip_scan);
3953 } else {
3954 _CompositeRow_8bppRgb2Rgb_NoBlend_RgbByteOrder(dest_scan, src_sc an, m_pSrcPalette, width, (m_DestFormat & 0xff) >> 3, clip_scan);
3955 }
3956 }
3957 return;
3958 }
3959 if (m_DestFormat == FXDIB_8bppMask) {
3960 _CompositeRow_Rgb2Mask(dest_scan, src_scan, width, clip_scan);
3961 return;
3962 }
3963 if ((m_DestFormat & 0xff) == 8) {
3964 if (m_Transparency & 8) {
3965 if (m_DestFormat & 0x0200) {
3966 _CompositeRow_1bppPal2Graya(dest_scan, src_scan, src_left, (cons t uint8_t*)m_pSrcPalette, width, m_BlendType, clip_scan, dst_extra_alpha);
3967 } else {
3968 _CompositeRow_1bppPal2Gray(dest_scan, src_scan, src_left, (const uint8_t*)m_pSrcPalette, width, m_BlendType, clip_scan);
3969 }
3970 } else {
3971 if (m_DestFormat & 0x0200)
3972 _CompositeRow_8bppPal2Graya(dest_scan, src_scan, (const uint8_t* )m_pSrcPalette, width, m_BlendType, clip_scan,
3973 dst_extra_alpha, src_extra_alpha);
3974 else
3975 _CompositeRow_8bppPal2Gray(dest_scan, src_scan, (const uint8_t*) m_pSrcPalette, width, m_BlendType, clip_scan,
3976 src_extra_alpha);
3977 }
3978 } else {
3979 switch (m_Transparency) {
3980 case 1+2:
3981 _CompositeRow_8bppRgb2Argb_NoBlend(dest_scan, src_scan, width, m _pSrcPalette, clip_scan,
3982 src_extra_alpha);
3983 break;
3984 case 1+2+8:
3985 _CompositeRow_1bppRgb2Argb_NoBlend(dest_scan, src_scan, src_left , width, m_pSrcPalette, clip_scan);
3986 break;
3987 case 0:
3988 _CompositeRow_8bppRgb2Rgb_NoBlend(dest_scan, src_scan, m_pSrcPal ette, width, (m_DestFormat & 0xff) >> 3, clip_scan,
3989 src_extra_alpha);
3990 break;
3991 case 0+8:
3992 _CompositeRow_1bppRgb2Rgb_NoBlend(dest_scan, src_scan, src_left, m_pSrcPalette, width, (m_DestFormat & 0xff) >> 3, clip_scan);
3993 break;
3994 case 0+2:
3995 _CompositeRow_8bppRgb2Rgb_NoBlend(dest_scan, src_scan, m_pSrcPal ette, width, (m_DestFormat & 0xff) >> 3, clip_scan,
3996 src_extra_alpha);
3997 break;
3998 case 0+2+8:
3999 _CompositeRow_1bppRgb2Rgba_NoBlend(dest_scan, src_scan, src_left , width, m_pSrcPalette, clip_scan,
4000 dst_extra_alpha);
4001 break;
4002 break;
4003 }
4004 }
4005 }
4006 void CFX_ScanlineCompositor::CompositeByteMaskLine(uint8_t* dest_scan, const uin t8_t* src_scan, int width, const uint8_t* clip_scan,
4007 uint8_t* dst_extra_alpha)
4008 {
4009 if (m_DestFormat == FXDIB_8bppMask) {
4010 _CompositeRow_ByteMask2Mask(dest_scan, src_scan, m_MaskAlpha, width, cli p_scan);
4011 } else if ((m_DestFormat & 0xff) == 8) {
4012 if (m_DestFormat & 0x0200) {
4013 _CompositeRow_ByteMask2Graya(dest_scan, src_scan, m_MaskAlpha, m_Mas kRed, width, clip_scan, dst_extra_alpha);
4014 } else {
4015 _CompositeRow_ByteMask2Gray(dest_scan, src_scan, m_MaskAlpha, m_Mask Red, width, clip_scan);
4016 }
4017 } else if (m_bRgbByteOrder) {
4018 if (m_DestFormat == FXDIB_Argb)
4019 _CompositeRow_ByteMask2Argb_RgbByteOrder(dest_scan, src_scan, m_Mask Alpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4020 width, m_BlendType, clip_scan);
4021 else
4022 _CompositeRow_ByteMask2Rgb_RgbByteOrder(dest_scan, src_scan, m_MaskA lpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4023 width, m_BlendType, (m_DestF ormat & 0xff) >> 3, clip_scan);
4024 return;
4025 } else if (m_DestFormat == FXDIB_Argb)
4026 _CompositeRow_ByteMask2Argb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4027 width, m_BlendType, clip_scan);
4028 else if (m_DestFormat == FXDIB_Rgb || m_DestFormat == FXDIB_Rgb32)
4029 _CompositeRow_ByteMask2Rgb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4030 width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
4031 else if (m_DestFormat == FXDIB_Rgba)
4032 _CompositeRow_ByteMask2Rgba(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue,
4033 width, m_BlendType, clip_scan, dst_extra_alp ha);
4034 }
4035 void CFX_ScanlineCompositor::CompositeBitMaskLine(uint8_t* dest_scan, const uint 8_t* src_scan, int src_left, int width, const uint8_t* clip_scan,
4036 uint8_t* dst_extra_alpha)
4037 {
4038 if (m_DestFormat == FXDIB_8bppMask) {
4039 _CompositeRow_BitMask2Mask(dest_scan, src_scan, m_MaskAlpha, src_left, w idth, clip_scan);
4040 } else if ((m_DestFormat & 0xff) == 8) {
4041 if (m_DestFormat & 0x0200)
4042 _CompositeRow_BitMask2Graya(dest_scan, src_scan, m_MaskAlpha, m_Mask Red, src_left, width, clip_scan,
4043 dst_extra_alpha); 5104 dst_extra_alpha);
4044 else { 5105 } else {
4045 _CompositeRow_BitMask2Gray(dest_scan, src_scan, m_MaskAlpha, m_MaskR ed, src_left, width, clip_scan); 5106 m_Compositor.CompositeRgbBitmapLine(dest_scan, src_scan, dest_width,
4046 } 5107 clip_scan, src_extra_alpha,
4047 } else if (m_bRgbByteOrder) { 5108 dst_extra_alpha);
4048 if (m_DestFormat == FXDIB_Argb) 5109 }
4049 _CompositeRow_BitMask2Argb_RgbByteOrder(dest_scan, src_scan, m_MaskA lpha, m_MaskRed, m_MaskGreen, m_MaskBlue, 5110 }
4050 src_left, width, m_BlendType , clip_scan); 5111 void CFX_BitmapComposer::ComposeScanline(int line,
4051 else 5112 const uint8_t* scanline,
4052 _CompositeRow_BitMask2Rgb_RgbByteOrder(dest_scan, src_scan, m_MaskAl pha, m_MaskRed, m_MaskGreen, m_MaskBlue, 5113 const uint8_t* scan_extra_alpha) {
4053 src_left, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan); 5114 if (m_bVertical) {
4054 return; 5115 ComposeScanlineV(line, scanline, scan_extra_alpha);
4055 } else if (m_DestFormat == FXDIB_Argb) 5116 return;
4056 _CompositeRow_BitMask2Argb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, 5117 }
4057 src_left, width, m_BlendType, clip_scan); 5118 const uint8_t* clip_scan = NULL;
4058 else if (m_DestFormat == FXDIB_Rgb || m_DestFormat == FXDIB_Rgb32) 5119 if (m_pClipMask)
4059 _CompositeRow_BitMask2Rgb(dest_scan, src_scan, m_MaskAlpha, m_MaskRed, m _MaskGreen, m_MaskBlue, 5120 clip_scan = m_pClipMask->GetBuffer() +
4060 src_left, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan); 5121 (m_DestTop + line - m_pClipRgn->GetBox().top) *
4061 } 5122 m_pClipMask->GetPitch() +
4062 FX_BOOL CFX_DIBitmap::CompositeBitmap(int dest_left, int dest_top, int width, in t height, 5123 (m_DestLeft - m_pClipRgn->GetBox().left);
4063 const CFX_DIBSource* pSrcBitmap, int src_l eft, int src_top, 5124 uint8_t* dest_scan = (uint8_t*)m_pBitmap->GetScanline(line + m_DestTop) +
4064 int blend_type, const CFX_ClipRgn* pClipRg n, FX_BOOL bRgbByteOrder, void* pIccTransform) 5125 m_DestLeft * m_pBitmap->GetBPP() / 8;
4065 { 5126 uint8_t* dest_alpha_scan =
4066 if (m_pBuffer == NULL) { 5127 m_pBitmap->m_pAlphaMask
4067 return FALSE; 5128 ? (uint8_t*)m_pBitmap->m_pAlphaMask->GetScanline(line + m_DestTop) +
4068 } 5129 m_DestLeft
4069 ASSERT(!pSrcBitmap->IsAlphaMask()); 5130 : NULL;
4070 ASSERT(m_bpp >= 8); 5131 DoCompose(dest_scan, scanline, m_DestWidth, clip_scan, scan_extra_alpha,
4071 if (pSrcBitmap->IsAlphaMask() || m_bpp < 8) { 5132 dest_alpha_scan);
4072 return FALSE; 5133 }
4073 } 5134 void CFX_BitmapComposer::ComposeScanlineV(int line,
4074 GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(), p SrcBitmap->GetHeight(), 5135 const uint8_t* scanline,
4075 src_left, src_top, pClipRgn); 5136 const uint8_t* scan_extra_alpha) {
4076 if (width == 0 || height == 0) { 5137 int i;
4077 return TRUE; 5138 int Bpp = m_pBitmap->GetBPP() / 8;
4078 } 5139 int dest_pitch = m_pBitmap->GetPitch();
4079 const CFX_DIBitmap* pClipMask = NULL; 5140 int dest_alpha_pitch =
4080 FX_RECT clip_box; 5141 m_pBitmap->m_pAlphaMask ? m_pBitmap->m_pAlphaMask->GetPitch() : 0;
4081 if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) { 5142 int dest_x = m_DestLeft + (m_bFlipX ? (m_DestWidth - line - 1) : line);
4082 ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF); 5143 uint8_t* dest_buf =
4083 pClipMask = pClipRgn->GetMask(); 5144 m_pBitmap->GetBuffer() + dest_x * Bpp + m_DestTop * dest_pitch;
4084 clip_box = pClipRgn->GetBox(); 5145 uint8_t* dest_alpha_buf = m_pBitmap->m_pAlphaMask
4085 } 5146 ? m_pBitmap->m_pAlphaMask->GetBuffer() +
4086 CFX_ScanlineCompositor compositor; 5147 dest_x + m_DestTop * dest_alpha_pitch
4087 if (!compositor.Init(GetFormat(), pSrcBitmap->GetFormat(), width, pSrcBitmap ->GetPalette(), 0, blend_type, 5148 : NULL;
4088 pClipMask != NULL, bRgbByteOrder, 0, pIccTransform)) { 5149 if (m_bFlipY) {
4089 return FALSE; 5150 dest_buf += dest_pitch * (m_DestHeight - 1);
4090 } 5151 dest_alpha_buf += dest_alpha_pitch * (m_DestHeight - 1);
4091 int dest_Bpp = m_bpp / 8; 5152 }
4092 int src_Bpp = pSrcBitmap->GetBPP() / 8; 5153 int y_step = dest_pitch;
4093 FX_BOOL bRgb = src_Bpp > 1 && !pSrcBitmap->IsCmykImage(); 5154 int y_alpha_step = dest_alpha_pitch;
4094 CFX_DIBitmap* pSrcAlphaMask = pSrcBitmap->m_pAlphaMask; 5155 if (m_bFlipY) {
4095 for (int row = 0; row < height; row ++) { 5156 y_step = -y_step;
4096 uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch + dest_left * dest_Bpp; 5157 y_alpha_step = -y_alpha_step;
4097 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l eft * src_Bpp; 5158 }
4098 const uint8_t* src_scan_extra_alpha = pSrcAlphaMask ? pSrcAlphaMask->Get Scanline(src_top + row) + src_left : NULL; 5159 uint8_t* src_scan = m_pScanlineV;
4099 uint8_t* dst_scan_extra_alpha = m_pAlphaMask ? (uint8_t*)m_pAlphaMask->G etScanline(dest_top + row) + dest_left : NULL; 5160 uint8_t* dest_scan = dest_buf;
4100 const uint8_t* clip_scan = NULL; 5161 for (i = 0; i < m_DestHeight; i++) {
4101 if (pClipMask) { 5162 for (int j = 0; j < Bpp; j++) {
4102 clip_scan = pClipMask->m_pBuffer + (dest_top + row - clip_box.top) * pClipMask->m_Pitch + (dest_left - clip_box.left); 5163 *src_scan++ = dest_scan[j];
4103 } 5164 }
4104 if (bRgb) { 5165 dest_scan += y_step;
4105 compositor.CompositeRgbBitmapLine(dest_scan, src_scan, width, clip_s can, src_scan_extra_alpha, dst_scan_extra_alpha); 5166 }
4106 } else { 5167 uint8_t* src_alpha_scan = m_pScanlineAlphaV;
4107 compositor.CompositePalBitmapLine(dest_scan, src_scan, src_left, wid th, clip_scan, src_scan_extra_alpha, dst_scan_extra_alpha); 5168 uint8_t* dest_alpha_scan = dest_alpha_buf;
4108 } 5169 if (dest_alpha_scan) {
4109 } 5170 for (i = 0; i < m_DestHeight; i++) {
4110 return TRUE; 5171 *src_alpha_scan++ = *dest_alpha_scan;
4111 } 5172 dest_alpha_scan += y_alpha_step;
4112 FX_BOOL CFX_DIBitmap::CompositeMask(int dest_left, int dest_top, int width, int height, 5173 }
4113 const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top, 5174 }
4114 int blend_type, const CFX_ClipRgn* pClipRgn, FX_BOOL bRgbByteOrder, int alpha_flag, void* pIccTransform) 5175 uint8_t* clip_scan = NULL;
4115 { 5176 if (m_pClipMask) {
4116 if (m_pBuffer == NULL) { 5177 clip_scan = m_pClipScanV;
4117 return FALSE; 5178 int clip_pitch = m_pClipMask->GetPitch();
4118 } 5179 const uint8_t* src_clip =
4119 ASSERT(pMask->IsAlphaMask()); 5180 m_pClipMask->GetBuffer() +
4120 ASSERT(m_bpp >= 8); 5181 (m_DestTop - m_pClipRgn->GetBox().top) * clip_pitch +
4121 if (!pMask->IsAlphaMask() || m_bpp < 8) { 5182 (dest_x - m_pClipRgn->GetBox().left);
4122 return FALSE;
4123 }
4124 GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(), pMask- >GetHeight(), src_left, src_top, pClipRgn);
4125 if (width == 0 || height == 0) {
4126 return TRUE;
4127 }
4128 int src_alpha = (uint8_t)(alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A( color);
4129 if (src_alpha == 0) {
4130 return TRUE;
4131 }
4132 const CFX_DIBitmap* pClipMask = NULL;
4133 FX_RECT clip_box;
4134 if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
4135 ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
4136 pClipMask = pClipRgn->GetMask();
4137 clip_box = pClipRgn->GetBox();
4138 }
4139 int src_bpp = pMask->GetBPP();
4140 int Bpp = GetBPP() / 8;
4141 CFX_ScanlineCompositor compositor;
4142 if (!compositor.Init(GetFormat(), pMask->GetFormat(), width, NULL, color, bl end_type, pClipMask != NULL, bRgbByteOrder, alpha_flag, pIccTransform)) {
4143 return FALSE;
4144 }
4145 for (int row = 0; row < height; row ++) {
4146 uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp;
4147 const uint8_t* src_scan = pMask->GetScanline(src_top + row);
4148 uint8_t* dst_scan_extra_alpha = m_pAlphaMask ? (uint8_t*)m_pAlphaMask->G etScanline(dest_top + row) + dest_left : NULL;
4149 const uint8_t* clip_scan = NULL;
4150 if (pClipMask) {
4151 clip_scan = pClipMask->m_pBuffer + (dest_top + row - clip_box.top) * pClipMask->m_Pitch + (dest_left - clip_box.left);
4152 }
4153 if (src_bpp == 1) {
4154 compositor.CompositeBitMaskLine(dest_scan, src_scan, src_left, width , clip_scan, dst_scan_extra_alpha);
4155 } else {
4156 compositor.CompositeByteMaskLine(dest_scan, src_scan + src_left, wid th, clip_scan, dst_scan_extra_alpha);
4157 }
4158 }
4159 return TRUE;
4160 }
4161 FX_BOOL CFX_DIBitmap::CompositeRect(int left, int top, int width, int height, FX _DWORD color, int alpha_flag, void* pIccTransform)
4162 {
4163 if (m_pBuffer == NULL) {
4164 return FALSE;
4165 }
4166 int src_alpha = (alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
4167 if (src_alpha == 0) {
4168 return TRUE;
4169 }
4170 FX_RECT rect(left, top, left + width, top + height);
4171 rect.Intersect(0, 0, m_Width, m_Height);
4172 if (rect.IsEmpty()) {
4173 return TRUE;
4174 }
4175 width = rect.Width();
4176 FX_DWORD dst_color;
4177 if (alpha_flag >> 8) {
4178 dst_color = FXCMYK_TODIB(color);
4179 } else {
4180 dst_color = FXARGB_TODIB(color);
4181 }
4182 uint8_t* color_p = (uint8_t*)&dst_color;
4183 if (m_bpp == 8) {
4184 uint8_t gray = 255;
4185 if (!IsAlphaMask()) {
4186 if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() && CFX_GE Module::Get()->GetCodecModule()->GetIccModule()) {
4187 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModu le()->GetIccModule();
4188 pIccModule->TranslateScanline(pIccTransform, &gray, color_p, 1);
4189 } else {
4190 if (alpha_flag >> 8) {
4191 uint8_t r, g, b;
4192 AdobeCMYK_to_sRGB1(color_p[0], color_p[1], color_p[2], color _p[3],
4193 r, g, b);
4194 gray = FXRGB2GRAY(r, g, b);
4195 } else {
4196 gray = (uint8_t)FXRGB2GRAY((int)color_p[2], color_p[1], colo r_p[0]);
4197 }
4198 }
4199 if (IsCmykImage()) {
4200 gray = ~gray;
4201 }
4202 }
4203 for (int row = rect.top; row < rect.bottom; row ++) {
4204 uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left;
4205 if (src_alpha == 255) {
4206 FXSYS_memset(dest_scan, gray, width);
4207 } else
4208 for (int col = 0; col < width; col ++) {
4209 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
4210 dest_scan ++;
4211 }
4212 }
4213 return TRUE;
4214 }
4215 if (m_bpp == 1) {
4216 ASSERT(!IsCmykImage() && (uint8_t)(alpha_flag >> 8) == 0);
4217 int left_shift = rect.left % 8;
4218 int right_shift = rect.right % 8;
4219 int width = rect.right / 8 - rect.left / 8;
4220 int index = 0;
4221 if (m_pPalette == NULL) {
4222 index = ((uint8_t)color == 0xff) ? 1 : 0;
4223 } else {
4224 for (int i = 0; i < 2; i ++)
4225 if (m_pPalette[i] == color) {
4226 index = i;
4227 }
4228 }
4229 for (int row = rect.top; row < rect.bottom; row ++) {
4230 uint8_t* dest_scan_top = (uint8_t*)GetScanline(row) + rect.left / 8;
4231 uint8_t* dest_scan_top_r = (uint8_t*)GetScanline(row) + rect.right / 8;
4232 uint8_t left_flag = *dest_scan_top & (255 << (8 - left_shift));
4233 uint8_t right_flag = *dest_scan_top_r & (255 >> right_shift);
4234 if (width) {
4235 FXSYS_memset(dest_scan_top + 1, index ? 255 : 0, width - 1);
4236 if (!index) {
4237 *dest_scan_top &= left_flag;
4238 *dest_scan_top_r &= right_flag;
4239 } else {
4240 *dest_scan_top |= ~left_flag;
4241 *dest_scan_top_r |= ~right_flag;
4242 }
4243 } else {
4244 if (!index) {
4245 *dest_scan_top &= left_flag | right_flag;
4246 } else {
4247 *dest_scan_top |= ~(left_flag | right_flag);
4248 }
4249 }
4250 }
4251 return TRUE;
4252 }
4253 ASSERT(m_bpp >= 24);
4254 if (m_bpp < 24) {
4255 return FALSE;
4256 }
4257 if (pIccTransform && CFX_GEModule::Get()->GetCodecModule()) {
4258 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
4259 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1);
4260 } else {
4261 if (alpha_flag >> 8 && !IsCmykImage())
4262 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), F XSYS_GetYValue(color), FXSYS_GetKValue(color),
4263 color_p[2], color_p[1], color_p[0]);
4264 else if (!(alpha_flag >> 8) && IsCmykImage()) {
4265 return FALSE;
4266 }
4267 }
4268 if(!IsCmykImage()) {
4269 color_p[3] = (uint8_t)src_alpha;
4270 }
4271 int Bpp = m_bpp / 8;
4272 FX_BOOL bAlpha = HasAlpha();
4273 FX_BOOL bArgb = GetFormat() == FXDIB_Argb ? TRUE : FALSE;
4274 if (src_alpha == 255) {
4275 for (int row = rect.top; row < rect.bottom; row ++) {
4276 uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp;
4277 uint8_t* dest_scan_alpha = m_pAlphaMask ? (uint8_t*)m_pAlphaMask->Ge tScanline(row) + rect.left : NULL;
4278 if (dest_scan_alpha) {
4279 FXSYS_memset(dest_scan_alpha, 0xff, width);
4280 }
4281 if (Bpp == 4) {
4282 FX_DWORD* scan = (FX_DWORD*)dest_scan;
4283 for (int col = 0; col < width; col ++) {
4284 *scan ++ = dst_color;
4285 }
4286 } else {
4287 for (int col = 0; col < width; col ++) {
4288 *dest_scan ++ = color_p[0];
4289 *dest_scan ++ = color_p[1];
4290 *dest_scan ++ = color_p[2];
4291 }
4292 }
4293 }
4294 return TRUE;
4295 }
4296 for (int row = rect.top; row < rect.bottom; row ++) {
4297 uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp;
4298 if (bAlpha) {
4299 if (bArgb) {
4300 for (int col = 0; col < width; col ++) {
4301 uint8_t back_alpha = dest_scan[3];
4302 if (back_alpha == 0) {
4303 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, color_p[ 2], color_p[1], color_p[0]));
4304 dest_scan += 4;
4305 continue;
4306 }
4307 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * s rc_alpha / 255;
4308 int alpha_ratio = src_alpha * 255 / dest_alpha;
4309 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[0], alpha _ratio);
4310 dest_scan ++;
4311 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[1], alpha _ratio);
4312 dest_scan ++;
4313 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[2], alpha _ratio);
4314 dest_scan ++;
4315 *dest_scan++ = dest_alpha;
4316 }
4317 } else {
4318 uint8_t* dest_scan_alpha = (uint8_t*)m_pAlphaMask->GetScanline(r ow) + rect.left;
4319 for (int col = 0; col < width; col ++) {
4320 uint8_t back_alpha = *dest_scan_alpha;
4321 if (back_alpha == 0) {
4322 *dest_scan_alpha++ = src_alpha;
4323 FXSYS_memcpy(dest_scan, color_p, Bpp);
4324 dest_scan += Bpp;
4325 continue;
4326 }
4327 uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * s rc_alpha / 255;
4328 *dest_scan_alpha ++ = dest_alpha;
4329 int alpha_ratio = src_alpha * 255 / dest_alpha;
4330 for(int comps = 0; comps < Bpp; comps ++) {
4331 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps ], alpha_ratio);
4332 dest_scan ++;
4333 }
4334 }
4335 }
4336 } else {
4337 for (int col = 0; col < width; col ++) {
4338 for(int comps = 0; comps < Bpp; comps ++) {
4339 if (comps == 3) {
4340 *dest_scan ++ = 255;
4341 continue;
4342 }
4343 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], s rc_alpha);
4344 dest_scan ++;
4345 }
4346 }
4347 }
4348 }
4349 return TRUE;
4350 }
4351 CFX_BitmapComposer::CFX_BitmapComposer()
4352 {
4353 m_pScanlineV = NULL;
4354 m_pScanlineAlphaV = NULL;
4355 m_pClipScanV = NULL;
4356 m_pAddClipScan = NULL;
4357 m_bRgbByteOrder = FALSE;
4358 m_BlendType = FXDIB_BLEND_NORMAL;
4359 }
4360 CFX_BitmapComposer::~CFX_BitmapComposer()
4361 {
4362 if (m_pScanlineV) {
4363 FX_Free(m_pScanlineV);
4364 }
4365 if (m_pScanlineAlphaV) {
4366 FX_Free(m_pScanlineAlphaV);
4367 }
4368 if (m_pClipScanV) {
4369 FX_Free(m_pClipScanV);
4370 }
4371 if (m_pAddClipScan) {
4372 FX_Free(m_pAddClipScan);
4373 }
4374 }
4375 void CFX_BitmapComposer::Compose(CFX_DIBitmap* pDest, const CFX_ClipRgn* pClipRg n, int bitmap_alpha,
4376 FX_DWORD mask_color, FX_RECT& dest_rect, FX_BOO L bVertical,
4377 FX_BOOL bFlipX, FX_BOOL bFlipY, FX_BOOL bRgbByt eOrder,
4378 int alpha_flag, void* pIccTransform, int blend_ type)
4379 {
4380 m_pBitmap = pDest;
4381 m_pClipRgn = pClipRgn;
4382 m_DestLeft = dest_rect.left;
4383 m_DestTop = dest_rect.top;
4384 m_DestWidth = dest_rect.Width();
4385 m_DestHeight = dest_rect.Height();
4386 m_BitmapAlpha = bitmap_alpha;
4387 m_MaskColor = mask_color;
4388 m_pClipMask = NULL;
4389 if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
4390 m_pClipMask = pClipRgn->GetMask();
4391 }
4392 m_bVertical = bVertical;
4393 m_bFlipX = bFlipX;
4394 m_bFlipY = bFlipY;
4395 m_AlphaFlag = alpha_flag;
4396 m_pIccTransform = pIccTransform;
4397 m_bRgbByteOrder = bRgbByteOrder;
4398 m_BlendType = blend_type;
4399 }
4400 FX_BOOL CFX_BitmapComposer::SetInfo(int width, int height, FXDIB_Format src_form at, FX_DWORD* pSrcPalette)
4401 {
4402 m_SrcFormat = src_format;
4403 if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, pSrcPalett e, m_MaskColor, FXDIB_BLEND_NORMAL,
4404 m_pClipMask != NULL || (m_BitmapAlpha < 255), m_bRgbB yteOrder, m_AlphaFlag, m_pIccTransform)) {
4405 return FALSE;
4406 }
4407 if (m_bVertical) {
4408 m_pScanlineV = FX_Alloc(uint8_t, m_pBitmap->GetBPP() / 8 * width + 4);
4409 m_pClipScanV = FX_Alloc(uint8_t, m_pBitmap->GetHeight());
4410 if (m_pBitmap->m_pAlphaMask) {
4411 m_pScanlineAlphaV = FX_Alloc(uint8_t, width + 4);
4412 }
4413 }
4414 if (m_BitmapAlpha < 255) {
4415 m_pAddClipScan = FX_Alloc(uint8_t, m_bVertical ? m_pBitmap->GetHeight() : m_pBitmap->GetWidth());
4416 }
4417 return TRUE;
4418 }
4419 void CFX_BitmapComposer::DoCompose(uint8_t* dest_scan, const uint8_t* src_scan, int dest_width, const uint8_t* clip_scan,
4420 const uint8_t* src_extra_alpha, uint8_t* dst_ extra_alpha)
4421 {
4422 if (m_BitmapAlpha < 255) {
4423 if (clip_scan) {
4424 for (int i = 0; i < dest_width; i ++) {
4425 m_pAddClipScan[i] = clip_scan[i] * m_BitmapAlpha / 255;
4426 }
4427 } else {
4428 FXSYS_memset(m_pAddClipScan, m_BitmapAlpha, dest_width);
4429 }
4430 clip_scan = m_pAddClipScan;
4431 }
4432 if (m_SrcFormat == FXDIB_8bppMask) {
4433 m_Compositor.CompositeByteMaskLine(dest_scan, src_scan, dest_width, clip _scan, dst_extra_alpha);
4434 } else if ((m_SrcFormat & 0xff) == 8) {
4435 m_Compositor.CompositePalBitmapLine(dest_scan, src_scan, 0, dest_width, clip_scan, src_extra_alpha, dst_extra_alpha);
4436 } else {
4437 m_Compositor.CompositeRgbBitmapLine(dest_scan, src_scan, dest_width, cli p_scan, src_extra_alpha, dst_extra_alpha);
4438 }
4439 }
4440 void CFX_BitmapComposer::ComposeScanline(int line, const uint8_t* scanline, cons t uint8_t* scan_extra_alpha)
4441 {
4442 if (m_bVertical) {
4443 ComposeScanlineV(line, scanline, scan_extra_alpha);
4444 return;
4445 }
4446 const uint8_t* clip_scan = NULL;
4447 if (m_pClipMask)
4448 clip_scan = m_pClipMask->GetBuffer() + (m_DestTop + line - m_pClipRgn->G etBox().top) *
4449 m_pClipMask->GetPitch() + (m_DestLeft - m_pClipRgn->GetBox() .left);
4450 uint8_t* dest_scan = (uint8_t*)m_pBitmap->GetScanline(line + m_DestTop) +
4451 m_DestLeft * m_pBitmap->GetBPP() / 8;
4452 uint8_t* dest_alpha_scan = m_pBitmap->m_pAlphaMask ?
4453 (uint8_t*)m_pBitmap->m_pAlphaMask->GetScanline(l ine + m_DestTop) + m_DestLeft : NULL;
4454 DoCompose(dest_scan, scanline, m_DestWidth, clip_scan, scan_extra_alpha, des t_alpha_scan);
4455 }
4456 void CFX_BitmapComposer::ComposeScanlineV(int line, const uint8_t* scanline, con st uint8_t* scan_extra_alpha)
4457 {
4458 int i;
4459 int Bpp = m_pBitmap->GetBPP() / 8;
4460 int dest_pitch = m_pBitmap->GetPitch();
4461 int dest_alpha_pitch = m_pBitmap->m_pAlphaMask ? m_pBitmap->m_pAlphaMask->Ge tPitch() : 0;
4462 int dest_x = m_DestLeft + (m_bFlipX ? (m_DestWidth - line - 1) : line);
4463 uint8_t* dest_buf = m_pBitmap->GetBuffer() + dest_x * Bpp + m_DestTop * dest _pitch;
4464 uint8_t* dest_alpha_buf = m_pBitmap->m_pAlphaMask ?
4465 m_pBitmap->m_pAlphaMask->GetBuffer() + dest_x + m _DestTop * dest_alpha_pitch : NULL;
4466 if (m_bFlipY) { 5183 if (m_bFlipY) {
4467 dest_buf += dest_pitch * (m_DestHeight - 1); 5184 src_clip += clip_pitch * (m_DestHeight - 1);
4468 dest_alpha_buf += dest_alpha_pitch * (m_DestHeight - 1); 5185 clip_pitch = -clip_pitch;
4469 } 5186 }
4470 int y_step = dest_pitch; 5187 for (i = 0; i < m_DestHeight; i++) {
4471 int y_alpha_step = dest_alpha_pitch; 5188 clip_scan[i] = *src_clip;
4472 if (m_bFlipY) { 5189 src_clip += clip_pitch;
4473 y_step = -y_step; 5190 }
4474 y_alpha_step = -y_alpha_step; 5191 }
4475 } 5192 DoCompose(m_pScanlineV, scanline, m_DestHeight, clip_scan, scan_extra_alpha,
4476 uint8_t* src_scan = m_pScanlineV; 5193 m_pScanlineAlphaV);
4477 uint8_t* dest_scan = dest_buf; 5194 src_scan = m_pScanlineV;
4478 for (i = 0; i < m_DestHeight; i ++) { 5195 dest_scan = dest_buf;
4479 for (int j = 0; j < Bpp; j ++) { 5196 for (i = 0; i < m_DestHeight; i++) {
4480 *src_scan++ = dest_scan[j]; 5197 for (int j = 0; j < Bpp; j++) {
4481 } 5198 dest_scan[j] = *src_scan++;
4482 dest_scan += y_step; 5199 }
4483 } 5200 dest_scan += y_step;
4484 uint8_t* src_alpha_scan = m_pScanlineAlphaV; 5201 }
4485 uint8_t* dest_alpha_scan = dest_alpha_buf; 5202 src_alpha_scan = m_pScanlineAlphaV;
4486 if (dest_alpha_scan) { 5203 dest_alpha_scan = dest_alpha_buf;
4487 for (i = 0; i < m_DestHeight; i ++) { 5204 if (dest_alpha_scan) {
4488 *src_alpha_scan++ = *dest_alpha_scan; 5205 for (i = 0; i < m_DestHeight; i++) {
4489 dest_alpha_scan += y_alpha_step; 5206 *dest_alpha_scan = *src_alpha_scan++;
4490 } 5207 dest_alpha_scan += y_alpha_step;
4491 } 5208 }
4492 uint8_t* clip_scan = NULL; 5209 }
4493 if (m_pClipMask) { 5210 }
4494 clip_scan = m_pClipScanV;
4495 int clip_pitch = m_pClipMask->GetPitch();
4496 const uint8_t* src_clip = m_pClipMask->GetBuffer() + (m_DestTop - m_pCli pRgn->GetBox().top) *
4497 clip_pitch + (dest_x - m_pClipRgn->GetBox().left);
4498 if (m_bFlipY) {
4499 src_clip += clip_pitch * (m_DestHeight - 1);
4500 clip_pitch = -clip_pitch;
4501 }
4502 for (i = 0; i < m_DestHeight; i ++) {
4503 clip_scan[i] = *src_clip;
4504 src_clip += clip_pitch;
4505 }
4506 }
4507 DoCompose(m_pScanlineV, scanline, m_DestHeight, clip_scan, scan_extra_alpha, m_pScanlineAlphaV);
4508 src_scan = m_pScanlineV;
4509 dest_scan = dest_buf;
4510 for (i = 0; i < m_DestHeight; i ++) {
4511 for (int j = 0; j < Bpp; j ++) {
4512 dest_scan[j] = *src_scan++;
4513 }
4514 dest_scan += y_step;
4515 }
4516 src_alpha_scan = m_pScanlineAlphaV;
4517 dest_alpha_scan = dest_alpha_buf;
4518 if (dest_alpha_scan) {
4519 for (i = 0; i < m_DestHeight; i ++) {
4520 *dest_alpha_scan = *src_alpha_scan++;
4521 dest_alpha_scan += y_alpha_step;
4522 }
4523 }
4524 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698