aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pixman/pixman/pixman-combine.c.template4879
-rw-r--r--pixman/test/Makefile.am4
-rw-r--r--pixman/test/alphamap.c16
-rw-r--r--pixman/test/blitters-test.c2
-rw-r--r--pixman/test/composite.c261
5 files changed, 2597 insertions, 2565 deletions
diff --git a/pixman/pixman/pixman-combine.c.template b/pixman/pixman/pixman-combine.c.template
index c129980a8..9b84de4bc 100644
--- a/pixman/pixman/pixman-combine.c.template
+++ b/pixman/pixman/pixman-combine.c.template
@@ -1,2436 +1,2443 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <math.h>
-#include <string.h>
-
-#include "pixman-private.h"
-
-#include "pixman-combine.h"
-
-/*** per channel helper functions ***/
-
-static void
-combine_mask_ca (comp4_t *src, comp4_t *mask)
-{
- comp4_t a = *mask;
-
- comp4_t x;
- comp2_t xa;
-
- if (!a)
- {
- *(src) = 0;
- return;
- }
-
- x = *(src);
- if (a == ~0)
- {
- x = x >> A_SHIFT;
- x |= x << G_SHIFT;
- x |= x << R_SHIFT;
- *(mask) = x;
- return;
- }
-
- xa = x >> A_SHIFT;
- UNcx4_MUL_UNcx4 (x, a);
- *(src) = x;
-
- UNcx4_MUL_UNc (a, xa);
- *(mask) = a;
-}
-
-static void
-combine_mask_value_ca (comp4_t *src, const comp4_t *mask)
-{
- comp4_t a = *mask;
- comp4_t x;
-
- if (!a)
- {
- *(src) = 0;
- return;
- }
-
- if (a == ~0)
- return;
-
- x = *(src);
- UNcx4_MUL_UNcx4 (x, a);
- *(src) = x;
-}
-
-static void
-combine_mask_alpha_ca (const comp4_t *src, comp4_t *mask)
-{
- comp4_t a = *(mask);
- comp4_t x;
-
- if (!a)
- return;
-
- x = *(src) >> A_SHIFT;
- if (x == MASK)
- return;
-
- if (a == ~0)
- {
- x |= x << G_SHIFT;
- x |= x << R_SHIFT;
- *(mask) = x;
- return;
- }
-
- UNcx4_MUL_UNc (a, x);
- *(mask) = a;
-}
-
-/*
- * There are two ways of handling alpha -- either as a single unified value or
- * a separate value for each component, hence each macro must have two
- * versions. The unified alpha version has a 'U' at the end of the name,
- * the component version has a 'C'. Similarly, functions which deal with
- * this difference will have two versions using the same convention.
- */
-
-/*
- * All of the composing functions
- */
-
-static force_inline comp4_t
-combine_mask (const comp4_t *src, const comp4_t *mask, int i)
-{
- comp4_t s, m;
-
- if (mask)
- {
- m = *(mask + i) >> A_SHIFT;
-
- if (!m)
- return 0;
- }
-
- s = *(src + i);
-
- if (mask)
- UNcx4_MUL_UNc (s, m);
-
- return s;
-}
-
-static void
-combine_clear (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- memset (dest, 0, width * sizeof(comp4_t));
-}
-
-static void
-combine_src_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- if (!mask)
- memcpy (dest, src, width * sizeof (comp4_t));
- else
- {
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
-
- *(dest + i) = s;
- }
- }
-}
-
-/* if the Src is opaque, call combine_src_u */
-static void
-combine_over_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t ia = ALPHA_c (~s);
-
- UNcx4_MUL_UNc_ADD_UNcx4 (d, ia, s);
- *(dest + i) = d;
- }
-}
-
-/* if the Dst is opaque, this is a noop */
-static void
-combine_over_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t ia = ALPHA_c (~*(dest + i));
- UNcx4_MUL_UNc_ADD_UNcx4 (s, ia, d);
- *(dest + i) = s;
- }
-}
-
-/* if the Dst is opaque, call combine_src_u */
-static void
-combine_in_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t a = ALPHA_c (*(dest + i));
- UNcx4_MUL_UNc (s, a);
- *(dest + i) = s;
- }
-}
-
-/* if the Src is opaque, this is a noop */
-static void
-combine_in_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t a = ALPHA_c (s);
- UNcx4_MUL_UNc (d, a);
- *(dest + i) = d;
- }
-}
-
-/* if the Dst is opaque, call combine_clear */
-static void
-combine_out_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t a = ALPHA_c (~*(dest + i));
- UNcx4_MUL_UNc (s, a);
- *(dest + i) = s;
- }
-}
-
-/* if the Src is opaque, call combine_clear */
-static void
-combine_out_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t a = ALPHA_c (~s);
- UNcx4_MUL_UNc (d, a);
- *(dest + i) = d;
- }
-}
-
-/* if the Src is opaque, call combine_in_u */
-/* if the Dst is opaque, call combine_over_u */
-/* if both the Src and Dst are opaque, call combine_src_u */
-static void
-combine_atop_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t dest_a = ALPHA_c (d);
- comp4_t src_ia = ALPHA_c (~s);
-
- UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (s, dest_a, d, src_ia);
- *(dest + i) = s;
- }
-}
-
-/* if the Src is opaque, call combine_over_reverse_u */
-/* if the Dst is opaque, call combine_in_reverse_u */
-/* if both the Src and Dst are opaque, call combine_dst_u */
-static void
-combine_atop_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t src_a = ALPHA_c (s);
- comp4_t dest_ia = ALPHA_c (~d);
-
- UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (s, dest_ia, d, src_a);
- *(dest + i) = s;
- }
-}
-
-/* if the Src is opaque, call combine_over_u */
-/* if the Dst is opaque, call combine_over_reverse_u */
-/* if both the Src and Dst are opaque, call combine_clear */
-static void
-combine_xor_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t src_ia = ALPHA_c (~s);
- comp4_t dest_ia = ALPHA_c (~d);
-
- UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (s, dest_ia, d, src_ia);
- *(dest + i) = s;
- }
-}
-
-static void
-combine_add_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- UNcx4_ADD_UNcx4 (d, s);
- *(dest + i) = d;
- }
-}
-
-/* if the Src is opaque, call combine_add_u */
-/* if the Dst is opaque, call combine_add_u */
-/* if both the Src and Dst are opaque, call combine_add_u */
-static void
-combine_saturate_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp2_t sa, da;
-
- sa = s >> A_SHIFT;
- da = ~d >> A_SHIFT;
- if (sa > da)
- {
- sa = DIV_UNc (da, sa);
- UNcx4_MUL_UNc (s, sa);
- }
- ;
- UNcx4_ADD_UNcx4 (d, s);
- *(dest + i) = d;
- }
-}
-
-/*
- * PDF blend modes:
- * The following blend modes have been taken from the PDF ISO 32000
- * specification, which at this point in time is available from
- * http://www.adobe.com/devnet/acrobat/pdfs/PDF32000_2008.pdf
- * The relevant chapters are 11.3.5 and 11.3.6.
- * The formula for computing the final pixel color given in 11.3.6 is:
- * αr × Cr = (1 – αs) × αb × Cb + (1 – αb) × αs × Cs + αb × αs × B(Cb, Cs)
- * with B() being the blend function.
- * Note that OVER is a special case of this operation, using B(Cb, Cs) = Cs
- *
- * These blend modes should match the SVG filter draft specification, as
- * it has been designed to mirror ISO 32000. Note that at the current point
- * no released draft exists that shows this, as the formulas have not been
- * updated yet after the release of ISO 32000.
- *
- * The default implementation here uses the PDF_SEPARABLE_BLEND_MODE and
- * PDF_NON_SEPARABLE_BLEND_MODE macros, which take the blend function as an
- * argument. Note that this implementation operates on premultiplied colors,
- * while the PDF specification does not. Therefore the code uses the formula
- * ar.Cra = (1 – as) . Dca + (1 – ad) . Sca + B(Dca, ad, Sca, as)
- */
-
-/*
- * Multiply
- * B(Dca, ad, Sca, as) = Dca.Sca
- */
-
-static void
-combine_multiply_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t ss = s;
- comp4_t src_ia = ALPHA_c (~s);
- comp4_t dest_ia = ALPHA_c (~d);
-
- UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (ss, dest_ia, d, src_ia);
- UNcx4_MUL_UNcx4 (d, s);
- UNcx4_ADD_UNcx4 (d, ss);
-
- *(dest + i) = d;
- }
-}
-
-static void
-combine_multiply_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t m = *(mask + i);
- comp4_t s = *(src + i);
- comp4_t d = *(dest + i);
- comp4_t r = d;
- comp4_t dest_ia = ALPHA_c (~d);
-
- combine_mask_value_ca (&s, &m);
-
- UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (r, ~m, s, dest_ia);
- UNcx4_MUL_UNcx4 (d, s);
- UNcx4_ADD_UNcx4 (r, d);
-
- *(dest + i) = r;
- }
-}
-
-#define PDF_SEPARABLE_BLEND_MODE(name) \
- static void \
- combine_ ## name ## _u (pixman_implementation_t *imp, \
- pixman_op_t op, \
- comp4_t * dest, \
- const comp4_t * src, \
- const comp4_t * mask, \
- int width) \
- { \
- int i; \
- for (i = 0; i < width; ++i) { \
- comp4_t s = combine_mask (src, mask, i); \
- comp4_t d = *(dest + i); \
- comp1_t sa = ALPHA_c (s); \
- comp1_t isa = ~sa; \
- comp1_t da = ALPHA_c (d); \
- comp1_t ida = ~da; \
- comp4_t result; \
- \
- result = d; \
- UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (result, isa, s, ida); \
- \
- *(dest + i) = result + \
- (DIV_ONE_UNc (sa * da) << A_SHIFT) + \
- (blend_ ## name (RED_c (d), da, RED_c (s), sa) << R_SHIFT) + \
- (blend_ ## name (GREEN_c (d), da, GREEN_c (s), sa) << G_SHIFT) + \
- (blend_ ## name (BLUE_c (d), da, BLUE_c (s), sa)); \
- } \
- } \
- \
- static void \
- combine_ ## name ## _ca (pixman_implementation_t *imp, \
- pixman_op_t op, \
- comp4_t * dest, \
- const comp4_t * src, \
- const comp4_t * mask, \
- int width) \
- { \
- int i; \
- for (i = 0; i < width; ++i) { \
- comp4_t m = *(mask + i); \
- comp4_t s = *(src + i); \
- comp4_t d = *(dest + i); \
- comp1_t da = ALPHA_c (d); \
- comp1_t ida = ~da; \
- comp4_t result; \
- \
- combine_mask_value_ca (&s, &m); \
- \
- result = d; \
- UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (result, ~m, s, ida); \
- \
- result += \
- (DIV_ONE_UNc (ALPHA_c (m) * da) << A_SHIFT) + \
- (blend_ ## name (RED_c (d), da, RED_c (s), RED_c (m)) << R_SHIFT) + \
- (blend_ ## name (GREEN_c (d), da, GREEN_c (s), GREEN_c (m)) << G_SHIFT) + \
- (blend_ ## name (BLUE_c (d), da, BLUE_c (s), BLUE_c (m))); \
- \
- *(dest + i) = result; \
- } \
- }
-
-/*
- * Screen
- * B(Dca, ad, Sca, as) = Dca.sa + Sca.da - Dca.Sca
- */
-static inline comp4_t
-blend_screen (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- return DIV_ONE_UNc (sca * da + dca * sa - sca * dca);
-}
-
-PDF_SEPARABLE_BLEND_MODE (screen)
-
-/*
- * Overlay
- * B(Dca, Da, Sca, Sa) =
- * if 2.Dca < Da
- * 2.Sca.Dca
- * otherwise
- * Sa.Da - 2.(Da - Dca).(Sa - Sca)
- */
-static inline comp4_t
-blend_overlay (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- comp4_t rca;
-
- if (2 * dca < da)
- rca = 2 * sca * dca;
- else
- rca = sa * da - 2 * (da - dca) * (sa - sca);
- return DIV_ONE_UNc (rca);
-}
-
-PDF_SEPARABLE_BLEND_MODE (overlay)
-
-/*
- * Darken
- * B(Dca, Da, Sca, Sa) = min (Sca.Da, Dca.Sa)
- */
-static inline comp4_t
-blend_darken (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- comp4_t s, d;
-
- s = sca * da;
- d = dca * sa;
- return DIV_ONE_UNc (s > d ? d : s);
-}
-
-PDF_SEPARABLE_BLEND_MODE (darken)
-
-/*
- * Lighten
- * B(Dca, Da, Sca, Sa) = max (Sca.Da, Dca.Sa)
- */
-static inline comp4_t
-blend_lighten (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- comp4_t s, d;
-
- s = sca * da;
- d = dca * sa;
- return DIV_ONE_UNc (s > d ? s : d);
-}
-
-PDF_SEPARABLE_BLEND_MODE (lighten)
-
-/*
- * Color dodge
- * B(Dca, Da, Sca, Sa) =
- * if Dca == 0
- * 0
- * if Sca == Sa
- * Sa.Da
- * otherwise
- * Sa.Da. min (1, Dca / Da / (1 - Sca/Sa))
- */
-static inline comp4_t
-blend_color_dodge (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- if (sca >= sa)
- {
- return dca == 0 ? 0 : DIV_ONE_UNc (sa * da);
- }
- else
- {
- comp4_t rca = dca * sa / (sa - sca);
- return DIV_ONE_UNc (sa * MIN (rca, da));
- }
-}
-
-PDF_SEPARABLE_BLEND_MODE (color_dodge)
-
-/*
- * Color burn
- * B(Dca, Da, Sca, Sa) =
- * if Dca == Da
- * Sa.Da
- * if Sca == 0
- * 0
- * otherwise
- * Sa.Da.(1 - min (1, (1 - Dca/Da).Sa / Sca))
- */
-static inline comp4_t
-blend_color_burn (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- if (sca == 0)
- {
- return dca < da ? 0 : DIV_ONE_UNc (sa * da);
- }
- else
- {
- comp4_t rca = (da - dca) * sa / sca;
- return DIV_ONE_UNc (sa * (MAX (rca, da) - rca));
- }
-}
-
-PDF_SEPARABLE_BLEND_MODE (color_burn)
-
-/*
- * Hard light
- * B(Dca, Da, Sca, Sa) =
- * if 2.Sca < Sa
- * 2.Sca.Dca
- * otherwise
- * Sa.Da - 2.(Da - Dca).(Sa - Sca)
- */
-static inline comp4_t
-blend_hard_light (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- if (2 * sca < sa)
- return DIV_ONE_UNc (2 * sca * dca);
- else
- return DIV_ONE_UNc (sa * da - 2 * (da - dca) * (sa - sca));
-}
-
-PDF_SEPARABLE_BLEND_MODE (hard_light)
-
-/*
- * Soft light
- * B(Dca, Da, Sca, Sa) =
- * if (2.Sca <= Sa)
- * Dca.(Sa - (1 - Dca/Da).(2.Sca - Sa))
- * otherwise if Dca.4 <= Da
- * Dca.(Sa + (2.Sca - Sa).((16.Dca/Da - 12).Dca/Da + 3)
- * otherwise
- * (Dca.Sa + (SQRT (Dca/Da).Da - Dca).(2.Sca - Sa))
- */
-static inline comp4_t
-blend_soft_light (comp4_t dca_org,
- comp4_t da_org,
- comp4_t sca_org,
- comp4_t sa_org)
-{
- double dca = dca_org * (1.0 / MASK);
- double da = da_org * (1.0 / MASK);
- double sca = sca_org * (1.0 / MASK);
- double sa = sa_org * (1.0 / MASK);
- double rca;
-
- if (2 * sca < sa)
- {
- if (da == 0)
- rca = dca * sa;
- else
- rca = dca * sa - dca * (da - dca) * (sa - 2 * sca) / da;
- }
- else if (da == 0)
- {
- rca = 0;
- }
- else if (4 * dca <= da)
- {
- rca = dca * sa +
- (2 * sca - sa) * dca * ((16 * dca / da - 12) * dca / da + 3);
- }
- else
- {
- rca = dca * sa + (sqrt (dca * da) - dca) * (2 * sca - sa);
- }
- return rca * MASK + 0.5;
-}
-
-PDF_SEPARABLE_BLEND_MODE (soft_light)
-
-/*
- * Difference
- * B(Dca, Da, Sca, Sa) = abs (Dca.Sa - Sca.Da)
- */
-static inline comp4_t
-blend_difference (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- comp4_t dcasa = dca * sa;
- comp4_t scada = sca * da;
-
- if (scada < dcasa)
- return DIV_ONE_UNc (dcasa - scada);
- else
- return DIV_ONE_UNc (scada - dcasa);
-}
-
-PDF_SEPARABLE_BLEND_MODE (difference)
-
-/*
- * Exclusion
- * B(Dca, Da, Sca, Sa) = (Sca.Da + Dca.Sa - 2.Sca.Dca)
- */
-
-/* This can be made faster by writing it directly and not using
- * PDF_SEPARABLE_BLEND_MODE, but that's a performance optimization */
-
-static inline comp4_t
-blend_exclusion (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
-{
- return DIV_ONE_UNc (sca * da + dca * sa - 2 * dca * sca);
-}
-
-PDF_SEPARABLE_BLEND_MODE (exclusion)
-
-#undef PDF_SEPARABLE_BLEND_MODE
-
-/*
- * PDF nonseperable blend modes are implemented using the following functions
- * to operate in Hsl space, with Cmax, Cmid, Cmin referring to the max, mid
- * and min value of the red, green and blue components.
- *
- * LUM (C) = 0.3 × Cred + 0.59 × Cgreen + 0.11 × Cblue
- *
- * clip_color (C):
- * l = LUM (C)
- * min = Cmin
- * max = Cmax
- * if n < 0.0
- * C = l + ( ( ( C – l ) × l ) ⁄ ( l – min ) )
- * if x > 1.0
- * C = l + ( ( ( C – l ) × ( 1 – l ) ) ⁄ ( max – l ) )
- * return C
- *
- * set_lum (C, l):
- * d = l – LUM (C)
- * C += d
- * return clip_color (C)
- *
- * SAT (C) = CH_MAX (C) - CH_MIN (C)
- *
- * set_sat (C, s):
- * if Cmax > Cmin
- * Cmid = ( ( ( Cmid – Cmin ) × s ) ⁄ ( Cmax – Cmin ) )
- * Cmax = s
- * else
- * Cmid = Cmax = 0.0
- * Cmin = 0.0
- * return C
- */
-
-/* For premultiplied colors, we need to know what happens when C is
- * multiplied by a real number. LUM and SAT are linear:
- *
- * LUM (r × C) = r × LUM (C) SAT (r * C) = r * SAT (C)
- *
- * If we extend clip_color with an extra argument a and change
- *
- * if x >= 1.0
- *
- * into
- *
- * if x >= a
- *
- * then clip_color is also linear:
- *
- * r * clip_color (C, a) = clip_color (r_c, ra);
- *
- * for positive r.
- *
- * Similarly, we can extend set_lum with an extra argument that is just passed
- * on to clip_color:
- *
- * r * set_lum ( C, l, a)
- *
- * = r × clip_color ( C + l - LUM (C), a)
- *
- * = clip_color ( r * C + r × l - r * LUM (C), r * a)
- *
- * = set_lum ( r * C, r * l, r * a)
- *
- * Finally, set_sat:
- *
- * r * set_sat (C, s) = set_sat (x * C, r * s)
- *
- * The above holds for all non-zero x, because they x'es in the fraction for
- * C_mid cancel out. Specifically, it holds for x = r:
- *
- * r * set_sat (C, s) = set_sat (r_c, rs)
- *
- */
-
-/* So, for the non-separable PDF blend modes, we have (using s, d for
- * non-premultiplied colors, and S, D for premultiplied:
- *
- * Color:
- *
- * a_s * a_d * B(s, d)
- * = a_s * a_d * set_lum (S/a_s, LUM (D/a_d), 1)
- * = set_lum (S * a_d, a_s * LUM (D), a_s * a_d)
- *
- *
- * Luminosity:
- *
- * a_s * a_d * B(s, d)
- * = a_s * a_d * set_lum (D/a_d, LUM(S/a_s), 1)
- * = set_lum (a_s * D, a_d * LUM(S), a_s * a_d)
- *
- *
- * Saturation:
- *
- * a_s * a_d * B(s, d)
- * = a_s * a_d * set_lum (set_sat (D/a_d, SAT (S/a_s)), LUM (D/a_d), 1)
- * = set_lum (a_s * a_d * set_sat (D/a_d, SAT (S/a_s)),
- * a_s * LUM (D), a_s * a_d)
- * = set_lum (set_sat (a_s * D, a_d * SAT (S), a_s * LUM (D), a_s * a_d))
- *
- * Hue:
- *
- * a_s * a_d * B(s, d)
- * = a_s * a_d * set_lum (set_sat (S/a_s, SAT (D/a_d)), LUM (D/a_d), 1)
- * = a_s * a_d * set_lum (set_sat (a_d * S, a_s * SAT (D)),
- * a_s * LUM (D), a_s * a_d)
- *
- */
-
-#define CH_MIN(c) (c[0] < c[1] ? (c[0] < c[2] ? c[0] : c[2]) : (c[1] < c[2] ? c[1] : c[2]))
-#define CH_MAX(c) (c[0] > c[1] ? (c[0] > c[2] ? c[0] : c[2]) : (c[1] > c[2] ? c[1] : c[2]))
-#define LUM(c) ((c[0] * 30 + c[1] * 59 + c[2] * 11) / 100)
-#define SAT(c) (CH_MAX (c) - CH_MIN (c))
-
-#define PDF_NON_SEPARABLE_BLEND_MODE(name) \
- static void \
- combine_ ## name ## _u (pixman_implementation_t *imp, \
- pixman_op_t op, \
- comp4_t *dest, \
- const comp4_t *src, \
- const comp4_t *mask, \
- int width) \
- { \
- int i; \
- for (i = 0; i < width; ++i) \
- { \
- comp4_t s = combine_mask (src, mask, i); \
- comp4_t d = *(dest + i); \
- comp1_t sa = ALPHA_c (s); \
- comp1_t isa = ~sa; \
- comp1_t da = ALPHA_c (d); \
- comp1_t ida = ~da; \
- comp4_t result; \
- comp4_t sc[3], dc[3], c[3]; \
- \
- result = d; \
- UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (result, isa, s, ida); \
- dc[0] = RED_c (d); \
- sc[0] = RED_c (s); \
- dc[1] = GREEN_c (d); \
- sc[1] = GREEN_c (s); \
- dc[2] = BLUE_c (d); \
- sc[2] = BLUE_c (s); \
- blend_ ## name (c, dc, da, sc, sa); \
- \
- *(dest + i) = result + \
- (DIV_ONE_UNc (sa * da) << A_SHIFT) + \
- (DIV_ONE_UNc (c[0]) << R_SHIFT) + \
- (DIV_ONE_UNc (c[1]) << G_SHIFT) + \
- (DIV_ONE_UNc (c[2])); \
- } \
- }
-
-static void
-set_lum (comp4_t dest[3], comp4_t src[3], comp4_t sa, comp4_t lum)
-{
- double a, l, min, max;
- double tmp[3];
-
- a = sa * (1.0 / MASK);
-
- l = lum * (1.0 / MASK);
- tmp[0] = src[0] * (1.0 / MASK);
- tmp[1] = src[1] * (1.0 / MASK);
- tmp[2] = src[2] * (1.0 / MASK);
-
- l = l - LUM (tmp);
- tmp[0] += l;
- tmp[1] += l;
- tmp[2] += l;
-
- /* clip_color */
- l = LUM (tmp);
- min = CH_MIN (tmp);
- max = CH_MAX (tmp);
-
- if (min < 0)
- {
- tmp[0] = l + (tmp[0] - l) * l / (l - min);
- tmp[1] = l + (tmp[1] - l) * l / (l - min);
- tmp[2] = l + (tmp[2] - l) * l / (l - min);
- }
- if (max > a)
- {
- tmp[0] = l + (tmp[0] - l) * (a - l) / (max - l);
- tmp[1] = l + (tmp[1] - l) * (a - l) / (max - l);
- tmp[2] = l + (tmp[2] - l) * (a - l) / (max - l);
- }
-
- dest[0] = tmp[0] * MASK + 0.5;
- dest[1] = tmp[1] * MASK + 0.5;
- dest[2] = tmp[2] * MASK + 0.5;
-}
-
-static void
-set_sat (comp4_t dest[3], comp4_t src[3], comp4_t sat)
-{
- int id[3];
- comp4_t min, max;
-
- if (src[0] > src[1])
- {
- if (src[0] > src[2])
- {
- id[0] = 0;
- if (src[1] > src[2])
- {
- id[1] = 1;
- id[2] = 2;
- }
- else
- {
- id[1] = 2;
- id[2] = 1;
- }
- }
- else
- {
- id[0] = 2;
- id[1] = 0;
- id[2] = 1;
- }
- }
- else
- {
- if (src[0] > src[2])
- {
- id[0] = 1;
- id[1] = 0;
- id[2] = 2;
- }
- else
- {
- id[2] = 0;
- if (src[1] > src[2])
- {
- id[0] = 1;
- id[1] = 2;
- }
- else
- {
- id[0] = 2;
- id[1] = 1;
- }
- }
- }
-
- max = dest[id[0]];
- min = dest[id[2]];
- if (max > min)
- {
- dest[id[1]] = (dest[id[1]] - min) * sat / (max - min);
- dest[id[0]] = sat;
- dest[id[2]] = 0;
- }
- else
- {
- dest[0] = dest[1] = dest[2] = 0;
- }
-}
-
-/*
- * Hue:
- * B(Cb, Cs) = set_lum (set_sat (Cs, SAT (Cb)), LUM (Cb))
- */
-static inline void
-blend_hsl_hue (comp4_t c[3],
- comp4_t dc[3],
- comp4_t da,
- comp4_t sc[3],
- comp4_t sa)
-{
- c[0] = sc[0] * da;
- c[1] = sc[1] * da;
- c[2] = sc[2] * da;
- set_sat (c, c, SAT (dc) * sa);
- set_lum (c, c, sa * da, LUM (dc) * sa);
-}
-
-PDF_NON_SEPARABLE_BLEND_MODE (hsl_hue)
-
-/*
- * Saturation:
- * B(Cb, Cs) = set_lum (set_sat (Cb, SAT (Cs)), LUM (Cb))
- */
-static inline void
-blend_hsl_saturation (comp4_t c[3],
- comp4_t dc[3],
- comp4_t da,
- comp4_t sc[3],
- comp4_t sa)
-{
- c[0] = dc[0] * sa;
- c[1] = dc[1] * sa;
- c[2] = dc[2] * sa;
- set_sat (c, c, SAT (sc) * da);
- set_lum (c, c, sa * da, LUM (dc) * sa);
-}
-
-PDF_NON_SEPARABLE_BLEND_MODE (hsl_saturation)
-
-/*
- * Color:
- * B(Cb, Cs) = set_lum (Cs, LUM (Cb))
- */
-static inline void
-blend_hsl_color (comp4_t c[3],
- comp4_t dc[3],
- comp4_t da,
- comp4_t sc[3],
- comp4_t sa)
-{
- c[0] = sc[0] * da;
- c[1] = sc[1] * da;
- c[2] = sc[2] * da;
- set_lum (c, c, sa * da, LUM (dc) * sa);
-}
-
-PDF_NON_SEPARABLE_BLEND_MODE (hsl_color)
-
-/*
- * Luminosity:
- * B(Cb, Cs) = set_lum (Cb, LUM (Cs))
- */
-static inline void
-blend_hsl_luminosity (comp4_t c[3],
- comp4_t dc[3],
- comp4_t da,
- comp4_t sc[3],
- comp4_t sa)
-{
- c[0] = dc[0] * sa;
- c[1] = dc[1] * sa;
- c[2] = dc[2] * sa;
- set_lum (c, c, sa * da, LUM (sc) * da);
-}
-
-PDF_NON_SEPARABLE_BLEND_MODE (hsl_luminosity)
-
-#undef SAT
-#undef LUM
-#undef CH_MAX
-#undef CH_MIN
-#undef PDF_NON_SEPARABLE_BLEND_MODE
-
-/* Overlay
- *
- * All of the disjoint composing functions
- *
- * The four entries in the first column indicate what source contributions
- * come from each of the four areas of the picture -- areas covered by neither
- * A nor B, areas covered only by A, areas covered only by B and finally
- * areas covered by both A and B.
- *
- * Disjoint Conjoint
- * Fa Fb Fa Fb
- * (0,0,0,0) 0 0 0 0
- * (0,A,0,A) 1 0 1 0
- * (0,0,B,B) 0 1 0 1
- * (0,A,B,A) 1 min((1-a)/b,1) 1 max(1-a/b,0)
- * (0,A,B,B) min((1-b)/a,1) 1 max(1-b/a,0) 1
- * (0,0,0,A) max(1-(1-b)/a,0) 0 min(1,b/a) 0
- * (0,0,0,B) 0 max(1-(1-a)/b,0) 0 min(a/b,1)
- * (0,A,0,0) min(1,(1-b)/a) 0 max(1-b/a,0) 0
- * (0,0,B,0) 0 min(1,(1-a)/b) 0 max(1-a/b,0)
- * (0,0,B,A) max(1-(1-b)/a,0) min(1,(1-a)/b) min(1,b/a) max(1-a/b,0)
- * (0,A,0,B) min(1,(1-b)/a) max(1-(1-a)/b,0) max(1-b/a,0) min(1,a/b)
- * (0,A,B,0) min(1,(1-b)/a) min(1,(1-a)/b) max(1-b/a,0) max(1-a/b,0)
- */
-
-#define COMBINE_A_OUT 1
-#define COMBINE_A_IN 2
-#define COMBINE_B_OUT 4
-#define COMBINE_B_IN 8
-
-#define COMBINE_CLEAR 0
-#define COMBINE_A (COMBINE_A_OUT | COMBINE_A_IN)
-#define COMBINE_B (COMBINE_B_OUT | COMBINE_B_IN)
-#define COMBINE_A_OVER (COMBINE_A_OUT | COMBINE_B_OUT | COMBINE_A_IN)
-#define COMBINE_B_OVER (COMBINE_A_OUT | COMBINE_B_OUT | COMBINE_B_IN)
-#define COMBINE_A_ATOP (COMBINE_B_OUT | COMBINE_A_IN)
-#define COMBINE_B_ATOP (COMBINE_A_OUT | COMBINE_B_IN)
-#define COMBINE_XOR (COMBINE_A_OUT | COMBINE_B_OUT)
-
-/* portion covered by a but not b */
-static comp1_t
-combine_disjoint_out_part (comp1_t a, comp1_t b)
-{
- /* min (1, (1-b) / a) */
-
- b = ~b; /* 1 - b */
- if (b >= a) /* 1 - b >= a -> (1-b)/a >= 1 */
- return MASK; /* 1 */
- return DIV_UNc (b, a); /* (1-b) / a */
-}
-
-/* portion covered by both a and b */
-static comp1_t
-combine_disjoint_in_part (comp1_t a, comp1_t b)
-{
- /* max (1-(1-b)/a,0) */
- /* = - min ((1-b)/a - 1, 0) */
- /* = 1 - min (1, (1-b)/a) */
-
- b = ~b; /* 1 - b */
- if (b >= a) /* 1 - b >= a -> (1-b)/a >= 1 */
- return 0; /* 1 - 1 */
- return ~DIV_UNc(b, a); /* 1 - (1-b) / a */
-}
-
-/* portion covered by a but not b */
-static comp1_t
-combine_conjoint_out_part (comp1_t a, comp1_t b)
-{
- /* max (1-b/a,0) */
- /* = 1-min(b/a,1) */
-
- /* min (1, (1-b) / a) */
-
- if (b >= a) /* b >= a -> b/a >= 1 */
- return 0x00; /* 0 */
- return ~DIV_UNc(b, a); /* 1 - b/a */
-}
-
-/* portion covered by both a and b */
-static comp1_t
-combine_conjoint_in_part (comp1_t a, comp1_t b)
-{
- /* min (1,b/a) */
-
- if (b >= a) /* b >= a -> b/a >= 1 */
- return MASK; /* 1 */
- return DIV_UNc (b, a); /* b/a */
-}
-
-#define GET_COMP(v, i) ((comp2_t) (comp1_t) ((v) >> i))
-
-#define ADD(x, y, i, t) \
- ((t) = GET_COMP (x, i) + GET_COMP (y, i), \
- (comp4_t) ((comp1_t) ((t) | (0 - ((t) >> G_SHIFT)))) << (i))
-
-#define GENERIC(x, y, i, ax, ay, t, u, v) \
- ((t) = (MUL_UNc (GET_COMP (y, i), ay, (u)) + \
- MUL_UNc (GET_COMP (x, i), ax, (v))), \
- (comp4_t) ((comp1_t) ((t) | \
- (0 - ((t) >> G_SHIFT)))) << (i))
-
-static void
-combine_disjoint_general_u (comp4_t * dest,
- const comp4_t *src,
- const comp4_t *mask,
- int width,
- comp1_t combine)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t m, n, o, p;
- comp2_t Fa, Fb, t, u, v;
- comp1_t sa = s >> A_SHIFT;
- comp1_t da = d >> A_SHIFT;
-
- switch (combine & COMBINE_A)
- {
- default:
- Fa = 0;
- break;
-
- case COMBINE_A_OUT:
- Fa = combine_disjoint_out_part (sa, da);
- break;
-
- case COMBINE_A_IN:
- Fa = combine_disjoint_in_part (sa, da);
- break;
-
- case COMBINE_A:
- Fa = MASK;
- break;
- }
-
- switch (combine & COMBINE_B)
- {
- default:
- Fb = 0;
- break;
-
- case COMBINE_B_OUT:
- Fb = combine_disjoint_out_part (da, sa);
- break;
-
- case COMBINE_B_IN:
- Fb = combine_disjoint_in_part (da, sa);
- break;
-
- case COMBINE_B:
- Fb = MASK;
- break;
- }
- m = GENERIC (s, d, 0, Fa, Fb, t, u, v);
- n = GENERIC (s, d, G_SHIFT, Fa, Fb, t, u, v);
- o = GENERIC (s, d, R_SHIFT, Fa, Fb, t, u, v);
- p = GENERIC (s, d, A_SHIFT, Fa, Fb, t, u, v);
- s = m | n | o | p;
- *(dest + i) = s;
- }
-}
-
-static void
-combine_disjoint_over_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp2_t a = s >> A_SHIFT;
-
- if (a != 0x00)
- {
- if (a != MASK)
- {
- comp4_t d = *(dest + i);
- a = combine_disjoint_out_part (d >> A_SHIFT, a);
- UNcx4_MUL_UNc_ADD_UNcx4 (d, a, s);
- s = d;
- }
-
- *(dest + i) = s;
- }
- }
-}
-
-static void
-combine_disjoint_in_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_IN);
-}
-
-static void
-combine_disjoint_in_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_IN);
-}
-
-static void
-combine_disjoint_out_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_OUT);
-}
-
-static void
-combine_disjoint_out_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_OUT);
-}
-
-static void
-combine_disjoint_atop_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_ATOP);
-}
-
-static void
-combine_disjoint_atop_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_ATOP);
-}
-
-static void
-combine_disjoint_xor_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_u (dest, src, mask, width, COMBINE_XOR);
-}
-
-static void
-combine_conjoint_general_u (comp4_t * dest,
- const comp4_t *src,
- const comp4_t *mask,
- int width,
- comp1_t combine)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = combine_mask (src, mask, i);
- comp4_t d = *(dest + i);
- comp4_t m, n, o, p;
- comp2_t Fa, Fb, t, u, v;
- comp1_t sa = s >> A_SHIFT;
- comp1_t da = d >> A_SHIFT;
-
- switch (combine & COMBINE_A)
- {
- default:
- Fa = 0;
- break;
-
- case COMBINE_A_OUT:
- Fa = combine_conjoint_out_part (sa, da);
- break;
-
- case COMBINE_A_IN:
- Fa = combine_conjoint_in_part (sa, da);
- break;
-
- case COMBINE_A:
- Fa = MASK;
- break;
- }
-
- switch (combine & COMBINE_B)
- {
- default:
- Fb = 0;
- break;
-
- case COMBINE_B_OUT:
- Fb = combine_conjoint_out_part (da, sa);
- break;
-
- case COMBINE_B_IN:
- Fb = combine_conjoint_in_part (da, sa);
- break;
-
- case COMBINE_B:
- Fb = MASK;
- break;
- }
-
- m = GENERIC (s, d, 0, Fa, Fb, t, u, v);
- n = GENERIC (s, d, G_SHIFT, Fa, Fb, t, u, v);
- o = GENERIC (s, d, R_SHIFT, Fa, Fb, t, u, v);
- p = GENERIC (s, d, A_SHIFT, Fa, Fb, t, u, v);
-
- s = m | n | o | p;
-
- *(dest + i) = s;
- }
-}
-
-static void
-combine_conjoint_over_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_OVER);
-}
-
-static void
-combine_conjoint_over_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_OVER);
-}
-
-static void
-combine_conjoint_in_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_IN);
-}
-
-static void
-combine_conjoint_in_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_IN);
-}
-
-static void
-combine_conjoint_out_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_OUT);
-}
-
-static void
-combine_conjoint_out_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_OUT);
-}
-
-static void
-combine_conjoint_atop_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_ATOP);
-}
-
-static void
-combine_conjoint_atop_reverse_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_ATOP);
-}
-
-static void
-combine_conjoint_xor_u (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_u (dest, src, mask, width, COMBINE_XOR);
-}
-
-/************************************************************************/
-/*********************** Per Channel functions **************************/
-/************************************************************************/
-
-static void
-combine_clear_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- memset (dest, 0, width * sizeof(comp4_t));
-}
-
-static void
-combine_src_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
-
- combine_mask_value_ca (&s, &m);
-
- *(dest + i) = s;
- }
-}
-
-static void
-combine_over_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
- comp4_t a;
-
- combine_mask_ca (&s, &m);
-
- a = ~m;
- if (a)
- {
- comp4_t d = *(dest + i);
- UNcx4_MUL_UNcx4_ADD_UNcx4 (d, a, s);
- s = d;
- }
-
- *(dest + i) = s;
- }
-}
-
-static void
-combine_over_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t d = *(dest + i);
- comp4_t a = ~d >> A_SHIFT;
-
- if (a)
- {
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
-
- UNcx4_MUL_UNcx4 (s, m);
- UNcx4_MUL_UNc_ADD_UNcx4 (s, a, d);
-
- *(dest + i) = s;
- }
- }
-}
-
-static void
-combine_in_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t d = *(dest + i);
- comp2_t a = d >> A_SHIFT;
- comp4_t s = 0;
-
- if (a)
- {
- comp4_t m = *(mask + i);
-
- s = *(src + i);
- combine_mask_value_ca (&s, &m);
-
- if (a != MASK)
- UNcx4_MUL_UNc (s, a);
- }
-
- *(dest + i) = s;
- }
-}
-
-static void
-combine_in_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
- comp4_t a;
-
- combine_mask_alpha_ca (&s, &m);
-
- a = m;
- if (a != ~0)
- {
- comp4_t d = 0;
-
- if (a)
- {
- d = *(dest + i);
- UNcx4_MUL_UNcx4 (d, a);
- }
-
- *(dest + i) = d;
- }
- }
-}
-
-static void
-combine_out_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t d = *(dest + i);
- comp2_t a = ~d >> A_SHIFT;
- comp4_t s = 0;
-
- if (a)
- {
- comp4_t m = *(mask + i);
-
- s = *(src + i);
- combine_mask_value_ca (&s, &m);
-
- if (a != MASK)
- UNcx4_MUL_UNc (s, a);
- }
-
- *(dest + i) = s;
- }
-}
-
-static void
-combine_out_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
- comp4_t a;
-
- combine_mask_alpha_ca (&s, &m);
-
- a = ~m;
- if (a != ~0)
- {
- comp4_t d = 0;
-
- if (a)
- {
- d = *(dest + i);
- UNcx4_MUL_UNcx4 (d, a);
- }
-
- *(dest + i) = d;
- }
- }
-}
-
-static void
-combine_atop_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t d = *(dest + i);
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
- comp4_t ad;
- comp2_t as = d >> A_SHIFT;
-
- combine_mask_ca (&s, &m);
-
- ad = ~m;
-
- UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (d, ad, s, as);
-
- *(dest + i) = d;
- }
-}
-
-static void
-combine_atop_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t d = *(dest + i);
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
- comp4_t ad;
- comp2_t as = ~d >> A_SHIFT;
-
- combine_mask_ca (&s, &m);
-
- ad = m;
-
- UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (d, ad, s, as);
-
- *(dest + i) = d;
- }
-}
-
-static void
-combine_xor_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t d = *(dest + i);
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
- comp4_t ad;
- comp2_t as = ~d >> A_SHIFT;
-
- combine_mask_ca (&s, &m);
-
- ad = ~m;
-
- UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (d, ad, s, as);
-
- *(dest + i) = d;
- }
-}
-
-static void
-combine_add_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s = *(src + i);
- comp4_t m = *(mask + i);
- comp4_t d = *(dest + i);
-
- combine_mask_value_ca (&s, &m);
-
- UNcx4_ADD_UNcx4 (d, s);
-
- *(dest + i) = d;
- }
-}
-
-static void
-combine_saturate_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s, d;
- comp2_t sa, sr, sg, sb, da;
- comp2_t t, u, v;
- comp4_t m, n, o, p;
-
- d = *(dest + i);
- s = *(src + i);
- m = *(mask + i);
-
- combine_mask_ca (&s, &m);
-
- sa = (m >> A_SHIFT);
- sr = (m >> R_SHIFT) & MASK;
- sg = (m >> G_SHIFT) & MASK;
- sb = m & MASK;
- da = ~d >> A_SHIFT;
-
- if (sb <= da)
- m = ADD (s, d, 0, t);
- else
- m = GENERIC (s, d, 0, (da << G_SHIFT) / sb, MASK, t, u, v);
-
- if (sg <= da)
- n = ADD (s, d, G_SHIFT, t);
- else
- n = GENERIC (s, d, G_SHIFT, (da << G_SHIFT) / sg, MASK, t, u, v);
-
- if (sr <= da)
- o = ADD (s, d, R_SHIFT, t);
- else
- o = GENERIC (s, d, R_SHIFT, (da << G_SHIFT) / sr, MASK, t, u, v);
-
- if (sa <= da)
- p = ADD (s, d, A_SHIFT, t);
- else
- p = GENERIC (s, d, A_SHIFT, (da << G_SHIFT) / sa, MASK, t, u, v);
-
- *(dest + i) = m | n | o | p;
- }
-}
-
-static void
-combine_disjoint_general_ca (comp4_t * dest,
- const comp4_t *src,
- const comp4_t *mask,
- int width,
- comp1_t combine)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s, d;
- comp4_t m, n, o, p;
- comp4_t Fa, Fb;
- comp2_t t, u, v;
- comp4_t sa;
- comp1_t da;
-
- s = *(src + i);
- m = *(mask + i);
- d = *(dest + i);
- da = d >> A_SHIFT;
-
- combine_mask_ca (&s, &m);
-
- sa = m;
-
- switch (combine & COMBINE_A)
- {
- default:
- Fa = 0;
- break;
-
- case COMBINE_A_OUT:
- m = (comp4_t)combine_disjoint_out_part ((comp1_t) (sa >> 0), da);
- n = (comp4_t)combine_disjoint_out_part ((comp1_t) (sa >> G_SHIFT), da) << G_SHIFT;
- o = (comp4_t)combine_disjoint_out_part ((comp1_t) (sa >> R_SHIFT), da) << R_SHIFT;
- p = (comp4_t)combine_disjoint_out_part ((comp1_t) (sa >> A_SHIFT), da) << A_SHIFT;
- Fa = m | n | o | p;
- break;
-
- case COMBINE_A_IN:
- m = (comp4_t)combine_disjoint_in_part ((comp1_t) (sa >> 0), da);
- n = (comp4_t)combine_disjoint_in_part ((comp1_t) (sa >> G_SHIFT), da) << G_SHIFT;
- o = (comp4_t)combine_disjoint_in_part ((comp1_t) (sa >> R_SHIFT), da) << R_SHIFT;
- p = (comp4_t)combine_disjoint_in_part ((comp1_t) (sa >> A_SHIFT), da) << A_SHIFT;
- Fa = m | n | o | p;
- break;
-
- case COMBINE_A:
- Fa = ~0;
- break;
- }
-
- switch (combine & COMBINE_B)
- {
- default:
- Fb = 0;
- break;
-
- case COMBINE_B_OUT:
- m = (comp4_t)combine_disjoint_out_part (da, (comp1_t) (sa >> 0));
- n = (comp4_t)combine_disjoint_out_part (da, (comp1_t) (sa >> G_SHIFT)) << G_SHIFT;
- o = (comp4_t)combine_disjoint_out_part (da, (comp1_t) (sa >> R_SHIFT)) << R_SHIFT;
- p = (comp4_t)combine_disjoint_out_part (da, (comp1_t) (sa >> A_SHIFT)) << A_SHIFT;
- Fb = m | n | o | p;
- break;
-
- case COMBINE_B_IN:
- m = (comp4_t)combine_disjoint_in_part (da, (comp1_t) (sa >> 0));
- n = (comp4_t)combine_disjoint_in_part (da, (comp1_t) (sa >> G_SHIFT)) << G_SHIFT;
- o = (comp4_t)combine_disjoint_in_part (da, (comp1_t) (sa >> R_SHIFT)) << R_SHIFT;
- p = (comp4_t)combine_disjoint_in_part (da, (comp1_t) (sa >> A_SHIFT)) << A_SHIFT;
- Fb = m | n | o | p;
- break;
-
- case COMBINE_B:
- Fb = ~0;
- break;
- }
- m = GENERIC (s, d, 0, GET_COMP (Fa, 0), GET_COMP (Fb, 0), t, u, v);
- n = GENERIC (s, d, G_SHIFT, GET_COMP (Fa, G_SHIFT), GET_COMP (Fb, G_SHIFT), t, u, v);
- o = GENERIC (s, d, R_SHIFT, GET_COMP (Fa, R_SHIFT), GET_COMP (Fb, R_SHIFT), t, u, v);
- p = GENERIC (s, d, A_SHIFT, GET_COMP (Fa, A_SHIFT), GET_COMP (Fb, A_SHIFT), t, u, v);
-
- s = m | n | o | p;
-
- *(dest + i) = s;
- }
-}
-
-static void
-combine_disjoint_over_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_OVER);
-}
-
-static void
-combine_disjoint_in_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_IN);
-}
-
-static void
-combine_disjoint_in_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_IN);
-}
-
-static void
-combine_disjoint_out_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_OUT);
-}
-
-static void
-combine_disjoint_out_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_OUT);
-}
-
-static void
-combine_disjoint_atop_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_ATOP);
-}
-
-static void
-combine_disjoint_atop_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_ATOP);
-}
-
-static void
-combine_disjoint_xor_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_disjoint_general_ca (dest, src, mask, width, COMBINE_XOR);
-}
-
-static void
-combine_conjoint_general_ca (comp4_t * dest,
- const comp4_t *src,
- const comp4_t *mask,
- int width,
- comp1_t combine)
-{
- int i;
-
- for (i = 0; i < width; ++i)
- {
- comp4_t s, d;
- comp4_t m, n, o, p;
- comp4_t Fa, Fb;
- comp2_t t, u, v;
- comp4_t sa;
- comp1_t da;
-
- s = *(src + i);
- m = *(mask + i);
- d = *(dest + i);
- da = d >> A_SHIFT;
-
- combine_mask_ca (&s, &m);
-
- sa = m;
-
- switch (combine & COMBINE_A)
- {
- default:
- Fa = 0;
- break;
-
- case COMBINE_A_OUT:
- m = (comp4_t)combine_conjoint_out_part ((comp1_t) (sa >> 0), da);
- n = (comp4_t)combine_conjoint_out_part ((comp1_t) (sa >> G_SHIFT), da) << G_SHIFT;
- o = (comp4_t)combine_conjoint_out_part ((comp1_t) (sa >> R_SHIFT), da) << R_SHIFT;
- p = (comp4_t)combine_conjoint_out_part ((comp1_t) (sa >> A_SHIFT), da) << A_SHIFT;
- Fa = m | n | o | p;
- break;
-
- case COMBINE_A_IN:
- m = (comp4_t)combine_conjoint_in_part ((comp1_t) (sa >> 0), da);
- n = (comp4_t)combine_conjoint_in_part ((comp1_t) (sa >> G_SHIFT), da) << G_SHIFT;
- o = (comp4_t)combine_conjoint_in_part ((comp1_t) (sa >> R_SHIFT), da) << R_SHIFT;
- p = (comp4_t)combine_conjoint_in_part ((comp1_t) (sa >> A_SHIFT), da) << A_SHIFT;
- Fa = m | n | o | p;
- break;
-
- case COMBINE_A:
- Fa = ~0;
- break;
- }
-
- switch (combine & COMBINE_B)
- {
- default:
- Fb = 0;
- break;
-
- case COMBINE_B_OUT:
- m = (comp4_t)combine_conjoint_out_part (da, (comp1_t) (sa >> 0));
- n = (comp4_t)combine_conjoint_out_part (da, (comp1_t) (sa >> G_SHIFT)) << G_SHIFT;
- o = (comp4_t)combine_conjoint_out_part (da, (comp1_t) (sa >> R_SHIFT)) << R_SHIFT;
- p = (comp4_t)combine_conjoint_out_part (da, (comp1_t) (sa >> A_SHIFT)) << A_SHIFT;
- Fb = m | n | o | p;
- break;
-
- case COMBINE_B_IN:
- m = (comp4_t)combine_conjoint_in_part (da, (comp1_t) (sa >> 0));
- n = (comp4_t)combine_conjoint_in_part (da, (comp1_t) (sa >> G_SHIFT)) << G_SHIFT;
- o = (comp4_t)combine_conjoint_in_part (da, (comp1_t) (sa >> R_SHIFT)) << R_SHIFT;
- p = (comp4_t)combine_conjoint_in_part (da, (comp1_t) (sa >> A_SHIFT)) << A_SHIFT;
- Fb = m | n | o | p;
- break;
-
- case COMBINE_B:
- Fb = ~0;
- break;
- }
- m = GENERIC (s, d, 0, GET_COMP (Fa, 0), GET_COMP (Fb, 0), t, u, v);
- n = GENERIC (s, d, G_SHIFT, GET_COMP (Fa, G_SHIFT), GET_COMP (Fb, G_SHIFT), t, u, v);
- o = GENERIC (s, d, R_SHIFT, GET_COMP (Fa, R_SHIFT), GET_COMP (Fb, R_SHIFT), t, u, v);
- p = GENERIC (s, d, A_SHIFT, GET_COMP (Fa, A_SHIFT), GET_COMP (Fb, A_SHIFT), t, u, v);
-
- s = m | n | o | p;
-
- *(dest + i) = s;
- }
-}
-
-static void
-combine_conjoint_over_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_OVER);
-}
-
-static void
-combine_conjoint_over_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_OVER);
-}
-
-static void
-combine_conjoint_in_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_IN);
-}
-
-static void
-combine_conjoint_in_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_IN);
-}
-
-static void
-combine_conjoint_out_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_OUT);
-}
-
-static void
-combine_conjoint_out_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_OUT);
-}
-
-static void
-combine_conjoint_atop_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_ATOP);
-}
-
-static void
-combine_conjoint_atop_reverse_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_ATOP);
-}
-
-static void
-combine_conjoint_xor_ca (pixman_implementation_t *imp,
- pixman_op_t op,
- comp4_t * dest,
- const comp4_t * src,
- const comp4_t * mask,
- int width)
-{
- combine_conjoint_general_ca (dest, src, mask, width, COMBINE_XOR);
-}
-
-void
-_pixman_setup_combiner_functions_width (pixman_implementation_t *imp)
-{
- /* Unified alpha */
- imp->combine_width[PIXMAN_OP_CLEAR] = combine_clear;
- imp->combine_width[PIXMAN_OP_SRC] = combine_src_u;
- /* dest */
- imp->combine_width[PIXMAN_OP_OVER] = combine_over_u;
- imp->combine_width[PIXMAN_OP_OVER_REVERSE] = combine_over_reverse_u;
- imp->combine_width[PIXMAN_OP_IN] = combine_in_u;
- imp->combine_width[PIXMAN_OP_IN_REVERSE] = combine_in_reverse_u;
- imp->combine_width[PIXMAN_OP_OUT] = combine_out_u;
- imp->combine_width[PIXMAN_OP_OUT_REVERSE] = combine_out_reverse_u;
- imp->combine_width[PIXMAN_OP_ATOP] = combine_atop_u;
- imp->combine_width[PIXMAN_OP_ATOP_REVERSE] = combine_atop_reverse_u;
- imp->combine_width[PIXMAN_OP_XOR] = combine_xor_u;
- imp->combine_width[PIXMAN_OP_ADD] = combine_add_u;
- imp->combine_width[PIXMAN_OP_SATURATE] = combine_saturate_u;
-
- /* Disjoint, unified */
- imp->combine_width[PIXMAN_OP_DISJOINT_CLEAR] = combine_clear;
- imp->combine_width[PIXMAN_OP_DISJOINT_SRC] = combine_src_u;
- /* dest */
- imp->combine_width[PIXMAN_OP_DISJOINT_OVER] = combine_disjoint_over_u;
- imp->combine_width[PIXMAN_OP_DISJOINT_OVER_REVERSE] = combine_saturate_u;
- imp->combine_width[PIXMAN_OP_DISJOINT_IN] = combine_disjoint_in_u;
- imp->combine_width[PIXMAN_OP_DISJOINT_IN_REVERSE] = combine_disjoint_in_reverse_u;
- imp->combine_width[PIXMAN_OP_DISJOINT_OUT] = combine_disjoint_out_u;
- imp->combine_width[PIXMAN_OP_DISJOINT_OUT_REVERSE] = combine_disjoint_out_reverse_u;
- imp->combine_width[PIXMAN_OP_DISJOINT_ATOP] = combine_disjoint_atop_u;
- imp->combine_width[PIXMAN_OP_DISJOINT_ATOP_REVERSE] = combine_disjoint_atop_reverse_u;
- imp->combine_width[PIXMAN_OP_DISJOINT_XOR] = combine_disjoint_xor_u;
-
- /* Conjoint, unified */
- imp->combine_width[PIXMAN_OP_CONJOINT_CLEAR] = combine_clear;
- imp->combine_width[PIXMAN_OP_CONJOINT_SRC] = combine_src_u;
- /* dest */
- imp->combine_width[PIXMAN_OP_CONJOINT_OVER] = combine_conjoint_over_u;
- imp->combine_width[PIXMAN_OP_CONJOINT_OVER_REVERSE] = combine_conjoint_over_reverse_u;
- imp->combine_width[PIXMAN_OP_CONJOINT_IN] = combine_conjoint_in_u;
- imp->combine_width[PIXMAN_OP_CONJOINT_IN_REVERSE] = combine_conjoint_in_reverse_u;
- imp->combine_width[PIXMAN_OP_CONJOINT_OUT] = combine_conjoint_out_u;
- imp->combine_width[PIXMAN_OP_CONJOINT_OUT_REVERSE] = combine_conjoint_out_reverse_u;
- imp->combine_width[PIXMAN_OP_CONJOINT_ATOP] = combine_conjoint_atop_u;
- imp->combine_width[PIXMAN_OP_CONJOINT_ATOP_REVERSE] = combine_conjoint_atop_reverse_u;
- imp->combine_width[PIXMAN_OP_CONJOINT_XOR] = combine_conjoint_xor_u;
-
- imp->combine_width[PIXMAN_OP_MULTIPLY] = combine_multiply_u;
- imp->combine_width[PIXMAN_OP_SCREEN] = combine_screen_u;
- imp->combine_width[PIXMAN_OP_OVERLAY] = combine_overlay_u;
- imp->combine_width[PIXMAN_OP_DARKEN] = combine_darken_u;
- imp->combine_width[PIXMAN_OP_LIGHTEN] = combine_lighten_u;
- imp->combine_width[PIXMAN_OP_COLOR_DODGE] = combine_color_dodge_u;
- imp->combine_width[PIXMAN_OP_COLOR_BURN] = combine_color_burn_u;
- imp->combine_width[PIXMAN_OP_HARD_LIGHT] = combine_hard_light_u;
- imp->combine_width[PIXMAN_OP_SOFT_LIGHT] = combine_soft_light_u;
- imp->combine_width[PIXMAN_OP_DIFFERENCE] = combine_difference_u;
- imp->combine_width[PIXMAN_OP_EXCLUSION] = combine_exclusion_u;
- imp->combine_width[PIXMAN_OP_HSL_HUE] = combine_hsl_hue_u;
- imp->combine_width[PIXMAN_OP_HSL_SATURATION] = combine_hsl_saturation_u;
- imp->combine_width[PIXMAN_OP_HSL_COLOR] = combine_hsl_color_u;
- imp->combine_width[PIXMAN_OP_HSL_LUMINOSITY] = combine_hsl_luminosity_u;
-
- /* Component alpha combiners */
- imp->combine_width_ca[PIXMAN_OP_CLEAR] = combine_clear_ca;
- imp->combine_width_ca[PIXMAN_OP_SRC] = combine_src_ca;
- /* dest */
- imp->combine_width_ca[PIXMAN_OP_OVER] = combine_over_ca;
- imp->combine_width_ca[PIXMAN_OP_OVER_REVERSE] = combine_over_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_IN] = combine_in_ca;
- imp->combine_width_ca[PIXMAN_OP_IN_REVERSE] = combine_in_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_OUT] = combine_out_ca;
- imp->combine_width_ca[PIXMAN_OP_OUT_REVERSE] = combine_out_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_ATOP] = combine_atop_ca;
- imp->combine_width_ca[PIXMAN_OP_ATOP_REVERSE] = combine_atop_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_XOR] = combine_xor_ca;
- imp->combine_width_ca[PIXMAN_OP_ADD] = combine_add_ca;
- imp->combine_width_ca[PIXMAN_OP_SATURATE] = combine_saturate_ca;
-
- /* Disjoint CA */
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_CLEAR] = combine_clear_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_SRC] = combine_src_ca;
- /* dest */
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_OVER] = combine_disjoint_over_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_OVER_REVERSE] = combine_saturate_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_IN] = combine_disjoint_in_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_IN_REVERSE] = combine_disjoint_in_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_OUT] = combine_disjoint_out_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_OUT_REVERSE] = combine_disjoint_out_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_ATOP] = combine_disjoint_atop_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_ATOP_REVERSE] = combine_disjoint_atop_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_DISJOINT_XOR] = combine_disjoint_xor_ca;
-
- /* Conjoint CA */
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_CLEAR] = combine_clear_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_SRC] = combine_src_ca;
- /* dest */
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_OVER] = combine_conjoint_over_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_OVER_REVERSE] = combine_conjoint_over_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_IN] = combine_conjoint_in_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_IN_REVERSE] = combine_conjoint_in_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_OUT] = combine_conjoint_out_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_OUT_REVERSE] = combine_conjoint_out_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_ATOP] = combine_conjoint_atop_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_ATOP_REVERSE] = combine_conjoint_atop_reverse_ca;
- imp->combine_width_ca[PIXMAN_OP_CONJOINT_XOR] = combine_conjoint_xor_ca;
-
- imp->combine_width_ca[PIXMAN_OP_MULTIPLY] = combine_multiply_ca;
- imp->combine_width_ca[PIXMAN_OP_SCREEN] = combine_screen_ca;
- imp->combine_width_ca[PIXMAN_OP_OVERLAY] = combine_overlay_ca;
- imp->combine_width_ca[PIXMAN_OP_DARKEN] = combine_darken_ca;
- imp->combine_width_ca[PIXMAN_OP_LIGHTEN] = combine_lighten_ca;
- imp->combine_width_ca[PIXMAN_OP_COLOR_DODGE] = combine_color_dodge_ca;
- imp->combine_width_ca[PIXMAN_OP_COLOR_BURN] = combine_color_burn_ca;
- imp->combine_width_ca[PIXMAN_OP_HARD_LIGHT] = combine_hard_light_ca;
- imp->combine_width_ca[PIXMAN_OP_SOFT_LIGHT] = combine_soft_light_ca;
- imp->combine_width_ca[PIXMAN_OP_DIFFERENCE] = combine_difference_ca;
- imp->combine_width_ca[PIXMAN_OP_EXCLUSION] = combine_exclusion_ca;
-
- /* It is not clear that these make sense, so leave them out for now */
- imp->combine_width_ca[PIXMAN_OP_HSL_HUE] = NULL;
- imp->combine_width_ca[PIXMAN_OP_HSL_SATURATION] = NULL;
- imp->combine_width_ca[PIXMAN_OP_HSL_COLOR] = NULL;
- imp->combine_width_ca[PIXMAN_OP_HSL_LUMINOSITY] = NULL;
-}
-
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <math.h>
+#include <string.h>
+
+#include "pixman-private.h"
+
+#include "pixman-combine.h"
+
+/*** per channel helper functions ***/
+
+static void
+combine_mask_ca (comp4_t *src, comp4_t *mask)
+{
+ comp4_t a = *mask;
+
+ comp4_t x;
+ comp2_t xa;
+
+ if (!a)
+ {
+ *(src) = 0;
+ return;
+ }
+
+ x = *(src);
+ if (a == ~0)
+ {
+ x = x >> A_SHIFT;
+ x |= x << G_SHIFT;
+ x |= x << R_SHIFT;
+ *(mask) = x;
+ return;
+ }
+
+ xa = x >> A_SHIFT;
+ UNcx4_MUL_UNcx4 (x, a);
+ *(src) = x;
+
+ UNcx4_MUL_UNc (a, xa);
+ *(mask) = a;
+}
+
+static void
+combine_mask_value_ca (comp4_t *src, const comp4_t *mask)
+{
+ comp4_t a = *mask;
+ comp4_t x;
+
+ if (!a)
+ {
+ *(src) = 0;
+ return;
+ }
+
+ if (a == ~0)
+ return;
+
+ x = *(src);
+ UNcx4_MUL_UNcx4 (x, a);
+ *(src) = x;
+}
+
+static void
+combine_mask_alpha_ca (const comp4_t *src, comp4_t *mask)
+{
+ comp4_t a = *(mask);
+ comp4_t x;
+
+ if (!a)
+ return;
+
+ x = *(src) >> A_SHIFT;
+ if (x == MASK)
+ return;
+
+ if (a == ~0)
+ {
+ x |= x << G_SHIFT;
+ x |= x << R_SHIFT;
+ *(mask) = x;
+ return;
+ }
+
+ UNcx4_MUL_UNc (a, x);
+ *(mask) = a;
+}
+
+/*
+ * There are two ways of handling alpha -- either as a single unified value or
+ * a separate value for each component, hence each macro must have two
+ * versions. The unified alpha version has a 'U' at the end of the name,
+ * the component version has a 'C'. Similarly, functions which deal with
+ * this difference will have two versions using the same convention.
+ */
+
+/*
+ * All of the composing functions
+ */
+
+static force_inline comp4_t
+combine_mask (const comp4_t *src, const comp4_t *mask, int i)
+{
+ comp4_t s, m;
+
+ if (mask)
+ {
+ m = *(mask + i) >> A_SHIFT;
+
+ if (!m)
+ return 0;
+ }
+
+ s = *(src + i);
+
+ if (mask)
+ UNcx4_MUL_UNc (s, m);
+
+ return s;
+}
+
+static void
+combine_clear (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ memset (dest, 0, width * sizeof(comp4_t));
+}
+
+static void
+combine_dst (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ return;
+}
+
+static void
+combine_src_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ if (!mask)
+ memcpy (dest, src, width * sizeof (comp4_t));
+ else
+ {
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+
+ *(dest + i) = s;
+ }
+ }
+}
+
+/* if the Src is opaque, call combine_src_u */
+static void
+combine_over_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t ia = ALPHA_c (~s);
+
+ UNcx4_MUL_UNc_ADD_UNcx4 (d, ia, s);
+ *(dest + i) = d;
+ }
+}
+
+/* if the Dst is opaque, this is a noop */
+static void
+combine_over_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t ia = ALPHA_c (~*(dest + i));
+ UNcx4_MUL_UNc_ADD_UNcx4 (s, ia, d);
+ *(dest + i) = s;
+ }
+}
+
+/* if the Dst is opaque, call combine_src_u */
+static void
+combine_in_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t a = ALPHA_c (*(dest + i));
+ UNcx4_MUL_UNc (s, a);
+ *(dest + i) = s;
+ }
+}
+
+/* if the Src is opaque, this is a noop */
+static void
+combine_in_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t a = ALPHA_c (s);
+ UNcx4_MUL_UNc (d, a);
+ *(dest + i) = d;
+ }
+}
+
+/* if the Dst is opaque, call combine_clear */
+static void
+combine_out_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t a = ALPHA_c (~*(dest + i));
+ UNcx4_MUL_UNc (s, a);
+ *(dest + i) = s;
+ }
+}
+
+/* if the Src is opaque, call combine_clear */
+static void
+combine_out_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t a = ALPHA_c (~s);
+ UNcx4_MUL_UNc (d, a);
+ *(dest + i) = d;
+ }
+}
+
+/* if the Src is opaque, call combine_in_u */
+/* if the Dst is opaque, call combine_over_u */
+/* if both the Src and Dst are opaque, call combine_src_u */
+static void
+combine_atop_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t dest_a = ALPHA_c (d);
+ comp4_t src_ia = ALPHA_c (~s);
+
+ UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (s, dest_a, d, src_ia);
+ *(dest + i) = s;
+ }
+}
+
+/* if the Src is opaque, call combine_over_reverse_u */
+/* if the Dst is opaque, call combine_in_reverse_u */
+/* if both the Src and Dst are opaque, call combine_dst_u */
+static void
+combine_atop_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t src_a = ALPHA_c (s);
+ comp4_t dest_ia = ALPHA_c (~d);
+
+ UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (s, dest_ia, d, src_a);
+ *(dest + i) = s;
+ }
+}
+
+/* if the Src is opaque, call combine_over_u */
+/* if the Dst is opaque, call combine_over_reverse_u */
+/* if both the Src and Dst are opaque, call combine_clear */
+static void
+combine_xor_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t src_ia = ALPHA_c (~s);
+ comp4_t dest_ia = ALPHA_c (~d);
+
+ UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (s, dest_ia, d, src_ia);
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_add_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ UNcx4_ADD_UNcx4 (d, s);
+ *(dest + i) = d;
+ }
+}
+
+/* if the Src is opaque, call combine_add_u */
+/* if the Dst is opaque, call combine_add_u */
+/* if both the Src and Dst are opaque, call combine_add_u */
+static void
+combine_saturate_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp2_t sa, da;
+
+ sa = s >> A_SHIFT;
+ da = ~d >> A_SHIFT;
+ if (sa > da)
+ {
+ sa = DIV_UNc (da, sa);
+ UNcx4_MUL_UNc (s, sa);
+ }
+ ;
+ UNcx4_ADD_UNcx4 (d, s);
+ *(dest + i) = d;
+ }
+}
+
+/*
+ * PDF blend modes:
+ * The following blend modes have been taken from the PDF ISO 32000
+ * specification, which at this point in time is available from
+ * http://www.adobe.com/devnet/acrobat/pdfs/PDF32000_2008.pdf
+ * The relevant chapters are 11.3.5 and 11.3.6.
+ * The formula for computing the final pixel color given in 11.3.6 is:
+ * αr × Cr = (1 – αs) × αb × Cb + (1 – αb) × αs × Cs + αb × αs × B(Cb, Cs)
+ * with B() being the blend function.
+ * Note that OVER is a special case of this operation, using B(Cb, Cs) = Cs
+ *
+ * These blend modes should match the SVG filter draft specification, as
+ * it has been designed to mirror ISO 32000. Note that at the current point
+ * no released draft exists that shows this, as the formulas have not been
+ * updated yet after the release of ISO 32000.
+ *
+ * The default implementation here uses the PDF_SEPARABLE_BLEND_MODE and
+ * PDF_NON_SEPARABLE_BLEND_MODE macros, which take the blend function as an
+ * argument. Note that this implementation operates on premultiplied colors,
+ * while the PDF specification does not. Therefore the code uses the formula
+ * ar.Cra = (1 – as) . Dca + (1 – ad) . Sca + B(Dca, ad, Sca, as)
+ */
+
+/*
+ * Multiply
+ * B(Dca, ad, Sca, as) = Dca.Sca
+ */
+
+static void
+combine_multiply_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t ss = s;
+ comp4_t src_ia = ALPHA_c (~s);
+ comp4_t dest_ia = ALPHA_c (~d);
+
+ UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (ss, dest_ia, d, src_ia);
+ UNcx4_MUL_UNcx4 (d, s);
+ UNcx4_ADD_UNcx4 (d, ss);
+
+ *(dest + i) = d;
+ }
+}
+
+static void
+combine_multiply_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t m = *(mask + i);
+ comp4_t s = *(src + i);
+ comp4_t d = *(dest + i);
+ comp4_t r = d;
+ comp4_t dest_ia = ALPHA_c (~d);
+
+ combine_mask_value_ca (&s, &m);
+
+ UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (r, ~m, s, dest_ia);
+ UNcx4_MUL_UNcx4 (d, s);
+ UNcx4_ADD_UNcx4 (r, d);
+
+ *(dest + i) = r;
+ }
+}
+
+#define PDF_SEPARABLE_BLEND_MODE(name) \
+ static void \
+ combine_ ## name ## _u (pixman_implementation_t *imp, \
+ pixman_op_t op, \
+ comp4_t * dest, \
+ const comp4_t * src, \
+ const comp4_t * mask, \
+ int width) \
+ { \
+ int i; \
+ for (i = 0; i < width; ++i) { \
+ comp4_t s = combine_mask (src, mask, i); \
+ comp4_t d = *(dest + i); \
+ comp1_t sa = ALPHA_c (s); \
+ comp1_t isa = ~sa; \
+ comp1_t da = ALPHA_c (d); \
+ comp1_t ida = ~da; \
+ comp4_t result; \
+ \
+ result = d; \
+ UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (result, isa, s, ida); \
+ \
+ *(dest + i) = result + \
+ (DIV_ONE_UNc (sa * da) << A_SHIFT) + \
+ (blend_ ## name (RED_c (d), da, RED_c (s), sa) << R_SHIFT) + \
+ (blend_ ## name (GREEN_c (d), da, GREEN_c (s), sa) << G_SHIFT) + \
+ (blend_ ## name (BLUE_c (d), da, BLUE_c (s), sa)); \
+ } \
+ } \
+ \
+ static void \
+ combine_ ## name ## _ca (pixman_implementation_t *imp, \
+ pixman_op_t op, \
+ comp4_t * dest, \
+ const comp4_t * src, \
+ const comp4_t * mask, \
+ int width) \
+ { \
+ int i; \
+ for (i = 0; i < width; ++i) { \
+ comp4_t m = *(mask + i); \
+ comp4_t s = *(src + i); \
+ comp4_t d = *(dest + i); \
+ comp1_t da = ALPHA_c (d); \
+ comp1_t ida = ~da; \
+ comp4_t result; \
+ \
+ combine_mask_value_ca (&s, &m); \
+ \
+ result = d; \
+ UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (result, ~m, s, ida); \
+ \
+ result += \
+ (DIV_ONE_UNc (ALPHA_c (m) * da) << A_SHIFT) + \
+ (blend_ ## name (RED_c (d), da, RED_c (s), RED_c (m)) << R_SHIFT) + \
+ (blend_ ## name (GREEN_c (d), da, GREEN_c (s), GREEN_c (m)) << G_SHIFT) + \
+ (blend_ ## name (BLUE_c (d), da, BLUE_c (s), BLUE_c (m))); \
+ \
+ *(dest + i) = result; \
+ } \
+ }
+
+/*
+ * Screen
+ * B(Dca, ad, Sca, as) = Dca.sa + Sca.da - Dca.Sca
+ */
+static inline comp4_t
+blend_screen (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ return DIV_ONE_UNc (sca * da + dca * sa - sca * dca);
+}
+
+PDF_SEPARABLE_BLEND_MODE (screen)
+
+/*
+ * Overlay
+ * B(Dca, Da, Sca, Sa) =
+ * if 2.Dca < Da
+ * 2.Sca.Dca
+ * otherwise
+ * Sa.Da - 2.(Da - Dca).(Sa - Sca)
+ */
+static inline comp4_t
+blend_overlay (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ comp4_t rca;
+
+ if (2 * dca < da)
+ rca = 2 * sca * dca;
+ else
+ rca = sa * da - 2 * (da - dca) * (sa - sca);
+ return DIV_ONE_UNc (rca);
+}
+
+PDF_SEPARABLE_BLEND_MODE (overlay)
+
+/*
+ * Darken
+ * B(Dca, Da, Sca, Sa) = min (Sca.Da, Dca.Sa)
+ */
+static inline comp4_t
+blend_darken (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ comp4_t s, d;
+
+ s = sca * da;
+ d = dca * sa;
+ return DIV_ONE_UNc (s > d ? d : s);
+}
+
+PDF_SEPARABLE_BLEND_MODE (darken)
+
+/*
+ * Lighten
+ * B(Dca, Da, Sca, Sa) = max (Sca.Da, Dca.Sa)
+ */
+static inline comp4_t
+blend_lighten (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ comp4_t s, d;
+
+ s = sca * da;
+ d = dca * sa;
+ return DIV_ONE_UNc (s > d ? s : d);
+}
+
+PDF_SEPARABLE_BLEND_MODE (lighten)
+
+/*
+ * Color dodge
+ * B(Dca, Da, Sca, Sa) =
+ * if Dca == 0
+ * 0
+ * if Sca == Sa
+ * Sa.Da
+ * otherwise
+ * Sa.Da. min (1, Dca / Da / (1 - Sca/Sa))
+ */
+static inline comp4_t
+blend_color_dodge (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ if (sca >= sa)
+ {
+ return dca == 0 ? 0 : DIV_ONE_UNc (sa * da);
+ }
+ else
+ {
+ comp4_t rca = dca * sa / (sa - sca);
+ return DIV_ONE_UNc (sa * MIN (rca, da));
+ }
+}
+
+PDF_SEPARABLE_BLEND_MODE (color_dodge)
+
+/*
+ * Color burn
+ * B(Dca, Da, Sca, Sa) =
+ * if Dca == Da
+ * Sa.Da
+ * if Sca == 0
+ * 0
+ * otherwise
+ * Sa.Da.(1 - min (1, (1 - Dca/Da).Sa / Sca))
+ */
+static inline comp4_t
+blend_color_burn (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ if (sca == 0)
+ {
+ return dca < da ? 0 : DIV_ONE_UNc (sa * da);
+ }
+ else
+ {
+ comp4_t rca = (da - dca) * sa / sca;
+ return DIV_ONE_UNc (sa * (MAX (rca, da) - rca));
+ }
+}
+
+PDF_SEPARABLE_BLEND_MODE (color_burn)
+
+/*
+ * Hard light
+ * B(Dca, Da, Sca, Sa) =
+ * if 2.Sca < Sa
+ * 2.Sca.Dca
+ * otherwise
+ * Sa.Da - 2.(Da - Dca).(Sa - Sca)
+ */
+static inline comp4_t
+blend_hard_light (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ if (2 * sca < sa)
+ return DIV_ONE_UNc (2 * sca * dca);
+ else
+ return DIV_ONE_UNc (sa * da - 2 * (da - dca) * (sa - sca));
+}
+
+PDF_SEPARABLE_BLEND_MODE (hard_light)
+
+/*
+ * Soft light
+ * B(Dca, Da, Sca, Sa) =
+ * if (2.Sca <= Sa)
+ * Dca.(Sa - (1 - Dca/Da).(2.Sca - Sa))
+ * otherwise if Dca.4 <= Da
+ * Dca.(Sa + (2.Sca - Sa).((16.Dca/Da - 12).Dca/Da + 3)
+ * otherwise
+ * (Dca.Sa + (SQRT (Dca/Da).Da - Dca).(2.Sca - Sa))
+ */
+static inline comp4_t
+blend_soft_light (comp4_t dca_org,
+ comp4_t da_org,
+ comp4_t sca_org,
+ comp4_t sa_org)
+{
+ double dca = dca_org * (1.0 / MASK);
+ double da = da_org * (1.0 / MASK);
+ double sca = sca_org * (1.0 / MASK);
+ double sa = sa_org * (1.0 / MASK);
+ double rca;
+
+ if (2 * sca < sa)
+ {
+ if (da == 0)
+ rca = dca * sa;
+ else
+ rca = dca * sa - dca * (da - dca) * (sa - 2 * sca) / da;
+ }
+ else if (da == 0)
+ {
+ rca = 0;
+ }
+ else if (4 * dca <= da)
+ {
+ rca = dca * sa +
+ (2 * sca - sa) * dca * ((16 * dca / da - 12) * dca / da + 3);
+ }
+ else
+ {
+ rca = dca * sa + (sqrt (dca * da) - dca) * (2 * sca - sa);
+ }
+ return rca * MASK + 0.5;
+}
+
+PDF_SEPARABLE_BLEND_MODE (soft_light)
+
+/*
+ * Difference
+ * B(Dca, Da, Sca, Sa) = abs (Dca.Sa - Sca.Da)
+ */
+static inline comp4_t
+blend_difference (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ comp4_t dcasa = dca * sa;
+ comp4_t scada = sca * da;
+
+ if (scada < dcasa)
+ return DIV_ONE_UNc (dcasa - scada);
+ else
+ return DIV_ONE_UNc (scada - dcasa);
+}
+
+PDF_SEPARABLE_BLEND_MODE (difference)
+
+/*
+ * Exclusion
+ * B(Dca, Da, Sca, Sa) = (Sca.Da + Dca.Sa - 2.Sca.Dca)
+ */
+
+/* This can be made faster by writing it directly and not using
+ * PDF_SEPARABLE_BLEND_MODE, but that's a performance optimization */
+
+static inline comp4_t
+blend_exclusion (comp4_t dca, comp4_t da, comp4_t sca, comp4_t sa)
+{
+ return DIV_ONE_UNc (sca * da + dca * sa - 2 * dca * sca);
+}
+
+PDF_SEPARABLE_BLEND_MODE (exclusion)
+
+#undef PDF_SEPARABLE_BLEND_MODE
+
+/*
+ * PDF nonseperable blend modes are implemented using the following functions
+ * to operate in Hsl space, with Cmax, Cmid, Cmin referring to the max, mid
+ * and min value of the red, green and blue components.
+ *
+ * LUM (C) = 0.3 × Cred + 0.59 × Cgreen + 0.11 × Cblue
+ *
+ * clip_color (C):
+ * l = LUM (C)
+ * min = Cmin
+ * max = Cmax
+ * if n < 0.0
+ * C = l + ( ( ( C – l ) × l ) ⁄ ( l – min ) )
+ * if x > 1.0
+ * C = l + ( ( ( C – l ) × ( 1 – l ) ) ⁄ ( max – l ) )
+ * return C
+ *
+ * set_lum (C, l):
+ * d = l – LUM (C)
+ * C += d
+ * return clip_color (C)
+ *
+ * SAT (C) = CH_MAX (C) - CH_MIN (C)
+ *
+ * set_sat (C, s):
+ * if Cmax > Cmin
+ * Cmid = ( ( ( Cmid – Cmin ) × s ) ⁄ ( Cmax – Cmin ) )
+ * Cmax = s
+ * else
+ * Cmid = Cmax = 0.0
+ * Cmin = 0.0
+ * return C
+ */
+
+/* For premultiplied colors, we need to know what happens when C is
+ * multiplied by a real number. LUM and SAT are linear:
+ *
+ * LUM (r × C) = r × LUM (C) SAT (r * C) = r * SAT (C)
+ *
+ * If we extend clip_color with an extra argument a and change
+ *
+ * if x >= 1.0
+ *
+ * into
+ *
+ * if x >= a
+ *
+ * then clip_color is also linear:
+ *
+ * r * clip_color (C, a) = clip_color (r_c, ra);
+ *
+ * for positive r.
+ *
+ * Similarly, we can extend set_lum with an extra argument that is just passed
+ * on to clip_color:
+ *
+ * r * set_lum ( C, l, a)
+ *
+ * = r × clip_color ( C + l - LUM (C), a)
+ *
+ * = clip_color ( r * C + r × l - r * LUM (C), r * a)
+ *
+ * = set_lum ( r * C, r * l, r * a)
+ *
+ * Finally, set_sat:
+ *
+ * r * set_sat (C, s) = set_sat (x * C, r * s)
+ *
+ * The above holds for all non-zero x, because they x'es in the fraction for
+ * C_mid cancel out. Specifically, it holds for x = r:
+ *
+ * r * set_sat (C, s) = set_sat (r_c, rs)
+ *
+ */
+
+/* So, for the non-separable PDF blend modes, we have (using s, d for
+ * non-premultiplied colors, and S, D for premultiplied:
+ *
+ * Color:
+ *
+ * a_s * a_d * B(s, d)
+ * = a_s * a_d * set_lum (S/a_s, LUM (D/a_d), 1)
+ * = set_lum (S * a_d, a_s * LUM (D), a_s * a_d)
+ *
+ *
+ * Luminosity:
+ *
+ * a_s * a_d * B(s, d)
+ * = a_s * a_d * set_lum (D/a_d, LUM(S/a_s), 1)
+ * = set_lum (a_s * D, a_d * LUM(S), a_s * a_d)
+ *
+ *
+ * Saturation:
+ *
+ * a_s * a_d * B(s, d)
+ * = a_s * a_d * set_lum (set_sat (D/a_d, SAT (S/a_s)), LUM (D/a_d), 1)
+ * = set_lum (a_s * a_d * set_sat (D/a_d, SAT (S/a_s)),
+ * a_s * LUM (D), a_s * a_d)
+ * = set_lum (set_sat (a_s * D, a_d * SAT (S), a_s * LUM (D), a_s * a_d))
+ *
+ * Hue:
+ *
+ * a_s * a_d * B(s, d)
+ * = a_s * a_d * set_lum (set_sat (S/a_s, SAT (D/a_d)), LUM (D/a_d), 1)
+ * = a_s * a_d * set_lum (set_sat (a_d * S, a_s * SAT (D)),
+ * a_s * LUM (D), a_s * a_d)
+ *
+ */
+
+#define CH_MIN(c) (c[0] < c[1] ? (c[0] < c[2] ? c[0] : c[2]) : (c[1] < c[2] ? c[1] : c[2]))
+#define CH_MAX(c) (c[0] > c[1] ? (c[0] > c[2] ? c[0] : c[2]) : (c[1] > c[2] ? c[1] : c[2]))
+#define LUM(c) ((c[0] * 30 + c[1] * 59 + c[2] * 11) / 100)
+#define SAT(c) (CH_MAX (c) - CH_MIN (c))
+
+#define PDF_NON_SEPARABLE_BLEND_MODE(name) \
+ static void \
+ combine_ ## name ## _u (pixman_implementation_t *imp, \
+ pixman_op_t op, \
+ comp4_t *dest, \
+ const comp4_t *src, \
+ const comp4_t *mask, \
+ int width) \
+ { \
+ int i; \
+ for (i = 0; i < width; ++i) \
+ { \
+ comp4_t s = combine_mask (src, mask, i); \
+ comp4_t d = *(dest + i); \
+ comp1_t sa = ALPHA_c (s); \
+ comp1_t isa = ~sa; \
+ comp1_t da = ALPHA_c (d); \
+ comp1_t ida = ~da; \
+ comp4_t result; \
+ comp4_t sc[3], dc[3], c[3]; \
+ \
+ result = d; \
+ UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc (result, isa, s, ida); \
+ dc[0] = RED_c (d); \
+ sc[0] = RED_c (s); \
+ dc[1] = GREEN_c (d); \
+ sc[1] = GREEN_c (s); \
+ dc[2] = BLUE_c (d); \
+ sc[2] = BLUE_c (s); \
+ blend_ ## name (c, dc, da, sc, sa); \
+ \
+ *(dest + i) = result + \
+ (DIV_ONE_UNc (sa * da) << A_SHIFT) + \
+ (DIV_ONE_UNc (c[0]) << R_SHIFT) + \
+ (DIV_ONE_UNc (c[1]) << G_SHIFT) + \
+ (DIV_ONE_UNc (c[2])); \
+ } \
+ }
+
+static void
+set_lum (comp4_t dest[3], comp4_t src[3], comp4_t sa, comp4_t lum)
+{
+ double a, l, min, max;
+ double tmp[3];
+
+ a = sa * (1.0 / MASK);
+
+ l = lum * (1.0 / MASK);
+ tmp[0] = src[0] * (1.0 / MASK);
+ tmp[1] = src[1] * (1.0 / MASK);
+ tmp[2] = src[2] * (1.0 / MASK);
+
+ l = l - LUM (tmp);
+ tmp[0] += l;
+ tmp[1] += l;
+ tmp[2] += l;
+
+ /* clip_color */
+ l = LUM (tmp);
+ min = CH_MIN (tmp);
+ max = CH_MAX (tmp);
+
+ if (min < 0)
+ {
+ tmp[0] = l + (tmp[0] - l) * l / (l - min);
+ tmp[1] = l + (tmp[1] - l) * l / (l - min);
+ tmp[2] = l + (tmp[2] - l) * l / (l - min);
+ }
+ if (max > a)
+ {
+ tmp[0] = l + (tmp[0] - l) * (a - l) / (max - l);
+ tmp[1] = l + (tmp[1] - l) * (a - l) / (max - l);
+ tmp[2] = l + (tmp[2] - l) * (a - l) / (max - l);
+ }
+
+ dest[0] = tmp[0] * MASK + 0.5;
+ dest[1] = tmp[1] * MASK + 0.5;
+ dest[2] = tmp[2] * MASK + 0.5;
+}
+
+static void
+set_sat (comp4_t dest[3], comp4_t src[3], comp4_t sat)
+{
+ int id[3];
+ comp4_t min, max;
+
+ if (src[0] > src[1])
+ {
+ if (src[0] > src[2])
+ {
+ id[0] = 0;
+ if (src[1] > src[2])
+ {
+ id[1] = 1;
+ id[2] = 2;
+ }
+ else
+ {
+ id[1] = 2;
+ id[2] = 1;
+ }
+ }
+ else
+ {
+ id[0] = 2;
+ id[1] = 0;
+ id[2] = 1;
+ }
+ }
+ else
+ {
+ if (src[0] > src[2])
+ {
+ id[0] = 1;
+ id[1] = 0;
+ id[2] = 2;
+ }
+ else
+ {
+ id[2] = 0;
+ if (src[1] > src[2])
+ {
+ id[0] = 1;
+ id[1] = 2;
+ }
+ else
+ {
+ id[0] = 2;
+ id[1] = 1;
+ }
+ }
+ }
+
+ max = dest[id[0]];
+ min = dest[id[2]];
+ if (max > min)
+ {
+ dest[id[1]] = (dest[id[1]] - min) * sat / (max - min);
+ dest[id[0]] = sat;
+ dest[id[2]] = 0;
+ }
+ else
+ {
+ dest[0] = dest[1] = dest[2] = 0;
+ }
+}
+
+/*
+ * Hue:
+ * B(Cb, Cs) = set_lum (set_sat (Cs, SAT (Cb)), LUM (Cb))
+ */
+static inline void
+blend_hsl_hue (comp4_t c[3],
+ comp4_t dc[3],
+ comp4_t da,
+ comp4_t sc[3],
+ comp4_t sa)
+{
+ c[0] = sc[0] * da;
+ c[1] = sc[1] * da;
+ c[2] = sc[2] * da;
+ set_sat (c, c, SAT (dc) * sa);
+ set_lum (c, c, sa * da, LUM (dc) * sa);
+}
+
+PDF_NON_SEPARABLE_BLEND_MODE (hsl_hue)
+
+/*
+ * Saturation:
+ * B(Cb, Cs) = set_lum (set_sat (Cb, SAT (Cs)), LUM (Cb))
+ */
+static inline void
+blend_hsl_saturation (comp4_t c[3],
+ comp4_t dc[3],
+ comp4_t da,
+ comp4_t sc[3],
+ comp4_t sa)
+{
+ c[0] = dc[0] * sa;
+ c[1] = dc[1] * sa;
+ c[2] = dc[2] * sa;
+ set_sat (c, c, SAT (sc) * da);
+ set_lum (c, c, sa * da, LUM (dc) * sa);
+}
+
+PDF_NON_SEPARABLE_BLEND_MODE (hsl_saturation)
+
+/*
+ * Color:
+ * B(Cb, Cs) = set_lum (Cs, LUM (Cb))
+ */
+static inline void
+blend_hsl_color (comp4_t c[3],
+ comp4_t dc[3],
+ comp4_t da,
+ comp4_t sc[3],
+ comp4_t sa)
+{
+ c[0] = sc[0] * da;
+ c[1] = sc[1] * da;
+ c[2] = sc[2] * da;
+ set_lum (c, c, sa * da, LUM (dc) * sa);
+}
+
+PDF_NON_SEPARABLE_BLEND_MODE (hsl_color)
+
+/*
+ * Luminosity:
+ * B(Cb, Cs) = set_lum (Cb, LUM (Cs))
+ */
+static inline void
+blend_hsl_luminosity (comp4_t c[3],
+ comp4_t dc[3],
+ comp4_t da,
+ comp4_t sc[3],
+ comp4_t sa)
+{
+ c[0] = dc[0] * sa;
+ c[1] = dc[1] * sa;
+ c[2] = dc[2] * sa;
+ set_lum (c, c, sa * da, LUM (sc) * da);
+}
+
+PDF_NON_SEPARABLE_BLEND_MODE (hsl_luminosity)
+
+#undef SAT
+#undef LUM
+#undef CH_MAX
+#undef CH_MIN
+#undef PDF_NON_SEPARABLE_BLEND_MODE
+
+/* Overlay
+ *
+ * All of the disjoint composing functions
+ *
+ * The four entries in the first column indicate what source contributions
+ * come from each of the four areas of the picture -- areas covered by neither
+ * A nor B, areas covered only by A, areas covered only by B and finally
+ * areas covered by both A and B.
+ *
+ * Disjoint Conjoint
+ * Fa Fb Fa Fb
+ * (0,0,0,0) 0 0 0 0
+ * (0,A,0,A) 1 0 1 0
+ * (0,0,B,B) 0 1 0 1
+ * (0,A,B,A) 1 min((1-a)/b,1) 1 max(1-a/b,0)
+ * (0,A,B,B) min((1-b)/a,1) 1 max(1-b/a,0) 1
+ * (0,0,0,A) max(1-(1-b)/a,0) 0 min(1,b/a) 0
+ * (0,0,0,B) 0 max(1-(1-a)/b,0) 0 min(a/b,1)
+ * (0,A,0,0) min(1,(1-b)/a) 0 max(1-b/a,0) 0
+ * (0,0,B,0) 0 min(1,(1-a)/b) 0 max(1-a/b,0)
+ * (0,0,B,A) max(1-(1-b)/a,0) min(1,(1-a)/b) min(1,b/a) max(1-a/b,0)
+ * (0,A,0,B) min(1,(1-b)/a) max(1-(1-a)/b,0) max(1-b/a,0) min(1,a/b)
+ * (0,A,B,0) min(1,(1-b)/a) min(1,(1-a)/b) max(1-b/a,0) max(1-a/b,0)
+ */
+
+#define COMBINE_A_OUT 1
+#define COMBINE_A_IN 2
+#define COMBINE_B_OUT 4
+#define COMBINE_B_IN 8
+
+#define COMBINE_CLEAR 0
+#define COMBINE_A (COMBINE_A_OUT | COMBINE_A_IN)
+#define COMBINE_B (COMBINE_B_OUT | COMBINE_B_IN)
+#define COMBINE_A_OVER (COMBINE_A_OUT | COMBINE_B_OUT | COMBINE_A_IN)
+#define COMBINE_B_OVER (COMBINE_A_OUT | COMBINE_B_OUT | COMBINE_B_IN)
+#define COMBINE_A_ATOP (COMBINE_B_OUT | COMBINE_A_IN)
+#define COMBINE_B_ATOP (COMBINE_A_OUT | COMBINE_B_IN)
+#define COMBINE_XOR (COMBINE_A_OUT | COMBINE_B_OUT)
+
+/* portion covered by a but not b */
+static comp1_t
+combine_disjoint_out_part (comp1_t a, comp1_t b)
+{
+ /* min (1, (1-b) / a) */
+
+ b = ~b; /* 1 - b */
+ if (b >= a) /* 1 - b >= a -> (1-b)/a >= 1 */
+ return MASK; /* 1 */
+ return DIV_UNc (b, a); /* (1-b) / a */
+}
+
+/* portion covered by both a and b */
+static comp1_t
+combine_disjoint_in_part (comp1_t a, comp1_t b)
+{
+ /* max (1-(1-b)/a,0) */
+ /* = - min ((1-b)/a - 1, 0) */
+ /* = 1 - min (1, (1-b)/a) */
+
+ b = ~b; /* 1 - b */
+ if (b >= a) /* 1 - b >= a -> (1-b)/a >= 1 */
+ return 0; /* 1 - 1 */
+ return ~DIV_UNc(b, a); /* 1 - (1-b) / a */
+}
+
+/* portion covered by a but not b */
+static comp1_t
+combine_conjoint_out_part (comp1_t a, comp1_t b)
+{
+ /* max (1-b/a,0) */
+ /* = 1-min(b/a,1) */
+
+ /* min (1, (1-b) / a) */
+
+ if (b >= a) /* b >= a -> b/a >= 1 */
+ return 0x00; /* 0 */
+ return ~DIV_UNc(b, a); /* 1 - b/a */
+}
+
+/* portion covered by both a and b */
+static comp1_t
+combine_conjoint_in_part (comp1_t a, comp1_t b)
+{
+ /* min (1,b/a) */
+
+ if (b >= a) /* b >= a -> b/a >= 1 */
+ return MASK; /* 1 */
+ return DIV_UNc (b, a); /* b/a */
+}
+
+#define GET_COMP(v, i) ((comp2_t) (comp1_t) ((v) >> i))
+
+#define ADD(x, y, i, t) \
+ ((t) = GET_COMP (x, i) + GET_COMP (y, i), \
+ (comp4_t) ((comp1_t) ((t) | (0 - ((t) >> G_SHIFT)))) << (i))
+
+#define GENERIC(x, y, i, ax, ay, t, u, v) \
+ ((t) = (MUL_UNc (GET_COMP (y, i), ay, (u)) + \
+ MUL_UNc (GET_COMP (x, i), ax, (v))), \
+ (comp4_t) ((comp1_t) ((t) | \
+ (0 - ((t) >> G_SHIFT)))) << (i))
+
+static void
+combine_disjoint_general_u (comp4_t * dest,
+ const comp4_t *src,
+ const comp4_t *mask,
+ int width,
+ comp1_t combine)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t m, n, o, p;
+ comp2_t Fa, Fb, t, u, v;
+ comp1_t sa = s >> A_SHIFT;
+ comp1_t da = d >> A_SHIFT;
+
+ switch (combine & COMBINE_A)
+ {
+ default:
+ Fa = 0;
+ break;
+
+ case COMBINE_A_OUT:
+ Fa = combine_disjoint_out_part (sa, da);
+ break;
+
+ case COMBINE_A_IN:
+ Fa = combine_disjoint_in_part (sa, da);
+ break;
+
+ case COMBINE_A:
+ Fa = MASK;
+ break;
+ }
+
+ switch (combine & COMBINE_B)
+ {
+ default:
+ Fb = 0;
+ break;
+
+ case COMBINE_B_OUT:
+ Fb = combine_disjoint_out_part (da, sa);
+ break;
+
+ case COMBINE_B_IN:
+ Fb = combine_disjoint_in_part (da, sa);
+ break;
+
+ case COMBINE_B:
+ Fb = MASK;
+ break;
+ }
+ m = GENERIC (s, d, 0, Fa, Fb, t, u, v);
+ n = GENERIC (s, d, G_SHIFT, Fa, Fb, t, u, v);
+ o = GENERIC (s, d, R_SHIFT, Fa, Fb, t, u, v);
+ p = GENERIC (s, d, A_SHIFT, Fa, Fb, t, u, v);
+ s = m | n | o | p;
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_disjoint_over_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp2_t a = s >> A_SHIFT;
+
+ if (s != 0x00)
+ {
+ comp4_t d = *(dest + i);
+ a = combine_disjoint_out_part (d >> A_SHIFT, a);
+ UNcx4_MUL_UNc_ADD_UNcx4 (d, a, s);
+
+ *(dest + i) = d;
+ }
+ }
+}
+
+static void
+combine_disjoint_in_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_IN);
+}
+
+static void
+combine_disjoint_in_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_IN);
+}
+
+static void
+combine_disjoint_out_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_OUT);
+}
+
+static void
+combine_disjoint_out_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_OUT);
+}
+
+static void
+combine_disjoint_atop_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_u (dest, src, mask, width, COMBINE_A_ATOP);
+}
+
+static void
+combine_disjoint_atop_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_u (dest, src, mask, width, COMBINE_B_ATOP);
+}
+
+static void
+combine_disjoint_xor_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_u (dest, src, mask, width, COMBINE_XOR);
+}
+
+static void
+combine_conjoint_general_u (comp4_t * dest,
+ const comp4_t *src,
+ const comp4_t *mask,
+ int width,
+ comp1_t combine)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = combine_mask (src, mask, i);
+ comp4_t d = *(dest + i);
+ comp4_t m, n, o, p;
+ comp2_t Fa, Fb, t, u, v;
+ comp1_t sa = s >> A_SHIFT;
+ comp1_t da = d >> A_SHIFT;
+
+ switch (combine & COMBINE_A)
+ {
+ default:
+ Fa = 0;
+ break;
+
+ case COMBINE_A_OUT:
+ Fa = combine_conjoint_out_part (sa, da);
+ break;
+
+ case COMBINE_A_IN:
+ Fa = combine_conjoint_in_part (sa, da);
+ break;
+
+ case COMBINE_A:
+ Fa = MASK;
+ break;
+ }
+
+ switch (combine & COMBINE_B)
+ {
+ default:
+ Fb = 0;
+ break;
+
+ case COMBINE_B_OUT:
+ Fb = combine_conjoint_out_part (da, sa);
+ break;
+
+ case COMBINE_B_IN:
+ Fb = combine_conjoint_in_part (da, sa);
+ break;
+
+ case COMBINE_B:
+ Fb = MASK;
+ break;
+ }
+
+ m = GENERIC (s, d, 0, Fa, Fb, t, u, v);
+ n = GENERIC (s, d, G_SHIFT, Fa, Fb, t, u, v);
+ o = GENERIC (s, d, R_SHIFT, Fa, Fb, t, u, v);
+ p = GENERIC (s, d, A_SHIFT, Fa, Fb, t, u, v);
+
+ s = m | n | o | p;
+
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_conjoint_over_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_OVER);
+}
+
+static void
+combine_conjoint_over_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_OVER);
+}
+
+static void
+combine_conjoint_in_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_IN);
+}
+
+static void
+combine_conjoint_in_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_IN);
+}
+
+static void
+combine_conjoint_out_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_OUT);
+}
+
+static void
+combine_conjoint_out_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_OUT);
+}
+
+static void
+combine_conjoint_atop_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_A_ATOP);
+}
+
+static void
+combine_conjoint_atop_reverse_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_B_ATOP);
+}
+
+static void
+combine_conjoint_xor_u (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_u (dest, src, mask, width, COMBINE_XOR);
+}
+
+/************************************************************************/
+/*********************** Per Channel functions **************************/
+/************************************************************************/
+
+static void
+combine_clear_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ memset (dest, 0, width * sizeof(comp4_t));
+}
+
+static void
+combine_src_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+
+ combine_mask_value_ca (&s, &m);
+
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_over_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+ comp4_t a;
+
+ combine_mask_ca (&s, &m);
+
+ a = ~m;
+ if (a)
+ {
+ comp4_t d = *(dest + i);
+ UNcx4_MUL_UNcx4_ADD_UNcx4 (d, a, s);
+ s = d;
+ }
+
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_over_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t d = *(dest + i);
+ comp4_t a = ~d >> A_SHIFT;
+
+ if (a)
+ {
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+
+ UNcx4_MUL_UNcx4 (s, m);
+ UNcx4_MUL_UNc_ADD_UNcx4 (s, a, d);
+
+ *(dest + i) = s;
+ }
+ }
+}
+
+static void
+combine_in_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t d = *(dest + i);
+ comp2_t a = d >> A_SHIFT;
+ comp4_t s = 0;
+
+ if (a)
+ {
+ comp4_t m = *(mask + i);
+
+ s = *(src + i);
+ combine_mask_value_ca (&s, &m);
+
+ if (a != MASK)
+ UNcx4_MUL_UNc (s, a);
+ }
+
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_in_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+ comp4_t a;
+
+ combine_mask_alpha_ca (&s, &m);
+
+ a = m;
+ if (a != ~0)
+ {
+ comp4_t d = 0;
+
+ if (a)
+ {
+ d = *(dest + i);
+ UNcx4_MUL_UNcx4 (d, a);
+ }
+
+ *(dest + i) = d;
+ }
+ }
+}
+
+static void
+combine_out_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t d = *(dest + i);
+ comp2_t a = ~d >> A_SHIFT;
+ comp4_t s = 0;
+
+ if (a)
+ {
+ comp4_t m = *(mask + i);
+
+ s = *(src + i);
+ combine_mask_value_ca (&s, &m);
+
+ if (a != MASK)
+ UNcx4_MUL_UNc (s, a);
+ }
+
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_out_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+ comp4_t a;
+
+ combine_mask_alpha_ca (&s, &m);
+
+ a = ~m;
+ if (a != ~0)
+ {
+ comp4_t d = 0;
+
+ if (a)
+ {
+ d = *(dest + i);
+ UNcx4_MUL_UNcx4 (d, a);
+ }
+
+ *(dest + i) = d;
+ }
+ }
+}
+
+static void
+combine_atop_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t d = *(dest + i);
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+ comp4_t ad;
+ comp2_t as = d >> A_SHIFT;
+
+ combine_mask_ca (&s, &m);
+
+ ad = ~m;
+
+ UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (d, ad, s, as);
+
+ *(dest + i) = d;
+ }
+}
+
+static void
+combine_atop_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t d = *(dest + i);
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+ comp4_t ad;
+ comp2_t as = ~d >> A_SHIFT;
+
+ combine_mask_ca (&s, &m);
+
+ ad = m;
+
+ UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (d, ad, s, as);
+
+ *(dest + i) = d;
+ }
+}
+
+static void
+combine_xor_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t d = *(dest + i);
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+ comp4_t ad;
+ comp2_t as = ~d >> A_SHIFT;
+
+ combine_mask_ca (&s, &m);
+
+ ad = ~m;
+
+ UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc (d, ad, s, as);
+
+ *(dest + i) = d;
+ }
+}
+
+static void
+combine_add_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s = *(src + i);
+ comp4_t m = *(mask + i);
+ comp4_t d = *(dest + i);
+
+ combine_mask_value_ca (&s, &m);
+
+ UNcx4_ADD_UNcx4 (d, s);
+
+ *(dest + i) = d;
+ }
+}
+
+static void
+combine_saturate_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s, d;
+ comp2_t sa, sr, sg, sb, da;
+ comp2_t t, u, v;
+ comp4_t m, n, o, p;
+
+ d = *(dest + i);
+ s = *(src + i);
+ m = *(mask + i);
+
+ combine_mask_ca (&s, &m);
+
+ sa = (m >> A_SHIFT);
+ sr = (m >> R_SHIFT) & MASK;
+ sg = (m >> G_SHIFT) & MASK;
+ sb = m & MASK;
+ da = ~d >> A_SHIFT;
+
+ if (sb <= da)
+ m = ADD (s, d, 0, t);
+ else
+ m = GENERIC (s, d, 0, (da << G_SHIFT) / sb, MASK, t, u, v);
+
+ if (sg <= da)
+ n = ADD (s, d, G_SHIFT, t);
+ else
+ n = GENERIC (s, d, G_SHIFT, (da << G_SHIFT) / sg, MASK, t, u, v);
+
+ if (sr <= da)
+ o = ADD (s, d, R_SHIFT, t);
+ else
+ o = GENERIC (s, d, R_SHIFT, (da << G_SHIFT) / sr, MASK, t, u, v);
+
+ if (sa <= da)
+ p = ADD (s, d, A_SHIFT, t);
+ else
+ p = GENERIC (s, d, A_SHIFT, (da << G_SHIFT) / sa, MASK, t, u, v);
+
+ *(dest + i) = m | n | o | p;
+ }
+}
+
+static void
+combine_disjoint_general_ca (comp4_t * dest,
+ const comp4_t *src,
+ const comp4_t *mask,
+ int width,
+ comp1_t combine)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s, d;
+ comp4_t m, n, o, p;
+ comp4_t Fa, Fb;
+ comp2_t t, u, v;
+ comp4_t sa;
+ comp1_t da;
+
+ s = *(src + i);
+ m = *(mask + i);
+ d = *(dest + i);
+ da = d >> A_SHIFT;
+
+ combine_mask_ca (&s, &m);
+
+ sa = m;
+
+ switch (combine & COMBINE_A)
+ {
+ default:
+ Fa = 0;
+ break;
+
+ case COMBINE_A_OUT:
+ m = (comp4_t)combine_disjoint_out_part ((comp1_t) (sa >> 0), da);
+ n = (comp4_t)combine_disjoint_out_part ((comp1_t) (sa >> G_SHIFT), da) << G_SHIFT;
+ o = (comp4_t)combine_disjoint_out_part ((comp1_t) (sa >> R_SHIFT), da) << R_SHIFT;
+ p = (comp4_t)combine_disjoint_out_part ((comp1_t) (sa >> A_SHIFT), da) << A_SHIFT;
+ Fa = m | n | o | p;
+ break;
+
+ case COMBINE_A_IN:
+ m = (comp4_t)combine_disjoint_in_part ((comp1_t) (sa >> 0), da);
+ n = (comp4_t)combine_disjoint_in_part ((comp1_t) (sa >> G_SHIFT), da) << G_SHIFT;
+ o = (comp4_t)combine_disjoint_in_part ((comp1_t) (sa >> R_SHIFT), da) << R_SHIFT;
+ p = (comp4_t)combine_disjoint_in_part ((comp1_t) (sa >> A_SHIFT), da) << A_SHIFT;
+ Fa = m | n | o | p;
+ break;
+
+ case COMBINE_A:
+ Fa = ~0;
+ break;
+ }
+
+ switch (combine & COMBINE_B)
+ {
+ default:
+ Fb = 0;
+ break;
+
+ case COMBINE_B_OUT:
+ m = (comp4_t)combine_disjoint_out_part (da, (comp1_t) (sa >> 0));
+ n = (comp4_t)combine_disjoint_out_part (da, (comp1_t) (sa >> G_SHIFT)) << G_SHIFT;
+ o = (comp4_t)combine_disjoint_out_part (da, (comp1_t) (sa >> R_SHIFT)) << R_SHIFT;
+ p = (comp4_t)combine_disjoint_out_part (da, (comp1_t) (sa >> A_SHIFT)) << A_SHIFT;
+ Fb = m | n | o | p;
+ break;
+
+ case COMBINE_B_IN:
+ m = (comp4_t)combine_disjoint_in_part (da, (comp1_t) (sa >> 0));
+ n = (comp4_t)combine_disjoint_in_part (da, (comp1_t) (sa >> G_SHIFT)) << G_SHIFT;
+ o = (comp4_t)combine_disjoint_in_part (da, (comp1_t) (sa >> R_SHIFT)) << R_SHIFT;
+ p = (comp4_t)combine_disjoint_in_part (da, (comp1_t) (sa >> A_SHIFT)) << A_SHIFT;
+ Fb = m | n | o | p;
+ break;
+
+ case COMBINE_B:
+ Fb = ~0;
+ break;
+ }
+ m = GENERIC (s, d, 0, GET_COMP (Fa, 0), GET_COMP (Fb, 0), t, u, v);
+ n = GENERIC (s, d, G_SHIFT, GET_COMP (Fa, G_SHIFT), GET_COMP (Fb, G_SHIFT), t, u, v);
+ o = GENERIC (s, d, R_SHIFT, GET_COMP (Fa, R_SHIFT), GET_COMP (Fb, R_SHIFT), t, u, v);
+ p = GENERIC (s, d, A_SHIFT, GET_COMP (Fa, A_SHIFT), GET_COMP (Fb, A_SHIFT), t, u, v);
+
+ s = m | n | o | p;
+
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_disjoint_over_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_OVER);
+}
+
+static void
+combine_disjoint_in_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_IN);
+}
+
+static void
+combine_disjoint_in_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_IN);
+}
+
+static void
+combine_disjoint_out_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_OUT);
+}
+
+static void
+combine_disjoint_out_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_OUT);
+}
+
+static void
+combine_disjoint_atop_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_ca (dest, src, mask, width, COMBINE_A_ATOP);
+}
+
+static void
+combine_disjoint_atop_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_ca (dest, src, mask, width, COMBINE_B_ATOP);
+}
+
+static void
+combine_disjoint_xor_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_disjoint_general_ca (dest, src, mask, width, COMBINE_XOR);
+}
+
+static void
+combine_conjoint_general_ca (comp4_t * dest,
+ const comp4_t *src,
+ const comp4_t *mask,
+ int width,
+ comp1_t combine)
+{
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ comp4_t s, d;
+ comp4_t m, n, o, p;
+ comp4_t Fa, Fb;
+ comp2_t t, u, v;
+ comp4_t sa;
+ comp1_t da;
+
+ s = *(src + i);
+ m = *(mask + i);
+ d = *(dest + i);
+ da = d >> A_SHIFT;
+
+ combine_mask_ca (&s, &m);
+
+ sa = m;
+
+ switch (combine & COMBINE_A)
+ {
+ default:
+ Fa = 0;
+ break;
+
+ case COMBINE_A_OUT:
+ m = (comp4_t)combine_conjoint_out_part ((comp1_t) (sa >> 0), da);
+ n = (comp4_t)combine_conjoint_out_part ((comp1_t) (sa >> G_SHIFT), da) << G_SHIFT;
+ o = (comp4_t)combine_conjoint_out_part ((comp1_t) (sa >> R_SHIFT), da) << R_SHIFT;
+ p = (comp4_t)combine_conjoint_out_part ((comp1_t) (sa >> A_SHIFT), da) << A_SHIFT;
+ Fa = m | n | o | p;
+ break;
+
+ case COMBINE_A_IN:
+ m = (comp4_t)combine_conjoint_in_part ((comp1_t) (sa >> 0), da);
+ n = (comp4_t)combine_conjoint_in_part ((comp1_t) (sa >> G_SHIFT), da) << G_SHIFT;
+ o = (comp4_t)combine_conjoint_in_part ((comp1_t) (sa >> R_SHIFT), da) << R_SHIFT;
+ p = (comp4_t)combine_conjoint_in_part ((comp1_t) (sa >> A_SHIFT), da) << A_SHIFT;
+ Fa = m | n | o | p;
+ break;
+
+ case COMBINE_A:
+ Fa = ~0;
+ break;
+ }
+
+ switch (combine & COMBINE_B)
+ {
+ default:
+ Fb = 0;
+ break;
+
+ case COMBINE_B_OUT:
+ m = (comp4_t)combine_conjoint_out_part (da, (comp1_t) (sa >> 0));
+ n = (comp4_t)combine_conjoint_out_part (da, (comp1_t) (sa >> G_SHIFT)) << G_SHIFT;
+ o = (comp4_t)combine_conjoint_out_part (da, (comp1_t) (sa >> R_SHIFT)) << R_SHIFT;
+ p = (comp4_t)combine_conjoint_out_part (da, (comp1_t) (sa >> A_SHIFT)) << A_SHIFT;
+ Fb = m | n | o | p;
+ break;
+
+ case COMBINE_B_IN:
+ m = (comp4_t)combine_conjoint_in_part (da, (comp1_t) (sa >> 0));
+ n = (comp4_t)combine_conjoint_in_part (da, (comp1_t) (sa >> G_SHIFT)) << G_SHIFT;
+ o = (comp4_t)combine_conjoint_in_part (da, (comp1_t) (sa >> R_SHIFT)) << R_SHIFT;
+ p = (comp4_t)combine_conjoint_in_part (da, (comp1_t) (sa >> A_SHIFT)) << A_SHIFT;
+ Fb = m | n | o | p;
+ break;
+
+ case COMBINE_B:
+ Fb = ~0;
+ break;
+ }
+ m = GENERIC (s, d, 0, GET_COMP (Fa, 0), GET_COMP (Fb, 0), t, u, v);
+ n = GENERIC (s, d, G_SHIFT, GET_COMP (Fa, G_SHIFT), GET_COMP (Fb, G_SHIFT), t, u, v);
+ o = GENERIC (s, d, R_SHIFT, GET_COMP (Fa, R_SHIFT), GET_COMP (Fb, R_SHIFT), t, u, v);
+ p = GENERIC (s, d, A_SHIFT, GET_COMP (Fa, A_SHIFT), GET_COMP (Fb, A_SHIFT), t, u, v);
+
+ s = m | n | o | p;
+
+ *(dest + i) = s;
+ }
+}
+
+static void
+combine_conjoint_over_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_OVER);
+}
+
+static void
+combine_conjoint_over_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_OVER);
+}
+
+static void
+combine_conjoint_in_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_IN);
+}
+
+static void
+combine_conjoint_in_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_IN);
+}
+
+static void
+combine_conjoint_out_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_OUT);
+}
+
+static void
+combine_conjoint_out_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_OUT);
+}
+
+static void
+combine_conjoint_atop_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_A_ATOP);
+}
+
+static void
+combine_conjoint_atop_reverse_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_B_ATOP);
+}
+
+static void
+combine_conjoint_xor_ca (pixman_implementation_t *imp,
+ pixman_op_t op,
+ comp4_t * dest,
+ const comp4_t * src,
+ const comp4_t * mask,
+ int width)
+{
+ combine_conjoint_general_ca (dest, src, mask, width, COMBINE_XOR);
+}
+
+void
+_pixman_setup_combiner_functions_width (pixman_implementation_t *imp)
+{
+ /* Unified alpha */
+ imp->combine_width[PIXMAN_OP_CLEAR] = combine_clear;
+ imp->combine_width[PIXMAN_OP_SRC] = combine_src_u;
+ imp->combine_width[PIXMAN_OP_DST] = combine_dst;
+ imp->combine_width[PIXMAN_OP_OVER] = combine_over_u;
+ imp->combine_width[PIXMAN_OP_OVER_REVERSE] = combine_over_reverse_u;
+ imp->combine_width[PIXMAN_OP_IN] = combine_in_u;
+ imp->combine_width[PIXMAN_OP_IN_REVERSE] = combine_in_reverse_u;
+ imp->combine_width[PIXMAN_OP_OUT] = combine_out_u;
+ imp->combine_width[PIXMAN_OP_OUT_REVERSE] = combine_out_reverse_u;
+ imp->combine_width[PIXMAN_OP_ATOP] = combine_atop_u;
+ imp->combine_width[PIXMAN_OP_ATOP_REVERSE] = combine_atop_reverse_u;
+ imp->combine_width[PIXMAN_OP_XOR] = combine_xor_u;
+ imp->combine_width[PIXMAN_OP_ADD] = combine_add_u;
+ imp->combine_width[PIXMAN_OP_SATURATE] = combine_saturate_u;
+
+ /* Disjoint, unified */
+ imp->combine_width[PIXMAN_OP_DISJOINT_CLEAR] = combine_clear;
+ imp->combine_width[PIXMAN_OP_DISJOINT_SRC] = combine_src_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_DST] = combine_dst;
+ imp->combine_width[PIXMAN_OP_DISJOINT_OVER] = combine_disjoint_over_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_OVER_REVERSE] = combine_saturate_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_IN] = combine_disjoint_in_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_IN_REVERSE] = combine_disjoint_in_reverse_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_OUT] = combine_disjoint_out_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_OUT_REVERSE] = combine_disjoint_out_reverse_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_ATOP] = combine_disjoint_atop_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_ATOP_REVERSE] = combine_disjoint_atop_reverse_u;
+ imp->combine_width[PIXMAN_OP_DISJOINT_XOR] = combine_disjoint_xor_u;
+
+ /* Conjoint, unified */
+ imp->combine_width[PIXMAN_OP_CONJOINT_CLEAR] = combine_clear;
+ imp->combine_width[PIXMAN_OP_CONJOINT_SRC] = combine_src_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_DST] = combine_dst;
+ imp->combine_width[PIXMAN_OP_CONJOINT_OVER] = combine_conjoint_over_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_OVER_REVERSE] = combine_conjoint_over_reverse_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_IN] = combine_conjoint_in_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_IN_REVERSE] = combine_conjoint_in_reverse_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_OUT] = combine_conjoint_out_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_OUT_REVERSE] = combine_conjoint_out_reverse_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_ATOP] = combine_conjoint_atop_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_ATOP_REVERSE] = combine_conjoint_atop_reverse_u;
+ imp->combine_width[PIXMAN_OP_CONJOINT_XOR] = combine_conjoint_xor_u;
+
+ imp->combine_width[PIXMAN_OP_MULTIPLY] = combine_multiply_u;
+ imp->combine_width[PIXMAN_OP_SCREEN] = combine_screen_u;
+ imp->combine_width[PIXMAN_OP_OVERLAY] = combine_overlay_u;
+ imp->combine_width[PIXMAN_OP_DARKEN] = combine_darken_u;
+ imp->combine_width[PIXMAN_OP_LIGHTEN] = combine_lighten_u;
+ imp->combine_width[PIXMAN_OP_COLOR_DODGE] = combine_color_dodge_u;
+ imp->combine_width[PIXMAN_OP_COLOR_BURN] = combine_color_burn_u;
+ imp->combine_width[PIXMAN_OP_HARD_LIGHT] = combine_hard_light_u;
+ imp->combine_width[PIXMAN_OP_SOFT_LIGHT] = combine_soft_light_u;
+ imp->combine_width[PIXMAN_OP_DIFFERENCE] = combine_difference_u;
+ imp->combine_width[PIXMAN_OP_EXCLUSION] = combine_exclusion_u;
+ imp->combine_width[PIXMAN_OP_HSL_HUE] = combine_hsl_hue_u;
+ imp->combine_width[PIXMAN_OP_HSL_SATURATION] = combine_hsl_saturation_u;
+ imp->combine_width[PIXMAN_OP_HSL_COLOR] = combine_hsl_color_u;
+ imp->combine_width[PIXMAN_OP_HSL_LUMINOSITY] = combine_hsl_luminosity_u;
+
+ /* Component alpha combiners */
+ imp->combine_width_ca[PIXMAN_OP_CLEAR] = combine_clear_ca;
+ imp->combine_width_ca[PIXMAN_OP_SRC] = combine_src_ca;
+ /* dest */
+ imp->combine_width_ca[PIXMAN_OP_OVER] = combine_over_ca;
+ imp->combine_width_ca[PIXMAN_OP_OVER_REVERSE] = combine_over_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_IN] = combine_in_ca;
+ imp->combine_width_ca[PIXMAN_OP_IN_REVERSE] = combine_in_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_OUT] = combine_out_ca;
+ imp->combine_width_ca[PIXMAN_OP_OUT_REVERSE] = combine_out_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_ATOP] = combine_atop_ca;
+ imp->combine_width_ca[PIXMAN_OP_ATOP_REVERSE] = combine_atop_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_XOR] = combine_xor_ca;
+ imp->combine_width_ca[PIXMAN_OP_ADD] = combine_add_ca;
+ imp->combine_width_ca[PIXMAN_OP_SATURATE] = combine_saturate_ca;
+
+ /* Disjoint CA */
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_CLEAR] = combine_clear_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_SRC] = combine_src_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_DST] = combine_dst;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_OVER] = combine_disjoint_over_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_OVER_REVERSE] = combine_saturate_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_IN] = combine_disjoint_in_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_IN_REVERSE] = combine_disjoint_in_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_OUT] = combine_disjoint_out_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_OUT_REVERSE] = combine_disjoint_out_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_ATOP] = combine_disjoint_atop_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_ATOP_REVERSE] = combine_disjoint_atop_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_DISJOINT_XOR] = combine_disjoint_xor_ca;
+
+ /* Conjoint CA */
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_CLEAR] = combine_clear_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_SRC] = combine_src_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_DST] = combine_dst;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_OVER] = combine_conjoint_over_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_OVER_REVERSE] = combine_conjoint_over_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_IN] = combine_conjoint_in_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_IN_REVERSE] = combine_conjoint_in_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_OUT] = combine_conjoint_out_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_OUT_REVERSE] = combine_conjoint_out_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_ATOP] = combine_conjoint_atop_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_ATOP_REVERSE] = combine_conjoint_atop_reverse_ca;
+ imp->combine_width_ca[PIXMAN_OP_CONJOINT_XOR] = combine_conjoint_xor_ca;
+
+ imp->combine_width_ca[PIXMAN_OP_MULTIPLY] = combine_multiply_ca;
+ imp->combine_width_ca[PIXMAN_OP_SCREEN] = combine_screen_ca;
+ imp->combine_width_ca[PIXMAN_OP_OVERLAY] = combine_overlay_ca;
+ imp->combine_width_ca[PIXMAN_OP_DARKEN] = combine_darken_ca;
+ imp->combine_width_ca[PIXMAN_OP_LIGHTEN] = combine_lighten_ca;
+ imp->combine_width_ca[PIXMAN_OP_COLOR_DODGE] = combine_color_dodge_ca;
+ imp->combine_width_ca[PIXMAN_OP_COLOR_BURN] = combine_color_burn_ca;
+ imp->combine_width_ca[PIXMAN_OP_HARD_LIGHT] = combine_hard_light_ca;
+ imp->combine_width_ca[PIXMAN_OP_SOFT_LIGHT] = combine_soft_light_ca;
+ imp->combine_width_ca[PIXMAN_OP_DIFFERENCE] = combine_difference_ca;
+ imp->combine_width_ca[PIXMAN_OP_EXCLUSION] = combine_exclusion_ca;
+
+ /* It is not clear that these make sense, so make them noops for now */
+ imp->combine_width_ca[PIXMAN_OP_HSL_HUE] = combine_dst;
+ imp->combine_width_ca[PIXMAN_OP_HSL_SATURATION] = combine_dst;
+ imp->combine_width_ca[PIXMAN_OP_HSL_COLOR] = combine_dst;
+ imp->combine_width_ca[PIXMAN_OP_HSL_LUMINOSITY] = combine_dst;
+}
+
diff --git a/pixman/test/Makefile.am b/pixman/test/Makefile.am
index e3ab89038..32b1d6327 100644
--- a/pixman/test/Makefile.am
+++ b/pixman/test/Makefile.am
@@ -23,7 +23,6 @@ TESTPROGRAMS = \
a1_trap_test_LDADD = $(TEST_LDADD)
fetch_test_LDADD = $(TEST_LDADD)
-composite_LDADD = $(TEST_LDADD)
gradient_crash_test_LDADD = $(TEST_LDADD)
trap_crasher_LDADD = $(TEST_LDADD)
oob_test_LDADD = $(TEST_LDADD)
@@ -49,6 +48,9 @@ alphamap_SOURCES = alphamap.c utils.c utils.h
alpha_loop_LDADD = $(TEST_LDADD)
alpha_loop_SOURCES = alpha-loop.c utils.c utils.h
+composite_LDADD = $(TEST_LDADD)
+composite_SOURCES = composite.c utils.c utils.h
+
# GTK using test programs
if HAVE_GTK
diff --git a/pixman/test/alphamap.c b/pixman/test/alphamap.c
index eb7a330f9..6d150cf69 100644
--- a/pixman/test/alphamap.c
+++ b/pixman/test/alphamap.c
@@ -45,15 +45,29 @@ format_name (pixman_format_code_t format)
return "<unknown - bug in alphamap.c>";
}
+static void
+on_destroy (pixman_image_t *image, void *data)
+{
+ uint32_t *bits = pixman_image_get_data (image);
+
+ fence_free (bits);
+}
+
static pixman_image_t *
make_image (pixman_format_code_t format)
{
uint32_t *bits;
uint8_t bpp = PIXMAN_FORMAT_BPP (format) / 8;
+ pixman_image_t *image;
bits = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * bpp);
- return pixman_image_create_bits (format, WIDTH, HEIGHT, bits, WIDTH * bpp);
+ image = pixman_image_create_bits (format, WIDTH, HEIGHT, bits, WIDTH * bpp);
+
+ if (image && bits)
+ pixman_image_set_destroy_function (image, on_destroy, NULL);
+
+ return image;
}
static pixman_image_t *
diff --git a/pixman/test/blitters-test.c b/pixman/test/blitters-test.c
index a9e8cc2ce..9e2a7f42f 100644
--- a/pixman/test/blitters-test.c
+++ b/pixman/test/blitters-test.c
@@ -465,6 +465,6 @@ main (int argc, const char *argv[])
}
return fuzzer_test_main("blitters", 2000000,
- 0x217CF14A,
+ 0x1DB8BDF8,
test_composite, argc, argv);
}
diff --git a/pixman/test/composite.c b/pixman/test/composite.c
index 426a887e3..e8a7e94dc 100644
--- a/pixman/test/composite.c
+++ b/pixman/test/composite.c
@@ -1,6 +1,8 @@
/*
* Copyright © 2005 Eric Anholt
* Copyright © 2009 Chris Wilson
+ * Copyright © 2010 Soeren Sandmann
+ * Copyright © 2010 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
@@ -20,15 +22,14 @@
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
-
+#define PIXMAN_USE_INTERNAL_API
#include <pixman.h>
#include <stdio.h>
#include <stdlib.h> /* abort() */
#include <math.h>
#include <config.h>
-
-#define FALSE 0
-#define TRUE !FALSE
+#include <time.h>
+#include "utils.h"
#define ARRAY_LENGTH(A) ((int) (sizeof (A) / sizeof ((A) [0])))
#define min(a,b) ((a) <= (b) ? (a) : (b))
@@ -50,14 +51,15 @@ struct format_t
const char *name;
};
-static color_t colors[] =
+static const color_t colors[] =
{
- /* these are premultiplied in main() */
{ 1.0, 1.0, 1.0, 1.0 },
+ { 1.0, 1.0, 1.0, 0.0 },
+ { 0.0, 0.0, 0.0, 1.0 },
+ { 0.0, 0.0, 0.0, 0.0 },
{ 1.0, 0.0, 0.0, 1.0 },
{ 0.0, 1.0, 0.0, 1.0 },
{ 0.0, 0.0, 1.0, 1.0 },
- { 0.0, 0.0, 0.0, 1.0 },
{ 0.5, 0.0, 0.0, 0.5 },
};
@@ -82,62 +84,66 @@ compute_pixman_color (const color_t *color,
out->alpha = _color_double_to_short (color->a);
}
+#define REPEAT 0x01000000
+#define FLAGS 0xff000000
+
+static const int sizes[] =
+{
+ 0,
+ 1,
+ 1 | REPEAT,
+ 10
+};
+
static const format_t formats[] =
{
#define P(x) { PIXMAN_##x, #x }
- P(a8),
- /* 32bpp formats */
+ /* 32 bpp formats */
P(a8r8g8b8),
P(x8r8g8b8),
P(a8b8g8r8),
P(x8b8g8r8),
P(b8g8r8a8),
P(b8g8r8x8),
-
- /* XXX: and here the errors begin! */
-#if 0
P(x2r10g10b10),
- P(a2r10g10b10),
P(x2b10g10r10),
+ P(a2r10g10b10),
P(a2b10g10r10),
- /* 24bpp formats */
+ /* 24 bpp formats */
P(r8g8b8),
P(b8g8r8),
-
- /* 16bpp formats */
P(r5g6b5),
P(b5g6r5),
- P(a1r5g5b5),
+ /* 16 bpp formats */
P(x1r5g5b5),
- P(a1b5g5r5),
P(x1b5g5r5),
- P(a4r4g4b4),
- P(x4r4g4b4),
+ P(a1r5g5b5),
+ P(a1b5g5r5),
P(a4b4g4r4),
P(x4b4g4r4),
+ P(a4r4g4b4),
+ P(x4r4g4b4),
- /* 8bpp formats */
+ /* 8 bpp formats */
P(a8),
P(r3g3b2),
P(b2g3r3),
P(a2r2g2b2),
P(a2b2g2r2),
-
P(x4a4),
- /* 4bpp formats */
+ /* 4 bpp formats */
P(a4),
P(r1g2b1),
P(b1g2r1),
P(a1r1g1b1),
P(a1b1g1r1),
- /* 1bpp formats */
+ /* 1 bpp formats */
P(a1)
-#endif
#undef P
};
@@ -482,8 +488,9 @@ static void
color_correct (pixman_format_code_t format,
color_t *color)
{
-#define round_pix(pix, mask) \
- ((int)((pix) * (mask) + .5) / (double) (mask))
+#define MASK(x) ((1 << (x)) - 1)
+#define round_pix(pix, m) \
+ ((int)((pix) * (MASK(m)) + .5) / (double) (MASK(m)))
if (PIXMAN_FORMAT_R (format) == 0)
{
@@ -504,6 +511,7 @@ color_correct (pixman_format_code_t format,
color->a = round_pix (color->a, PIXMAN_FORMAT_A (format));
#undef round_pix
+#undef MASK
}
static void
@@ -594,18 +602,15 @@ get_pixel (pixman_image_t *image,
}
static double
-eval_diff (color_t *expected, color_t *test)
+eval_diff (color_t *expected, color_t *test, pixman_format_code_t format)
{
double rscale, gscale, bscale, ascale;
double rdiff, gdiff, bdiff, adiff;
- /* XXX: Need to be provided mask shifts so we can produce useful error
- * values.
- */
- rscale = 1.0 * (1 << 5);
- gscale = 1.0 * (1 << 6);
- bscale = 1.0 * (1 << 5);
- ascale = 1.0 * 32;
+ rscale = 1.0 * ((1 << PIXMAN_FORMAT_R (format)) - 1);
+ gscale = 1.0 * ((1 << PIXMAN_FORMAT_G (format)) - 1);
+ bscale = 1.0 * ((1 << PIXMAN_FORMAT_B (format)) - 1);
+ ascale = 1.0 * ((1 << PIXMAN_FORMAT_A (format)) - 1);
rdiff = fabs (test->r - expected->r) * rscale;
bdiff = fabs (test->g - expected->g) * gscale;
@@ -699,7 +704,12 @@ composite_test (image_t *dst,
&expected, component_alpha);
color_correct (dst->format->format, &expected);
- diff = eval_diff (&expected, &result);
+ diff = eval_diff (&expected, &result, dst->format->format);
+
+ /* FIXME: We should find out what deviation is acceptable. 3.0
+ * is clearly absurd for 2 bit formats for example. On the other
+ * hand currently 1.0 does not work.
+ */
if (diff > 3.0)
{
char buf[40];
@@ -717,7 +727,7 @@ composite_test (image_t *dst,
result.r, result.g, result.b, result.a,
*(unsigned long *) pixman_image_get_data (dst->image),
expected.r, expected.g, expected.b, expected.a);
-
+
if (mask != NULL)
{
printf ("src color: %.2f %.2f %.2f %.2f\n"
@@ -751,9 +761,6 @@ composite_test (image_t *dst,
return success;
}
-#define REPEAT 0x01000000
-#define FLAGS 0xff000000
-
static void
image_init (image_t *info,
int color,
@@ -766,7 +773,7 @@ image_init (image_t *info,
compute_pixman_color (info->color, &fill);
info->format = &formats[format];
- info->size = size & ~FLAGS;
+ info->size = sizes[size] & ~FLAGS;
info->repeat = PIXMAN_REPEAT_NONE;
if (info->size)
@@ -800,103 +807,105 @@ image_fini (image_t *info)
pixman_image_unref (info->image);
}
-int
-main (void)
+static int
+random_size (void)
+{
+ return lcg_rand_n (ARRAY_LENGTH (sizes));
+}
+
+static int
+random_color (void)
{
- pixman_bool_t ok, group_ok = TRUE, ca;
- int i, d, m, s;
- int tests_passed = 0, tests_total = 0;
- int sizes[] = { 1, 1 | REPEAT, 10 };
- int num_tests;
+ return lcg_rand_n (ARRAY_LENGTH (colors));
+}
+
+static int
+random_format (void)
+{
+ return lcg_rand_n (ARRAY_LENGTH (formats));
+}
+
+static pixman_bool_t
+run_test (uint32_t seed)
+{
+ image_t src, mask, dst;
+ const operator_t *op;
+ int ca;
+ int ok;
+
+ lcg_srand (seed);
+
+ image_init (&dst, random_color(), random_format(), 1);
+ image_init (&src, random_color(), random_format(), random_size());
+ image_init (&mask, random_color(), random_format(), random_size());
+
+ op = &(operators [lcg_rand_n (ARRAY_LENGTH (operators))]);
+
+ ca = lcg_rand_n (3);
- for (i = 0; i < ARRAY_LENGTH (colors); i++)
+ switch (ca)
{
- colors[i].r *= colors[i].a;
- colors[i].g *= colors[i].a;
- colors[i].b *= colors[i].a;
+ case 0:
+ ok = composite_test (&dst, op, &src, NULL, FALSE);
+ break;
+ case 1:
+ ok = composite_test (&dst, op, &src, &mask, FALSE);
+ break;
+ case 2:
+ ok = composite_test (&dst, op, &src, &mask,
+ mask.size? TRUE : FALSE);
+ break;
+ default:
+ ok = FALSE;
+ break;
}
- num_tests = ARRAY_LENGTH (colors) * ARRAY_LENGTH (formats);
+ image_fini (&src);
+ image_fini (&mask);
+ image_fini (&dst);
- for (d = 0; d < num_tests; d++)
- {
- image_t dst;
+ return ok;
+}
- image_init (
- &dst, d / ARRAY_LENGTH (formats), d % ARRAY_LENGTH (formats), 1);
+int
+main (int argc, char **argv)
+{
+#define N_TESTS (8 * 1024 * 1024)
+ int result = 0;
+ int i;
+ if (argc > 1)
+ {
+ char *end;
+
+ i = strtol (argv[1], &end, 0);
- for (s = -ARRAY_LENGTH (colors);
- s < ARRAY_LENGTH (sizes) * num_tests;
- s++)
+ if (end != argv[1])
{
- image_t src;
-
- if (s < 0)
- {
- image_init (&src, -s - 1, 0, 0);
- }
+ if (!run_test (i))
+ return 1;
else
- {
- image_init (&src,
- s / ARRAY_LENGTH (sizes) / ARRAY_LENGTH (formats),
- s / ARRAY_LENGTH (sizes) % ARRAY_LENGTH (formats),
- sizes[s % ARRAY_LENGTH (sizes)]);
- }
-
- for (m = -ARRAY_LENGTH (colors);
- m < ARRAY_LENGTH (sizes) * num_tests;
- m++)
- {
- image_t mask;
-
- if (m < 0)
- {
- image_init (&mask, -m - 1, 0, 0);
- }
- else
- {
- image_init (
- &mask,
- m / ARRAY_LENGTH (sizes) / ARRAY_LENGTH (formats),
- m / ARRAY_LENGTH (sizes) % ARRAY_LENGTH (formats),
- sizes[m % ARRAY_LENGTH (sizes)]);
- }
-
- for (ca = -1; ca <= 1; ca++)
- {
- for (i = 0; i < ARRAY_LENGTH (operators); i++)
- {
- const operator_t *op = &operators[i];
-
- switch (ca)
- {
- case -1:
- ok = composite_test (&dst, op, &src, NULL, FALSE);
- break;
- case 0:
- ok = composite_test (&dst, op, &src, &mask, FALSE);
- break;
- case 1:
- ok = composite_test (&dst, op, &src, &mask,
- mask.size? TRUE : FALSE);
- break;
- default:
- ok = FALSE; /* Silence GCC */
- break;
- }
- group_ok = group_ok && ok;
- tests_passed += ok;
- tests_total++;
- }
- }
-
- image_fini (&mask);
- }
- image_fini (&src);
+ return 0;
+ }
+ else
+ {
+ printf ("Usage:\n\n %s <number>\n\n", argv[0]);
+ return -1;
}
- image_fini (&dst);
}
- return group_ok == FALSE;
+#ifdef USE_OPENMP
+# pragma omp parallel for default(none) shared(result) shared(argv)
+#endif
+ for (i = 1; i <= N_TESTS; ++i)
+ {
+ if (!result && !run_test (i))
+ {
+ printf ("Test %d failed.\n", i);
+
+ result = i;
+ }
+ }
+
+ return result;
}