diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-09-22 04:03:48 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-09-22 04:03:48 -0400 |
commit | 85709cd99f8ec0ae61c445b52061b1ec0f5df6b6 (patch) | |
tree | 61d720c81980c3e9c24bbf53db6a14f7539eca89 | |
parent | a9752e228eaddf2e173cb8b2851bba88c304f2fa (diff) |
Add component alpha for hslhsl-component
-rw-r--r-- | pixman/pixman-combine-float.c | 84 |
1 files changed, 64 insertions, 20 deletions
diff --git a/pixman/pixman-combine-float.c b/pixman/pixman-combine-float.c index d873b38d..ccad91c7 100644 --- a/pixman/pixman-combine-float.c +++ b/pixman/pixman-combine-float.c @@ -615,25 +615,25 @@ maxf (float a, float b) } static force_inline float -channel_min (rgb_t *c) +channel_min (const rgb_t *c) { return minf (minf (c->r, c->g), c->b); } static force_inline float -channel_max (rgb_t *c) +channel_max (const rgb_t *c) { return maxf (maxf (c->r, c->g), c->b); } static force_inline float -get_lum (rgb_t *c) +get_lum (const rgb_t *c) { return c->r * 0.3f + c->g * 0.59f + c->b * 0.11f; } static force_inline float -get_sat (rgb_t *c) +get_sat (const rgb_t *c) { return channel_max (c) - channel_min (c); } @@ -762,8 +762,8 @@ set_sat (rgb_t *src, float sat) */ static force_inline void blend_hsl_hue (rgb_t *res, - rgb_t *dest, float da, - rgb_t *src, float sa) + const rgb_t *dest, float da, + const rgb_t *src, float sa) { res->r = src->r * da; res->g = src->g * da; @@ -779,8 +779,8 @@ blend_hsl_hue (rgb_t *res, */ static force_inline void blend_hsl_saturation (rgb_t *res, - rgb_t *dest, float da, - rgb_t *src, float sa) + const rgb_t *dest, float da, + const rgb_t *src, float sa) { res->r = dest->r * sa; res->g = dest->g * sa; @@ -796,8 +796,8 @@ blend_hsl_saturation (rgb_t *res, */ static force_inline void blend_hsl_color (rgb_t *res, - rgb_t *dest, float da, - rgb_t *src, float sa) + const rgb_t *dest, float da, + const rgb_t *src, float sa) { res->r = src->r * da; res->g = src->g * da; @@ -812,8 +812,8 @@ blend_hsl_color (rgb_t *res, */ static force_inline void blend_hsl_luminosity (rgb_t *res, - rgb_t *dest, float da, - rgb_t *src, float sa) + const rgb_t *dest, float da, + const rgb_t *src, float sa) { res->r = dest->r * sa; res->g = dest->g * sa; @@ -822,6 +822,12 @@ blend_hsl_luminosity (rgb_t *res, set_lum (res, sa * da, get_lum (src) * da); } +static force_inline float +lerp (float d, float s, float m) +{ + return d * (1.0f - m) + m * s; +} + #define MAKE_NON_SEPARABLE_PDF_COMBINERS(name) \ static void \ combine_ ## name ## _u_float (pixman_implementation_t *imp, \ @@ -852,7 +858,6 @@ blend_hsl_luminosity (rgb_t *res, { \ float ma = mask[i + 0]; \ \ - /* Component alpha is not supported for HSL modes */ \ sa *= ma; \ sc.r *= ma; \ sc.g *= ma; \ @@ -862,9 +867,48 @@ blend_hsl_luminosity (rgb_t *res, blend_ ## name (&rc, &dc, da, &sc, sa); \ \ dest[i + 0] = sa + da - sa * da; \ - dest[i + 1] = (1-sa)*dc.r + (1-da)*sc.r + rc.r; \ - dest[i + 2] = (1-sa)*dc.g + (1-da)*sc.g + rc.g; \ - dest[i + 3] = (1-sa)*dc.b + (1-da)*sc.b + rc.b; \ + dest[i + 1] = (1 - sa) * dc.r + (1 - da) * sc.r + rc.r; \ + dest[i + 2] = (1 - sa) * dc.g + (1 - da) * sc.g + rc.g; \ + dest[i + 3] = (1 - sa) * dc.b + (1 - da) * sc.b + rc.b; \ + } \ + } \ + \ + static void \ + combine_ ## name ## _ca_float (pixman_implementation_t *imp, \ + pixman_op_t op, \ + float *dest, \ + const float *src, \ + const float *mask, \ + int n_pixels) \ + { \ + int i; \ + \ + for (i = 0; i < 4 * n_pixels; i += 4) \ + { \ + float sa, da; \ + rgb_t sc, dc, rc; \ + \ + sa = src[i + 0]; \ + sc.r = src[i + 1]; \ + sc.g = src[i + 2]; \ + sc.b = src[i + 3]; \ + \ + da = dest[i + 0]; \ + dc.r = dest[i + 1]; \ + dc.g = dest[i + 2]; \ + dc.b = dest[i + 3]; \ + \ + blend_ ## name (&rc, &dc, da, &sc, sa); \ + \ + rc.r = (1 - sa) * dc.r + (1 - da) * sc.r + rc.r; \ + rc.g = (1 - sa) * dc.g + (1 - da) * sc.g + rc.g; \ + rc.b = (1 - sa) * dc.b + (1 - da) * sc.b + rc.b; \ + sa = sa + da - sa * da; \ + \ + dest[i + 0] = lerp (dest[i + 0], sa, mask[i + 0]); \ + dest[i + 1] = lerp (dest[i + 1], rc.r, mask[i + 1]); \ + dest[i + 2] = lerp (dest[i + 2], rc.g, mask[i + 2]); \ + dest[i + 3] = lerp (dest[i + 3], rc.b, mask[i + 3]); \ } \ } @@ -996,8 +1040,8 @@ _pixman_setup_combiner_functions_float (pixman_implementation_t *imp) imp->combine_float_ca[PIXMAN_OP_EXCLUSION] = combine_exclusion_ca_float; /* It is not clear that these make sense, so make them noops for now */ - imp->combine_float_ca[PIXMAN_OP_HSL_HUE] = combine_dst_u_float; - imp->combine_float_ca[PIXMAN_OP_HSL_SATURATION] = combine_dst_u_float; - imp->combine_float_ca[PIXMAN_OP_HSL_COLOR] = combine_dst_u_float; - imp->combine_float_ca[PIXMAN_OP_HSL_LUMINOSITY] = combine_dst_u_float; + imp->combine_float_ca[PIXMAN_OP_HSL_HUE] = combine_hsl_hue_ca_float; + imp->combine_float_ca[PIXMAN_OP_HSL_SATURATION] = combine_hsl_saturation_ca_float; + imp->combine_float_ca[PIXMAN_OP_HSL_COLOR] = combine_hsl_color_ca_float; + imp->combine_float_ca[PIXMAN_OP_HSL_LUMINOSITY] = combine_hsl_luminosity_ca_float; } |