Re: [Gimp-developer] Need help with Python plugin exporting to raw file (using Gimp 2.9)

It should not be a problem I think since I work on both Mac and
Windows. GTK3 and friends build just fine for me on those platforms.

What problems are you envisaging?


On Sat, Feb 21, 2015 at 8:11 AM, Joao S. O. Bueno <gwidion gmail com> wrote:
On 21 February 2015 at 10:35, Partha Bagchi <partha1b gmail com> wrote:
Hi João,

What's your timeframe for modifying pygimp to use introspection? I
have not yet built glib and friends with introspection because it's a
pain and it's finicky. :)

No idea on "timeframes" . Introspection as it is now, since GIMP
itself does not make use of it,
is mostly needed for the UI parts of Pygimp.  (i.e. changing from
traditional pygtk
to gobject introspection gtk)  - but I jsut remebered the major blocker there:
GUI building with gobject introspection is known not to work well with
GTK2 - we'd
need to change pygimp to gtk3.

That would not be a problem for Linux systems (hey, Pygimp used
TCL based Tk widgets when it first debut), it should be a nono for
packagers for Mac OS X and Windows.

Can someone who works on the installers  give me some feedback on that?


On Fri, Feb 20, 2015 at 11:54 PM, Joao S. O. Bueno <gwidion gmail com> wrote:
Hi  -
I've actually comitted the above method - but beware it is subject to
some changes.

I've added the "precision" read-only property to gimp-images, and the
"get_data" method
to drawables (layers and channels) -
get_data returns a Python array.array object - it even features
conveninent methods
to write itself to a file ( -
For now, it  takes an optional string argument representing a BABL pixel format
( and will return an array of
the apropriate data type.
The default is "RGBA float" - but I think it would be better to change
it to default to the
drawable native data type- still allowing an explicit format to be passed.

I will probably keep it the return type an array, but possibly
subclass it to an object that can
take in 2D indexes to ease pixel access, as  currently existing python
"pixel_region" object allows
(thus: data[100, 50] will be as valid as data[50 * drawable.width +
100] to get to a single pixels.

On the short term roadmap there is a "set_data"  - (or maybe "blit ")?

And at the point in time it is possible to use gobject introspection along
pygimp (it can't be done in a straightforward way), make
drawable.get_buffer directly available and returning a Gegl buffer
wrapped in a convenient Python object.

On 21 February 2015 at 00:49, Joao S. O. Bueno <gwidion gmail com> wrote:
Getting there... no need to poke me for now -

GIMP 2.9.1 Python Console
Python 2.7.5 (default, Nov  3 2014, 14:26:24)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)]
img = gimp.image_list()[0]
a = img.layers[0].get_data()
array('f', [0.0003035269910469651, 0.0003035269910469651,
0.0003035269910469651, 0.6235294342041016, 0.0003035269910469651,
0.0003035269910469651, 0.0003035269910469651, 0.6235294342041016,

On 20 February 2015 at 09:50, Joao S. O. Bueno <gwidion gmail com> wrote:
Hi Alek_

it turns out that the Python bindings for GIMP had not been updated to
deal with higher precision images as of yet.

Don't despair - since you had built GIMP master, this is as good time
as any to get it going. :-)

You can get to know the image precision (and even set it) thorugh the
PDB, though, with a call to:


Now - for the actual business: I think there are two ways to go - one
short term, with
a "get" and "set" buffer method on Python drawables that will just
copy the inner image data
and make it available in a Python array. That would suffice for most
needs like yours, I guess.

The other, longer term and proper way, is to write calls to get the
proper GEGL Buffer objects
in Python, using GEGL Python bindings - that will allow the use of any
of GEGL's operations
on GIMP Image data and commit it back - but it will also require the
python-gegl package.

Those bindings are currently living in my personal repo, and  could
work for you right now, as they do allow access to the buffer data -
but you have to build GEGL with the extra "--enable-introspection"
switich to get then going.
( )

But -- let's focus in enabling one to get the high-depth pixel
contents from GIMP without need for those for now.
Feel free to poke me again in 24 hours if there are no news on this subject.


On 19 February 2015 at 23:06, Alek _ <spectatoe outlook com> wrote:

I'm using Gimp 2.9 experimental build, which I downloaded from, to specifically have edit ability with 16-bit per channel
images.  I originally posted in and was told I should try here.

I'm trying to write a Python plugin to export an image as a raw file
(just data, no header).  The current option to export as raw image data
(File -> Export as -> Raw image data) seems to only support writing out as 8-bit even when the image 
 is greater than 8-bit.  So I wanted to write a plugin so I could export
 my 16-bit per channel image to a raw file with the 16-bit data

My image is a 16-bit grayscale 3x3 image with a checkerboard pattern of alternating white and black 

I used the sample script '' from
 as a guide on how to iterate through every pixel.  I have some
questions and ran into some problems.  What I have so far can be seen here 
(  It just iterates through the pixels and outputs values to the
error console.

1. How do I query for the precision?  That is, I want to know if the
current image is 8-bit gamma integer, or 16-bit linear integer, or
something else.  I looked at the image object's attributes and didn't
find anything.

2. When I get the pixel value from srcTile[x,y], the value is always
8-bit.  With the white pixels, the value should be 65535 but I got 255.  How do I get the
proper value?  When I use the Color Picker tool with info window, it says 65535 for white.  How do I 
get that value?

3. My code creates a new layer from visible and then queries the pixels from that.  In my image, all 
values returned are 255 even for the black pixels.  When I put my checkboard pattern on the Background 
layer and query that layer, I get correct values (though in 8-bit).  For any other layer other than 
Background, the values are always 255.  I don't know what I'm doing wrong.

Can someone help me or point me in the right direction?


gimp-developer-list mailing list
List address:    gimp-developer-list gnome org
List membership:
List archives:
gimp-developer-list mailing list
List address:    gimp-developer-list gnome org
List membership:
List archives:

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