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