Re: Python

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Samuel,
On Mon, Sep 29, 2008 at 7:40 PM, Samuel <samuel_albrecht@xxxxxx> 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 thefollowing approach, which does notrequire any knowledge of tiles and is quite simple. If you are copyinglarge areas (eg 1024x1024), a tile based approach may be moreappropriate.

# 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 asecond for a VGA picture). Note that the above assumes  certainsimilarities between the layers -- ie. they are of the samedimensions,and they either both have an alpha channel or they bothlack an alpha channel. It also assumes they are of the same type (asin, both belonging to an RGB image, or both belonging to an Indexedimage, or both belonging to a Greyscale image)
HTH,David

-- Everything has reasons. Nothing has justification.Äio havas kialojn; NeniaÄo havas pravigeron._______________________________________________Gimp-developer mailing listGimp-developer@xxxxxxxxxxxxxxxxxxxxxxxxxxx://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux