[cairo] Image surface : BGRA or ARGB ?
Timothée Lecomte
timothee.lecomte at ens.fr
Wed Mar 22 15:45:57 PST 2006
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."
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
More information about the cairo
mailing list