gfx/cairo/libpixman/src/pixman-combine64.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* WARNING: This file is generated by combine.pl from combine.inc.
michael@0 2 Please edit one of those files rather than this one. */
michael@0 3
michael@0 4 #line 1 "pixman-combine.c.template"
michael@0 5 #ifdef HAVE_CONFIG_H
michael@0 6 #include <config.h>
michael@0 7 #endif
michael@0 8
michael@0 9 #include <math.h>
michael@0 10 #include <string.h>
michael@0 11
michael@0 12 #include "pixman-private.h"
michael@0 13
michael@0 14 #include "pixman-combine64.h"
michael@0 15
michael@0 16 /*** per channel helper functions ***/
michael@0 17
michael@0 18 static void
michael@0 19 combine_mask_ca (uint64_t *src, uint64_t *mask)
michael@0 20 {
michael@0 21 uint64_t a = *mask;
michael@0 22
michael@0 23 uint64_t x;
michael@0 24 uint32_t xa;
michael@0 25
michael@0 26 if (!a)
michael@0 27 {
michael@0 28 *(src) = 0;
michael@0 29 return;
michael@0 30 }
michael@0 31
michael@0 32 x = *(src);
michael@0 33 if (a == ~0)
michael@0 34 {
michael@0 35 x = x >> A_SHIFT;
michael@0 36 x |= x << G_SHIFT;
michael@0 37 x |= x << R_SHIFT;
michael@0 38 *(mask) = x;
michael@0 39 return;
michael@0 40 }
michael@0 41
michael@0 42 xa = x >> A_SHIFT;
michael@0 43 UN16x4_MUL_UN16x4 (x, a);
michael@0 44 *(src) = x;
michael@0 45
michael@0 46 UN16x4_MUL_UN16 (a, xa);
michael@0 47 *(mask) = a;
michael@0 48 }
michael@0 49
michael@0 50 static void
michael@0 51 combine_mask_value_ca (uint64_t *src, const uint64_t *mask)
michael@0 52 {
michael@0 53 uint64_t a = *mask;
michael@0 54 uint64_t x;
michael@0 55
michael@0 56 if (!a)
michael@0 57 {
michael@0 58 *(src) = 0;
michael@0 59 return;
michael@0 60 }
michael@0 61
michael@0 62 if (a == ~0)
michael@0 63 return;
michael@0 64
michael@0 65 x = *(src);
michael@0 66 UN16x4_MUL_UN16x4 (x, a);
michael@0 67 *(src) = x;
michael@0 68 }
michael@0 69
michael@0 70 static void
michael@0 71 combine_mask_alpha_ca (const uint64_t *src, uint64_t *mask)
michael@0 72 {
michael@0 73 uint64_t a = *(mask);
michael@0 74 uint64_t x;
michael@0 75
michael@0 76 if (!a)
michael@0 77 return;
michael@0 78
michael@0 79 x = *(src) >> A_SHIFT;
michael@0 80 if (x == MASK)
michael@0 81 return;
michael@0 82
michael@0 83 if (a == ~0)
michael@0 84 {
michael@0 85 x |= x << G_SHIFT;
michael@0 86 x |= x << R_SHIFT;
michael@0 87 *(mask) = x;
michael@0 88 return;
michael@0 89 }
michael@0 90
michael@0 91 UN16x4_MUL_UN16 (a, x);
michael@0 92 *(mask) = a;
michael@0 93 }
michael@0 94
michael@0 95 /*
michael@0 96 * There are two ways of handling alpha -- either as a single unified value or
michael@0 97 * a separate value for each component, hence each macro must have two
michael@0 98 * versions. The unified alpha version has a 'U' at the end of the name,
michael@0 99 * the component version has a 'C'. Similarly, functions which deal with
michael@0 100 * this difference will have two versions using the same convention.
michael@0 101 */
michael@0 102
michael@0 103 /*
michael@0 104 * All of the composing functions
michael@0 105 */
michael@0 106
michael@0 107 static force_inline uint64_t
michael@0 108 combine_mask (const uint64_t *src, const uint64_t *mask, int i)
michael@0 109 {
michael@0 110 uint64_t s, m;
michael@0 111
michael@0 112 if (mask)
michael@0 113 {
michael@0 114 m = *(mask + i) >> A_SHIFT;
michael@0 115
michael@0 116 if (!m)
michael@0 117 return 0;
michael@0 118 }
michael@0 119
michael@0 120 s = *(src + i);
michael@0 121
michael@0 122 if (mask)
michael@0 123 UN16x4_MUL_UN16 (s, m);
michael@0 124
michael@0 125 return s;
michael@0 126 }
michael@0 127
michael@0 128 static void
michael@0 129 combine_clear (pixman_implementation_t *imp,
michael@0 130 pixman_op_t op,
michael@0 131 uint64_t * dest,
michael@0 132 const uint64_t * src,
michael@0 133 const uint64_t * mask,
michael@0 134 int width)
michael@0 135 {
michael@0 136 memset (dest, 0, width * sizeof(uint64_t));
michael@0 137 }
michael@0 138
michael@0 139 static void
michael@0 140 combine_dst (pixman_implementation_t *imp,
michael@0 141 pixman_op_t op,
michael@0 142 uint64_t * dest,
michael@0 143 const uint64_t * src,
michael@0 144 const uint64_t * mask,
michael@0 145 int width)
michael@0 146 {
michael@0 147 return;
michael@0 148 }
michael@0 149
michael@0 150 static void
michael@0 151 combine_src_u (pixman_implementation_t *imp,
michael@0 152 pixman_op_t op,
michael@0 153 uint64_t * dest,
michael@0 154 const uint64_t * src,
michael@0 155 const uint64_t * mask,
michael@0 156 int width)
michael@0 157 {
michael@0 158 int i;
michael@0 159
michael@0 160 if (!mask)
michael@0 161 memcpy (dest, src, width * sizeof (uint64_t));
michael@0 162 else
michael@0 163 {
michael@0 164 for (i = 0; i < width; ++i)
michael@0 165 {
michael@0 166 uint64_t s = combine_mask (src, mask, i);
michael@0 167
michael@0 168 *(dest + i) = s;
michael@0 169 }
michael@0 170 }
michael@0 171 }
michael@0 172
michael@0 173 /* if the Src is opaque, call combine_src_u */
michael@0 174 static void
michael@0 175 combine_over_u (pixman_implementation_t *imp,
michael@0 176 pixman_op_t op,
michael@0 177 uint64_t * dest,
michael@0 178 const uint64_t * src,
michael@0 179 const uint64_t * mask,
michael@0 180 int width)
michael@0 181 {
michael@0 182 int i;
michael@0 183
michael@0 184 for (i = 0; i < width; ++i)
michael@0 185 {
michael@0 186 uint64_t s = combine_mask (src, mask, i);
michael@0 187 uint64_t d = *(dest + i);
michael@0 188 uint64_t ia = ALPHA_16 (~s);
michael@0 189
michael@0 190 UN16x4_MUL_UN16_ADD_UN16x4 (d, ia, s);
michael@0 191 *(dest + i) = d;
michael@0 192 }
michael@0 193 }
michael@0 194
michael@0 195 /* if the Dst is opaque, this is a noop */
michael@0 196 static void
michael@0 197 combine_over_reverse_u (pixman_implementation_t *imp,
michael@0 198 pixman_op_t op,
michael@0 199 uint64_t * dest,
michael@0 200 const uint64_t * src,
michael@0 201 const uint64_t * mask,
michael@0 202 int width)
michael@0 203 {
michael@0 204 int i;
michael@0 205
michael@0 206 for (i = 0; i < width; ++i)
michael@0 207 {
michael@0 208 uint64_t s = combine_mask (src, mask, i);
michael@0 209 uint64_t d = *(dest + i);
michael@0 210 uint64_t ia = ALPHA_16 (~*(dest + i));
michael@0 211 UN16x4_MUL_UN16_ADD_UN16x4 (s, ia, d);
michael@0 212 *(dest + i) = s;
michael@0 213 }
michael@0 214 }
michael@0 215
michael@0 216 /* if the Dst is opaque, call combine_src_u */
michael@0 217 static void
michael@0 218 combine_in_u (pixman_implementation_t *imp,
michael@0 219 pixman_op_t op,
michael@0 220 uint64_t * dest,
michael@0 221 const uint64_t * src,
michael@0 222 const uint64_t * mask,
michael@0 223 int width)
michael@0 224 {
michael@0 225 int i;
michael@0 226
michael@0 227 for (i = 0; i < width; ++i)
michael@0 228 {
michael@0 229 uint64_t s = combine_mask (src, mask, i);
michael@0 230 uint64_t a = ALPHA_16 (*(dest + i));
michael@0 231 UN16x4_MUL_UN16 (s, a);
michael@0 232 *(dest + i) = s;
michael@0 233 }
michael@0 234 }
michael@0 235
michael@0 236 /* if the Src is opaque, this is a noop */
michael@0 237 static void
michael@0 238 combine_in_reverse_u (pixman_implementation_t *imp,
michael@0 239 pixman_op_t op,
michael@0 240 uint64_t * dest,
michael@0 241 const uint64_t * src,
michael@0 242 const uint64_t * mask,
michael@0 243 int width)
michael@0 244 {
michael@0 245 int i;
michael@0 246
michael@0 247 for (i = 0; i < width; ++i)
michael@0 248 {
michael@0 249 uint64_t s = combine_mask (src, mask, i);
michael@0 250 uint64_t d = *(dest + i);
michael@0 251 uint64_t a = ALPHA_16 (s);
michael@0 252 UN16x4_MUL_UN16 (d, a);
michael@0 253 *(dest + i) = d;
michael@0 254 }
michael@0 255 }
michael@0 256
michael@0 257 /* if the Dst is opaque, call combine_clear */
michael@0 258 static void
michael@0 259 combine_out_u (pixman_implementation_t *imp,
michael@0 260 pixman_op_t op,
michael@0 261 uint64_t * dest,
michael@0 262 const uint64_t * src,
michael@0 263 const uint64_t * mask,
michael@0 264 int width)
michael@0 265 {
michael@0 266 int i;
michael@0 267
michael@0 268 for (i = 0; i < width; ++i)
michael@0 269 {
michael@0 270 uint64_t s = combine_mask (src, mask, i);
michael@0 271 uint64_t a = ALPHA_16 (~*(dest + i));
michael@0 272 UN16x4_MUL_UN16 (s, a);
michael@0 273 *(dest + i) = s;
michael@0 274 }
michael@0 275 }
michael@0 276
michael@0 277 /* if the Src is opaque, call combine_clear */
michael@0 278 static void
michael@0 279 combine_out_reverse_u (pixman_implementation_t *imp,
michael@0 280 pixman_op_t op,
michael@0 281 uint64_t * dest,
michael@0 282 const uint64_t * src,
michael@0 283 const uint64_t * mask,
michael@0 284 int width)
michael@0 285 {
michael@0 286 int i;
michael@0 287
michael@0 288 for (i = 0; i < width; ++i)
michael@0 289 {
michael@0 290 uint64_t s = combine_mask (src, mask, i);
michael@0 291 uint64_t d = *(dest + i);
michael@0 292 uint64_t a = ALPHA_16 (~s);
michael@0 293 UN16x4_MUL_UN16 (d, a);
michael@0 294 *(dest + i) = d;
michael@0 295 }
michael@0 296 }
michael@0 297
michael@0 298 /* if the Src is opaque, call combine_in_u */
michael@0 299 /* if the Dst is opaque, call combine_over_u */
michael@0 300 /* if both the Src and Dst are opaque, call combine_src_u */
michael@0 301 static void
michael@0 302 combine_atop_u (pixman_implementation_t *imp,
michael@0 303 pixman_op_t op,
michael@0 304 uint64_t * dest,
michael@0 305 const uint64_t * src,
michael@0 306 const uint64_t * mask,
michael@0 307 int width)
michael@0 308 {
michael@0 309 int i;
michael@0 310
michael@0 311 for (i = 0; i < width; ++i)
michael@0 312 {
michael@0 313 uint64_t s = combine_mask (src, mask, i);
michael@0 314 uint64_t d = *(dest + i);
michael@0 315 uint64_t dest_a = ALPHA_16 (d);
michael@0 316 uint64_t src_ia = ALPHA_16 (~s);
michael@0 317
michael@0 318 UN16x4_MUL_UN16_ADD_UN16x4_MUL_UN16 (s, dest_a, d, src_ia);
michael@0 319 *(dest + i) = s;
michael@0 320 }
michael@0 321 }
michael@0 322
michael@0 323 /* if the Src is opaque, call combine_over_reverse_u */
michael@0 324 /* if the Dst is opaque, call combine_in_reverse_u */
michael@0 325 /* if both the Src and Dst are opaque, call combine_dst_u */
michael@0 326 static void
michael@0 327 combine_atop_reverse_u (pixman_implementation_t *imp,
michael@0 328 pixman_op_t op,
michael@0 329 uint64_t * dest,
michael@0 330 const uint64_t * src,
michael@0 331 const uint64_t * mask,
michael@0 332 int width)
michael@0 333 {
michael@0 334 int i;
michael@0 335
michael@0 336 for (i = 0; i < width; ++i)
michael@0 337 {
michael@0 338 uint64_t s = combine_mask (src, mask, i);
michael@0 339 uint64_t d = *(dest + i);
michael@0 340 uint64_t src_a = ALPHA_16 (s);
michael@0 341 uint64_t dest_ia = ALPHA_16 (~d);
michael@0 342
michael@0 343 UN16x4_MUL_UN16_ADD_UN16x4_MUL_UN16 (s, dest_ia, d, src_a);
michael@0 344 *(dest + i) = s;
michael@0 345 }
michael@0 346 }
michael@0 347
michael@0 348 /* if the Src is opaque, call combine_over_u */
michael@0 349 /* if the Dst is opaque, call combine_over_reverse_u */
michael@0 350 /* if both the Src and Dst are opaque, call combine_clear */
michael@0 351 static void
michael@0 352 combine_xor_u (pixman_implementation_t *imp,
michael@0 353 pixman_op_t op,
michael@0 354 uint64_t * dest,
michael@0 355 const uint64_t * src,
michael@0 356 const uint64_t * mask,
michael@0 357 int width)
michael@0 358 {
michael@0 359 int i;
michael@0 360
michael@0 361 for (i = 0; i < width; ++i)
michael@0 362 {
michael@0 363 uint64_t s = combine_mask (src, mask, i);
michael@0 364 uint64_t d = *(dest + i);
michael@0 365 uint64_t src_ia = ALPHA_16 (~s);
michael@0 366 uint64_t dest_ia = ALPHA_16 (~d);
michael@0 367
michael@0 368 UN16x4_MUL_UN16_ADD_UN16x4_MUL_UN16 (s, dest_ia, d, src_ia);
michael@0 369 *(dest + i) = s;
michael@0 370 }
michael@0 371 }
michael@0 372
michael@0 373 static void
michael@0 374 combine_add_u (pixman_implementation_t *imp,
michael@0 375 pixman_op_t op,
michael@0 376 uint64_t * dest,
michael@0 377 const uint64_t * src,
michael@0 378 const uint64_t * mask,
michael@0 379 int width)
michael@0 380 {
michael@0 381 int i;
michael@0 382
michael@0 383 for (i = 0; i < width; ++i)
michael@0 384 {
michael@0 385 uint64_t s = combine_mask (src, mask, i);
michael@0 386 uint64_t d = *(dest + i);
michael@0 387 UN16x4_ADD_UN16x4 (d, s);
michael@0 388 *(dest + i) = d;
michael@0 389 }
michael@0 390 }
michael@0 391
michael@0 392 /* if the Src is opaque, call combine_add_u */
michael@0 393 /* if the Dst is opaque, call combine_add_u */
michael@0 394 /* if both the Src and Dst are opaque, call combine_add_u */
michael@0 395 static void
michael@0 396 combine_saturate_u (pixman_implementation_t *imp,
michael@0 397 pixman_op_t op,
michael@0 398 uint64_t * dest,
michael@0 399 const uint64_t * src,
michael@0 400 const uint64_t * mask,
michael@0 401 int width)
michael@0 402 {
michael@0 403 int i;
michael@0 404
michael@0 405 for (i = 0; i < width; ++i)
michael@0 406 {
michael@0 407 uint64_t s = combine_mask (src, mask, i);
michael@0 408 uint64_t d = *(dest + i);
michael@0 409 uint32_t sa, da;
michael@0 410
michael@0 411 sa = s >> A_SHIFT;
michael@0 412 da = ~d >> A_SHIFT;
michael@0 413 if (sa > da)
michael@0 414 {
michael@0 415 sa = DIV_UN16 (da, sa);
michael@0 416 UN16x4_MUL_UN16 (s, sa);
michael@0 417 }
michael@0 418 ;
michael@0 419 UN16x4_ADD_UN16x4 (d, s);
michael@0 420 *(dest + i) = d;
michael@0 421 }
michael@0 422 }
michael@0 423
michael@0 424 /*
michael@0 425 * PDF blend modes:
michael@0 426 * The following blend modes have been taken from the PDF ISO 32000
michael@0 427 * specification, which at this point in time is available from
michael@0 428 * http://www.adobe.com/devnet/acrobat/pdfs/PDF32000_2008.pdf
michael@0 429 * The relevant chapters are 11.3.5 and 11.3.6.
michael@0 430 * The formula for computing the final pixel color given in 11.3.6 is:
michael@0 431 * αr × Cr = (1 – αs) × αb × Cb + (1 – αb) × αs × Cs + αb × αs × B(Cb, Cs)
michael@0 432 * with B() being the blend function.
michael@0 433 * Note that OVER is a special case of this operation, using B(Cb, Cs) = Cs
michael@0 434 *
michael@0 435 * These blend modes should match the SVG filter draft specification, as
michael@0 436 * it has been designed to mirror ISO 32000. Note that at the current point
michael@0 437 * no released draft exists that shows this, as the formulas have not been
michael@0 438 * updated yet after the release of ISO 32000.
michael@0 439 *
michael@0 440 * The default implementation here uses the PDF_SEPARABLE_BLEND_MODE and
michael@0 441 * PDF_NON_SEPARABLE_BLEND_MODE macros, which take the blend function as an
michael@0 442 * argument. Note that this implementation operates on premultiplied colors,
michael@0 443 * while the PDF specification does not. Therefore the code uses the formula
michael@0 444 * Cra = (1 – as) . Dca + (1 – ad) . Sca + B(Dca, ad, Sca, as)
michael@0 445 */
michael@0 446
michael@0 447 /*
michael@0 448 * Multiply
michael@0 449 * B(Dca, ad, Sca, as) = Dca.Sca
michael@0 450 */
michael@0 451
michael@0 452 static void
michael@0 453 combine_multiply_u (pixman_implementation_t *imp,
michael@0 454 pixman_op_t op,
michael@0 455 uint64_t * dest,
michael@0 456 const uint64_t * src,
michael@0 457 const uint64_t * mask,
michael@0 458 int width)
michael@0 459 {
michael@0 460 int i;
michael@0 461
michael@0 462 for (i = 0; i < width; ++i)
michael@0 463 {
michael@0 464 uint64_t s = combine_mask (src, mask, i);
michael@0 465 uint64_t d = *(dest + i);
michael@0 466 uint64_t ss = s;
michael@0 467 uint64_t src_ia = ALPHA_16 (~s);
michael@0 468 uint64_t dest_ia = ALPHA_16 (~d);
michael@0 469
michael@0 470 UN16x4_MUL_UN16_ADD_UN16x4_MUL_UN16 (ss, dest_ia, d, src_ia);
michael@0 471 UN16x4_MUL_UN16x4 (d, s);
michael@0 472 UN16x4_ADD_UN16x4 (d, ss);
michael@0 473
michael@0 474 *(dest + i) = d;
michael@0 475 }
michael@0 476 }
michael@0 477
michael@0 478 static void
michael@0 479 combine_multiply_ca (pixman_implementation_t *imp,
michael@0 480 pixman_op_t op,
michael@0 481 uint64_t * dest,
michael@0 482 const uint64_t * src,
michael@0 483 const uint64_t * mask,
michael@0 484 int width)
michael@0 485 {
michael@0 486 int i;
michael@0 487
michael@0 488 for (i = 0; i < width; ++i)
michael@0 489 {
michael@0 490 uint64_t m = *(mask + i);
michael@0 491 uint64_t s = *(src + i);
michael@0 492 uint64_t d = *(dest + i);
michael@0 493 uint64_t r = d;
michael@0 494 uint64_t dest_ia = ALPHA_16 (~d);
michael@0 495
michael@0 496 combine_mask_value_ca (&s, &m);
michael@0 497
michael@0 498 UN16x4_MUL_UN16x4_ADD_UN16x4_MUL_UN16 (r, ~m, s, dest_ia);
michael@0 499 UN16x4_MUL_UN16x4 (d, s);
michael@0 500 UN16x4_ADD_UN16x4 (r, d);
michael@0 501
michael@0 502 *(dest + i) = r;
michael@0 503 }
michael@0 504 }
michael@0 505
michael@0 506 #define PDF_SEPARABLE_BLEND_MODE(name) \
michael@0 507 static void \
michael@0 508 combine_ ## name ## _u (pixman_implementation_t *imp, \
michael@0 509 pixman_op_t op, \
michael@0 510 uint64_t * dest, \
michael@0 511 const uint64_t * src, \
michael@0 512 const uint64_t * mask, \
michael@0 513 int width) \
michael@0 514 { \
michael@0 515 int i; \
michael@0 516 for (i = 0; i < width; ++i) { \
michael@0 517 uint64_t s = combine_mask (src, mask, i); \
michael@0 518 uint64_t d = *(dest + i); \
michael@0 519 uint16_t sa = ALPHA_16 (s); \
michael@0 520 uint16_t isa = ~sa; \
michael@0 521 uint16_t da = ALPHA_16 (d); \
michael@0 522 uint16_t ida = ~da; \
michael@0 523 uint64_t result; \
michael@0 524 \
michael@0 525 result = d; \
michael@0 526 UN16x4_MUL_UN16_ADD_UN16x4_MUL_UN16 (result, isa, s, ida); \
michael@0 527 \
michael@0 528 *(dest + i) = result + \
michael@0 529 (DIV_ONE_UN16 (sa * (uint64_t)da) << A_SHIFT) + \
michael@0 530 (blend_ ## name (RED_16 (d), da, RED_16 (s), sa) << R_SHIFT) + \
michael@0 531 (blend_ ## name (GREEN_16 (d), da, GREEN_16 (s), sa) << G_SHIFT) + \
michael@0 532 (blend_ ## name (BLUE_16 (d), da, BLUE_16 (s), sa)); \
michael@0 533 } \
michael@0 534 } \
michael@0 535 \
michael@0 536 static void \
michael@0 537 combine_ ## name ## _ca (pixman_implementation_t *imp, \
michael@0 538 pixman_op_t op, \
michael@0 539 uint64_t * dest, \
michael@0 540 const uint64_t * src, \
michael@0 541 const uint64_t * mask, \
michael@0 542 int width) \
michael@0 543 { \
michael@0 544 int i; \
michael@0 545 for (i = 0; i < width; ++i) { \
michael@0 546 uint64_t m = *(mask + i); \
michael@0 547 uint64_t s = *(src + i); \
michael@0 548 uint64_t d = *(dest + i); \
michael@0 549 uint16_t da = ALPHA_16 (d); \
michael@0 550 uint16_t ida = ~da; \
michael@0 551 uint64_t result; \
michael@0 552 \
michael@0 553 combine_mask_value_ca (&s, &m); \
michael@0 554 \
michael@0 555 result = d; \
michael@0 556 UN16x4_MUL_UN16x4_ADD_UN16x4_MUL_UN16 (result, ~m, s, ida); \
michael@0 557 \
michael@0 558 result += \
michael@0 559 (DIV_ONE_UN16 (ALPHA_16 (m) * (uint64_t)da) << A_SHIFT) + \
michael@0 560 (blend_ ## name (RED_16 (d), da, RED_16 (s), RED_16 (m)) << R_SHIFT) + \
michael@0 561 (blend_ ## name (GREEN_16 (d), da, GREEN_16 (s), GREEN_16 (m)) << G_SHIFT) + \
michael@0 562 (blend_ ## name (BLUE_16 (d), da, BLUE_16 (s), BLUE_16 (m))); \
michael@0 563 \
michael@0 564 *(dest + i) = result; \
michael@0 565 } \
michael@0 566 }
michael@0 567
michael@0 568 /*
michael@0 569 * Screen
michael@0 570 * B(Dca, ad, Sca, as) = Dca.sa + Sca.da - Dca.Sca
michael@0 571 */
michael@0 572 static inline uint64_t
michael@0 573 blend_screen (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 574 {
michael@0 575 return DIV_ONE_UN16 (sca * da + dca * sa - sca * dca);
michael@0 576 }
michael@0 577
michael@0 578 PDF_SEPARABLE_BLEND_MODE (screen)
michael@0 579
michael@0 580 /*
michael@0 581 * Overlay
michael@0 582 * B(Dca, Da, Sca, Sa) =
michael@0 583 * if 2.Dca < Da
michael@0 584 * 2.Sca.Dca
michael@0 585 * otherwise
michael@0 586 * Sa.Da - 2.(Da - Dca).(Sa - Sca)
michael@0 587 */
michael@0 588 static inline uint64_t
michael@0 589 blend_overlay (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 590 {
michael@0 591 uint64_t rca;
michael@0 592
michael@0 593 if (2 * dca < da)
michael@0 594 rca = 2 * sca * dca;
michael@0 595 else
michael@0 596 rca = sa * da - 2 * (da - dca) * (sa - sca);
michael@0 597 return DIV_ONE_UN16 (rca);
michael@0 598 }
michael@0 599
michael@0 600 PDF_SEPARABLE_BLEND_MODE (overlay)
michael@0 601
michael@0 602 /*
michael@0 603 * Darken
michael@0 604 * B(Dca, Da, Sca, Sa) = min (Sca.Da, Dca.Sa)
michael@0 605 */
michael@0 606 static inline uint64_t
michael@0 607 blend_darken (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 608 {
michael@0 609 uint64_t s, d;
michael@0 610
michael@0 611 s = sca * da;
michael@0 612 d = dca * sa;
michael@0 613 return DIV_ONE_UN16 (s > d ? d : s);
michael@0 614 }
michael@0 615
michael@0 616 PDF_SEPARABLE_BLEND_MODE (darken)
michael@0 617
michael@0 618 /*
michael@0 619 * Lighten
michael@0 620 * B(Dca, Da, Sca, Sa) = max (Sca.Da, Dca.Sa)
michael@0 621 */
michael@0 622 static inline uint64_t
michael@0 623 blend_lighten (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 624 {
michael@0 625 uint64_t s, d;
michael@0 626
michael@0 627 s = sca * da;
michael@0 628 d = dca * sa;
michael@0 629 return DIV_ONE_UN16 (s > d ? s : d);
michael@0 630 }
michael@0 631
michael@0 632 PDF_SEPARABLE_BLEND_MODE (lighten)
michael@0 633
michael@0 634 /*
michael@0 635 * Color dodge
michael@0 636 * B(Dca, Da, Sca, Sa) =
michael@0 637 * if Dca == 0
michael@0 638 * 0
michael@0 639 * if Sca == Sa
michael@0 640 * Sa.Da
michael@0 641 * otherwise
michael@0 642 * Sa.Da. min (1, Dca / Da / (1 - Sca/Sa))
michael@0 643 */
michael@0 644 static inline uint64_t
michael@0 645 blend_color_dodge (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 646 {
michael@0 647 if (sca >= sa)
michael@0 648 {
michael@0 649 return dca == 0 ? 0 : DIV_ONE_UN16 (sa * da);
michael@0 650 }
michael@0 651 else
michael@0 652 {
michael@0 653 uint64_t rca = dca * sa / (sa - sca);
michael@0 654 return DIV_ONE_UN16 (sa * MIN (rca, da));
michael@0 655 }
michael@0 656 }
michael@0 657
michael@0 658 PDF_SEPARABLE_BLEND_MODE (color_dodge)
michael@0 659
michael@0 660 /*
michael@0 661 * Color burn
michael@0 662 * B(Dca, Da, Sca, Sa) =
michael@0 663 * if Dca == Da
michael@0 664 * Sa.Da
michael@0 665 * if Sca == 0
michael@0 666 * 0
michael@0 667 * otherwise
michael@0 668 * Sa.Da.(1 - min (1, (1 - Dca/Da).Sa / Sca))
michael@0 669 */
michael@0 670 static inline uint64_t
michael@0 671 blend_color_burn (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 672 {
michael@0 673 if (sca == 0)
michael@0 674 {
michael@0 675 return dca < da ? 0 : DIV_ONE_UN16 (sa * da);
michael@0 676 }
michael@0 677 else
michael@0 678 {
michael@0 679 uint64_t rca = (da - dca) * sa / sca;
michael@0 680 return DIV_ONE_UN16 (sa * (MAX (rca, da) - rca));
michael@0 681 }
michael@0 682 }
michael@0 683
michael@0 684 PDF_SEPARABLE_BLEND_MODE (color_burn)
michael@0 685
michael@0 686 /*
michael@0 687 * Hard light
michael@0 688 * B(Dca, Da, Sca, Sa) =
michael@0 689 * if 2.Sca < Sa
michael@0 690 * 2.Sca.Dca
michael@0 691 * otherwise
michael@0 692 * Sa.Da - 2.(Da - Dca).(Sa - Sca)
michael@0 693 */
michael@0 694 static inline uint64_t
michael@0 695 blend_hard_light (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 696 {
michael@0 697 if (2 * sca < sa)
michael@0 698 return DIV_ONE_UN16 (2 * sca * dca);
michael@0 699 else
michael@0 700 return DIV_ONE_UN16 (sa * da - 2 * (da - dca) * (sa - sca));
michael@0 701 }
michael@0 702
michael@0 703 PDF_SEPARABLE_BLEND_MODE (hard_light)
michael@0 704
michael@0 705 /*
michael@0 706 * Soft light
michael@0 707 * B(Dca, Da, Sca, Sa) =
michael@0 708 * if (2.Sca <= Sa)
michael@0 709 * Dca.(Sa - (1 - Dca/Da).(2.Sca - Sa))
michael@0 710 * otherwise if Dca.4 <= Da
michael@0 711 * Dca.(Sa + (2.Sca - Sa).((16.Dca/Da - 12).Dca/Da + 3)
michael@0 712 * otherwise
michael@0 713 * (Dca.Sa + (SQRT (Dca/Da).Da - Dca).(2.Sca - Sa))
michael@0 714 */
michael@0 715 static inline uint64_t
michael@0 716 blend_soft_light (uint64_t dca_org,
michael@0 717 uint64_t da_org,
michael@0 718 uint64_t sca_org,
michael@0 719 uint64_t sa_org)
michael@0 720 {
michael@0 721 double dca = dca_org * (1.0 / MASK);
michael@0 722 double da = da_org * (1.0 / MASK);
michael@0 723 double sca = sca_org * (1.0 / MASK);
michael@0 724 double sa = sa_org * (1.0 / MASK);
michael@0 725 double rca;
michael@0 726
michael@0 727 if (2 * sca < sa)
michael@0 728 {
michael@0 729 if (da == 0)
michael@0 730 rca = dca * sa;
michael@0 731 else
michael@0 732 rca = dca * sa - dca * (da - dca) * (sa - 2 * sca) / da;
michael@0 733 }
michael@0 734 else if (da == 0)
michael@0 735 {
michael@0 736 rca = 0;
michael@0 737 }
michael@0 738 else if (4 * dca <= da)
michael@0 739 {
michael@0 740 rca = dca * sa +
michael@0 741 (2 * sca - sa) * dca * ((16 * dca / da - 12) * dca / da + 3);
michael@0 742 }
michael@0 743 else
michael@0 744 {
michael@0 745 rca = dca * sa + (sqrt (dca * da) - dca) * (2 * sca - sa);
michael@0 746 }
michael@0 747 return rca * MASK + 0.5;
michael@0 748 }
michael@0 749
michael@0 750 PDF_SEPARABLE_BLEND_MODE (soft_light)
michael@0 751
michael@0 752 /*
michael@0 753 * Difference
michael@0 754 * B(Dca, Da, Sca, Sa) = abs (Dca.Sa - Sca.Da)
michael@0 755 */
michael@0 756 static inline uint64_t
michael@0 757 blend_difference (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 758 {
michael@0 759 uint64_t dcasa = dca * sa;
michael@0 760 uint64_t scada = sca * da;
michael@0 761
michael@0 762 if (scada < dcasa)
michael@0 763 return DIV_ONE_UN16 (dcasa - scada);
michael@0 764 else
michael@0 765 return DIV_ONE_UN16 (scada - dcasa);
michael@0 766 }
michael@0 767
michael@0 768 PDF_SEPARABLE_BLEND_MODE (difference)
michael@0 769
michael@0 770 /*
michael@0 771 * Exclusion
michael@0 772 * B(Dca, Da, Sca, Sa) = (Sca.Da + Dca.Sa - 2.Sca.Dca)
michael@0 773 */
michael@0 774
michael@0 775 /* This can be made faster by writing it directly and not using
michael@0 776 * PDF_SEPARABLE_BLEND_MODE, but that's a performance optimization */
michael@0 777
michael@0 778 static inline uint64_t
michael@0 779 blend_exclusion (uint64_t dca, uint64_t da, uint64_t sca, uint64_t sa)
michael@0 780 {
michael@0 781 return DIV_ONE_UN16 (sca * da + dca * sa - 2 * dca * sca);
michael@0 782 }
michael@0 783
michael@0 784 PDF_SEPARABLE_BLEND_MODE (exclusion)
michael@0 785
michael@0 786 #undef PDF_SEPARABLE_BLEND_MODE
michael@0 787
michael@0 788 /*
michael@0 789 * PDF nonseperable blend modes are implemented using the following functions
michael@0 790 * to operate in Hsl space, with Cmax, Cmid, Cmin referring to the max, mid
michael@0 791 * and min value of the red, green and blue components.
michael@0 792 *
michael@0 793 * LUM (C) = 0.3 × Cred + 0.59 × Cgreen + 0.11 × Cblue
michael@0 794 *
michael@0 795 * clip_color (C):
michael@0 796 * l = LUM (C)
michael@0 797 * min = Cmin
michael@0 798 * max = Cmax
michael@0 799 * if n < 0.0
michael@0 800 * C = l + ( ( ( C – l ) × l ) ⁄ ( l – min ) )
michael@0 801 * if x > 1.0
michael@0 802 * C = l + ( ( ( C – l ) × ( 1 – l ) ) ⁄ ( max – l ) )
michael@0 803 * return C
michael@0 804 *
michael@0 805 * set_lum (C, l):
michael@0 806 * d = l – LUM (C)
michael@0 807 * C += d
michael@0 808 * return clip_color (C)
michael@0 809 *
michael@0 810 * SAT (C) = CH_MAX (C) - CH_MIN (C)
michael@0 811 *
michael@0 812 * set_sat (C, s):
michael@0 813 * if Cmax > Cmin
michael@0 814 * Cmid = ( ( ( Cmid – Cmin ) × s ) ⁄ ( Cmax – Cmin ) )
michael@0 815 * Cmax = s
michael@0 816 * else
michael@0 817 * Cmid = Cmax = 0.0
michael@0 818 * Cmin = 0.0
michael@0 819 * return C
michael@0 820 */
michael@0 821
michael@0 822 /* For premultiplied colors, we need to know what happens when C is
michael@0 823 * multiplied by a real number. LUM and SAT are linear:
michael@0 824 *
michael@0 825 * LUM (r × C) = r × LUM (C) SAT (r * C) = r * SAT (C)
michael@0 826 *
michael@0 827 * If we extend clip_color with an extra argument a and change
michael@0 828 *
michael@0 829 * if x >= 1.0
michael@0 830 *
michael@0 831 * into
michael@0 832 *
michael@0 833 * if x >= a
michael@0 834 *
michael@0 835 * then clip_color is also linear:
michael@0 836 *
michael@0 837 * r * clip_color (C, a) = clip_color (r_c, ra);
michael@0 838 *
michael@0 839 * for positive r.
michael@0 840 *
michael@0 841 * Similarly, we can extend set_lum with an extra argument that is just passed
michael@0 842 * on to clip_color:
michael@0 843 *
michael@0 844 * r * set_lum ( C, l, a)
michael@0 845 *
michael@0 846 * = r × clip_color ( C + l - LUM (C), a)
michael@0 847 *
michael@0 848 * = clip_color ( r * C + r × l - r * LUM (C), r * a)
michael@0 849 *
michael@0 850 * = set_lum ( r * C, r * l, r * a)
michael@0 851 *
michael@0 852 * Finally, set_sat:
michael@0 853 *
michael@0 854 * r * set_sat (C, s) = set_sat (x * C, r * s)
michael@0 855 *
michael@0 856 * The above holds for all non-zero x, because the x'es in the fraction for
michael@0 857 * C_mid cancel out. Specifically, it holds for x = r:
michael@0 858 *
michael@0 859 * r * set_sat (C, s) = set_sat (r_c, rs)
michael@0 860 *
michael@0 861 */
michael@0 862
michael@0 863 /* So, for the non-separable PDF blend modes, we have (using s, d for
michael@0 864 * non-premultiplied colors, and S, D for premultiplied:
michael@0 865 *
michael@0 866 * Color:
michael@0 867 *
michael@0 868 * a_s * a_d * B(s, d)
michael@0 869 * = a_s * a_d * set_lum (S/a_s, LUM (D/a_d), 1)
michael@0 870 * = set_lum (S * a_d, a_s * LUM (D), a_s * a_d)
michael@0 871 *
michael@0 872 *
michael@0 873 * Luminosity:
michael@0 874 *
michael@0 875 * a_s * a_d * B(s, d)
michael@0 876 * = a_s * a_d * set_lum (D/a_d, LUM(S/a_s), 1)
michael@0 877 * = set_lum (a_s * D, a_d * LUM(S), a_s * a_d)
michael@0 878 *
michael@0 879 *
michael@0 880 * Saturation:
michael@0 881 *
michael@0 882 * a_s * a_d * B(s, d)
michael@0 883 * = a_s * a_d * set_lum (set_sat (D/a_d, SAT (S/a_s)), LUM (D/a_d), 1)
michael@0 884 * = set_lum (a_s * a_d * set_sat (D/a_d, SAT (S/a_s)),
michael@0 885 * a_s * LUM (D), a_s * a_d)
michael@0 886 * = set_lum (set_sat (a_s * D, a_d * SAT (S), a_s * LUM (D), a_s * a_d))
michael@0 887 *
michael@0 888 * Hue:
michael@0 889 *
michael@0 890 * a_s * a_d * B(s, d)
michael@0 891 * = a_s * a_d * set_lum (set_sat (S/a_s, SAT (D/a_d)), LUM (D/a_d), 1)
michael@0 892 * = set_lum (set_sat (a_d * S, a_s * SAT (D)), a_s * LUM (D), a_s * a_d)
michael@0 893 *
michael@0 894 */
michael@0 895
michael@0 896 #define CH_MIN(c) (c[0] < c[1] ? (c[0] < c[2] ? c[0] : c[2]) : (c[1] < c[2] ? c[1] : c[2]))
michael@0 897 #define CH_MAX(c) (c[0] > c[1] ? (c[0] > c[2] ? c[0] : c[2]) : (c[1] > c[2] ? c[1] : c[2]))
michael@0 898 #define LUM(c) ((c[0] * 30 + c[1] * 59 + c[2] * 11) / 100)
michael@0 899 #define SAT(c) (CH_MAX (c) - CH_MIN (c))
michael@0 900
michael@0 901 #define PDF_NON_SEPARABLE_BLEND_MODE(name) \
michael@0 902 static void \
michael@0 903 combine_ ## name ## _u (pixman_implementation_t *imp, \
michael@0 904 pixman_op_t op, \
michael@0 905 uint64_t *dest, \
michael@0 906 const uint64_t *src, \
michael@0 907 const uint64_t *mask, \
michael@0 908 int width) \
michael@0 909 { \
michael@0 910 int i; \
michael@0 911 for (i = 0; i < width; ++i) \
michael@0 912 { \
michael@0 913 uint64_t s = combine_mask (src, mask, i); \
michael@0 914 uint64_t d = *(dest + i); \
michael@0 915 uint16_t sa = ALPHA_16 (s); \
michael@0 916 uint16_t isa = ~sa; \
michael@0 917 uint16_t da = ALPHA_16 (d); \
michael@0 918 uint16_t ida = ~da; \
michael@0 919 uint64_t result; \
michael@0 920 uint64_t sc[3], dc[3], c[3]; \
michael@0 921 \
michael@0 922 result = d; \
michael@0 923 UN16x4_MUL_UN16_ADD_UN16x4_MUL_UN16 (result, isa, s, ida); \
michael@0 924 dc[0] = RED_16 (d); \
michael@0 925 sc[0] = RED_16 (s); \
michael@0 926 dc[1] = GREEN_16 (d); \
michael@0 927 sc[1] = GREEN_16 (s); \
michael@0 928 dc[2] = BLUE_16 (d); \
michael@0 929 sc[2] = BLUE_16 (s); \
michael@0 930 blend_ ## name (c, dc, da, sc, sa); \
michael@0 931 \
michael@0 932 *(dest + i) = result + \
michael@0 933 (DIV_ONE_UN16 (sa * (uint64_t)da) << A_SHIFT) + \
michael@0 934 (DIV_ONE_UN16 (c[0]) << R_SHIFT) + \
michael@0 935 (DIV_ONE_UN16 (c[1]) << G_SHIFT) + \
michael@0 936 (DIV_ONE_UN16 (c[2])); \
michael@0 937 } \
michael@0 938 }
michael@0 939
michael@0 940 static void
michael@0 941 set_lum (uint64_t dest[3], uint64_t src[3], uint64_t sa, uint64_t lum)
michael@0 942 {
michael@0 943 double a, l, min, max;
michael@0 944 double tmp[3];
michael@0 945
michael@0 946 a = sa * (1.0 / MASK);
michael@0 947
michael@0 948 l = lum * (1.0 / MASK);
michael@0 949 tmp[0] = src[0] * (1.0 / MASK);
michael@0 950 tmp[1] = src[1] * (1.0 / MASK);
michael@0 951 tmp[2] = src[2] * (1.0 / MASK);
michael@0 952
michael@0 953 l = l - LUM (tmp);
michael@0 954 tmp[0] += l;
michael@0 955 tmp[1] += l;
michael@0 956 tmp[2] += l;
michael@0 957
michael@0 958 /* clip_color */
michael@0 959 l = LUM (tmp);
michael@0 960 min = CH_MIN (tmp);
michael@0 961 max = CH_MAX (tmp);
michael@0 962
michael@0 963 if (min < 0)
michael@0 964 {
michael@0 965 if (l - min == 0.0)
michael@0 966 {
michael@0 967 tmp[0] = 0;
michael@0 968 tmp[1] = 0;
michael@0 969 tmp[2] = 0;
michael@0 970 }
michael@0 971 else
michael@0 972 {
michael@0 973 tmp[0] = l + (tmp[0] - l) * l / (l - min);
michael@0 974 tmp[1] = l + (tmp[1] - l) * l / (l - min);
michael@0 975 tmp[2] = l + (tmp[2] - l) * l / (l - min);
michael@0 976 }
michael@0 977 }
michael@0 978 if (max > a)
michael@0 979 {
michael@0 980 if (max - l == 0.0)
michael@0 981 {
michael@0 982 tmp[0] = a;
michael@0 983 tmp[1] = a;
michael@0 984 tmp[2] = a;
michael@0 985 }
michael@0 986 else
michael@0 987 {
michael@0 988 tmp[0] = l + (tmp[0] - l) * (a - l) / (max - l);
michael@0 989 tmp[1] = l + (tmp[1] - l) * (a - l) / (max - l);
michael@0 990 tmp[2] = l + (tmp[2] - l) * (a - l) / (max - l);
michael@0 991 }
michael@0 992 }
michael@0 993
michael@0 994 dest[0] = tmp[0] * MASK + 0.5;
michael@0 995 dest[1] = tmp[1] * MASK + 0.5;
michael@0 996 dest[2] = tmp[2] * MASK + 0.5;
michael@0 997 }
michael@0 998
michael@0 999 static void
michael@0 1000 set_sat (uint64_t dest[3], uint64_t src[3], uint64_t sat)
michael@0 1001 {
michael@0 1002 int id[3];
michael@0 1003 uint64_t min, max;
michael@0 1004
michael@0 1005 if (src[0] > src[1])
michael@0 1006 {
michael@0 1007 if (src[0] > src[2])
michael@0 1008 {
michael@0 1009 id[0] = 0;
michael@0 1010 if (src[1] > src[2])
michael@0 1011 {
michael@0 1012 id[1] = 1;
michael@0 1013 id[2] = 2;
michael@0 1014 }
michael@0 1015 else
michael@0 1016 {
michael@0 1017 id[1] = 2;
michael@0 1018 id[2] = 1;
michael@0 1019 }
michael@0 1020 }
michael@0 1021 else
michael@0 1022 {
michael@0 1023 id[0] = 2;
michael@0 1024 id[1] = 0;
michael@0 1025 id[2] = 1;
michael@0 1026 }
michael@0 1027 }
michael@0 1028 else
michael@0 1029 {
michael@0 1030 if (src[0] > src[2])
michael@0 1031 {
michael@0 1032 id[0] = 1;
michael@0 1033 id[1] = 0;
michael@0 1034 id[2] = 2;
michael@0 1035 }
michael@0 1036 else
michael@0 1037 {
michael@0 1038 id[2] = 0;
michael@0 1039 if (src[1] > src[2])
michael@0 1040 {
michael@0 1041 id[0] = 1;
michael@0 1042 id[1] = 2;
michael@0 1043 }
michael@0 1044 else
michael@0 1045 {
michael@0 1046 id[0] = 2;
michael@0 1047 id[1] = 1;
michael@0 1048 }
michael@0 1049 }
michael@0 1050 }
michael@0 1051
michael@0 1052 max = dest[id[0]];
michael@0 1053 min = dest[id[2]];
michael@0 1054 if (max > min)
michael@0 1055 {
michael@0 1056 dest[id[1]] = (dest[id[1]] - min) * sat / (max - min);
michael@0 1057 dest[id[0]] = sat;
michael@0 1058 dest[id[2]] = 0;
michael@0 1059 }
michael@0 1060 else
michael@0 1061 {
michael@0 1062 dest[0] = dest[1] = dest[2] = 0;
michael@0 1063 }
michael@0 1064 }
michael@0 1065
michael@0 1066 /*
michael@0 1067 * Hue:
michael@0 1068 * B(Cb, Cs) = set_lum (set_sat (Cs, SAT (Cb)), LUM (Cb))
michael@0 1069 */
michael@0 1070 static inline void
michael@0 1071 blend_hsl_hue (uint64_t c[3],
michael@0 1072 uint64_t dc[3],
michael@0 1073 uint64_t da,
michael@0 1074 uint64_t sc[3],
michael@0 1075 uint64_t sa)
michael@0 1076 {
michael@0 1077 c[0] = sc[0] * da;
michael@0 1078 c[1] = sc[1] * da;
michael@0 1079 c[2] = sc[2] * da;
michael@0 1080 set_sat (c, c, SAT (dc) * sa);
michael@0 1081 set_lum (c, c, sa * da, LUM (dc) * sa);
michael@0 1082 }
michael@0 1083
michael@0 1084 PDF_NON_SEPARABLE_BLEND_MODE (hsl_hue)
michael@0 1085
michael@0 1086 /*
michael@0 1087 * Saturation:
michael@0 1088 * B(Cb, Cs) = set_lum (set_sat (Cb, SAT (Cs)), LUM (Cb))
michael@0 1089 */
michael@0 1090 static inline void
michael@0 1091 blend_hsl_saturation (uint64_t c[3],
michael@0 1092 uint64_t dc[3],
michael@0 1093 uint64_t da,
michael@0 1094 uint64_t sc[3],
michael@0 1095 uint64_t sa)
michael@0 1096 {
michael@0 1097 c[0] = dc[0] * sa;
michael@0 1098 c[1] = dc[1] * sa;
michael@0 1099 c[2] = dc[2] * sa;
michael@0 1100 set_sat (c, c, SAT (sc) * da);
michael@0 1101 set_lum (c, c, sa * da, LUM (dc) * sa);
michael@0 1102 }
michael@0 1103
michael@0 1104 PDF_NON_SEPARABLE_BLEND_MODE (hsl_saturation)
michael@0 1105
michael@0 1106 /*
michael@0 1107 * Color:
michael@0 1108 * B(Cb, Cs) = set_lum (Cs, LUM (Cb))
michael@0 1109 */
michael@0 1110 static inline void
michael@0 1111 blend_hsl_color (uint64_t c[3],
michael@0 1112 uint64_t dc[3],
michael@0 1113 uint64_t da,
michael@0 1114 uint64_t sc[3],
michael@0 1115 uint64_t sa)
michael@0 1116 {
michael@0 1117 c[0] = sc[0] * da;
michael@0 1118 c[1] = sc[1] * da;
michael@0 1119 c[2] = sc[2] * da;
michael@0 1120 set_lum (c, c, sa * da, LUM (dc) * sa);
michael@0 1121 }
michael@0 1122
michael@0 1123 PDF_NON_SEPARABLE_BLEND_MODE (hsl_color)
michael@0 1124
michael@0 1125 /*
michael@0 1126 * Luminosity:
michael@0 1127 * B(Cb, Cs) = set_lum (Cb, LUM (Cs))
michael@0 1128 */
michael@0 1129 static inline void
michael@0 1130 blend_hsl_luminosity (uint64_t c[3],
michael@0 1131 uint64_t dc[3],
michael@0 1132 uint64_t da,
michael@0 1133 uint64_t sc[3],
michael@0 1134 uint64_t sa)
michael@0 1135 {
michael@0 1136 c[0] = dc[0] * sa;
michael@0 1137 c[1] = dc[1] * sa;
michael@0 1138 c[2] = dc[2] * sa;
michael@0 1139 set_lum (c, c, sa * da, LUM (sc) * da);
michael@0 1140 }
michael@0 1141
michael@0 1142 PDF_NON_SEPARABLE_BLEND_MODE (hsl_luminosity)
michael@0 1143
michael@0 1144 #undef SAT
michael@0 1145 #undef LUM
michael@0 1146 #undef CH_MAX
michael@0 1147 #undef CH_MIN
michael@0 1148 #undef PDF_NON_SEPARABLE_BLEND_MODE
michael@0 1149
michael@0 1150 /* All of the disjoint/conjoint composing functions
michael@0 1151 *
michael@0 1152 * The four entries in the first column indicate what source contributions
michael@0 1153 * come from each of the four areas of the picture -- areas covered by neither
michael@0 1154 * A nor B, areas covered only by A, areas covered only by B and finally
michael@0 1155 * areas covered by both A and B.
michael@0 1156 *
michael@0 1157 * Disjoint Conjoint
michael@0 1158 * Fa Fb Fa Fb
michael@0 1159 * (0,0,0,0) 0 0 0 0
michael@0 1160 * (0,A,0,A) 1 0 1 0
michael@0 1161 * (0,0,B,B) 0 1 0 1
michael@0 1162 * (0,A,B,A) 1 min((1-a)/b,1) 1 max(1-a/b,0)
michael@0 1163 * (0,A,B,B) min((1-b)/a,1) 1 max(1-b/a,0) 1
michael@0 1164 * (0,0,0,A) max(1-(1-b)/a,0) 0 min(1,b/a) 0
michael@0 1165 * (0,0,0,B) 0 max(1-(1-a)/b,0) 0 min(a/b,1)
michael@0 1166 * (0,A,0,0) min(1,(1-b)/a) 0 max(1-b/a,0) 0
michael@0 1167 * (0,0,B,0) 0 min(1,(1-a)/b) 0 max(1-a/b,0)
michael@0 1168 * (0,0,B,A) max(1-(1-b)/a,0) min(1,(1-a)/b) min(1,b/a) max(1-a/b,0)
michael@0 1169 * (0,A,0,B) min(1,(1-b)/a) max(1-(1-a)/b,0) max(1-b/a,0) min(1,a/b)
michael@0 1170 * (0,A,B,0) min(1,(1-b)/a) min(1,(1-a)/b) max(1-b/a,0) max(1-a/b,0)
michael@0 1171 *
michael@0 1172 * See http://marc.info/?l=xfree-render&m=99792000027857&w=2 for more
michael@0 1173 * information about these operators.
michael@0 1174 */
michael@0 1175
michael@0 1176 #define COMBINE_A_OUT 1
michael@0 1177 #define COMBINE_A_IN 2
michael@0 1178 #define COMBINE_B_OUT 4
michael@0 1179 #define COMBINE_B_IN 8
michael@0 1180
michael@0 1181 #define COMBINE_CLEAR 0
michael@0 1182 #define COMBINE_A (COMBINE_A_OUT | COMBINE_A_IN)
michael@0 1183 #define COMBINE_B (COMBINE_B_OUT | COMBINE_B_IN)
michael@0 1184 #define COMBINE_A_OVER (COMBINE_A_OUT | COMBINE_B_OUT | COMBINE_A_IN)
michael@0 1185 #define COMBINE_B_OVER (COMBINE_A_OUT | COMBINE_B_OUT | COMBINE_B_IN)
michael@0 1186 #define COMBINE_A_ATOP (COMBINE_B_OUT | COMBINE_A_IN)
michael@0 1187 #define COMBINE_B_ATOP (COMBINE_A_OUT | COMBINE_B_IN)
michael@0 1188 #define COMBINE_XOR (COMBINE_A_OUT | COMBINE_B_OUT)
michael@0 1189
michael@0 1190 /* portion covered by a but not b */
michael@0 1191 static uint16_t
michael@0 1192 combine_disjoint_out_part (uint16_t a, uint16_t b)
michael@0 1193 {
michael@0 1194 /* min (1, (1-b) / a) */
michael@0 1195
michael@0 1196 b = ~b; /* 1 - b */
michael@0 1197 if (b >= a) /* 1 - b >= a -> (1-b)/a >= 1 */
michael@0 1198 return MASK; /* 1 */
michael@0 1199 return DIV_UN16 (b, a); /* (1-b) / a */
michael@0 1200 }
michael@0 1201
michael@0 1202 /* portion covered by both a and b */
michael@0 1203 static uint16_t
michael@0 1204 combine_disjoint_in_part (uint16_t a, uint16_t b)
michael@0 1205 {
michael@0 1206 /* max (1-(1-b)/a,0) */
michael@0 1207 /* = - min ((1-b)/a - 1, 0) */
michael@0 1208 /* = 1 - min (1, (1-b)/a) */
michael@0 1209
michael@0 1210 b = ~b; /* 1 - b */
michael@0 1211 if (b >= a) /* 1 - b >= a -> (1-b)/a >= 1 */
michael@0 1212 return 0; /* 1 - 1 */
michael@0 1213 return ~DIV_UN16(b, a); /* 1 - (1-b) / a */
michael@0 1214 }
michael@0 1215
michael@0 1216 /* portion covered by a but not b */
michael@0 1217 static uint16_t
michael@0 1218 combine_conjoint_out_part (uint16_t a, uint16_t b)
michael@0 1219 {
michael@0 1220 /* max (1-b/a,0) */
michael@0 1221 /* = 1-min(b/a,1) */
michael@0 1222
michael@0 1223 /* min (1, (1-b) / a) */
michael@0 1224
michael@0 1225 if (b >= a) /* b >= a -> b/a >= 1 */
michael@0 1226 return 0x00; /* 0 */
michael@0 1227 return ~DIV_UN16(b, a); /* 1 - b/a */
michael@0 1228 }
michael@0 1229
michael@0 1230 /* portion covered by both a and b */
michael@0 1231 static uint16_t
michael@0 1232 combine_conjoint_in_part (uint16_t a, uint16_t b)
michael@0 1233 {
michael@0 1234 /* min (1,b/a) */
michael@0 1235
michael@0 1236 if (b >= a) /* b >= a -> b/a >= 1 */
michael@0 1237 return MASK; /* 1 */
michael@0 1238 return DIV_UN16 (b, a); /* b/a */
michael@0 1239 }
michael@0 1240
michael@0 1241 #define GET_COMP(v, i) ((uint32_t) (uint16_t) ((v) >> i))
michael@0 1242
michael@0 1243 #define ADD(x, y, i, t) \
michael@0 1244 ((t) = GET_COMP (x, i) + GET_COMP (y, i), \
michael@0 1245 (uint64_t) ((uint16_t) ((t) | (0 - ((t) >> G_SHIFT)))) << (i))
michael@0 1246
michael@0 1247 #define GENERIC(x, y, i, ax, ay, t, u, v) \
michael@0 1248 ((t) = (MUL_UN16 (GET_COMP (y, i), ay, (u)) + \
michael@0 1249 MUL_UN16 (GET_COMP (x, i), ax, (v))), \
michael@0 1250 (uint64_t) ((uint16_t) ((t) | \
michael@0 1251 (0 - ((t) >> G_SHIFT)))) << (i))
michael@0 1252
michael@0 1253 static void
michael@0 1254 combine_disjoint_general_u (uint64_t * dest,
michael@0 1255 const uint64_t *src,
michael@0 1256 const uint64_t *mask,
michael@0 1257 int width,
michael@0 1258 uint16_t combine)
michael@0 1259 {
michael@0 1260 int i;
michael@0 1261
michael@0 1262 for (i = 0; i < width; ++i)
michael@0 1263 {
michael@0 1264 uint64_t s = combine_mask (src, mask, i);
michael@0 1265 uint64_t d = *(dest + i);
michael@0 1266 uint64_t m, n, o, p;
michael@0 1267 uint32_t Fa, Fb, t, u, v;
michael@0 1268 uint16_t sa = s >> A_SHIFT;
michael@0 1269 uint16_t da = d >> A_SHIFT;
michael@0 1270
michael@0 1271 switch (combine & COMBINE_A)
michael@0 1272 {
michael@0 1273 default:
michael@0 1274 Fa = 0;
michael@0 1275 break;
michael@0 1276
michael@0 1277 case COMBINE_A_OUT:
michael@0 1278 Fa = combine_disjoint_out_part (sa, da);
michael@0 1279 break;
michael@0 1280
michael@0 1281 case COMBINE_A_IN:
michael@0 1282 Fa = combine_disjoint_in_part (sa, da);
michael@0 1283 break;
michael@0 1284
michael@0 1285 case COMBINE_A:
michael@0 1286 Fa = MASK;
michael@0 1287 break;
michael@0 1288 }
michael@0 1289
michael@0 1290 switch (combine & COMBINE_B)
michael@0 1291 {
michael@0 1292 default:
michael@0 1293 Fb = 0;
michael@0 1294 break;
michael@0 1295
michael@0 1296 case COMBINE_B_OUT:
michael@0 1297 Fb = combine_disjoint_out_part (da, sa);
michael@0 1298 break;
michael@0 1299
michael@0 1300 case COMBINE_B_IN:
michael@0 1301 Fb = combine_disjoint_in_part (da, sa);
michael@0 1302 break;
michael@0 1303
michael@0 1304 case COMBINE_B:
michael@0 1305 Fb = MASK;
michael@0 1306 break;
michael@0 1307 }
michael@0 1308 m = GENERIC (s, d, 0, Fa, Fb, t, u, v);
michael@0 1309 n = GENERIC (s, d, G_SHIFT, Fa, Fb, t, u, v);
michael@0 1310 o = GENERIC (s, d, R_SHIFT, Fa, Fb, t, u, v);
michael@0 1311 p = GENERIC (s, d, A_SHIFT, Fa, Fb, t, u, v);
michael@0 1312 s = m | n | o | p;
michael@0 1313 *(dest + i) = s;
michael@0 1314 }
michael@0 1315 }
michael@0 1316
michael@0 1317 static void
michael@0 1318 combine_disjoint_over_u (pixman_implementation_t *imp,
michael@0 1319 pixman_op_t op,
michael@0 1320 uint64_t * dest,
michael@0 1321 const uint64_t * src,
michael@0 1322 const uint64_t * mask,
michael@0 1323 int width)
michael@0 1324 {
michael@0 1325 int i;
michael@0 1326
michael@0 1327 for (i = 0; i < width; ++i)
michael@0 1328 {
michael@0 1329 uint64_t s = combine_mask (src, mask, i);
michael@0 1330 uint32_t a = s >> A_SHIFT;
michael@0 1331
michael@0 1332 if (s != 0x00)
michael@0 1333 {
michael@0 1334 uint64_t d = *(dest + i);
michael@0 1335 a = combine_disjoint_out_part (d >> A_SHIFT, a);
michael@0 1336 UN16x4_MUL_UN16_ADD_UN16x4 (d, a, s);
michael@0 1337
michael@0 1338 *(dest + i) = d;
michael@0 1339 }
michael@0 1340 }
michael@0 1341 }
michael@0 1342
michael@0 1343 static void
michael@0 1344 combine_disjoint_in_u (pixman_implementation_t *imp,
michael@0 1345 pixman_op_t op,
michael@0 1346 uint64_t * dest,
michael@0 1347 const uint64_t * src,
michael@0 1348 const uint64_t * mask,
michael@0 1349 int width)
michael@0 1350 {
michael@0 1351 combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_IN);
michael@0 1352 }
michael@0 1353
michael@0 1354 static void
michael@0 1355 combine_disjoint_in_reverse_u (pixman_implementation_t *imp,
michael@0 1356 pixman_op_t op,
michael@0 1357 uint64_t * dest,
michael@0 1358 const uint64_t * src,
michael@0 1359 const uint64_t * mask,
michael@0 1360 int width)
michael@0 1361 {
michael@0 1362 combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_IN);
michael@0 1363 }
michael@0 1364
michael@0 1365 static void
michael@0 1366 combine_disjoint_out_u (pixman_implementation_t *imp,
michael@0 1367 pixman_op_t op,
michael@0 1368 uint64_t * dest,
michael@0 1369 const uint64_t * src,
michael@0 1370 const uint64_t * mask,
michael@0 1371 int width)
michael@0 1372 {
michael@0 1373 combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_OUT);
michael@0 1374 }
michael@0 1375
michael@0 1376 static void
michael@0 1377 combine_disjoint_out_reverse_u (pixman_implementation_t *imp,
michael@0 1378 pixman_op_t op,
michael@0 1379 uint64_t * dest,
michael@0 1380 const uint64_t * src,
michael@0 1381 const uint64_t * mask,
michael@0 1382 int width)
michael@0 1383 {
michael@0 1384 combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_OUT);
michael@0 1385 }
michael@0 1386
michael@0 1387 static void
michael@0 1388 combine_disjoint_atop_u (pixman_implementation_t *imp,
michael@0 1389 pixman_op_t op,
michael@0 1390 uint64_t * dest,
michael@0 1391 const uint64_t * src,
michael@0 1392 const uint64_t * mask,
michael@0 1393 int width)
michael@0 1394 {
michael@0 1395 combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_ATOP);
michael@0 1396 }
michael@0 1397
michael@0 1398 static void
michael@0 1399 combine_disjoint_atop_reverse_u (pixman_implementation_t *imp,
michael@0 1400 pixman_op_t op,
michael@0 1401 uint64_t * dest,
michael@0 1402 const uint64_t * src,
michael@0 1403 const uint64_t * mask,
michael@0 1404 int width)
michael@0 1405 {
michael@0 1406 combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_ATOP);
michael@0 1407 }
michael@0 1408
michael@0 1409 static void
michael@0 1410 combine_disjoint_xor_u (pixman_implementation_t *imp,
michael@0 1411 pixman_op_t op,
michael@0 1412 uint64_t * dest,
michael@0 1413 const uint64_t * src,
michael@0 1414 const uint64_t * mask,
michael@0 1415 int width)
michael@0 1416 {
michael@0 1417 combine_disjoint_general_u (dest, src, mask, width, COMBINE_XOR);
michael@0 1418 }
michael@0 1419
michael@0 1420 static void
michael@0 1421 combine_conjoint_general_u (uint64_t * dest,
michael@0 1422 const uint64_t *src,
michael@0 1423 const uint64_t *mask,
michael@0 1424 int width,
michael@0 1425 uint16_t combine)
michael@0 1426 {
michael@0 1427 int i;
michael@0 1428
michael@0 1429 for (i = 0; i < width; ++i)
michael@0 1430 {
michael@0 1431 uint64_t s = combine_mask (src, mask, i);
michael@0 1432 uint64_t d = *(dest + i);
michael@0 1433 uint64_t m, n, o, p;
michael@0 1434 uint32_t Fa, Fb, t, u, v;
michael@0 1435 uint16_t sa = s >> A_SHIFT;
michael@0 1436 uint16_t da = d >> A_SHIFT;
michael@0 1437
michael@0 1438 switch (combine & COMBINE_A)
michael@0 1439 {
michael@0 1440 default:
michael@0 1441 Fa = 0;
michael@0 1442 break;
michael@0 1443
michael@0 1444 case COMBINE_A_OUT:
michael@0 1445 Fa = combine_conjoint_out_part (sa, da);
michael@0 1446 break;
michael@0 1447
michael@0 1448 case COMBINE_A_IN:
michael@0 1449 Fa = combine_conjoint_in_part (sa, da);
michael@0 1450 break;
michael@0 1451
michael@0 1452 case COMBINE_A:
michael@0 1453 Fa = MASK;
michael@0 1454 break;
michael@0 1455 }
michael@0 1456
michael@0 1457 switch (combine & COMBINE_B)
michael@0 1458 {
michael@0 1459 default:
michael@0 1460 Fb = 0;
michael@0 1461 break;
michael@0 1462
michael@0 1463 case COMBINE_B_OUT:
michael@0 1464 Fb = combine_conjoint_out_part (da, sa);
michael@0 1465 break;
michael@0 1466
michael@0 1467 case COMBINE_B_IN:
michael@0 1468 Fb = combine_conjoint_in_part (da, sa);
michael@0 1469 break;
michael@0 1470
michael@0 1471 case COMBINE_B:
michael@0 1472 Fb = MASK;
michael@0 1473 break;
michael@0 1474 }
michael@0 1475
michael@0 1476 m = GENERIC (s, d, 0, Fa, Fb, t, u, v);
michael@0 1477 n = GENERIC (s, d, G_SHIFT, Fa, Fb, t, u, v);
michael@0 1478 o = GENERIC (s, d, R_SHIFT, Fa, Fb, t, u, v);
michael@0 1479 p = GENERIC (s, d, A_SHIFT, Fa, Fb, t, u, v);
michael@0 1480
michael@0 1481 s = m | n | o | p;
michael@0 1482
michael@0 1483 *(dest + i) = s;
michael@0 1484 }
michael@0 1485 }
michael@0 1486
michael@0 1487 static void
michael@0 1488 combine_conjoint_over_u (pixman_implementation_t *imp,
michael@0 1489 pixman_op_t op,
michael@0 1490 uint64_t * dest,
michael@0 1491 const uint64_t * src,
michael@0 1492 const uint64_t * mask,
michael@0 1493 int width)
michael@0 1494 {
michael@0 1495 combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_OVER);
michael@0 1496 }
michael@0 1497
michael@0 1498 static void
michael@0 1499 combine_conjoint_over_reverse_u (pixman_implementation_t *imp,
michael@0 1500 pixman_op_t op,
michael@0 1501 uint64_t * dest,
michael@0 1502 const uint64_t * src,
michael@0 1503 const uint64_t * mask,
michael@0 1504 int width)
michael@0 1505 {
michael@0 1506 combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_OVER);
michael@0 1507 }
michael@0 1508
michael@0 1509 static void
michael@0 1510 combine_conjoint_in_u (pixman_implementation_t *imp,
michael@0 1511 pixman_op_t op,
michael@0 1512 uint64_t * dest,
michael@0 1513 const uint64_t * src,
michael@0 1514 const uint64_t * mask,
michael@0 1515 int width)
michael@0 1516 {
michael@0 1517 combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_IN);
michael@0 1518 }
michael@0 1519
michael@0 1520 static void
michael@0 1521 combine_conjoint_in_reverse_u (pixman_implementation_t *imp,
michael@0 1522 pixman_op_t op,
michael@0 1523 uint64_t * dest,
michael@0 1524 const uint64_t * src,
michael@0 1525 const uint64_t * mask,
michael@0 1526 int width)
michael@0 1527 {
michael@0 1528 combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_IN);
michael@0 1529 }
michael@0 1530
michael@0 1531 static void
michael@0 1532 combine_conjoint_out_u (pixman_implementation_t *imp,
michael@0 1533 pixman_op_t op,
michael@0 1534 uint64_t * dest,
michael@0 1535 const uint64_t * src,
michael@0 1536 const uint64_t * mask,
michael@0 1537 int width)
michael@0 1538 {
michael@0 1539 combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_OUT);
michael@0 1540 }
michael@0 1541
michael@0 1542 static void
michael@0 1543 combine_conjoint_out_reverse_u (pixman_implementation_t *imp,
michael@0 1544 pixman_op_t op,
michael@0 1545 uint64_t * dest,
michael@0 1546 const uint64_t * src,
michael@0 1547 const uint64_t * mask,
michael@0 1548 int width)
michael@0 1549 {
michael@0 1550 combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_OUT);
michael@0 1551 }
michael@0 1552
michael@0 1553 static void
michael@0 1554 combine_conjoint_atop_u (pixman_implementation_t *imp,
michael@0 1555 pixman_op_t op,
michael@0 1556 uint64_t * dest,
michael@0 1557 const uint64_t * src,
michael@0 1558 const uint64_t * mask,
michael@0 1559 int width)
michael@0 1560 {
michael@0 1561 combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_ATOP);
michael@0 1562 }
michael@0 1563
michael@0 1564 static void
michael@0 1565 combine_conjoint_atop_reverse_u (pixman_implementation_t *imp,
michael@0 1566 pixman_op_t op,
michael@0 1567 uint64_t * dest,
michael@0 1568 const uint64_t * src,
michael@0 1569 const uint64_t * mask,
michael@0 1570 int width)
michael@0 1571 {
michael@0 1572 combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_ATOP);
michael@0 1573 }
michael@0 1574
michael@0 1575 static void
michael@0 1576 combine_conjoint_xor_u (pixman_implementation_t *imp,
michael@0 1577 pixman_op_t op,
michael@0 1578 uint64_t * dest,
michael@0 1579 const uint64_t * src,
michael@0 1580 const uint64_t * mask,
michael@0 1581 int width)
michael@0 1582 {
michael@0 1583 combine_conjoint_general_u (dest, src, mask, width, COMBINE_XOR);
michael@0 1584 }
michael@0 1585
michael@0 1586 /************************************************************************/
michael@0 1587 /*********************** Per Channel functions **************************/
michael@0 1588 /************************************************************************/
michael@0 1589
michael@0 1590 static void
michael@0 1591 combine_clear_ca (pixman_implementation_t *imp,
michael@0 1592 pixman_op_t op,
michael@0 1593 uint64_t * dest,
michael@0 1594 const uint64_t * src,
michael@0 1595 const uint64_t * mask,
michael@0 1596 int width)
michael@0 1597 {
michael@0 1598 memset (dest, 0, width * sizeof(uint64_t));
michael@0 1599 }
michael@0 1600
michael@0 1601 static void
michael@0 1602 combine_src_ca (pixman_implementation_t *imp,
michael@0 1603 pixman_op_t op,
michael@0 1604 uint64_t * dest,
michael@0 1605 const uint64_t * src,
michael@0 1606 const uint64_t * mask,
michael@0 1607 int width)
michael@0 1608 {
michael@0 1609 int i;
michael@0 1610
michael@0 1611 for (i = 0; i < width; ++i)
michael@0 1612 {
michael@0 1613 uint64_t s = *(src + i);
michael@0 1614 uint64_t m = *(mask + i);
michael@0 1615
michael@0 1616 combine_mask_value_ca (&s, &m);
michael@0 1617
michael@0 1618 *(dest + i) = s;
michael@0 1619 }
michael@0 1620 }
michael@0 1621
michael@0 1622 static void
michael@0 1623 combine_over_ca (pixman_implementation_t *imp,
michael@0 1624 pixman_op_t op,
michael@0 1625 uint64_t * dest,
michael@0 1626 const uint64_t * src,
michael@0 1627 const uint64_t * mask,
michael@0 1628 int width)
michael@0 1629 {
michael@0 1630 int i;
michael@0 1631
michael@0 1632 for (i = 0; i < width; ++i)
michael@0 1633 {
michael@0 1634 uint64_t s = *(src + i);
michael@0 1635 uint64_t m = *(mask + i);
michael@0 1636 uint64_t a;
michael@0 1637
michael@0 1638 combine_mask_ca (&s, &m);
michael@0 1639
michael@0 1640 a = ~m;
michael@0 1641 if (a)
michael@0 1642 {
michael@0 1643 uint64_t d = *(dest + i);
michael@0 1644 UN16x4_MUL_UN16x4_ADD_UN16x4 (d, a, s);
michael@0 1645 s = d;
michael@0 1646 }
michael@0 1647
michael@0 1648 *(dest + i) = s;
michael@0 1649 }
michael@0 1650 }
michael@0 1651
michael@0 1652 static void
michael@0 1653 combine_over_reverse_ca (pixman_implementation_t *imp,
michael@0 1654 pixman_op_t op,
michael@0 1655 uint64_t * dest,
michael@0 1656 const uint64_t * src,
michael@0 1657 const uint64_t * mask,
michael@0 1658 int width)
michael@0 1659 {
michael@0 1660 int i;
michael@0 1661
michael@0 1662 for (i = 0; i < width; ++i)
michael@0 1663 {
michael@0 1664 uint64_t d = *(dest + i);
michael@0 1665 uint64_t a = ~d >> A_SHIFT;
michael@0 1666
michael@0 1667 if (a)
michael@0 1668 {
michael@0 1669 uint64_t s = *(src + i);
michael@0 1670 uint64_t m = *(mask + i);
michael@0 1671
michael@0 1672 UN16x4_MUL_UN16x4 (s, m);
michael@0 1673 UN16x4_MUL_UN16_ADD_UN16x4 (s, a, d);
michael@0 1674
michael@0 1675 *(dest + i) = s;
michael@0 1676 }
michael@0 1677 }
michael@0 1678 }
michael@0 1679
michael@0 1680 static void
michael@0 1681 combine_in_ca (pixman_implementation_t *imp,
michael@0 1682 pixman_op_t op,
michael@0 1683 uint64_t * dest,
michael@0 1684 const uint64_t * src,
michael@0 1685 const uint64_t * mask,
michael@0 1686 int width)
michael@0 1687 {
michael@0 1688 int i;
michael@0 1689
michael@0 1690 for (i = 0; i < width; ++i)
michael@0 1691 {
michael@0 1692 uint64_t d = *(dest + i);
michael@0 1693 uint32_t a = d >> A_SHIFT;
michael@0 1694 uint64_t s = 0;
michael@0 1695
michael@0 1696 if (a)
michael@0 1697 {
michael@0 1698 uint64_t m = *(mask + i);
michael@0 1699
michael@0 1700 s = *(src + i);
michael@0 1701 combine_mask_value_ca (&s, &m);
michael@0 1702
michael@0 1703 if (a != MASK)
michael@0 1704 UN16x4_MUL_UN16 (s, a);
michael@0 1705 }
michael@0 1706
michael@0 1707 *(dest + i) = s;
michael@0 1708 }
michael@0 1709 }
michael@0 1710
michael@0 1711 static void
michael@0 1712 combine_in_reverse_ca (pixman_implementation_t *imp,
michael@0 1713 pixman_op_t op,
michael@0 1714 uint64_t * dest,
michael@0 1715 const uint64_t * src,
michael@0 1716 const uint64_t * mask,
michael@0 1717 int width)
michael@0 1718 {
michael@0 1719 int i;
michael@0 1720
michael@0 1721 for (i = 0; i < width; ++i)
michael@0 1722 {
michael@0 1723 uint64_t s = *(src + i);
michael@0 1724 uint64_t m = *(mask + i);
michael@0 1725 uint64_t a;
michael@0 1726
michael@0 1727 combine_mask_alpha_ca (&s, &m);
michael@0 1728
michael@0 1729 a = m;
michael@0 1730 if (a != ~0)
michael@0 1731 {
michael@0 1732 uint64_t d = 0;
michael@0 1733
michael@0 1734 if (a)
michael@0 1735 {
michael@0 1736 d = *(dest + i);
michael@0 1737 UN16x4_MUL_UN16x4 (d, a);
michael@0 1738 }
michael@0 1739
michael@0 1740 *(dest + i) = d;
michael@0 1741 }
michael@0 1742 }
michael@0 1743 }
michael@0 1744
michael@0 1745 static void
michael@0 1746 combine_out_ca (pixman_implementation_t *imp,
michael@0 1747 pixman_op_t op,
michael@0 1748 uint64_t * dest,
michael@0 1749 const uint64_t * src,
michael@0 1750 const uint64_t * mask,
michael@0 1751 int width)
michael@0 1752 {
michael@0 1753 int i;
michael@0 1754
michael@0 1755 for (i = 0; i < width; ++i)
michael@0 1756 {
michael@0 1757 uint64_t d = *(dest + i);
michael@0 1758 uint32_t a = ~d >> A_SHIFT;
michael@0 1759 uint64_t s = 0;
michael@0 1760
michael@0 1761 if (a)
michael@0 1762 {
michael@0 1763 uint64_t m = *(mask + i);
michael@0 1764
michael@0 1765 s = *(src + i);
michael@0 1766 combine_mask_value_ca (&s, &m);
michael@0 1767
michael@0 1768 if (a != MASK)
michael@0 1769 UN16x4_MUL_UN16 (s, a);
michael@0 1770 }
michael@0 1771
michael@0 1772 *(dest + i) = s;
michael@0 1773 }
michael@0 1774 }
michael@0 1775
michael@0 1776 static void
michael@0 1777 combine_out_reverse_ca (pixman_implementation_t *imp,
michael@0 1778 pixman_op_t op,
michael@0 1779 uint64_t * dest,
michael@0 1780 const uint64_t * src,
michael@0 1781 const uint64_t * mask,
michael@0 1782 int width)
michael@0 1783 {
michael@0 1784 int i;
michael@0 1785
michael@0 1786 for (i = 0; i < width; ++i)
michael@0 1787 {
michael@0 1788 uint64_t s = *(src + i);
michael@0 1789 uint64_t m = *(mask + i);
michael@0 1790 uint64_t a;
michael@0 1791
michael@0 1792 combine_mask_alpha_ca (&s, &m);
michael@0 1793
michael@0 1794 a = ~m;
michael@0 1795 if (a != ~0)
michael@0 1796 {
michael@0 1797 uint64_t d = 0;
michael@0 1798
michael@0 1799 if (a)
michael@0 1800 {
michael@0 1801 d = *(dest + i);
michael@0 1802 UN16x4_MUL_UN16x4 (d, a);
michael@0 1803 }
michael@0 1804
michael@0 1805 *(dest + i) = d;
michael@0 1806 }
michael@0 1807 }
michael@0 1808 }
michael@0 1809
michael@0 1810 static void
michael@0 1811 combine_atop_ca (pixman_implementation_t *imp,
michael@0 1812 pixman_op_t op,
michael@0 1813 uint64_t * dest,
michael@0 1814 const uint64_t * src,
michael@0 1815 const uint64_t * mask,
michael@0 1816 int width)
michael@0 1817 {
michael@0 1818 int i;
michael@0 1819
michael@0 1820 for (i = 0; i < width; ++i)
michael@0 1821 {
michael@0 1822 uint64_t d = *(dest + i);
michael@0 1823 uint64_t s = *(src + i);
michael@0 1824 uint64_t m = *(mask + i);
michael@0 1825 uint64_t ad;
michael@0 1826 uint32_t as = d >> A_SHIFT;
michael@0 1827
michael@0 1828 combine_mask_ca (&s, &m);
michael@0 1829
michael@0 1830 ad = ~m;
michael@0 1831
michael@0 1832 UN16x4_MUL_UN16x4_ADD_UN16x4_MUL_UN16 (d, ad, s, as);
michael@0 1833
michael@0 1834 *(dest + i) = d;
michael@0 1835 }
michael@0 1836 }
michael@0 1837
michael@0 1838 static void
michael@0 1839 combine_atop_reverse_ca (pixman_implementation_t *imp,
michael@0 1840 pixman_op_t op,
michael@0 1841 uint64_t * dest,
michael@0 1842 const uint64_t * src,
michael@0 1843 const uint64_t * mask,
michael@0 1844 int width)
michael@0 1845 {
michael@0 1846 int i;
michael@0 1847
michael@0 1848 for (i = 0; i < width; ++i)
michael@0 1849 {
michael@0 1850 uint64_t d = *(dest + i);
michael@0 1851 uint64_t s = *(src + i);
michael@0 1852 uint64_t m = *(mask + i);
michael@0 1853 uint64_t ad;
michael@0 1854 uint32_t as = ~d >> A_SHIFT;
michael@0 1855
michael@0 1856 combine_mask_ca (&s, &m);
michael@0 1857
michael@0 1858 ad = m;
michael@0 1859
michael@0 1860 UN16x4_MUL_UN16x4_ADD_UN16x4_MUL_UN16 (d, ad, s, as);
michael@0 1861
michael@0 1862 *(dest + i) = d;
michael@0 1863 }
michael@0 1864 }
michael@0 1865
michael@0 1866 static void
michael@0 1867 combine_xor_ca (pixman_implementation_t *imp,
michael@0 1868 pixman_op_t op,
michael@0 1869 uint64_t * dest,
michael@0 1870 const uint64_t * src,
michael@0 1871 const uint64_t * mask,
michael@0 1872 int width)
michael@0 1873 {
michael@0 1874 int i;
michael@0 1875
michael@0 1876 for (i = 0; i < width; ++i)
michael@0 1877 {
michael@0 1878 uint64_t d = *(dest + i);
michael@0 1879 uint64_t s = *(src + i);
michael@0 1880 uint64_t m = *(mask + i);
michael@0 1881 uint64_t ad;
michael@0 1882 uint32_t as = ~d >> A_SHIFT;
michael@0 1883
michael@0 1884 combine_mask_ca (&s, &m);
michael@0 1885
michael@0 1886 ad = ~m;
michael@0 1887
michael@0 1888 UN16x4_MUL_UN16x4_ADD_UN16x4_MUL_UN16 (d, ad, s, as);
michael@0 1889
michael@0 1890 *(dest + i) = d;
michael@0 1891 }
michael@0 1892 }
michael@0 1893
michael@0 1894 static void
michael@0 1895 combine_add_ca (pixman_implementation_t *imp,
michael@0 1896 pixman_op_t op,
michael@0 1897 uint64_t * dest,
michael@0 1898 const uint64_t * src,
michael@0 1899 const uint64_t * mask,
michael@0 1900 int width)
michael@0 1901 {
michael@0 1902 int i;
michael@0 1903
michael@0 1904 for (i = 0; i < width; ++i)
michael@0 1905 {
michael@0 1906 uint64_t s = *(src + i);
michael@0 1907 uint64_t m = *(mask + i);
michael@0 1908 uint64_t d = *(dest + i);
michael@0 1909
michael@0 1910 combine_mask_value_ca (&s, &m);
michael@0 1911
michael@0 1912 UN16x4_ADD_UN16x4 (d, s);
michael@0 1913
michael@0 1914 *(dest + i) = d;
michael@0 1915 }
michael@0 1916 }
michael@0 1917
michael@0 1918 static void
michael@0 1919 combine_saturate_ca (pixman_implementation_t *imp,
michael@0 1920 pixman_op_t op,
michael@0 1921 uint64_t * dest,
michael@0 1922 const uint64_t * src,
michael@0 1923 const uint64_t * mask,
michael@0 1924 int width)
michael@0 1925 {
michael@0 1926 int i;
michael@0 1927
michael@0 1928 for (i = 0; i < width; ++i)
michael@0 1929 {
michael@0 1930 uint64_t s, d;
michael@0 1931 uint32_t sa, sr, sg, sb, da;
michael@0 1932 uint32_t t, u, v;
michael@0 1933 uint64_t m, n, o, p;
michael@0 1934
michael@0 1935 d = *(dest + i);
michael@0 1936 s = *(src + i);
michael@0 1937 m = *(mask + i);
michael@0 1938
michael@0 1939 combine_mask_ca (&s, &m);
michael@0 1940
michael@0 1941 sa = (m >> A_SHIFT);
michael@0 1942 sr = (m >> R_SHIFT) & MASK;
michael@0 1943 sg = (m >> G_SHIFT) & MASK;
michael@0 1944 sb = m & MASK;
michael@0 1945 da = ~d >> A_SHIFT;
michael@0 1946
michael@0 1947 if (sb <= da)
michael@0 1948 m = ADD (s, d, 0, t);
michael@0 1949 else
michael@0 1950 m = GENERIC (s, d, 0, (da << G_SHIFT) / sb, MASK, t, u, v);
michael@0 1951
michael@0 1952 if (sg <= da)
michael@0 1953 n = ADD (s, d, G_SHIFT, t);
michael@0 1954 else
michael@0 1955 n = GENERIC (s, d, G_SHIFT, (da << G_SHIFT) / sg, MASK, t, u, v);
michael@0 1956
michael@0 1957 if (sr <= da)
michael@0 1958 o = ADD (s, d, R_SHIFT, t);
michael@0 1959 else
michael@0 1960 o = GENERIC (s, d, R_SHIFT, (da << G_SHIFT) / sr, MASK, t, u, v);
michael@0 1961
michael@0 1962 if (sa <= da)
michael@0 1963 p = ADD (s, d, A_SHIFT, t);
michael@0 1964 else
michael@0 1965 p = GENERIC (s, d, A_SHIFT, (da << G_SHIFT) / sa, MASK, t, u, v);
michael@0 1966
michael@0 1967 *(dest + i) = m | n | o | p;
michael@0 1968 }
michael@0 1969 }
michael@0 1970
michael@0 1971 static void
michael@0 1972 combine_disjoint_general_ca (uint64_t * dest,
michael@0 1973 const uint64_t *src,
michael@0 1974 const uint64_t *mask,
michael@0 1975 int width,
michael@0 1976 uint16_t combine)
michael@0 1977 {
michael@0 1978 int i;
michael@0 1979
michael@0 1980 for (i = 0; i < width; ++i)
michael@0 1981 {
michael@0 1982 uint64_t s, d;
michael@0 1983 uint64_t m, n, o, p;
michael@0 1984 uint64_t Fa, Fb;
michael@0 1985 uint32_t t, u, v;
michael@0 1986 uint64_t sa;
michael@0 1987 uint16_t da;
michael@0 1988
michael@0 1989 s = *(src + i);
michael@0 1990 m = *(mask + i);
michael@0 1991 d = *(dest + i);
michael@0 1992 da = d >> A_SHIFT;
michael@0 1993
michael@0 1994 combine_mask_ca (&s, &m);
michael@0 1995
michael@0 1996 sa = m;
michael@0 1997
michael@0 1998 switch (combine & COMBINE_A)
michael@0 1999 {
michael@0 2000 default:
michael@0 2001 Fa = 0;
michael@0 2002 break;
michael@0 2003
michael@0 2004 case COMBINE_A_OUT:
michael@0 2005 m = (uint64_t)combine_disjoint_out_part ((uint16_t) (sa >> 0), da);
michael@0 2006 n = (uint64_t)combine_disjoint_out_part ((uint16_t) (sa >> G_SHIFT), da) << G_SHIFT;
michael@0 2007 o = (uint64_t)combine_disjoint_out_part ((uint16_t) (sa >> R_SHIFT), da) << R_SHIFT;
michael@0 2008 p = (uint64_t)combine_disjoint_out_part ((uint16_t) (sa >> A_SHIFT), da) << A_SHIFT;
michael@0 2009 Fa = m | n | o | p;
michael@0 2010 break;
michael@0 2011
michael@0 2012 case COMBINE_A_IN:
michael@0 2013 m = (uint64_t)combine_disjoint_in_part ((uint16_t) (sa >> 0), da);
michael@0 2014 n = (uint64_t)combine_disjoint_in_part ((uint16_t) (sa >> G_SHIFT), da) << G_SHIFT;
michael@0 2015 o = (uint64_t)combine_disjoint_in_part ((uint16_t) (sa >> R_SHIFT), da) << R_SHIFT;
michael@0 2016 p = (uint64_t)combine_disjoint_in_part ((uint16_t) (sa >> A_SHIFT), da) << A_SHIFT;
michael@0 2017 Fa = m | n | o | p;
michael@0 2018 break;
michael@0 2019
michael@0 2020 case COMBINE_A:
michael@0 2021 Fa = ~0;
michael@0 2022 break;
michael@0 2023 }
michael@0 2024
michael@0 2025 switch (combine & COMBINE_B)
michael@0 2026 {
michael@0 2027 default:
michael@0 2028 Fb = 0;
michael@0 2029 break;
michael@0 2030
michael@0 2031 case COMBINE_B_OUT:
michael@0 2032 m = (uint64_t)combine_disjoint_out_part (da, (uint16_t) (sa >> 0));
michael@0 2033 n = (uint64_t)combine_disjoint_out_part (da, (uint16_t) (sa >> G_SHIFT)) << G_SHIFT;
michael@0 2034 o = (uint64_t)combine_disjoint_out_part (da, (uint16_t) (sa >> R_SHIFT)) << R_SHIFT;
michael@0 2035 p = (uint64_t)combine_disjoint_out_part (da, (uint16_t) (sa >> A_SHIFT)) << A_SHIFT;
michael@0 2036 Fb = m | n | o | p;
michael@0 2037 break;
michael@0 2038
michael@0 2039 case COMBINE_B_IN:
michael@0 2040 m = (uint64_t)combine_disjoint_in_part (da, (uint16_t) (sa >> 0));
michael@0 2041 n = (uint64_t)combine_disjoint_in_part (da, (uint16_t) (sa >> G_SHIFT)) << G_SHIFT;
michael@0 2042 o = (uint64_t)combine_disjoint_in_part (da, (uint16_t) (sa >> R_SHIFT)) << R_SHIFT;
michael@0 2043 p = (uint64_t)combine_disjoint_in_part (da, (uint16_t) (sa >> A_SHIFT)) << A_SHIFT;
michael@0 2044 Fb = m | n | o | p;
michael@0 2045 break;
michael@0 2046
michael@0 2047 case COMBINE_B:
michael@0 2048 Fb = ~0;
michael@0 2049 break;
michael@0 2050 }
michael@0 2051 m = GENERIC (s, d, 0, GET_COMP (Fa, 0), GET_COMP (Fb, 0), t, u, v);
michael@0 2052 n = GENERIC (s, d, G_SHIFT, GET_COMP (Fa, G_SHIFT), GET_COMP (Fb, G_SHIFT), t, u, v);
michael@0 2053 o = GENERIC (s, d, R_SHIFT, GET_COMP (Fa, R_SHIFT), GET_COMP (Fb, R_SHIFT), t, u, v);
michael@0 2054 p = GENERIC (s, d, A_SHIFT, GET_COMP (Fa, A_SHIFT), GET_COMP (Fb, A_SHIFT), t, u, v);
michael@0 2055
michael@0 2056 s = m | n | o | p;
michael@0 2057
michael@0 2058 *(dest + i) = s;
michael@0 2059 }
michael@0 2060 }
michael@0 2061
michael@0 2062 static void
michael@0 2063 combine_disjoint_over_ca (pixman_implementation_t *imp,
michael@0 2064 pixman_op_t op,
michael@0 2065 uint64_t * dest,
michael@0 2066 const uint64_t * src,
michael@0 2067 const uint64_t * mask,
michael@0 2068 int width)
michael@0 2069 {
michael@0 2070 combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_OVER);
michael@0 2071 }
michael@0 2072
michael@0 2073 static void
michael@0 2074 combine_disjoint_in_ca (pixman_implementation_t *imp,
michael@0 2075 pixman_op_t op,
michael@0 2076 uint64_t * dest,
michael@0 2077 const uint64_t * src,
michael@0 2078 const uint64_t * mask,
michael@0 2079 int width)
michael@0 2080 {
michael@0 2081 combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_IN);
michael@0 2082 }
michael@0 2083
michael@0 2084 static void
michael@0 2085 combine_disjoint_in_reverse_ca (pixman_implementation_t *imp,
michael@0 2086 pixman_op_t op,
michael@0 2087 uint64_t * dest,
michael@0 2088 const uint64_t * src,
michael@0 2089 const uint64_t * mask,
michael@0 2090 int width)
michael@0 2091 {
michael@0 2092 combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_IN);
michael@0 2093 }
michael@0 2094
michael@0 2095 static void
michael@0 2096 combine_disjoint_out_ca (pixman_implementation_t *imp,
michael@0 2097 pixman_op_t op,
michael@0 2098 uint64_t * dest,
michael@0 2099 const uint64_t * src,
michael@0 2100 const uint64_t * mask,
michael@0 2101 int width)
michael@0 2102 {
michael@0 2103 combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_OUT);
michael@0 2104 }
michael@0 2105
michael@0 2106 static void
michael@0 2107 combine_disjoint_out_reverse_ca (pixman_implementation_t *imp,
michael@0 2108 pixman_op_t op,
michael@0 2109 uint64_t * dest,
michael@0 2110 const uint64_t * src,
michael@0 2111 const uint64_t * mask,
michael@0 2112 int width)
michael@0 2113 {
michael@0 2114 combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_OUT);
michael@0 2115 }
michael@0 2116
michael@0 2117 static void
michael@0 2118 combine_disjoint_atop_ca (pixman_implementation_t *imp,
michael@0 2119 pixman_op_t op,
michael@0 2120 uint64_t * dest,
michael@0 2121 const uint64_t * src,
michael@0 2122 const uint64_t * mask,
michael@0 2123 int width)
michael@0 2124 {
michael@0 2125 combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_ATOP);
michael@0 2126 }
michael@0 2127
michael@0 2128 static void
michael@0 2129 combine_disjoint_atop_reverse_ca (pixman_implementation_t *imp,
michael@0 2130 pixman_op_t op,
michael@0 2131 uint64_t * dest,
michael@0 2132 const uint64_t * src,
michael@0 2133 const uint64_t * mask,
michael@0 2134 int width)
michael@0 2135 {
michael@0 2136 combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_ATOP);
michael@0 2137 }
michael@0 2138
michael@0 2139 static void
michael@0 2140 combine_disjoint_xor_ca (pixman_implementation_t *imp,
michael@0 2141 pixman_op_t op,
michael@0 2142 uint64_t * dest,
michael@0 2143 const uint64_t * src,
michael@0 2144 const uint64_t * mask,
michael@0 2145 int width)
michael@0 2146 {
michael@0 2147 combine_disjoint_general_ca (dest, src, mask, width, COMBINE_XOR);
michael@0 2148 }
michael@0 2149
michael@0 2150 static void
michael@0 2151 combine_conjoint_general_ca (uint64_t * dest,
michael@0 2152 const uint64_t *src,
michael@0 2153 const uint64_t *mask,
michael@0 2154 int width,
michael@0 2155 uint16_t combine)
michael@0 2156 {
michael@0 2157 int i;
michael@0 2158
michael@0 2159 for (i = 0; i < width; ++i)
michael@0 2160 {
michael@0 2161 uint64_t s, d;
michael@0 2162 uint64_t m, n, o, p;
michael@0 2163 uint64_t Fa, Fb;
michael@0 2164 uint32_t t, u, v;
michael@0 2165 uint64_t sa;
michael@0 2166 uint16_t da;
michael@0 2167
michael@0 2168 s = *(src + i);
michael@0 2169 m = *(mask + i);
michael@0 2170 d = *(dest + i);
michael@0 2171 da = d >> A_SHIFT;
michael@0 2172
michael@0 2173 combine_mask_ca (&s, &m);
michael@0 2174
michael@0 2175 sa = m;
michael@0 2176
michael@0 2177 switch (combine & COMBINE_A)
michael@0 2178 {
michael@0 2179 default:
michael@0 2180 Fa = 0;
michael@0 2181 break;
michael@0 2182
michael@0 2183 case COMBINE_A_OUT:
michael@0 2184 m = (uint64_t)combine_conjoint_out_part ((uint16_t) (sa >> 0), da);
michael@0 2185 n = (uint64_t)combine_conjoint_out_part ((uint16_t) (sa >> G_SHIFT), da) << G_SHIFT;
michael@0 2186 o = (uint64_t)combine_conjoint_out_part ((uint16_t) (sa >> R_SHIFT), da) << R_SHIFT;
michael@0 2187 p = (uint64_t)combine_conjoint_out_part ((uint16_t) (sa >> A_SHIFT), da) << A_SHIFT;
michael@0 2188 Fa = m | n | o | p;
michael@0 2189 break;
michael@0 2190
michael@0 2191 case COMBINE_A_IN:
michael@0 2192 m = (uint64_t)combine_conjoint_in_part ((uint16_t) (sa >> 0), da);
michael@0 2193 n = (uint64_t)combine_conjoint_in_part ((uint16_t) (sa >> G_SHIFT), da) << G_SHIFT;
michael@0 2194 o = (uint64_t)combine_conjoint_in_part ((uint16_t) (sa >> R_SHIFT), da) << R_SHIFT;
michael@0 2195 p = (uint64_t)combine_conjoint_in_part ((uint16_t) (sa >> A_SHIFT), da) << A_SHIFT;
michael@0 2196 Fa = m | n | o | p;
michael@0 2197 break;
michael@0 2198
michael@0 2199 case COMBINE_A:
michael@0 2200 Fa = ~0;
michael@0 2201 break;
michael@0 2202 }
michael@0 2203
michael@0 2204 switch (combine & COMBINE_B)
michael@0 2205 {
michael@0 2206 default:
michael@0 2207 Fb = 0;
michael@0 2208 break;
michael@0 2209
michael@0 2210 case COMBINE_B_OUT:
michael@0 2211 m = (uint64_t)combine_conjoint_out_part (da, (uint16_t) (sa >> 0));
michael@0 2212 n = (uint64_t)combine_conjoint_out_part (da, (uint16_t) (sa >> G_SHIFT)) << G_SHIFT;
michael@0 2213 o = (uint64_t)combine_conjoint_out_part (da, (uint16_t) (sa >> R_SHIFT)) << R_SHIFT;
michael@0 2214 p = (uint64_t)combine_conjoint_out_part (da, (uint16_t) (sa >> A_SHIFT)) << A_SHIFT;
michael@0 2215 Fb = m | n | o | p;
michael@0 2216 break;
michael@0 2217
michael@0 2218 case COMBINE_B_IN:
michael@0 2219 m = (uint64_t)combine_conjoint_in_part (da, (uint16_t) (sa >> 0));
michael@0 2220 n = (uint64_t)combine_conjoint_in_part (da, (uint16_t) (sa >> G_SHIFT)) << G_SHIFT;
michael@0 2221 o = (uint64_t)combine_conjoint_in_part (da, (uint16_t) (sa >> R_SHIFT)) << R_SHIFT;
michael@0 2222 p = (uint64_t)combine_conjoint_in_part (da, (uint16_t) (sa >> A_SHIFT)) << A_SHIFT;
michael@0 2223 Fb = m | n | o | p;
michael@0 2224 break;
michael@0 2225
michael@0 2226 case COMBINE_B:
michael@0 2227 Fb = ~0;
michael@0 2228 break;
michael@0 2229 }
michael@0 2230 m = GENERIC (s, d, 0, GET_COMP (Fa, 0), GET_COMP (Fb, 0), t, u, v);
michael@0 2231 n = GENERIC (s, d, G_SHIFT, GET_COMP (Fa, G_SHIFT), GET_COMP (Fb, G_SHIFT), t, u, v);
michael@0 2232 o = GENERIC (s, d, R_SHIFT, GET_COMP (Fa, R_SHIFT), GET_COMP (Fb, R_SHIFT), t, u, v);
michael@0 2233 p = GENERIC (s, d, A_SHIFT, GET_COMP (Fa, A_SHIFT), GET_COMP (Fb, A_SHIFT), t, u, v);
michael@0 2234
michael@0 2235 s = m | n | o | p;
michael@0 2236
michael@0 2237 *(dest + i) = s;
michael@0 2238 }
michael@0 2239 }
michael@0 2240
michael@0 2241 static void
michael@0 2242 combine_conjoint_over_ca (pixman_implementation_t *imp,
michael@0 2243 pixman_op_t op,
michael@0 2244 uint64_t * dest,
michael@0 2245 const uint64_t * src,
michael@0 2246 const uint64_t * mask,
michael@0 2247 int width)
michael@0 2248 {
michael@0 2249 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_OVER);
michael@0 2250 }
michael@0 2251
michael@0 2252 static void
michael@0 2253 combine_conjoint_over_reverse_ca (pixman_implementation_t *imp,
michael@0 2254 pixman_op_t op,
michael@0 2255 uint64_t * dest,
michael@0 2256 const uint64_t * src,
michael@0 2257 const uint64_t * mask,
michael@0 2258 int width)
michael@0 2259 {
michael@0 2260 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_OVER);
michael@0 2261 }
michael@0 2262
michael@0 2263 static void
michael@0 2264 combine_conjoint_in_ca (pixman_implementation_t *imp,
michael@0 2265 pixman_op_t op,
michael@0 2266 uint64_t * dest,
michael@0 2267 const uint64_t * src,
michael@0 2268 const uint64_t * mask,
michael@0 2269 int width)
michael@0 2270 {
michael@0 2271 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_IN);
michael@0 2272 }
michael@0 2273
michael@0 2274 static void
michael@0 2275 combine_conjoint_in_reverse_ca (pixman_implementation_t *imp,
michael@0 2276 pixman_op_t op,
michael@0 2277 uint64_t * dest,
michael@0 2278 const uint64_t * src,
michael@0 2279 const uint64_t * mask,
michael@0 2280 int width)
michael@0 2281 {
michael@0 2282 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_IN);
michael@0 2283 }
michael@0 2284
michael@0 2285 static void
michael@0 2286 combine_conjoint_out_ca (pixman_implementation_t *imp,
michael@0 2287 pixman_op_t op,
michael@0 2288 uint64_t * dest,
michael@0 2289 const uint64_t * src,
michael@0 2290 const uint64_t * mask,
michael@0 2291 int width)
michael@0 2292 {
michael@0 2293 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_OUT);
michael@0 2294 }
michael@0 2295
michael@0 2296 static void
michael@0 2297 combine_conjoint_out_reverse_ca (pixman_implementation_t *imp,
michael@0 2298 pixman_op_t op,
michael@0 2299 uint64_t * dest,
michael@0 2300 const uint64_t * src,
michael@0 2301 const uint64_t * mask,
michael@0 2302 int width)
michael@0 2303 {
michael@0 2304 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_OUT);
michael@0 2305 }
michael@0 2306
michael@0 2307 static void
michael@0 2308 combine_conjoint_atop_ca (pixman_implementation_t *imp,
michael@0 2309 pixman_op_t op,
michael@0 2310 uint64_t * dest,
michael@0 2311 const uint64_t * src,
michael@0 2312 const uint64_t * mask,
michael@0 2313 int width)
michael@0 2314 {
michael@0 2315 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_ATOP);
michael@0 2316 }
michael@0 2317
michael@0 2318 static void
michael@0 2319 combine_conjoint_atop_reverse_ca (pixman_implementation_t *imp,
michael@0 2320 pixman_op_t op,
michael@0 2321 uint64_t * dest,
michael@0 2322 const uint64_t * src,
michael@0 2323 const uint64_t * mask,
michael@0 2324 int width)
michael@0 2325 {
michael@0 2326 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_ATOP);
michael@0 2327 }
michael@0 2328
michael@0 2329 static void
michael@0 2330 combine_conjoint_xor_ca (pixman_implementation_t *imp,
michael@0 2331 pixman_op_t op,
michael@0 2332 uint64_t * dest,
michael@0 2333 const uint64_t * src,
michael@0 2334 const uint64_t * mask,
michael@0 2335 int width)
michael@0 2336 {
michael@0 2337 combine_conjoint_general_ca (dest, src, mask, width, COMBINE_XOR);
michael@0 2338 }
michael@0 2339
michael@0 2340 void
michael@0 2341 _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp)
michael@0 2342 {
michael@0 2343 /* Unified alpha */
michael@0 2344 imp->combine_64[PIXMAN_OP_CLEAR] = combine_clear;
michael@0 2345 imp->combine_64[PIXMAN_OP_SRC] = combine_src_u;
michael@0 2346 imp->combine_64[PIXMAN_OP_DST] = combine_dst;
michael@0 2347 imp->combine_64[PIXMAN_OP_OVER] = combine_over_u;
michael@0 2348 imp->combine_64[PIXMAN_OP_OVER_REVERSE] = combine_over_reverse_u;
michael@0 2349 imp->combine_64[PIXMAN_OP_IN] = combine_in_u;
michael@0 2350 imp->combine_64[PIXMAN_OP_IN_REVERSE] = combine_in_reverse_u;
michael@0 2351 imp->combine_64[PIXMAN_OP_OUT] = combine_out_u;
michael@0 2352 imp->combine_64[PIXMAN_OP_OUT_REVERSE] = combine_out_reverse_u;
michael@0 2353 imp->combine_64[PIXMAN_OP_ATOP] = combine_atop_u;
michael@0 2354 imp->combine_64[PIXMAN_OP_ATOP_REVERSE] = combine_atop_reverse_u;
michael@0 2355 imp->combine_64[PIXMAN_OP_XOR] = combine_xor_u;
michael@0 2356 imp->combine_64[PIXMAN_OP_ADD] = combine_add_u;
michael@0 2357 imp->combine_64[PIXMAN_OP_SATURATE] = combine_saturate_u;
michael@0 2358
michael@0 2359 /* Disjoint, unified */
michael@0 2360 imp->combine_64[PIXMAN_OP_DISJOINT_CLEAR] = combine_clear;
michael@0 2361 imp->combine_64[PIXMAN_OP_DISJOINT_SRC] = combine_src_u;
michael@0 2362 imp->combine_64[PIXMAN_OP_DISJOINT_DST] = combine_dst;
michael@0 2363 imp->combine_64[PIXMAN_OP_DISJOINT_OVER] = combine_disjoint_over_u;
michael@0 2364 imp->combine_64[PIXMAN_OP_DISJOINT_OVER_REVERSE] = combine_saturate_u;
michael@0 2365 imp->combine_64[PIXMAN_OP_DISJOINT_IN] = combine_disjoint_in_u;
michael@0 2366 imp->combine_64[PIXMAN_OP_DISJOINT_IN_REVERSE] = combine_disjoint_in_reverse_u;
michael@0 2367 imp->combine_64[PIXMAN_OP_DISJOINT_OUT] = combine_disjoint_out_u;
michael@0 2368 imp->combine_64[PIXMAN_OP_DISJOINT_OUT_REVERSE] = combine_disjoint_out_reverse_u;
michael@0 2369 imp->combine_64[PIXMAN_OP_DISJOINT_ATOP] = combine_disjoint_atop_u;
michael@0 2370 imp->combine_64[PIXMAN_OP_DISJOINT_ATOP_REVERSE] = combine_disjoint_atop_reverse_u;
michael@0 2371 imp->combine_64[PIXMAN_OP_DISJOINT_XOR] = combine_disjoint_xor_u;
michael@0 2372
michael@0 2373 /* Conjoint, unified */
michael@0 2374 imp->combine_64[PIXMAN_OP_CONJOINT_CLEAR] = combine_clear;
michael@0 2375 imp->combine_64[PIXMAN_OP_CONJOINT_SRC] = combine_src_u;
michael@0 2376 imp->combine_64[PIXMAN_OP_CONJOINT_DST] = combine_dst;
michael@0 2377 imp->combine_64[PIXMAN_OP_CONJOINT_OVER] = combine_conjoint_over_u;
michael@0 2378 imp->combine_64[PIXMAN_OP_CONJOINT_OVER_REVERSE] = combine_conjoint_over_reverse_u;
michael@0 2379 imp->combine_64[PIXMAN_OP_CONJOINT_IN] = combine_conjoint_in_u;
michael@0 2380 imp->combine_64[PIXMAN_OP_CONJOINT_IN_REVERSE] = combine_conjoint_in_reverse_u;
michael@0 2381 imp->combine_64[PIXMAN_OP_CONJOINT_OUT] = combine_conjoint_out_u;
michael@0 2382 imp->combine_64[PIXMAN_OP_CONJOINT_OUT_REVERSE] = combine_conjoint_out_reverse_u;
michael@0 2383 imp->combine_64[PIXMAN_OP_CONJOINT_ATOP] = combine_conjoint_atop_u;
michael@0 2384 imp->combine_64[PIXMAN_OP_CONJOINT_ATOP_REVERSE] = combine_conjoint_atop_reverse_u;
michael@0 2385 imp->combine_64[PIXMAN_OP_CONJOINT_XOR] = combine_conjoint_xor_u;
michael@0 2386
michael@0 2387 imp->combine_64[PIXMAN_OP_MULTIPLY] = combine_multiply_u;
michael@0 2388 imp->combine_64[PIXMAN_OP_SCREEN] = combine_screen_u;
michael@0 2389 imp->combine_64[PIXMAN_OP_OVERLAY] = combine_overlay_u;
michael@0 2390 imp->combine_64[PIXMAN_OP_DARKEN] = combine_darken_u;
michael@0 2391 imp->combine_64[PIXMAN_OP_LIGHTEN] = combine_lighten_u;
michael@0 2392 imp->combine_64[PIXMAN_OP_COLOR_DODGE] = combine_color_dodge_u;
michael@0 2393 imp->combine_64[PIXMAN_OP_COLOR_BURN] = combine_color_burn_u;
michael@0 2394 imp->combine_64[PIXMAN_OP_HARD_LIGHT] = combine_hard_light_u;
michael@0 2395 imp->combine_64[PIXMAN_OP_SOFT_LIGHT] = combine_soft_light_u;
michael@0 2396 imp->combine_64[PIXMAN_OP_DIFFERENCE] = combine_difference_u;
michael@0 2397 imp->combine_64[PIXMAN_OP_EXCLUSION] = combine_exclusion_u;
michael@0 2398 imp->combine_64[PIXMAN_OP_HSL_HUE] = combine_hsl_hue_u;
michael@0 2399 imp->combine_64[PIXMAN_OP_HSL_SATURATION] = combine_hsl_saturation_u;
michael@0 2400 imp->combine_64[PIXMAN_OP_HSL_COLOR] = combine_hsl_color_u;
michael@0 2401 imp->combine_64[PIXMAN_OP_HSL_LUMINOSITY] = combine_hsl_luminosity_u;
michael@0 2402
michael@0 2403 /* Component alpha combiners */
michael@0 2404 imp->combine_64_ca[PIXMAN_OP_CLEAR] = combine_clear_ca;
michael@0 2405 imp->combine_64_ca[PIXMAN_OP_SRC] = combine_src_ca;
michael@0 2406 /* dest */
michael@0 2407 imp->combine_64_ca[PIXMAN_OP_OVER] = combine_over_ca;
michael@0 2408 imp->combine_64_ca[PIXMAN_OP_OVER_REVERSE] = combine_over_reverse_ca;
michael@0 2409 imp->combine_64_ca[PIXMAN_OP_IN] = combine_in_ca;
michael@0 2410 imp->combine_64_ca[PIXMAN_OP_IN_REVERSE] = combine_in_reverse_ca;
michael@0 2411 imp->combine_64_ca[PIXMAN_OP_OUT] = combine_out_ca;
michael@0 2412 imp->combine_64_ca[PIXMAN_OP_OUT_REVERSE] = combine_out_reverse_ca;
michael@0 2413 imp->combine_64_ca[PIXMAN_OP_ATOP] = combine_atop_ca;
michael@0 2414 imp->combine_64_ca[PIXMAN_OP_ATOP_REVERSE] = combine_atop_reverse_ca;
michael@0 2415 imp->combine_64_ca[PIXMAN_OP_XOR] = combine_xor_ca;
michael@0 2416 imp->combine_64_ca[PIXMAN_OP_ADD] = combine_add_ca;
michael@0 2417 imp->combine_64_ca[PIXMAN_OP_SATURATE] = combine_saturate_ca;
michael@0 2418
michael@0 2419 /* Disjoint CA */
michael@0 2420 imp->combine_64_ca[PIXMAN_OP_DISJOINT_CLEAR] = combine_clear_ca;
michael@0 2421 imp->combine_64_ca[PIXMAN_OP_DISJOINT_SRC] = combine_src_ca;
michael@0 2422 imp->combine_64_ca[PIXMAN_OP_DISJOINT_DST] = combine_dst;
michael@0 2423 imp->combine_64_ca[PIXMAN_OP_DISJOINT_OVER] = combine_disjoint_over_ca;
michael@0 2424 imp->combine_64_ca[PIXMAN_OP_DISJOINT_OVER_REVERSE] = combine_saturate_ca;
michael@0 2425 imp->combine_64_ca[PIXMAN_OP_DISJOINT_IN] = combine_disjoint_in_ca;
michael@0 2426 imp->combine_64_ca[PIXMAN_OP_DISJOINT_IN_REVERSE] = combine_disjoint_in_reverse_ca;
michael@0 2427 imp->combine_64_ca[PIXMAN_OP_DISJOINT_OUT] = combine_disjoint_out_ca;
michael@0 2428 imp->combine_64_ca[PIXMAN_OP_DISJOINT_OUT_REVERSE] = combine_disjoint_out_reverse_ca;
michael@0 2429 imp->combine_64_ca[PIXMAN_OP_DISJOINT_ATOP] = combine_disjoint_atop_ca;
michael@0 2430 imp->combine_64_ca[PIXMAN_OP_DISJOINT_ATOP_REVERSE] = combine_disjoint_atop_reverse_ca;
michael@0 2431 imp->combine_64_ca[PIXMAN_OP_DISJOINT_XOR] = combine_disjoint_xor_ca;
michael@0 2432
michael@0 2433 /* Conjoint CA */
michael@0 2434 imp->combine_64_ca[PIXMAN_OP_CONJOINT_CLEAR] = combine_clear_ca;
michael@0 2435 imp->combine_64_ca[PIXMAN_OP_CONJOINT_SRC] = combine_src_ca;
michael@0 2436 imp->combine_64_ca[PIXMAN_OP_CONJOINT_DST] = combine_dst;
michael@0 2437 imp->combine_64_ca[PIXMAN_OP_CONJOINT_OVER] = combine_conjoint_over_ca;
michael@0 2438 imp->combine_64_ca[PIXMAN_OP_CONJOINT_OVER_REVERSE] = combine_conjoint_over_reverse_ca;
michael@0 2439 imp->combine_64_ca[PIXMAN_OP_CONJOINT_IN] = combine_conjoint_in_ca;
michael@0 2440 imp->combine_64_ca[PIXMAN_OP_CONJOINT_IN_REVERSE] = combine_conjoint_in_reverse_ca;
michael@0 2441 imp->combine_64_ca[PIXMAN_OP_CONJOINT_OUT] = combine_conjoint_out_ca;
michael@0 2442 imp->combine_64_ca[PIXMAN_OP_CONJOINT_OUT_REVERSE] = combine_conjoint_out_reverse_ca;
michael@0 2443 imp->combine_64_ca[PIXMAN_OP_CONJOINT_ATOP] = combine_conjoint_atop_ca;
michael@0 2444 imp->combine_64_ca[PIXMAN_OP_CONJOINT_ATOP_REVERSE] = combine_conjoint_atop_reverse_ca;
michael@0 2445 imp->combine_64_ca[PIXMAN_OP_CONJOINT_XOR] = combine_conjoint_xor_ca;
michael@0 2446
michael@0 2447 imp->combine_64_ca[PIXMAN_OP_MULTIPLY] = combine_multiply_ca;
michael@0 2448 imp->combine_64_ca[PIXMAN_OP_SCREEN] = combine_screen_ca;
michael@0 2449 imp->combine_64_ca[PIXMAN_OP_OVERLAY] = combine_overlay_ca;
michael@0 2450 imp->combine_64_ca[PIXMAN_OP_DARKEN] = combine_darken_ca;
michael@0 2451 imp->combine_64_ca[PIXMAN_OP_LIGHTEN] = combine_lighten_ca;
michael@0 2452 imp->combine_64_ca[PIXMAN_OP_COLOR_DODGE] = combine_color_dodge_ca;
michael@0 2453 imp->combine_64_ca[PIXMAN_OP_COLOR_BURN] = combine_color_burn_ca;
michael@0 2454 imp->combine_64_ca[PIXMAN_OP_HARD_LIGHT] = combine_hard_light_ca;
michael@0 2455 imp->combine_64_ca[PIXMAN_OP_SOFT_LIGHT] = combine_soft_light_ca;
michael@0 2456 imp->combine_64_ca[PIXMAN_OP_DIFFERENCE] = combine_difference_ca;
michael@0 2457 imp->combine_64_ca[PIXMAN_OP_EXCLUSION] = combine_exclusion_ca;
michael@0 2458
michael@0 2459 /* It is not clear that these make sense, so make them noops for now */
michael@0 2460 imp->combine_64_ca[PIXMAN_OP_HSL_HUE] = combine_dst;
michael@0 2461 imp->combine_64_ca[PIXMAN_OP_HSL_SATURATION] = combine_dst;
michael@0 2462 imp->combine_64_ca[PIXMAN_OP_HSL_COLOR] = combine_dst;
michael@0 2463 imp->combine_64_ca[PIXMAN_OP_HSL_LUMINOSITY] = combine_dst;
michael@0 2464 }
michael@0 2465

mercurial