(07-14-2025, 05:52 PM)teapot Wrote: Hi Ofnuts, Yes, that's right. The image's precision can be integers or floats of 16 or 32 bits.
OK, so
- I create a 32-bit image, and fill with a (100%,50%,25%) color (values in the FG color selector, in other words #FF8040).
- Get a pixel region. rgn.bpp is 3, so data is converted to one byte per channel.
- Call pdb.gimp_plugin_enable_precision()
- rgn.bpp is now 12 (coherent with 32-bit per channel (no alpha channel).
Code:
➤> rgn=image.active_layer.get_pixel_rgn(0,0,10,10)
➤> rgn.bpp # Check the precision of the returned data
3
➤> # Tell Gimp we are a big boy and can be told the truth
➤> pdb.gimp_plugin_enable_precision()
➤> rgn=image.active_layer.get_pixel_rgn(0,0,10,10)
➤> rgn.bpp
12
➤> # OK, much better (no alpha, so 3 channels of 4 bytes each)
➤> # Let's try some decoding
➤> import struct
➤> struct.unpack('f',rgn[0,0][0:4]) # Native order, get 1 for Red, as expected
(1.0,)
➤> struct.unpack('<f',rgn[0,0][0:4]) # Little-endian order (same as native on my x86 PC, still OK)
(1.0,)
➤> struct.unpack('>f',rgn[0,0][0:4]) # Big-endian, WTF
(4.600602988224807e-41,)
➤> struct.unpack('f',rgn[0,0][4:8]) # Green (obviously linear)
(0.21586056053638458,)
➤> struct.unpack('f',rgn[0,0][8:12]) # Blue (obviously linear too)
(0.051269471645355225,)
➤>