[cairo] Image surface : BGRA or ARGB ?
Behdad Esfahbod
behdad at cs.toronto.edu
Wed Mar 22 15:50:49 PST 2006
On Wed, 22 Mar 2006, [iso-8859-1] Timothée Lecomte wrote:
> Hi
>
> I have noticed a difference between the documentation and the actual
> behaviour of cairo_image_surface_create_for_data().
>
> The buffer is supposed to be in the format ARGB :
>
> "CAIRO_FORMAT_ARGB32 each pixel is a 32-bit quantity, with alpha in the
> upper 8 bits, then red, then green, then blue."
Upper 8 bits maps to the fourth byte in a little-endian machine
like the intels.
behdad
> However, in practise, I found it to be BGRA.
>
> Test case (cr is the actual context where you will want to draw on):
>
> unsigned char * image255;
> cairo_surface_t *image_surface;
> cairo_pattern_t *pattern;
> cairo_matrix_t matrix;
>
> /* cairo image buffer, in the format BGRABGRA... */
> image255 = (unsigned char*) malloc(4*sizeof(unsigned char));
> *(image255) = 1;
> *(image255 +1) = 0;
> *(image255 +2) = 1;
> *(image255 +3) = 0;
>
> image_surface = cairo_image_surface_create_for_data(image255,
> CAIRO_FORMAT_RGB24, 1, 1, 4*1);
>
> double scale_x = 1./100;
> double scale_y = 1./100;
>
> pattern = cairo_pattern_create_for_surface( image_surface );
> cairo_pattern_set_filter(pattern,CAIRO_FILTER_FAST);
> cairo_matrix_init_scale(&matrix,scale_x,scale_y);
> cairo_pattern_set_matrix(pattern,&matrix);
> cairo_set_source(cr,pattern);
> cairo_paint(cr);
> cairo_pattern_destroy(pattern);
> cairo_surface_destroy(image_surface);
> free(image255);
>
>
> Is the problem in my code, in cairo code or in the cairo doc ?
> Should I post a bug report for it ?
>
> Best regards,
>
> Timothée
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo
>
>
--behdad
http://behdad.org/
"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
-- Dan Bern, "New American Language"
More information about the cairo
mailing list