Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get_pixel_rgn() function in gimp 3 python
#5
(04-04-2021, 05:02 AM)ksoman Wrote: Is there any function in gimp 3 python which replaces layer.get_pixel_rgn(0, 0, layer.width, layer.height) ? I tried but this function is not working.

You may already have answered the question but for the sake of others following the same path the following works for me:

Code:
width = drawable.get_width()
height = drawable.get_height()

buffer = drawable.get_buffer()

rect = Gegl.Rectangle.new(0, 0, width, height)
src_pixels = buffer.get(rect, 1.0, None, Gegl.AbyssPolicy.CLAMP)

(You might want to consider not reading the whole of the image in one go if you are working with large files - possible read a row at a time and iterate through the image.)

Note, however, that whilst this works for images in 8-bit integer encoding so that src_pixels[0] = pixel(0,0) red, src_pixels[1] = pixel(0,1) blue etc things look like a work in progress for higher bit-depths.

For 16-bit integer src_pixels is still an 8-bit array but is twice the length. You would have to combine bytes to get the pixel components. Similarly for 32-bit integers there is a further doubling of the array size.

Floating-point values don't seem to convert to the values that I was expecting - this might be as the result of the conversion form 8-bit integer to floating-point form, I don't know.

The function to get the components of a pixel also only seems to give 8-bit values regardless of the bit-depth of the image - and for higher bit-depths these are not just truncated values they are just wrong.

Code:
pixel = drawable.get_pixel(1, 1)

(These comments apply to GIMP V2.99.6)
Reply


Messages In This Thread
RE: get_pixel_rgn() function in gimp 3 python - by programmer_ceds - 05-04-2021, 03:35 PM

Forum Jump: