Re: Questions about linear gradient results using image surface

Petr Kobalíček <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAB2Z3Of5EC9fwQ+m0HA8qQ=Gf9kHf3bMcTdeJK4niB__tJc2Ug@mail.gmail.com>
Hello,

I think that this behavior is caused by the fact, that Cairo uses
[0.5, 0.5] as pixel center. The value here would be different that
expected value at [0, 0]

I think that:

gradient = cairo_pattern_create_linear(1, 0, 199, 0);

is workaround for your problem.

Best,
Petr

On Thu, Jun 28, 2012 at 11:49 AM, Dongyeon Kim <[email protected]> wrote:
> Hello all,
>
> I have some questions about linear gradient results using image surface.
> Below is a sample code to draw a rectangle with linear gradient pattern fill.
> (You can also see the code here: http://codepad.org/kPzFYk72)
>
> ///////////////// TEST CODE BEGINS /////////////////
> cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 50);
> cr = cairo_create(cairo_surface);
>
> cairo_pattern_t *gradient;
> gradient = cairo_pattern_create_linear(0, 0, 200, 0);
> cairo_pattern_add_color_stop_rgb(gradient, 0.0, 1.0, 0.0, 0.0);
> cairo_pattern_add_color_stop_rgb(gradient, 0.25, 0.0, 1.0, 0.0);
> cairo_pattern_add_color_stop_rgb(gradient, 0.75, 0.0, 1.0, 0.0);
> cairo_pattern_add_color_stop_rgb(gradient, 1.0, 1.0, 0.0, 0.0);
>
> cairo_set_source(cr, gradient);
> cairo_rectangle (cr, 0, 0, 200, 50);
> cairo_fill(cr);
> cairo_surface_write_to_png(cairo_surface, "result_linear_gradient.png");
> ///////////////// TEST CODE ENDS /////////////////
>
> It is a simple code to draw a gradient with four stops.
> Since I have put color stops at offset 0 and 1 to red, I expected the result surface to have value RGBA(255, 0, 0, 255) at the leftmost and rightmost pixels, but the result image shows that the leftmost edge has a pixel value of RGBA(253, 1, 0, 255), and the rightmost edge a value of RGBA(252, 2, 0, 255).
>
> Is this normal behavior in Cairo? What should I do to get exact color values at both ends?
>
> Thanks,
> Dongyeon Kim
> --
> cairo mailing list
> [email protected]
> http://lists.cairographics.org/mailman/listinfo/cairo
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.