Hi!
I'm trying to write a script in Python that is similar to the built-in "animation-play" plugin. I am currently trying to figure out how to draw a preview of my image in a GTK window. "animation-play" does this by copying pixel regions from the image and then "manually" (> 400 lines of C code) converting them into a buffer that can then be drawn using "gdk_draw_rgb_image()".
I'd rather not (for performance reasons alone) re-implement this pixel buffer conversion in my skript, so I wonder if there is a more convenient way for doing this.
Are there plugins/procedures available (preferrably written in C) to do this "pixel buffer" conversion?
Is there a Python script/plugin out there that has a custom UI with a preview function? (I only found one that uses a temporary layer in the orginial Image for the preview)
I found a "GimpPreview" in the C API, but that does not seem to be available in the Python API?
(EDIT: Moved this to the plugins forum)
Update: For now I just limit
Update: For now I just limit my script to RGBA images and use the byte string from the pixel region directly:
buffer = pr[ pr.x : pr.x + pr.w, pr.y : pr.y + pr.h ] window.draw_rgb_32_image( gc, 0, 0, pr.w, pr.h, gtk.gdk.RGB_DITHER_NONE, buffer, pr.w * 4 )GDK also has functions for RGB, grayscale and indexed images, so maybe I don't have to convert the buffer after all...
Supposedly...
There is supposed to be a preview widget exposed in python, but I have never been able to get it to work.
I've asked i a couple of places.
Looking at the source for the pygimp plugin (gimpui.c) there appears
to be widget constructors exposed in python:
/* ----------- GimpDrawablePreview ----------- */
#line 1952 "gimpui.override"
static int
_wrap_gimp_drawable_preview_new(PyGObject *self, PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "drawable", NULL };
PyGimpDrawable *py_drawable;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!|:GimpDrawablePreview.__init__", kwlist,
PyGimpDrawable_Type, &py_drawable))
return -1;
if (!py_drawable->drawable)
py_drawable->drawable = gimp_drawable_get(py_drawable->ID);
if (pygobject_construct(self, "drawable", py_drawable->drawable, NULL))
return -1;
g_object_set_data_full(self->obj, "pygimp-drawable-preview-pydrawable",
py_drawable,
(GDestroyNotify)pygimp_decref_callback);
Py_INCREF(py_drawable);
return 0;
}
along with all the methods in the docs
http://developer.gimp.org/api/2.0/libgimp/GimpDrawablePreview.html
exposed as well.
Looking in the binary_gimpui.pyd these objects exist, specifically,
the pygimp-drawable-preview-pydrawable one.
Also mentioned here: http://forum.meetthegimp.org/index.php?topic=87.0
I've been trying to get anything to work with this but no luck yet. I'm hoping someone who actually understands python will give this a shot ;)
-Rob A>