Hi Samuel,

On Mon, Sep 29, 2008 at 7:40 PM, Samuel <[EMAIL PROTECTED]> wrote:
> I have been at the GIMP IRC channel and they told me that C is faster than 
> Python if I want many pixel ops. I wrote a test plugin in Python which copies 
> a layer pixel per pixel to another one and it needs several minutes for a vga 
> picture.

Sven has covered how to access tiles faster. There is also the
following approach, which does not
require any knowledge of tiles and is quite simple. If you are copying
large areas (eg 1024x1024), a tile based approach may be more

# create a pixel region:

pr = sourcelayer.get_pixel_rgn (0, 0, sourcelayer.width,
sourcelayer.height, False, False)

# then you read all pixels from that region

pixels = pr[:,:]

# create another region on the destination

pr2 = destlayer.get_pixel_rgn (0, 0, destlayer.width,
destlayer.height, True, False)

# and write the stored pixels

pr2[:,:] = pixels

Every pixel has now been copied (on my machine, this takes less than a
second for a VGA picture). Note that the above assumes  certain
similarities between the layers -- ie. they are of the same
dimensions,and they either both have an alpha channel or they both
lack an alpha channel. It also assumes they are of the same type (as
in, both belonging to an RGB image, or both belonging to an Indexed
image, or both belonging to a Greyscale image)


Everything has reasons. Nothing has justification.
Ĉio havas kialojn; Neniaĵo havas pravigeron.
Gimp-developer mailing list

Reply via email to