Previous | Next

Pixel regions


# from arclayer.py
srcRgn = layer.get_pixel_rgn(0, 0, w, h, False, False)
src_pixels = array("B", srcRgn[0:srcWidth, 0:srcHeight])

dstRgn = destDrawable.get_pixel_rgn(0, 0, w, w, True, True)
p_size = len(srcRgn[0,0])       
dest_pixels = array("B", "\x00" * (w * h * p_size))

# Loop over the region:    
for x in xrange(0, srcWidth - 1) :
  for y in xrange(0, srcHeight) :
    newval = src_pixels[src_pos: src_pos + p_size]
    dest_pixels[dest_pos : dest_pos + p_size] = newval
  gimp.progress_update(float(x)/layer.width)

# Copy the whole array back to the pixel region:
dstRgn[0:newWidth, 0:newHeight] = dest_pixels.tostring() 

dstDrawable.flush()
dstDrawable.merge_shadow(TRUE)
dstDrawable.update(0, 0, newwidth, newheight)
arclayer is mine and is in the gimp-plugin-template.

"B" in the python array class means an array of unsigned int. Nice that they made it so clear.


Written this way, arclayer is almost as fast as the C version.

Written four other ways, it's way slow.


(Next slide: fast)