bgo#603550 - Compute the luminance correctly when generating a mask

Thanks to Mike Lewis for the patch.

https://bugzilla.gnome.org/show_bug.cgi?id=603550
parent eb766567
......@@ -701,9 +701,28 @@ rsvg_cairo_generate_mask (cairo_t * cr, RsvgMask * self, RsvgDrawingCtx * ctx, R
guint8 *row_data = (pixels + (row * rowstride));
for (i = 0; i < width; i++) {
guint32 *pixel = (guint32 *) row_data + i;
*pixel = ((((*pixel & 0x00ff0000) >> 16) * 13817 +
((*pixel & 0x0000ff00) >> 8) * 46518 +
((*pixel & 0x000000ff)) * 4688) * state->opacity);
/*
* Assuming, the pixel is linear RGB (not sRGB)
* y = luminance
* Y = 0.2126 R + 0.7152 G + 0.0722 B
* 1.0 opacity = 255
*
* When Y = 1.0, pixel for mask should be 0xFFFFFFFF
* (you get 1.0 luminance from 255 from R, G and B)
*
* r_mult = 0xFFFFFFFF / (255.0 * 255.0) * .2126 = 14042.45 ~= 14042
* g_mult = 0xFFFFFFFF / (255.0 * 255.0) * .7152 = 47239.69 ~= 47240
* b_mult = 0xFFFFFFFF / (255.0 * 255.0) * .0722 = 4768.88 ~= 4769
*
* This allows for the following expected behaviour:
* (we only care about the most sig byte)
* if pixel = 0x00FFFFFF, pixel' = 0xFF......
* if pixel = 0x00020202, pixel' = 0x02......
* if pixel = 0x00000000, pixel' = 0x00......
*/
*pixel = ((((*pixel & 0x00ff0000) >> 16) * 14042 +
((*pixel & 0x0000ff00) >> 8) * 47240 +
((*pixel & 0x000000ff) ) * 4769 ) * state->opacity);
}
}
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="744.09448819"
height="1052.3622047">
<defs
id="defs34">
<mask
maskUnits="userSpaceOnUse"
id="masky"
x="0"
y="0"
width='500'
height='500'>
<g>
<rect
style="fill:white; stroke:none"
id="rect128"
width="500"
height="500"
x="0"
y="0" />
</g>
</mask>
</defs>
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<rect
style="fill:#000000;fill-opacity:1;stroke:none"
id="rect42"
width="600"
height="300"
x="0"
y="0"/>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<g mask="url(#masky)" >
<rect
style="fill:#000000;fill-opacity:1;stroke:none"
id="rect42"
width="600"
height="300"
x="0"
y="300"/>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
<rect
style="fill:#000000;fill-opacity:1;stroke:none"
id="rect42"
width="50"
height="600"
x="275"
y="0"/>
</svg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment