GimpUi.export_image function not usable from Python
GIMP version: current master
Operating System: Windows 10 Home, 64-bit
Package: self built
The current plug-in API has the following function defined in gimpexport.c.
GimpExportReturn
gimp_export_image (GimpImage **image,
gint *n_drawables,
GimpDrawable ***drawables,
const gchar *format_name,
GimpExportCapabilities capabilities)
The comments say that it may return a new image and drawables. This is fine in C but in languages like Python we cannot change the parameters which makes it difficult if not impossible to call this function from within a Python plug-in.
Reproduction
Always
Reproduction steps:
- Use code like this to call from Python, assuming you have valid image, etc parameters
export = GimpUi.export_image (image, n_drawables, drawables, "ora", flags)
…
Expected result: A return value from export
Actual result: Crash that image is not a GimpImage
Additional information
This kind of API is difficult to handle for certain languages. We should change the signature of export_image and maybe other similar functions to make it easier to be called.
Part of the discussion that took place on IRC:
<Wormnest> Jehan: Do you have any idea about the Q I asked earlier?
<Wormnest> How would I use GimpUi.export_image from python? export = GimpUi.export_image (image, drawables, "ora", flags) does not work nor does export = GimpUi.export_image (GObject.Value(Gimp.Image, image), drawables, "ora", flags)
<Jehan> GimpUi.export_image(image, [drawable1, drawable1], "png", GimpUi.ExportCapabilities.CAN_HANDLE_RGB |GimpUi.ExportCapabilities.CAN_HANDLE_ALPHA)
<Wormnest> I am assuming that is because the C type is c:type="GimpDrawable*** and can return a changed image pointer which as far as I know in python you can´t have a changed parameter
<Jehan> Wormnest: ^ doesn't this work?
<Jehan> Wormnest: oh right, it's an in/out.
<Jehan> Wormnest: my guess is that it won't work in its current version.
<Wormnest> Jehan: yes, that´s what I was starting to think
<Jehan> Wormnest: seriously we should really review this API. It's just horrible deprecated madness.
<Wormnest> Jehan: Do you want me to add a report that we need a new API call to support this
<Jehan> Wormnest: first we'd need to at least add the appropriate metadata. Maybe test. Was it like (inout) or something?
<Wormnest> Jehan: I have no idea about the introspection API, never studied it so far.
<Jehan> Yep it's inout.
<Jehan> @image: (inout): Pointer to the image.
<Jehan> Wormnest: @drawables is also (inout) as well as @n_drawables.
<Jehan> And probably some (transfer full) are needed.
<Jehan> Grumbl, this API has always been horrible in my book.
<Jehan> Also it has a GUI which has actually been deprecated for years (before 2.8!), and only raised with a specific dev environment variable, which explains why it is inside GimpUi even though there appears to be no reason why (we never see the GUI).
<Jehan> Wormnest: yeah I guess we just really need to review this call in depth and just remove it/replace it by something sane. :-D
<Jehan> Wormnest: do a report, good idea. :-)
<Wormnest> Jehan: ok will add a report for the export_image
<Jehan> Wormnest: ah yeah you can ask nielsdg about this function too. Though I really feel we should overhaul it anyway.
<Jehan> Wormnest: this export function is really like a symbol of GIMP old ways.
<Jehan> Wormnest: like API technical debt at its finest. :-D
<Wormnest> Jehan: Yes, it seems best to change this and other similar functions.