2012-04-30 10:24:23 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* file-gegl.c -- GEGL based file format plug-in
|
|
|
|
* Copyright (C) 2012 Simon Budig <simon@gimp.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2012-04-30 10:24:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2012-05-01 06:00:44 +08:00
|
|
|
#define PLUG_IN_BINARY "file-gegl"
|
2012-04-30 10:24:23 +08:00
|
|
|
|
|
|
|
|
2012-10-30 06:40:11 +08:00
|
|
|
typedef struct _FileFormat FileFormat;
|
|
|
|
|
|
|
|
struct _FileFormat
|
|
|
|
{
|
|
|
|
const gchar *file_type;
|
|
|
|
const gchar *mime_type;
|
|
|
|
const gchar *extensions;
|
|
|
|
const gchar *magic;
|
|
|
|
|
|
|
|
const gchar *load_proc;
|
|
|
|
const gchar *load_blurb;
|
|
|
|
const gchar *load_help;
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
const gchar *load_op;
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
const gchar *export_proc;
|
|
|
|
const gchar *export_blurb;
|
|
|
|
const gchar *export_help;
|
|
|
|
const gchar *export_op;
|
2012-10-30 06:40:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
typedef struct _Goat Goat;
|
|
|
|
typedef struct _GoatClass GoatClass;
|
|
|
|
|
|
|
|
struct _Goat
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GoatClass
|
|
|
|
{
|
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define GOAT_TYPE (goat_get_type ())
|
2023-10-19 00:29:37 +08:00
|
|
|
#define GOAT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOAT_TYPE, Goat))
|
2019-08-26 00:15:04 +08:00
|
|
|
|
|
|
|
GType goat_get_type (void) G_GNUC_CONST;
|
|
|
|
|
2023-08-06 01:07:04 +08:00
|
|
|
static GList * goat_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * goat_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * goat_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags *flags,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data);
|
2024-04-13 23:10:25 +08:00
|
|
|
static GimpValueArray * goat_export (GimpProcedure *procedure,
|
2023-08-06 01:07:04 +08:00
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GFile *file,
|
2024-05-07 02:38:12 +08:00
|
|
|
GimpExportOptions *options,
|
2023-08-06 01:07:04 +08:00
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data);
|
|
|
|
|
|
|
|
static GimpImage * load_image (GFile *file,
|
|
|
|
const gchar *gegl_op,
|
|
|
|
GError **error);
|
2024-04-13 23:10:25 +08:00
|
|
|
static gboolean export_image (GFile *file,
|
2023-08-06 01:07:04 +08:00
|
|
|
const gchar *gegl_op,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GError **error);
|
2019-08-26 00:15:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Goat, goat, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (GOAT_TYPE)
|
2022-05-26 06:59:36 +08:00
|
|
|
DEFINE_STD_SET_I18N
|
2012-10-30 06:40:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
static const FileFormat file_formats[] =
|
|
|
|
{
|
2018-01-13 00:16:37 +08:00
|
|
|
{
|
|
|
|
N_("Radiance RGBE"),
|
|
|
|
"image/vnd.radiance",
|
|
|
|
"hdr",
|
2021-12-17 23:56:43 +08:00
|
|
|
"0,string,#?",
|
2018-01-13 00:16:37 +08:00
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
"file-rgbe-load",
|
2018-01-13 00:16:37 +08:00
|
|
|
"Load files in the RGBE file format",
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
"This procedure loads images in the RGBE format, using gegl:rgbe-load",
|
|
|
|
"gegl:rgbe-load",
|
2018-01-13 00:16:37 +08:00
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
"file-rgbe-export",
|
2018-01-13 08:27:01 +08:00
|
|
|
"Saves files in the RGBE file format",
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
"This procedure exports images in the RGBE format, using gegl:rgbe-save",
|
|
|
|
"gegl:rgbe-save",
|
2018-01-13 00:16:37 +08:00
|
|
|
},
|
2015-02-18 16:10:14 +08:00
|
|
|
{
|
|
|
|
N_("OpenEXR image"),
|
|
|
|
"image/x-exr",
|
|
|
|
"exr",
|
|
|
|
"0,lelong,20000630",
|
|
|
|
|
2015-02-18 16:16:22 +08:00
|
|
|
/* no EXR loading (implemented in native GIMP plug-in) */
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
NULL, NULL, NULL, NULL,
|
2015-02-18 16:10:14 +08:00
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
"file-exr-export",
|
2015-02-18 16:10:14 +08:00
|
|
|
"Saves files in the OpenEXR file format",
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
"This procedure saves images in the OpenEXR format, using gegl:exr-save",
|
|
|
|
"gegl:exr-save"
|
2012-10-30 06:40:11 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
static void
|
|
|
|
goat_class_init (GoatClass *klass)
|
2012-04-30 10:24:23 +08:00
|
|
|
{
|
2019-08-26 00:15:04 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
plug_in_class->query_procedures = goat_query_procedures;
|
|
|
|
plug_in_class->create_procedure = goat_create_procedure;
|
2022-05-26 06:59:36 +08:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
2019-08-26 00:15:04 +08:00
|
|
|
}
|
2012-04-30 10:24:23 +08:00
|
|
|
|
|
|
|
static void
|
2019-08-26 00:15:04 +08:00
|
|
|
goat_init (Goat *goat)
|
2012-04-30 10:24:23 +08:00
|
|
|
{
|
2019-08-26 00:15:04 +08:00
|
|
|
}
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
static GList *
|
|
|
|
goat_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
|
|
|
gint i;
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (file_formats); i++)
|
|
|
|
{
|
|
|
|
const FileFormat *format = &file_formats[i];
|
|
|
|
|
|
|
|
if (format->load_proc)
|
|
|
|
list = g_list_append (list, g_strdup (format->load_proc));
|
2012-05-01 06:00:44 +08:00
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
if (format->export_proc)
|
|
|
|
list = g_list_append (list, g_strdup (format->export_proc));
|
2019-08-26 00:15:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpProcedure *
|
|
|
|
goat_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
|
|
|
gint i;
|
2012-05-01 06:00:44 +08:00
|
|
|
|
2012-10-30 06:40:11 +08:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (file_formats); i++)
|
|
|
|
{
|
|
|
|
const FileFormat *format = &file_formats[i];
|
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
if (! g_strcmp0 (name, format->load_proc))
|
2015-02-18 16:10:14 +08:00
|
|
|
{
|
2023-08-06 09:21:27 +08:00
|
|
|
procedure = gimp_load_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
goat_load,
|
|
|
|
(gpointer) format, NULL);
|
2019-08-26 00:15:04 +08:00
|
|
|
|
2024-04-20 06:04:39 +08:00
|
|
|
gimp_procedure_set_menu_label (procedure, _(format->file_type));
|
2019-08-26 00:15:04 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
format->load_blurb,
|
|
|
|
format->load_help,
|
|
|
|
name);
|
|
|
|
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
format->mime_type);
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
format->extensions);
|
|
|
|
gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
format->magic);
|
2015-02-18 16:10:14 +08:00
|
|
|
}
|
2024-04-13 23:10:25 +08:00
|
|
|
else if (! g_strcmp0 (name, format->export_proc))
|
2012-10-30 06:40:11 +08:00
|
|
|
{
|
2024-04-20 11:08:57 +08:00
|
|
|
procedure = gimp_export_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
FALSE, goat_export,
|
|
|
|
(gpointer) format, NULL);
|
2019-08-26 00:15:04 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "*");
|
|
|
|
|
2024-04-20 06:04:39 +08:00
|
|
|
gimp_procedure_set_menu_label (procedure, _(format->file_type));
|
2019-08-26 00:15:04 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2024-04-13 23:10:25 +08:00
|
|
|
format->export_blurb,
|
|
|
|
format->export_help,
|
2019-08-26 00:15:04 +08:00
|
|
|
name);
|
|
|
|
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
format->mime_type);
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
format->extensions);
|
2024-05-07 02:38:12 +08:00
|
|
|
|
|
|
|
gimp_export_procedure_set_capabilities (GIMP_EXPORT_PROCEDURE (procedure),
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_INDEXED |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_ALPHA,
|
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
|
|
|
NULL, NULL, NULL);
|
2012-10-30 06:40:11 +08:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 00:15:04 +08:00
|
|
|
|
|
|
|
return procedure;
|
2012-04-30 10:24:23 +08:00
|
|
|
}
|
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
static GimpValueArray *
|
2023-08-06 01:07:04 +08:00
|
|
|
goat_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags *flags,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data)
|
2012-04-30 10:24:23 +08:00
|
|
|
{
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
const FileFormat *format = run_data;
|
|
|
|
GimpValueArray *return_vals;
|
|
|
|
GimpImage *image;
|
|
|
|
GError *error = NULL;
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2012-11-28 03:58:05 +08:00
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
image = load_image (file, format->load_op, &error);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
if (! image)
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
return return_vals;
|
|
|
|
}
|
2019-08-19 18:05:12 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
static GimpValueArray *
|
2024-04-13 23:10:25 +08:00
|
|
|
goat_export (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GFile *file,
|
2024-05-07 02:38:12 +08:00
|
|
|
GimpExportOptions *options,
|
2024-04-13 23:10:25 +08:00
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data)
|
2019-08-26 00:15:04 +08:00
|
|
|
{
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
const FileFormat *format = run_data;
|
2019-08-26 00:15:04 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2024-04-30 12:25:51 +08:00
|
|
|
GimpExportReturn export = GIMP_EXPORT_IGNORE;
|
2024-04-30 21:50:24 +08:00
|
|
|
GList *drawables;
|
|
|
|
GError *error = NULL;
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
gegl_init (NULL, NULL);
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2024-05-07 02:38:12 +08:00
|
|
|
export = gimp_export_options_get_image (options, &image);
|
2024-04-30 21:50:24 +08:00
|
|
|
drawables = gimp_image_list_layers (image);
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2024-04-30 21:50:24 +08:00
|
|
|
if (! export_image (file, format->export_op, image, drawables->data,
|
2019-08-26 00:15:04 +08:00
|
|
|
&error))
|
2012-04-30 10:24:23 +08:00
|
|
|
{
|
2019-08-26 00:15:04 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
2012-04-30 10:24:23 +08:00
|
|
|
}
|
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
2024-04-30 21:50:24 +08:00
|
|
|
gimp_image_delete (image);
|
2012-05-01 06:00:44 +08:00
|
|
|
|
2024-04-30 21:50:24 +08:00
|
|
|
g_list_free (drawables);
|
2019-08-26 00:15:04 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure, status, error);
|
2012-04-30 10:24:23 +08:00
|
|
|
}
|
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
static GimpImage *
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
load_image (GFile *file,
|
|
|
|
const gchar *gegl_op,
|
|
|
|
GError **error)
|
2012-04-30 10:24:23 +08:00
|
|
|
{
|
2019-08-26 00:15:04 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GimpLayer *layer;
|
2012-04-30 10:24:23 +08:00
|
|
|
GimpImageType image_type;
|
|
|
|
GimpImageBaseType base_type;
|
|
|
|
GimpPrecision precision;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2012-10-30 06:40:11 +08:00
|
|
|
GeglNode *graph;
|
|
|
|
GeglNode *sink;
|
|
|
|
GeglNode *source;
|
|
|
|
GeglBuffer *src_buf = NULL;
|
|
|
|
GeglBuffer *dest_buf = NULL;
|
|
|
|
const Babl *format;
|
2012-04-30 10:24:23 +08:00
|
|
|
|
|
|
|
gimp_progress_init_printf (_("Opening '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2012-04-30 10:24:23 +08:00
|
|
|
|
|
|
|
graph = gegl_node_new ();
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2012-04-30 10:24:23 +08:00
|
|
|
source = gegl_node_new_child (graph,
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
"operation", gegl_op,
|
2021-10-02 00:56:12 +08:00
|
|
|
"path", g_file_peek_path (file),
|
2012-04-30 10:24:23 +08:00
|
|
|
NULL);
|
2012-10-30 06:40:11 +08:00
|
|
|
sink = gegl_node_new_child (graph,
|
|
|
|
"operation", "gegl:buffer-sink",
|
|
|
|
"buffer", &src_buf,
|
|
|
|
NULL);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2023-06-13 23:03:49 +08:00
|
|
|
gegl_node_link (source, sink);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
|
|
|
gegl_node_process (sink);
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2012-04-30 10:24:23 +08:00
|
|
|
g_object_unref (graph);
|
|
|
|
|
2012-10-30 06:40:11 +08:00
|
|
|
if (! src_buf)
|
2012-04-30 10:24:23 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("Could not open '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2019-08-26 00:15:04 +08:00
|
|
|
return NULL;
|
2012-04-30 10:24:23 +08:00
|
|
|
}
|
|
|
|
|
2012-10-30 06:40:11 +08:00
|
|
|
gimp_progress_update (0.33);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2012-10-30 06:40:11 +08:00
|
|
|
width = gegl_buffer_get_width (src_buf);
|
2012-04-30 10:24:23 +08:00
|
|
|
height = gegl_buffer_get_height (src_buf);
|
|
|
|
format = gegl_buffer_get_format (src_buf);
|
|
|
|
|
2013-06-23 22:51:24 +08:00
|
|
|
if (babl_format_is_palette (format))
|
2012-04-30 10:24:23 +08:00
|
|
|
{
|
|
|
|
base_type = GIMP_INDEXED;
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2012-04-30 10:24:23 +08:00
|
|
|
if (babl_format_has_alpha (format))
|
|
|
|
image_type = GIMP_INDEXEDA_IMAGE;
|
|
|
|
else
|
|
|
|
image_type = GIMP_INDEXED_IMAGE;
|
2013-06-23 22:51:24 +08:00
|
|
|
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_U8_NON_LINEAR;
|
2012-04-30 10:24:23 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-23 22:51:24 +08:00
|
|
|
const Babl *model = babl_format_get_model (format);
|
|
|
|
const Babl *type = babl_format_get_type (format, 0);
|
|
|
|
gboolean linear = TRUE;
|
|
|
|
|
|
|
|
if (model == babl_model ("Y") ||
|
|
|
|
model == babl_model ("Y'") ||
|
|
|
|
model == babl_model ("YA") ||
|
|
|
|
model == babl_model ("Y'A"))
|
|
|
|
{
|
|
|
|
base_type = GIMP_GRAY;
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2013-06-23 22:51:24 +08:00
|
|
|
if (babl_format_has_alpha (format))
|
|
|
|
image_type = GIMP_GRAYA_IMAGE;
|
|
|
|
else
|
|
|
|
image_type = GIMP_GRAY_IMAGE;
|
|
|
|
|
|
|
|
if (model == babl_model ("Y'") ||
|
|
|
|
model == babl_model ("Y'A"))
|
|
|
|
linear = FALSE;
|
|
|
|
}
|
2012-04-30 10:24:23 +08:00
|
|
|
else
|
2013-06-23 22:51:24 +08:00
|
|
|
{
|
|
|
|
base_type = GIMP_RGB;
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2013-06-23 22:51:24 +08:00
|
|
|
if (babl_format_has_alpha (format))
|
|
|
|
image_type = GIMP_RGBA_IMAGE;
|
|
|
|
else
|
|
|
|
image_type = GIMP_RGB_IMAGE;
|
|
|
|
|
|
|
|
if (model == babl_model ("R'G'B'") ||
|
|
|
|
model == babl_model ("R'G'B'A"))
|
|
|
|
linear = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linear)
|
|
|
|
{
|
|
|
|
if (type == babl_type ("u8"))
|
|
|
|
precision = GIMP_PRECISION_U8_LINEAR;
|
|
|
|
else if (type == babl_type ("u16"))
|
|
|
|
precision = GIMP_PRECISION_U16_LINEAR;
|
|
|
|
else if (type == babl_type ("u32"))
|
|
|
|
precision = GIMP_PRECISION_U32_LINEAR;
|
|
|
|
else if (type == babl_type ("half"))
|
|
|
|
precision = GIMP_PRECISION_HALF_LINEAR;
|
|
|
|
else
|
|
|
|
precision = GIMP_PRECISION_FLOAT_LINEAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (type == babl_type ("u8"))
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_U8_NON_LINEAR;
|
2013-06-23 22:51:24 +08:00
|
|
|
else if (type == babl_type ("u16"))
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_U16_NON_LINEAR;
|
2013-06-23 22:51:24 +08:00
|
|
|
else if (type == babl_type ("u32"))
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_U32_NON_LINEAR;
|
2013-06-23 22:51:24 +08:00
|
|
|
else if (type == babl_type ("half"))
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_HALF_NON_LINEAR;
|
2013-06-23 22:51:24 +08:00
|
|
|
else
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_FLOAT_NON_LINEAR;
|
2013-06-23 22:51:24 +08:00
|
|
|
}
|
|
|
|
}
|
2012-04-30 10:24:23 +08:00
|
|
|
|
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
image = gimp_image_new_with_precision (width, height,
|
|
|
|
base_type, precision);
|
|
|
|
layer = gimp_layer_new (image,
|
|
|
|
_("Background"),
|
|
|
|
width, height,
|
|
|
|
image_type,
|
|
|
|
100,
|
|
|
|
gimp_image_get_default_new_layer_mode (image));
|
|
|
|
gimp_image_insert_layer (image, layer, NULL, 0);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
dest_buf = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2012-10-30 06:40:11 +08:00
|
|
|
gimp_progress_update (0.66);
|
|
|
|
|
2015-05-25 04:32:55 +08:00
|
|
|
gegl_buffer_copy (src_buf, NULL, GEGL_ABYSS_NONE, dest_buf, NULL);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
|
|
|
g_object_unref (src_buf);
|
|
|
|
g_object_unref (dest_buf);
|
|
|
|
|
2012-10-30 06:40:11 +08:00
|
|
|
gimp_progress_update (1.0);
|
2012-04-30 10:24:23 +08:00
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
return image;
|
2012-04-30 10:24:23 +08:00
|
|
|
}
|
|
|
|
|
2012-05-01 06:00:44 +08:00
|
|
|
static gboolean
|
2024-04-13 23:10:25 +08:00
|
|
|
export_image (GFile *file,
|
|
|
|
const gchar *gegl_op,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GError **error)
|
2012-05-01 06:00:44 +08:00
|
|
|
{
|
2012-10-30 06:40:11 +08:00
|
|
|
GeglNode *graph;
|
|
|
|
GeglNode *source;
|
|
|
|
GeglNode *sink;
|
2012-05-01 06:00:44 +08:00
|
|
|
GeglBuffer *src_buf;
|
|
|
|
|
2019-08-26 00:15:04 +08:00
|
|
|
src_buf = gimp_drawable_get_buffer (drawable);
|
2012-05-01 06:00:44 +08:00
|
|
|
|
|
|
|
graph = gegl_node_new ();
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2012-05-01 06:00:44 +08:00
|
|
|
source = gegl_node_new_child (graph,
|
|
|
|
"operation", "gegl:buffer-source",
|
2012-10-30 06:40:11 +08:00
|
|
|
"buffer", src_buf,
|
2012-05-01 06:00:44 +08:00
|
|
|
NULL);
|
|
|
|
sink = gegl_node_new_child (graph,
|
plug-ins: in file-gegl, use the accurate load/save GEGL operation…
… rather than generic "gegl:load" and "gegl:save".
In particular, it means using "gegl:rgbe-load|save" for RGBE images and
"gegl:exr-save" for EXR exporting.
Without this, we could encounter weird run cases where for instance, we
would detect a RGBE image through the file magic number in GIMP,
redirect the load to file-gegl, but "gegl:load" only relies on file
extension. So if the file extension was not ".hdr", "gegl:load" could
redirect to a different handler operation meant for another format,
hence break proper loading. If no extension was matched, it could even
redirect to a fallback handler, such as Image Magick.
This breaks loading or saving images which we would be otherwise able to
load/save. And it could also have some security implications. So let's
fix this by setting the accurate operations to use for each specific
file formats we want to support through the file-gegl plug-in.
2021-12-18 00:19:34 +08:00
|
|
|
"operation", gegl_op,
|
2021-10-02 00:56:12 +08:00
|
|
|
"path", g_file_peek_path (file),
|
2012-05-01 06:00:44 +08:00
|
|
|
NULL);
|
|
|
|
|
2023-06-13 23:03:49 +08:00
|
|
|
gegl_node_link (source, sink);
|
2012-05-01 06:00:44 +08:00
|
|
|
|
|
|
|
gegl_node_process (sink);
|
2012-10-30 06:40:11 +08:00
|
|
|
|
2012-05-01 06:00:44 +08:00
|
|
|
g_object_unref (graph);
|
|
|
|
g_object_unref (src_buf);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|