[cairo] Pixel color rounding issue
spitzak at gmail.com
Tue Dec 7 07:00:29 PST 2010
This is why Cairo needs either an API that takes 4 8-bit numbers, or a
"set the current color to this 1x1 image".
These rounding problems are not going to go away. If you change it like
requested, you will just get the "wrong" answer for somebody else. The
need to make the color exactly match a color used in an image is very
important for UI graphics.
Alejandro Garcia Castro wrote:
> I'm working in WebKitGTK+ project, we have found a issue regarding
> colors in some of the tests we are running. These tests are run
> through all the ports and we try to share results with other graphical
> engines. After commeting it with Company, in this case we would like
> to check with you if in this case this is something expected and we
> should generate different results for cairo/webkitgtk or something we
> would like to change.
> These tests are using the canvas tag to render a path with a color an
> checking the pixels to test if the color set is the same in the pixel.
> For cairo, setting a RGBA of (255, 20, 0, 0.5) results in a pixel with
> (255, 18, 0, 0.5). The result comes due to the different conversions of
> color for it's representation:
> double -> 4 uint16 (cairo) -> 1 uint32 (pixman)
> The first one does not add much error but in the second one we are
> truncating the color like:
> static uint32_t
> color_to_uint32 (const pixman_color_t *color)
> (color->alpha >> 8 << 24) |
> (color->red >> 8 << 16) |
> (color->green & 0xff00) |
> (color->blue >> 8);
> Due to premultiplication if alpha is big the rounding errors getting
> the color are bigger but we were wondering if it would make sense to
> round instead of trunc in this case to make it more accurate.
> Anyway, it is true this is an issue for the users because the result
> is similar, just a matter of testing correctness. I've attached a
> cairo only test to check the issue.
> Thanks for the comments in advance.
> cairo mailing list
> cairo at cairographics.org
More information about the cairo