user1276209
user1276209

Reputation:

PyGTK gtk.gdk.Pixbuf.copy_area erroneously copying alpha bits

Here is a picture illustrating the issue I am having:

This picture was created with the following:

cube.copy_area(0, 0, cube.get_width(), cube.get_height(), self.canvas, o2i[0], o2i[1])

where cube and canvas are of the type gtk.gdk.Pixbuf. o2i is simply a tuple containing the results of an isometric placement function that draws back to front.

The issue I'm having, as I hope is evident, is that in copying cube, which has an alpha channel, to canvas, the copy_area() function is also setting the bits in the destination Pixbuf to 0 alpha. This makes sense if copy_area() really just copies one buffer stream into another at an offset, but is clearly not my intent. Is there any way to copy the contents of one Pixbuf into another, using the source Pixbuf's alpha channel as a copy mask?

For reference, here is PyGTK's documentation for copy_area().

Upvotes: 0

Views: 365

Answers (1)

Christoph Burschka
Christoph Burschka

Reputation: 4689

I think what you want is composite(). It's somewhat inconvenient to use because it handles the coordinates differently, but something like this should make it work exactly like copy_area:

def copy_area_composite(source_buf, source_x, source_y, width, height, dest_buf, dest_x, dest_y):
    source_buf.composite(dest_buf, dest_x, dest_y, width, height, dest_x-src_x, dest_y-rect_y, 1, 1, GdkPixbuf.InterpType.NEAREST, 255)

Upvotes: 1

Related Questions