From c1c86afa877b80a284365bcdaee11986bdd7da1f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 5 Sep 2008 05:04:09 +0100 Subject: [PATCH] [ps] Use floating point values when flattening color. Use the full-precision color values when computing the alpha-blended color. --- src/cairo-ps-surface.c | 24 +++++++++++------------ test/Makefile.am | 1 + test/over-around-source-ps-rgb24-ref.png | Bin 0 -> 538 bytes 3 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 test/over-around-source-ps-rgb24-ref.png diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index f2c4b7319..c31ed2b0a 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -1504,7 +1504,7 @@ _cairo_ps_surface_analyze_operation (cairo_ps_surface_t *surface, * surface. If the analysis surface determines that there is * anything drawn under this operation, a fallback image will be * used. Otherwise the operation will be replayed during the - * render stage and we blend the transarency into the white + * render stage and we blend the transparency into the white * background to convert the pattern to opaque. */ @@ -2089,21 +2089,19 @@ _cairo_ps_surface_flatten_transparency (cairo_ps_surface_t *surface, double *green, double *blue) { - *red = color->red; + *red = color->red; *green = color->green; - *blue = color->blue; + *blue = color->blue; - if (!CAIRO_COLOR_IS_OPAQUE(color)) { + if (! CAIRO_COLOR_IS_OPAQUE (color)) { + *red *= color->alpha; + *green *= color->alpha; + *blue *= color->alpha; if (surface->content == CAIRO_CONTENT_COLOR_ALPHA) { - uint8_t one_minus_alpha = 255 - (color->alpha_short >> 8); - - *red = ((color->red_short >> 8) + one_minus_alpha) / 255.0; - *green = ((color->green_short >> 8) + one_minus_alpha) / 255.0; - *blue = ((color->blue_short >> 8) + one_minus_alpha) / 255.0; - } else { - *red = (color->red_short >> 8) / 255.0; - *green = (color->green_short >> 8) / 255.0; - *blue = (color->blue_short >> 8) / 255.0; + double one_minus_alpha = 1. - color->alpha; + *red += one_minus_alpha; + *green += one_minus_alpha; + *blue += one_minus_alpha; } } } diff --git a/test/Makefile.am b/test/Makefile.am index fcc16015a..562f4d49b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -546,6 +546,7 @@ REFERENCE_IMAGES = \ over-above-source-ref.png \ over-above-source-rgb24-ref.png \ over-around-source-ps-argb32-ref.png \ + over-around-source-ps-rgb24-ref.png \ over-around-source-quartz-ref.png \ over-around-source-quartz-rgb24-ref.png \ over-around-source-ref.png \ diff --git a/test/over-around-source-ps-rgb24-ref.png b/test/over-around-source-ps-rgb24-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..ee325eab34fb7b668526de710eff7998812c341e GIT binary patch literal 538 zcmV+#0_FXQP)XR&0vCnz6F7~+tY&an<+7{4q77oo>I5cPB(42)sb6I=j z?GfLa0Qa`g=2zH57BnkdLN|pdf&LPP^X6nd-j z@bn6%YnbZ%_Asw-H-*s{qQ`pUdutd0*T5L4_RpHN>ffqon!+t3waB(puEQ{iWe8MROTq)WW;_tPev&%s;Lrlsw#3kNK)Q znPiQYSNOBeAmLXQ48pU4HlmpKssX~5EEt5BmQTBYm$FV_PZkWqN#qI{Us6hhg@dwS z5MIq))#b|*1!ba8C<|KQtoWX0Kdmf)*FzmbsVr!OcWw$}Y|;zh`A~;YDGQo?c;}|D z${xMp3YlI-c#2B{>&oVM9~^mlM7Y`@KW@K)58T%Ek~K@t?o$7Xq~)&07(pcqZJu<3 zS{B+87EH3xhOl6kg{FlCFIi|(Sn!sGri6u~$U+ms!qH?Qw6Jhg*_=&~b`xgaa3@_L cPVUzH0|g