[cairo-bugs] [Bug 43158] Does not hold to requested or stated pixel formats

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Tue Nov 22 02:58:14 PST 2011


https://bugs.freedesktop.org/show_bug.cgi?id=43158

Andrea Canciani <ranma42 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #1 from Andrea Canciani <ranma42 at gmail.com> 2011-11-22 02:58:14 PST ---
(In reply to comment #0)
> On my machine, the following code will illustrate cairo's failure to store its
> image surface in the requested format.
> Results indicate that the used format comes out BGRA32 no matter what it says
> it has chosen.

You should never access RGBA32 or RGB24 as single bytes.
As explained in
http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t they
should be used as 32-bits quantities.

> I can't tell how I can figure out which backend I'm running under, so I've put
> this in "general".

You're using the image backend, but the same issue should happen everywhere.

Please fix as suggested and check again.

> 
> #include <cairo/cairo.h>
> #include <stdio.h>
> #include <stdint.h>
> int main(int argc, char** argv){
>     const int w=10, h=10;
>     cairo_surface_t* ul = cairo_image_surface_create(
>         CAIRO_FORMAT_RGB24,w,h);
>     printf("%d\n", cairo_image_surface_get_format(ul));
>     cairo_t* draw = cairo_create(ul);
>     cairo_set_source_rgba(draw,1,0.5,0.27,1);
>     cairo_paint(draw);
>     uint8_t* dat = (uint8_t*)(cairo_image_surface_get_data(ul));
>     for(unsigned iy=0; iy<h; ++iy){
>         for(unsigned ix=0; ix<w; ++ix){
>             unsigned pixelP = cairo_image_surface_get_stride(ul)*iy + ix;

     uint32_t* dat32 = (uint32_t*)(dat + pixelP);

             printf(
                 "%x, %x, %x, %x\n",
                 (dat32[0] >> 24) & 0xff,
                 (dat32[0] >> 16) & 0xff,
                 (dat32[0] >> 8) & 0xff,
                 (dat32[0] >> 0) & 0xff);
>         }
>         printf("%c", '\n');
>     }
> }

Please try the modified code and reopen the bugreport if the problem persists.

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA Contact for the bug.


More information about the cairo-bugs mailing list