2013-05-04 09:55:49 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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/>.
|
2013-05-04 09:55:49 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
|
|
|
#include "openexr-wrapper.h"
|
|
|
|
|
2016-04-19 02:05:51 +08:00
|
|
|
#define LOAD_PROC "file-exr-load"
|
|
|
|
#define PLUG_IN_BINARY "file-exr"
|
|
|
|
#define PLUG_IN_VERSION "0.0.0"
|
2013-05-04 09:55:49 +08:00
|
|
|
|
|
|
|
|
2019-08-16 01:00:10 +08:00
|
|
|
typedef struct _Exr Exr;
|
|
|
|
typedef struct _ExrClass ExrClass;
|
2016-04-19 02:05:51 +08:00
|
|
|
|
2019-08-16 01:00:10 +08:00
|
|
|
struct _Exr
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
2016-04-19 02:05:51 +08:00
|
|
|
|
2019-08-16 01:00:10 +08:00
|
|
|
struct _ExrClass
|
2013-05-04 09:55:49 +08:00
|
|
|
{
|
2019-08-16 01:00:10 +08:00
|
|
|
GimpPlugInClass parent_class;
|
2013-05-04 09:55:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-16 01:00:10 +08:00
|
|
|
#define EXR_TYPE (exr_get_type ())
|
|
|
|
#define EXR (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXR_TYPE, Exr))
|
|
|
|
|
|
|
|
GType exr_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * exr_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * exr_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * exr_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data);
|
|
|
|
|
2019-09-12 03:48:34 +08:00
|
|
|
static GimpImage * load_image (GFile *file,
|
2019-08-16 01:00:10 +08:00
|
|
|
gboolean interactive,
|
|
|
|
GError **error);
|
|
|
|
static void sanitize_comment (gchar *comment);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Exr, exr, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (EXR_TYPE)
|
2013-05-04 09:55:49 +08:00
|
|
|
|
2016-04-19 02:05:51 +08:00
|
|
|
|
2013-05-04 09:55:49 +08:00
|
|
|
static void
|
2019-08-16 01:00:10 +08:00
|
|
|
exr_class_init (ExrClass *klass)
|
2013-05-04 09:55:49 +08:00
|
|
|
{
|
2019-08-16 01:00:10 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = exr_query_procedures;
|
|
|
|
plug_in_class->create_procedure = exr_create_procedure;
|
2013-05-04 09:55:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-16 01:00:10 +08:00
|
|
|
exr_init (Exr *exr)
|
2013-05-04 09:55:49 +08:00
|
|
|
{
|
2019-08-16 01:00:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
exr_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
return g_list_append (NULL, g_strdup (LOAD_PROC));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpProcedure *
|
|
|
|
exr_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
|
|
|
|
|
|
|
if (! strcmp (name, LOAD_PROC))
|
|
|
|
{
|
2019-08-30 18:52:28 +08:00
|
|
|
procedure = gimp_load_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
2019-08-16 01:00:10 +08:00
|
|
|
exr_load, NULL, NULL);
|
|
|
|
|
|
|
|
gimp_procedure_set_menu_label (procedure, N_("OpenEXR image"));
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"Loads files in the OpenEXR file format",
|
|
|
|
"This plug-in loads OpenEXR files. ",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Dominik Ernst <dernst@gmx.de>, "
|
|
|
|
"Mukund Sivaraman <muks@banu.com>",
|
|
|
|
"Dominik Ernst <dernst@gmx.de>, "
|
|
|
|
"Mukund Sivaraman <muks@banu.com>",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"image/x-exr");
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"exr");
|
|
|
|
gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"0,long,0x762f3101");
|
|
|
|
}
|
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
|
|
|
exr_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data)
|
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
2019-08-16 06:54:34 +08:00
|
|
|
GimpImage *image;
|
2019-08-16 01:00:10 +08:00
|
|
|
GError *error = NULL;
|
2013-05-04 09:55:49 +08:00
|
|
|
|
|
|
|
INIT_I18N ();
|
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
2019-09-12 03:48:34 +08:00
|
|
|
image = load_image (file, run_mode == GIMP_RUN_INTERACTIVE,
|
2019-08-16 06:54:34 +08:00
|
|
|
&error);
|
2013-05-04 09:55:49 +08:00
|
|
|
|
2019-08-16 06:54:34 +08:00
|
|
|
if (! image)
|
2019-08-16 01:00:10 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
2013-05-04 09:55:49 +08:00
|
|
|
|
2019-08-16 01:00:10 +08:00
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
2013-05-04 09:55:49 +08:00
|
|
|
|
2019-08-16 06:54:34 +08:00
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
2013-05-04 09:55:49 +08:00
|
|
|
|
2019-08-16 01:00:10 +08:00
|
|
|
return return_vals;
|
2013-05-04 09:55:49 +08:00
|
|
|
}
|
|
|
|
|
2019-08-16 06:54:34 +08:00
|
|
|
static GimpImage *
|
2019-09-12 03:48:34 +08:00
|
|
|
load_image (GFile *file,
|
2013-05-04 09:55:49 +08:00
|
|
|
gboolean interactive,
|
|
|
|
GError **error)
|
|
|
|
{
|
2016-04-19 02:05:51 +08:00
|
|
|
EXRLoader *loader;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gboolean has_alpha;
|
2013-05-04 09:55:49 +08:00
|
|
|
GimpImageBaseType image_type;
|
2016-04-19 02:05:51 +08:00
|
|
|
GimpPrecision image_precision;
|
2019-08-16 06:54:34 +08:00
|
|
|
GimpImage *image = NULL;
|
2016-04-19 02:05:51 +08:00
|
|
|
GimpImageType layer_type;
|
2019-08-16 06:54:34 +08:00
|
|
|
GimpLayer *layer;
|
2016-04-19 02:05:51 +08:00
|
|
|
const Babl *format;
|
|
|
|
GeglBuffer *buffer = NULL;
|
|
|
|
gint bpp;
|
|
|
|
gint tile_height;
|
|
|
|
gchar *pixels = NULL;
|
|
|
|
gint begin;
|
|
|
|
gint32 success = FALSE;
|
2019-06-25 23:55:49 +08:00
|
|
|
gchar *comment = NULL;
|
|
|
|
GimpColorProfile *profile = NULL;
|
2016-04-22 20:41:34 +08:00
|
|
|
guchar *exif_data;
|
|
|
|
guint exif_size;
|
2016-04-22 23:01:58 +08:00
|
|
|
guchar *xmp_data;
|
|
|
|
guint xmp_size;
|
2016-04-22 20:41:34 +08:00
|
|
|
|
2014-07-23 22:39:00 +08:00
|
|
|
gimp_progress_init_printf (_("Opening '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2014-07-23 22:39:00 +08:00
|
|
|
|
2021-10-02 00:14:14 +08:00
|
|
|
loader = exr_loader_new (g_file_peek_path (file));
|
2016-04-19 02:05:51 +08:00
|
|
|
|
|
|
|
if (! loader)
|
2013-05-04 09:55:49 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("Error opening file '%s' for reading"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2013-05-04 09:55:49 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-04-19 02:05:51 +08:00
|
|
|
width = exr_loader_get_width (loader);
|
2013-05-04 09:55:49 +08:00
|
|
|
height = exr_loader_get_height (loader);
|
2016-04-19 02:05:51 +08:00
|
|
|
|
2013-05-04 09:55:49 +08:00
|
|
|
if ((width < 1) || (height < 1))
|
|
|
|
{
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("Error querying image dimensions from '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2013-05-04 09:55:49 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
has_alpha = exr_loader_has_alpha (loader) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
switch (exr_loader_get_precision (loader))
|
|
|
|
{
|
|
|
|
case PREC_UINT:
|
2013-06-23 22:51:24 +08:00
|
|
|
image_precision = GIMP_PRECISION_U32_LINEAR;
|
2013-05-04 09:55:49 +08:00
|
|
|
break;
|
|
|
|
case PREC_HALF:
|
2013-06-23 22:51:24 +08:00
|
|
|
image_precision = GIMP_PRECISION_HALF_LINEAR;
|
2013-05-04 09:55:49 +08:00
|
|
|
break;
|
|
|
|
case PREC_FLOAT:
|
2013-06-23 22:51:24 +08:00
|
|
|
image_precision = GIMP_PRECISION_FLOAT_LINEAR;
|
2013-05-04 09:55:49 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("Error querying image precision from '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2013-05-04 09:55:49 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (exr_loader_get_image_type (loader))
|
|
|
|
{
|
|
|
|
case IMAGE_TYPE_RGB:
|
|
|
|
image_type = GIMP_RGB;
|
|
|
|
layer_type = has_alpha ? GIMP_RGBA_IMAGE : GIMP_RGB_IMAGE;
|
|
|
|
break;
|
|
|
|
case IMAGE_TYPE_GRAY:
|
2013-05-07 14:17:01 +08:00
|
|
|
image_type = GIMP_GRAY;
|
2013-05-04 09:55:49 +08:00
|
|
|
layer_type = has_alpha ? GIMP_GRAYA_IMAGE : GIMP_GRAY_IMAGE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("Error querying image type from '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2013-05-04 09:55:49 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = gimp_image_new_with_precision (width, height,
|
|
|
|
image_type, image_precision);
|
2019-08-16 06:54:34 +08:00
|
|
|
if (! image)
|
2013-05-04 09:55:49 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, 0, 0,
|
|
|
|
_("Could not create new image for '%s': %s"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file),
|
2019-08-16 01:03:09 +08:00
|
|
|
gimp_pdb_get_last_error (gimp_get_pdb ()));
|
2013-05-04 09:55:49 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_image_set_file (image, file);
|
2013-05-04 09:55:49 +08:00
|
|
|
|
2019-06-25 23:55:49 +08:00
|
|
|
/* try to load an icc profile, it will be generated on the fly if
|
|
|
|
* chromaticities are given
|
|
|
|
*/
|
|
|
|
if (image_type == GIMP_RGB)
|
|
|
|
{
|
|
|
|
profile = exr_loader_get_profile (loader);
|
|
|
|
|
|
|
|
if (profile)
|
|
|
|
gimp_image_set_color_profile (image, profile);
|
|
|
|
}
|
|
|
|
|
2013-05-04 09:55:49 +08:00
|
|
|
layer = gimp_layer_new (image, _("Background"), width, height,
|
2017-08-22 02:04:25 +08:00
|
|
|
layer_type, 100,
|
|
|
|
gimp_image_get_default_new_layer_mode (image));
|
2019-08-16 06:54:34 +08:00
|
|
|
gimp_image_insert_layer (image, layer, NULL, 0);
|
2013-05-04 09:55:49 +08:00
|
|
|
|
2019-08-16 06:54:34 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
|
|
|
|
format = gimp_drawable_get_format (GIMP_DRAWABLE (layer));
|
2013-05-04 09:55:49 +08:00
|
|
|
bpp = babl_format_get_bytes_per_pixel (format);
|
|
|
|
|
|
|
|
tile_height = gimp_tile_height ();
|
|
|
|
pixels = g_new0 (gchar, tile_height * width * bpp);
|
|
|
|
|
|
|
|
for (begin = 0; begin < height; begin += tile_height)
|
|
|
|
{
|
2016-04-19 02:05:51 +08:00
|
|
|
gint end;
|
|
|
|
gint num;
|
|
|
|
gint i;
|
|
|
|
|
2013-05-04 09:55:49 +08:00
|
|
|
end = MIN (begin + tile_height, height);
|
|
|
|
num = end - begin;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2016-04-19 02:05:51 +08:00
|
|
|
gint retval;
|
|
|
|
|
2013-05-04 09:55:49 +08:00
|
|
|
retval = exr_loader_read_pixel_row (loader,
|
|
|
|
pixels + (i * width * bpp),
|
|
|
|
bpp, begin + i);
|
|
|
|
if (retval < 0)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("Error reading pixel data from '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2013-05-04 09:55:49 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, begin, width, num),
|
|
|
|
0, NULL, pixels, GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
|
|
|
gimp_progress_update ((gdouble) begin / (gdouble) height);
|
|
|
|
}
|
|
|
|
|
2016-04-22 20:41:34 +08:00
|
|
|
/* try to read the file comment */
|
|
|
|
comment = exr_loader_get_comment (loader);
|
|
|
|
if (comment)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite;
|
|
|
|
|
2016-04-25 05:31:25 +08:00
|
|
|
sanitize_comment (comment);
|
2016-04-22 20:41:34 +08:00
|
|
|
parasite = gimp_parasite_new ("gimp-comment",
|
|
|
|
GIMP_PARASITE_PERSISTENT,
|
|
|
|
strlen (comment) + 1,
|
|
|
|
comment);
|
|
|
|
gimp_image_attach_parasite (image, parasite);
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
2019-06-25 23:55:49 +08:00
|
|
|
/* check if the image contains Exif or Xmp data and read it */
|
2016-04-22 20:41:34 +08:00
|
|
|
exif_data = exr_loader_get_exif (loader, &exif_size);
|
2019-06-25 23:55:49 +08:00
|
|
|
xmp_data = exr_loader_get_xmp (loader, &xmp_size);
|
|
|
|
|
|
|
|
if (exif_data || xmp_data)
|
2016-04-22 20:41:34 +08:00
|
|
|
{
|
2019-06-25 23:55:49 +08:00
|
|
|
GimpMetadata *metadata = gimp_metadata_new ();
|
|
|
|
GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
|
|
|
|
|
|
|
|
if (exif_data)
|
2016-04-22 20:41:34 +08:00
|
|
|
{
|
2019-06-25 23:55:49 +08:00
|
|
|
gimp_metadata_set_from_exif (metadata, exif_data, exif_size, NULL);
|
|
|
|
g_free (exif_data);
|
2016-04-22 20:41:34 +08:00
|
|
|
}
|
|
|
|
|
2019-06-25 23:55:49 +08:00
|
|
|
if (xmp_data)
|
2016-04-22 23:01:58 +08:00
|
|
|
{
|
2019-06-25 23:55:49 +08:00
|
|
|
gimp_metadata_set_from_xmp (metadata, xmp_data, xmp_size, NULL);
|
|
|
|
g_free (xmp_data);
|
2016-04-22 23:01:58 +08:00
|
|
|
}
|
2016-04-23 04:49:06 +08:00
|
|
|
|
2019-06-25 23:55:49 +08:00
|
|
|
if (comment)
|
|
|
|
flags &= ~GIMP_METADATA_LOAD_COMMENT;
|
2016-04-22 23:01:58 +08:00
|
|
|
|
2019-06-25 23:55:49 +08:00
|
|
|
if (profile)
|
|
|
|
flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
|
2016-04-22 20:41:34 +08:00
|
|
|
|
2019-06-25 23:55:49 +08:00
|
|
|
gimp_image_metadata_load_finish (image, "image/exr",
|
app, libgimp, plug-ins: move Orientation metadata handling into core.
Orientation is now handled by core code, just next to profile conversion
handling.
One of the first consequence is that we don't need to have a non-GUI
version gimp_image_metadata_load_finish_batch() in libgimp, next to a
GUI version of the gimp_image_metadata_load_finish() function in
libgimpui. This makes for simpler API.
Also a plug-in which wishes to get access to the rotation dialog
provided by GIMP without loading ligimpui/GTK+ (for whatever reason)
will still have the feature.
The main advantage is that the "Don't ask me again" feature is now
handled by a settings in `Preferences > Image Import & Export` as the
"Metadata rotation policy". Until now it was saved as a global parasite,
which made it virtually non-editable once you checked it once (no easy
way to edit parasites except by scripts). So say you refused the
rotation once while checking "Don't ask again", and GIMP will forever
discard the rotation metadata without giving you a sane way to change
your mind. Of course, I could have passed the settings to plug-ins
through the PDB, but I find it a lot better to simply handle such
settings core-side.
The dialog code is basically the same as an app/dialogs/ as it was in
libgimp, with the minor improvement that it now takes the scale ratio
into account (basically the maximum thumbnail size will be bigger on
higher density displays).
Only downside of the move to the core is that this rotation dialog is
raised only when you open an image from the core, not as a PDB call. So
a plug-in which makes say a "file-jpeg-load" PDB call, even in
INTERACTIVE run mode, won't have rotation processed. Note that this was
already the same for embedded color profile conversion. This can be
wanted or not. Anyway some additional libgimp calls might be of interest
to explicitly call the core dialogs.
2020-09-24 01:59:09 +08:00
|
|
|
metadata, flags);
|
2019-06-25 23:55:49 +08:00
|
|
|
g_object_unref (metadata);
|
|
|
|
}
|
2016-04-22 20:41:34 +08:00
|
|
|
|
2013-05-04 09:55:49 +08:00
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
2016-04-19 02:05:51 +08:00
|
|
|
success = TRUE;
|
2013-05-04 09:55:49 +08:00
|
|
|
|
|
|
|
out:
|
2019-06-25 23:55:49 +08:00
|
|
|
g_clear_object (&profile);
|
|
|
|
g_clear_object (&buffer);
|
|
|
|
g_clear_pointer (&pixels, g_free);
|
|
|
|
g_clear_pointer (&comment, g_free);
|
|
|
|
g_clear_pointer (&loader, exr_loader_unref);
|
2013-05-04 09:55:49 +08:00
|
|
|
|
2016-04-19 02:05:51 +08:00
|
|
|
if (success)
|
|
|
|
return image;
|
|
|
|
|
2019-08-16 06:54:34 +08:00
|
|
|
if (image)
|
2016-04-19 02:05:51 +08:00
|
|
|
gimp_image_delete (image);
|
|
|
|
|
2019-08-16 06:54:34 +08:00
|
|
|
return NULL;
|
2013-05-04 09:55:49 +08:00
|
|
|
}
|
2016-04-22 20:41:34 +08:00
|
|
|
|
|
|
|
/* copy & pasted from file-jpeg/jpeg-load.c */
|
|
|
|
static void
|
2016-04-25 05:31:25 +08:00
|
|
|
sanitize_comment (gchar *comment)
|
2016-04-22 20:41:34 +08:00
|
|
|
{
|
2019-06-26 22:51:26 +08:00
|
|
|
const gchar *start_invalid;
|
|
|
|
|
|
|
|
if (! g_utf8_validate (comment, -1, &start_invalid))
|
2016-04-22 20:41:34 +08:00
|
|
|
{
|
2019-06-26 22:51:26 +08:00
|
|
|
guchar *c;
|
2016-04-23 04:49:06 +08:00
|
|
|
|
2019-06-26 22:51:26 +08:00
|
|
|
for (c = (guchar *) start_invalid; *c; c++)
|
2016-04-23 04:49:06 +08:00
|
|
|
{
|
|
|
|
if (*c > 126 || (*c < 32 && *c != '\t' && *c != '\n' && *c != '\r'))
|
|
|
|
*c = '?';
|
|
|
|
}
|
2016-04-22 20:41:34 +08:00
|
|
|
}
|
|
|
|
}
|