1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| void gdk_pixbuf_copy_area_with_alpha(const GdkPixbuf *src_pixbuf,
int src_x, int src_y, int width, int height, GdkPixbuf *dest_pixbuf,
int dest_x, int dest_y)
{
if (src_pixbuf && (gdk_pixbuf_get_n_channels(src_pixbuf)>3))
{
guchar *pixel_src=NULL;
guchar *pixel_dest=NULL;
register gint i=0, j=0;
gint x=dest_x, y=dest_y;
gint dest_width=gdk_pixbuf_get_height(dest_pixbuf);
if (!dest_pixbuf)
dest_pixbuf=gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
// Ajout du canal alpha au cas où sur le pixbuf destination.
if (gdk_pixbuf_get_n_channels(dest_pixbuf)<4)
{
GdkPixbuf *desta=NULL;
desta=gdk_pixbuf_add_alpha(dest_pixbuf, TRUE, 255, 255, 255);
g_object_unref(dest_pixbuf);
dest_pixbuf=desta;
}
pixel_src=gdk_pixbuf_get_pixels(src_pixbuf);
pixel_dest=gdk_pixbuf_get_pixels(dest_pixbuf);
for (j=src_y; j < src_y+height; j++)
{
x=dest_x;
for (i=src_x; i < src_x+width; i++)
{
if (pixel_src[(i*4)+(j*width*4)+3]!=0)
{
pixel_dest[(x*4)+(y*dest_width*4) ]=pixel_src[(i*4)+(j*width*4) ];
pixel_dest[(x*4)+(y*dest_width*4)+1]=pixel_src[(i*4)+(j*width*4)+1];
pixel_dest[(x*4)+(y*dest_width*4)+2]=pixel_src[(i*4)+(j*width*4)+2];
}
x++;
}
y++;
}
}
} |
Partager