[cairo] [Bug 35407] New: boundary of image gets wrong color

Bill Spitzak spitzak at gmail.com
Fri Mar 18 11:06:21 PDT 2011


That's double premultiplication of the image border.

The immediate solution is to use CAIRO_EXTEND_REPEAT (or any setting 
other than none) and always use a rectangle to crop the result to the 
area you expect.

I also still recommend that cairo be altered so that CAIRO_EXTEND_NONE 
does this automatically, as the current behavior is useless and not at 
all what a beginning user expects. Using "min" for the intersection with 
the current region+mask will avoid double premultiplication, which would 
be much better than what the cairo client can do (unless more complex 
methods of intersecting paths are added).

bugzilla-daemon at freedesktop.org wrote:
> https://bugs.freedesktop.org/show_bug.cgi?id=35407
> 
>            Summary: boundary of image gets wrong color
>            Product: cairo
>            Version: 1.10.2
>           Platform: ARM
>         OS/Version: Linux (All)
>             Status: NEW
>           Severity: major
>           Priority: medium
>          Component: general
>         AssignedTo: cworth at cworth.org
>         ReportedBy: clock9 at naver.com
>          QAContact: cairo-bugs at cairographics.org
> 
> 
> Created an attachment (id=44569)
>  --> (https://bugs.freedesktop.org/attachment.cgi?id=44569)
> result of test.
> 
> I got a problem in cairo 1.10.2.
> 
> The boundary of an image I try to draw has wrong color.
> 
> It's 1 pixel outer box.
> 
> you can see it with the attached file.
> 
> 
> '_cairo_image_surface_paint' function (It's not in 1.8.8 so
> '_cairo_surface_fallback_paint' function is used),
> and the decimal scaling, and the alpha property of the image surface,
> seem to make this issue.
> 
> please take this issue and please let me know how to make it right.
> 
> 
> ================================================
> my test code and conditions are below.
> ================================================
> A. The conditions
> 
> 1. set operator as CAIRO_OPERATOR_SOURCE
> 2. scale factor is decimal not integer. like cairo_scale(cr,4.1) in the test
> code
> 3. the image surface has no alpha format.
> 
> B. The Test Code
> 
> {
>     char outfile[100];
> 
>     uint32_t* dst_buffer = create_buffer32(480*800, 0xff00ff00);
> 
>     cairo_surface_t* cairo_surface = cairo_image_surface_create_for_data (
>                                                           (unsigned
> char*)dst_buffer,
>                                                            CAIRO_FORMAT_RGB24,
>                                                           480, 800,
>                                                          
> cairo_format_stride_for_width(CAIRO_FORMAT_RGB24,
>                                                           480));
>     cairo_t* cr = cairo_create(cairo_surface); 
> 
>     cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
> 
>     cairo_scale(cr,4.1, 4.1);
> 
>     cairo_surface_t* src_surface =
> cairo_image_surface_create_from_png("/white.png"); // just white image file
> 25x16.
> 
>     cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
> 
>     cairo_pattern_t* pattern = cairo_pattern_create_for_surface(src_surface);
> 
>     cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
> 
>     cairo_matrix_t matrix = { 1.0, 0, 0, 1.0, 0, 0 };
> 
>     cairo_pattern_set_matrix(pattern, &matrix);
> 
>     cairo_translate(cr, 8, 8);
> 
>     cairo_set_source(cr, pattern);
> 
>     cairo_pattern_destroy(pattern);
> 
>     cairo_rectangle(cr, 0, 0, 25, 16);
> 
>     cairo_clip(cr);
> 
>     cairo_paint_with_alpha(cr, 1.0);
> 
>     sprintf(outfile,"test.png");
> 
>     cairo_surface_write_to_png(cairo_surface,outfile);
> 
>     cairo_surface_destroy(src_surface);
> 
>     cairo_surface_destroy(cairo_surface);
> 
>     cairo_destroy(cr);
> 
>     destroy_buffer32(dst_buffer);    
> }
> 


More information about the cairo mailing list