2000-05-31 21:24:14 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
2003-07-03 08:47:26 +08:00
|
|
|
* Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
|
2000-05-31 21:24:14 +08:00
|
|
|
*
|
2019-09-11 03:38:11 +08:00
|
|
|
* gimpfile_pdb.c
|
2000-05-31 21:24:14 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2000-05-31 21:24:14 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2000-05-31 21:24:14 +08:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-06-02 05:18:04 +08:00
|
|
|
* Lesser General Public License for more details.
|
2000-05-31 21:24:14 +08:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2000-05-31 21:24:14 +08:00
|
|
|
*/
|
|
|
|
|
2007-01-09 18:52:47 +08:00
|
|
|
/* NOTE: This file is auto-generated by pdbgen.pl */
|
2000-05-31 21:24:14 +08:00
|
|
|
|
2002-05-14 07:30:23 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2022-03-28 21:13:17 +08:00
|
|
|
#include "stamp-pdbgen.h"
|
|
|
|
|
2000-06-02 05:18:04 +08:00
|
|
|
#include "gimp.h"
|
2000-05-31 21:24:14 +08:00
|
|
|
|
2010-07-07 17:43:10 +08:00
|
|
|
|
|
|
|
/**
|
2019-09-11 03:38:11 +08:00
|
|
|
* SECTION: gimpfile
|
|
|
|
* @title: gimpfile
|
2017-02-18 22:08:25 +08:00
|
|
|
* @short_description: Image file operations (load, save, etc.)
|
2010-07-07 17:43:10 +08:00
|
|
|
*
|
2017-02-18 22:08:25 +08:00
|
|
|
* Image file operations (load, save, etc.)
|
2010-07-07 17:43:10 +08:00
|
|
|
**/
|
|
|
|
|
|
|
|
|
2000-08-25 23:38:38 +08:00
|
|
|
/**
|
|
|
|
* gimp_file_load:
|
|
|
|
* @run_mode: The run mode.
|
2019-09-12 03:48:34 +08:00
|
|
|
* @file: The file to load.
|
2000-08-25 23:38:38 +08:00
|
|
|
*
|
2005-10-17 23:15:20 +08:00
|
|
|
* Loads an image file by invoking the right load handler.
|
2000-08-25 23:38:38 +08:00
|
|
|
*
|
2004-06-22 16:54:27 +08:00
|
|
|
* This procedure invokes the correct file load handler using magic if
|
|
|
|
* possible, and falling back on the file's extension and/or prefix if
|
2020-04-14 02:25:32 +08:00
|
|
|
* not.
|
2000-08-25 23:38:38 +08:00
|
|
|
*
|
2019-08-15 16:01:08 +08:00
|
|
|
* Returns: (transfer none): The output image.
|
2010-09-16 04:07:36 +08:00
|
|
|
**/
|
2019-08-11 20:20:05 +08:00
|
|
|
GimpImage *
|
2001-12-19 08:13:16 +08:00
|
|
|
gimp_file_load (GimpRunMode run_mode,
|
2019-09-12 03:48:34 +08:00
|
|
|
GFile *file)
|
2000-08-25 23:38:38 +08:00
|
|
|
{
|
2019-07-30 16:51:16 +08:00
|
|
|
GimpValueArray *args;
|
|
|
|
GimpValueArray *return_vals;
|
2019-08-11 20:20:05 +08:00
|
|
|
GimpImage *image = NULL;
|
2000-08-25 23:38:38 +08:00
|
|
|
|
2019-08-08 19:01:50 +08:00
|
|
|
args = gimp_value_array_new_from_types (NULL,
|
|
|
|
GIMP_TYPE_RUN_MODE, run_mode,
|
2019-09-12 03:48:34 +08:00
|
|
|
G_TYPE_FILE, file,
|
2019-07-30 16:51:16 +08:00
|
|
|
G_TYPE_NONE);
|
|
|
|
|
2023-10-17 04:07:55 +08:00
|
|
|
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
|
|
|
"gimp-file-load",
|
|
|
|
args);
|
2019-07-30 16:51:16 +08:00
|
|
|
gimp_value_array_unref (args);
|
2000-08-25 23:38:38 +08:00
|
|
|
|
2019-09-04 07:49:35 +08:00
|
|
|
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
2019-09-04 08:49:33 +08:00
|
|
|
image = GIMP_VALUES_GET_IMAGE (return_vals, 1);
|
2000-08-25 23:38:38 +08:00
|
|
|
|
2019-07-30 16:51:16 +08:00
|
|
|
gimp_value_array_unref (return_vals);
|
2000-08-25 23:38:38 +08:00
|
|
|
|
2019-08-11 20:20:05 +08:00
|
|
|
return image;
|
2000-08-25 23:38:38 +08:00
|
|
|
}
|
|
|
|
|
2005-10-17 23:15:20 +08:00
|
|
|
/**
|
|
|
|
* gimp_file_load_layer:
|
|
|
|
* @run_mode: The run mode.
|
2019-08-11 20:20:05 +08:00
|
|
|
* @image: Destination image.
|
2019-09-12 03:48:34 +08:00
|
|
|
* @file: The file to load.
|
2005-10-17 23:15:20 +08:00
|
|
|
*
|
2006-11-04 01:12:27 +08:00
|
|
|
* Loads an image file as a layer for an existing image.
|
2005-10-17 23:15:20 +08:00
|
|
|
*
|
|
|
|
* This procedure behaves like the file-load procedure but opens the
|
2006-11-04 01:12:27 +08:00
|
|
|
* specified image as a layer for an existing image. The returned layer
|
2010-09-06 06:03:29 +08:00
|
|
|
* needs to be added to the existing image with
|
|
|
|
* gimp_image_insert_layer().
|
2005-10-17 23:15:20 +08:00
|
|
|
*
|
2019-08-15 18:12:25 +08:00
|
|
|
* Returns: (transfer none): The layer created when loading the image file.
|
2005-10-17 23:15:20 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2010-09-16 04:07:36 +08:00
|
|
|
**/
|
2019-08-13 19:59:33 +08:00
|
|
|
GimpLayer *
|
2005-10-17 23:15:20 +08:00
|
|
|
gimp_file_load_layer (GimpRunMode run_mode,
|
2019-08-11 20:20:05 +08:00
|
|
|
GimpImage *image,
|
2019-09-12 03:48:34 +08:00
|
|
|
GFile *file)
|
2005-10-17 23:15:20 +08:00
|
|
|
{
|
2019-07-30 16:51:16 +08:00
|
|
|
GimpValueArray *args;
|
|
|
|
GimpValueArray *return_vals;
|
2019-08-13 19:59:33 +08:00
|
|
|
GimpLayer *layer = NULL;
|
2005-10-17 23:15:20 +08:00
|
|
|
|
2019-08-08 19:01:50 +08:00
|
|
|
args = gimp_value_array_new_from_types (NULL,
|
|
|
|
GIMP_TYPE_RUN_MODE, run_mode,
|
2019-08-29 17:25:35 +08:00
|
|
|
GIMP_TYPE_IMAGE, image,
|
2019-09-12 03:48:34 +08:00
|
|
|
G_TYPE_FILE, file,
|
2019-07-30 16:51:16 +08:00
|
|
|
G_TYPE_NONE);
|
2005-10-17 23:15:20 +08:00
|
|
|
|
2023-10-17 04:07:55 +08:00
|
|
|
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
|
|
|
"gimp-file-load-layer",
|
|
|
|
args);
|
2019-07-30 16:51:16 +08:00
|
|
|
gimp_value_array_unref (args);
|
2005-10-17 23:15:20 +08:00
|
|
|
|
2019-09-04 07:49:35 +08:00
|
|
|
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
2019-09-04 08:49:33 +08:00
|
|
|
layer = GIMP_VALUES_GET_LAYER (return_vals, 1);
|
2019-07-30 16:51:16 +08:00
|
|
|
|
|
|
|
gimp_value_array_unref (return_vals);
|
2005-10-17 23:15:20 +08:00
|
|
|
|
2019-08-13 19:59:33 +08:00
|
|
|
return layer;
|
2005-10-17 23:15:20 +08:00
|
|
|
}
|
|
|
|
|
2006-11-04 01:12:27 +08:00
|
|
|
/**
|
|
|
|
* gimp_file_load_layers:
|
|
|
|
* @run_mode: The run mode.
|
2019-08-11 20:20:05 +08:00
|
|
|
* @image: Destination image.
|
2019-09-12 03:48:34 +08:00
|
|
|
* @file: The file to load.
|
2019-08-01 04:51:35 +08:00
|
|
|
* @num_layers: (out): The number of loaded layers.
|
2006-11-04 01:12:27 +08:00
|
|
|
*
|
|
|
|
* Loads an image file as layers for an existing image.
|
|
|
|
*
|
|
|
|
* This procedure behaves like the file-load procedure but opens the
|
|
|
|
* specified image as layers for an existing image. The returned layers
|
2010-09-06 06:03:29 +08:00
|
|
|
* needs to be added to the existing image with
|
|
|
|
* gimp_image_insert_layer().
|
2006-11-04 01:12:27 +08:00
|
|
|
*
|
2019-09-05 18:57:43 +08:00
|
|
|
* Returns: (array length=num_layers) (element-type GimpLayer) (transfer container):
|
2019-08-05 04:09:04 +08:00
|
|
|
* The list of loaded layers.
|
|
|
|
* The returned value must be freed with g_free().
|
2006-11-04 01:12:27 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2010-09-16 04:07:36 +08:00
|
|
|
**/
|
2019-09-05 18:57:43 +08:00
|
|
|
GimpLayer **
|
2006-11-04 01:12:27 +08:00
|
|
|
gimp_file_load_layers (GimpRunMode run_mode,
|
2019-08-11 20:20:05 +08:00
|
|
|
GimpImage *image,
|
2019-09-12 03:48:34 +08:00
|
|
|
GFile *file,
|
2006-11-04 01:12:27 +08:00
|
|
|
gint *num_layers)
|
|
|
|
{
|
2019-07-30 16:51:16 +08:00
|
|
|
GimpValueArray *args;
|
|
|
|
GimpValueArray *return_vals;
|
2019-09-05 18:57:43 +08:00
|
|
|
GimpLayer **layers = NULL;
|
2006-11-04 01:12:27 +08:00
|
|
|
|
2019-08-08 19:01:50 +08:00
|
|
|
args = gimp_value_array_new_from_types (NULL,
|
|
|
|
GIMP_TYPE_RUN_MODE, run_mode,
|
2019-08-29 17:25:35 +08:00
|
|
|
GIMP_TYPE_IMAGE, image,
|
2019-09-12 03:48:34 +08:00
|
|
|
G_TYPE_FILE, file,
|
2019-07-30 16:51:16 +08:00
|
|
|
G_TYPE_NONE);
|
|
|
|
|
2023-10-17 04:07:55 +08:00
|
|
|
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
|
|
|
"gimp-file-load-layers",
|
|
|
|
args);
|
2019-07-30 16:51:16 +08:00
|
|
|
gimp_value_array_unref (args);
|
2006-11-04 01:12:27 +08:00
|
|
|
|
|
|
|
*num_layers = 0;
|
|
|
|
|
2019-09-04 07:49:35 +08:00
|
|
|
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
2006-11-04 01:12:27 +08:00
|
|
|
{
|
2019-09-04 08:49:33 +08:00
|
|
|
*num_layers = GIMP_VALUES_GET_INT (return_vals, 1);
|
2021-08-26 23:18:32 +08:00
|
|
|
{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) layers = g_memdup2 (a->data, a->length * sizeof (gpointer)); };
|
2006-11-04 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2019-07-30 16:51:16 +08:00
|
|
|
gimp_value_array_unref (return_vals);
|
2006-11-04 01:12:27 +08:00
|
|
|
|
2019-09-05 18:57:43 +08:00
|
|
|
return layers;
|
2006-11-04 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2000-08-25 23:38:38 +08:00
|
|
|
/**
|
|
|
|
* gimp_file_save:
|
|
|
|
* @run_mode: The run mode.
|
2019-08-11 20:20:05 +08:00
|
|
|
* @image: Input image.
|
2019-09-12 03:48:34 +08:00
|
|
|
* @file: The file to save the image in.
|
app, libgimp*, pdb, plug-ins: review and enhance MR !1549.
- Fix annotations for gimp_export_options_get_image() to make it
actually introspectable with the GimpImage being both input and
output. Even though the logic doesn't change much (the input image may
be overriden or not), it doesn't matter for introspection because
images are handled centrally by libgimp and therefore must not be
freed. Actually deleting the image from the central list of images
though remains a manual action depending on code logic, not some
automatic action to be handled by binding engines.
- Add G_GNUC_WARN_UNUSED_RESULT to gimp_export_options_get_image()
because ignoring the returned value is rarely a good idea (as you
usually want to delete the image).
- Remove gimp_export_options_new(): we don't need this constructor
because at this point, the best is to tell plug-in developers to just
pass NULL everywhere. This leaves us free to create a more useful
default constructor if needed, in the future. Main description for
GimpExportOptions has also been updated to say this.
- Add a data_destroy callback for the user data passed in
gimp_export_procedure_set_capabilities().
- Fixing annotations of 'export_options' object from pdb/pdb.pl: input
args would actually be (nullable) and would not transfer ownership
(calling code must still free the object). Return value's ownership on
the other hand is fully transfered.
- Add C and Python unit testing for GimpExportOptions and
gimp_export_options_get_image() in particular.
- Fix or improve various details.
Note that I have also considered for a long time changing the signature
of gimp_export_options_get_image() to return a boolean indicating
whether `image` had been replaced (hence needed deletion) or not. This
also meant getting rid of the GimpExportReturn enum. Right now it would
work because there are no third case, but I was considering the future
possibility that for instance we got some impossible conversion for some
future capability. I'm not sure it would ever happen; and for sure, this
is not desirable because it implies an export failure a bit late in the
workflow. But just in case, let's keep the enum return value. It does
not even make the using code that much more complicated (well just a
value comparison instead of a simple boolean test).
2024-08-17 21:06:27 +08:00
|
|
|
* @options: (nullable): Export option settings.
|
2000-08-25 23:38:38 +08:00
|
|
|
*
|
|
|
|
* Saves a file by extension.
|
|
|
|
*
|
|
|
|
* This procedure invokes the correct file save handler according to
|
2020-04-14 02:25:32 +08:00
|
|
|
* the file's extension and/or prefix.
|
app, libgimp*, pdb, plug-ins: review and enhance MR !1549.
- Fix annotations for gimp_export_options_get_image() to make it
actually introspectable with the GimpImage being both input and
output. Even though the logic doesn't change much (the input image may
be overriden or not), it doesn't matter for introspection because
images are handled centrally by libgimp and therefore must not be
freed. Actually deleting the image from the central list of images
though remains a manual action depending on code logic, not some
automatic action to be handled by binding engines.
- Add G_GNUC_WARN_UNUSED_RESULT to gimp_export_options_get_image()
because ignoring the returned value is rarely a good idea (as you
usually want to delete the image).
- Remove gimp_export_options_new(): we don't need this constructor
because at this point, the best is to tell plug-in developers to just
pass NULL everywhere. This leaves us free to create a more useful
default constructor if needed, in the future. Main description for
GimpExportOptions has also been updated to say this.
- Add a data_destroy callback for the user data passed in
gimp_export_procedure_set_capabilities().
- Fixing annotations of 'export_options' object from pdb/pdb.pl: input
args would actually be (nullable) and would not transfer ownership
(calling code must still free the object). Return value's ownership on
the other hand is fully transfered.
- Add C and Python unit testing for GimpExportOptions and
gimp_export_options_get_image() in particular.
- Fix or improve various details.
Note that I have also considered for a long time changing the signature
of gimp_export_options_get_image() to return a boolean indicating
whether `image` had been replaced (hence needed deletion) or not. This
also meant getting rid of the GimpExportReturn enum. Right now it would
work because there are no third case, but I was considering the future
possibility that for instance we got some impossible conversion for some
future capability. I'm not sure it would ever happen; and for sure, this
is not desirable because it implies an export failure a bit late in the
workflow. But just in case, let's keep the enum return value. It does
not even make the using code that much more complicated (well just a
value comparison instead of a simple boolean test).
2024-08-17 21:06:27 +08:00
|
|
|
* The @options argument is currently unused and should be set to %NULL
|
|
|
|
* right now.
|
2000-08-25 23:38:38 +08:00
|
|
|
*
|
|
|
|
* Returns: TRUE on success.
|
2010-09-16 04:07:36 +08:00
|
|
|
**/
|
2000-08-25 23:38:38 +08:00
|
|
|
gboolean
|
2024-05-07 02:38:12 +08:00
|
|
|
gimp_file_save (GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GFile *file,
|
|
|
|
GimpExportOptions *options)
|
2000-08-25 23:38:38 +08:00
|
|
|
{
|
2019-07-30 16:51:16 +08:00
|
|
|
GimpValueArray *args;
|
|
|
|
GimpValueArray *return_vals;
|
2000-08-25 23:38:38 +08:00
|
|
|
gboolean success = TRUE;
|
|
|
|
|
2019-08-08 19:01:50 +08:00
|
|
|
args = gimp_value_array_new_from_types (NULL,
|
|
|
|
GIMP_TYPE_RUN_MODE, run_mode,
|
2019-08-29 17:25:35 +08:00
|
|
|
GIMP_TYPE_IMAGE, image,
|
2019-09-12 03:48:34 +08:00
|
|
|
G_TYPE_FILE, file,
|
2024-05-07 02:38:12 +08:00
|
|
|
GIMP_TYPE_EXPORT_OPTIONS, options,
|
2019-07-30 16:51:16 +08:00
|
|
|
G_TYPE_NONE);
|
2000-08-25 23:38:38 +08:00
|
|
|
|
2023-10-17 04:07:55 +08:00
|
|
|
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
|
|
|
"gimp-file-save",
|
|
|
|
args);
|
2019-07-30 16:51:16 +08:00
|
|
|
gimp_value_array_unref (args);
|
2000-08-25 23:38:38 +08:00
|
|
|
|
2019-09-04 07:49:35 +08:00
|
|
|
success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
|
2019-07-30 16:51:16 +08:00
|
|
|
|
|
|
|
gimp_value_array_unref (return_vals);
|
2006-11-06 16:12:37 +08:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_file_save_thumbnail:
|
2019-08-11 20:20:05 +08:00
|
|
|
* @image: The image.
|
2019-09-12 03:48:34 +08:00
|
|
|
* @file: The file the thumbnail belongs to.
|
2006-11-06 16:12:37 +08:00
|
|
|
*
|
|
|
|
* Saves a thumbnail for the given image
|
|
|
|
*
|
|
|
|
* This procedure saves a thumbnail for the given image according to
|
|
|
|
* the Free Desktop Thumbnail Managing Standard. The thumbnail is saved
|
2020-04-14 02:25:32 +08:00
|
|
|
* so that it belongs to the given file. This means you have to save
|
|
|
|
* the image under this name first, otherwise this procedure will fail.
|
|
|
|
* This procedure may become useful if you want to explicitly save a
|
|
|
|
* thumbnail with a file.
|
2006-11-06 16:12:37 +08:00
|
|
|
*
|
|
|
|
* Returns: TRUE on success.
|
2010-09-16 04:07:36 +08:00
|
|
|
**/
|
2006-11-06 16:12:37 +08:00
|
|
|
gboolean
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_save_thumbnail (GimpImage *image,
|
|
|
|
GFile *file)
|
2006-11-06 16:12:37 +08:00
|
|
|
{
|
2019-07-30 16:51:16 +08:00
|
|
|
GimpValueArray *args;
|
|
|
|
GimpValueArray *return_vals;
|
2006-11-06 16:12:37 +08:00
|
|
|
gboolean success = TRUE;
|
|
|
|
|
2019-08-08 19:01:50 +08:00
|
|
|
args = gimp_value_array_new_from_types (NULL,
|
2019-08-29 17:25:35 +08:00
|
|
|
GIMP_TYPE_IMAGE, image,
|
2019-09-12 03:48:34 +08:00
|
|
|
G_TYPE_FILE, file,
|
2019-07-30 16:51:16 +08:00
|
|
|
G_TYPE_NONE);
|
|
|
|
|
2023-10-17 04:07:55 +08:00
|
|
|
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
|
|
|
"gimp-file-save-thumbnail",
|
|
|
|
args);
|
2019-07-30 16:51:16 +08:00
|
|
|
gimp_value_array_unref (args);
|
2006-11-06 16:12:37 +08:00
|
|
|
|
2019-09-04 07:49:35 +08:00
|
|
|
success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
|
2006-11-06 16:12:37 +08:00
|
|
|
|
2019-07-30 16:51:16 +08:00
|
|
|
gimp_value_array_unref (return_vals);
|
2000-08-25 23:38:38 +08:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|