Reputation: 41
I am trying to perform alpha blending with pixman_image_fill_boxes().
void blend1(void *di, int p, int w, int h, int r, int g, int b, int a)
{
pixman_color_t color = { .red = r, .green = g, .blue = b, .alpha = a };
pixman_image_t *dst = pixman_image_create_bits(PIXMAN_r8g8b8a8, w, h, di, p);
pixman_box32_t box = { .x1 = 0, .y1 = 0, .x2 = w, .y2 = h };
pixman_image_fill_boxes(PIXMAN_OP_OVER, dst, &color, 1, &box);
pixman_image_unref(dst);
}
But di
remains unchanged. After some debugging, _pixman_implementation_lookup_composite() seems to return noop implementation.
Where am I going wrong with this simple operation ?
Upvotes: 1
Views: 45
Reputation: 41
pixman_color_t
has u16 channels, instead of usual u8. And the values must be between 0 to 0xffff, instead of usual 0 to 0xff.
bug
pixman_color_t color = { .red = r, .green = g, .blue = b, .alpha = a };
fix
pixman_color_t color;
color.red = (double)r*0xffff/0xff;
color.green = (double)g*0xffff/0xff;
color.blue = (double)b*0xffff/0xff;
color.alpha = (double)a*0xffff/0xff;
// premul
color.red = color.red*color.alpha/0xffff;
color.green = color.green*color.alpha/0xffff;
color.blue = color.blue*color.alpha/0xffff;
Pixel format also corrected to PIXMAN_a8r8g8b8
.
Upvotes: 1