[gimp] libgimp, plug-ins: split metadata loading into prepare() and finish()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp, plug-ins: split metadata loading into prepare() and finish()
- Date: Sun, 27 Oct 2013 14:25:42 +0000 (UTC)
commit 7cbe83d911e58b75983e6bf549bbe34325058075
Author: Michael Natterer <mitch gimp org>
Date: Sun Oct 27 15:22:35 2013 +0100
libgimp,plug-ins: split metadata loading into prepare() and finish()
So the plug-in has the chance to decide whether it wants to trust the
metadata information (e.g. resolution). Also reorder parameters in
gimp_image_metadata_save_finish(). Change all plug-ins accordingly.
libgimp/gimpmetadata.c | 65 +++++++++++++++++++++++++------------
libgimp/gimpmetadata.h | 30 ++++++++++-------
libgimp/gimpui.def | 3 +-
libgimpbase/gimpmetadata.h | 11 ++++++
plug-ins/common/file-jp2-load.c | 18 +++++++++--
plug-ins/common/file-png.c | 20 +++++++++--
plug-ins/common/file-tiff-load.c | 19 +++++++++--
plug-ins/common/file-tiff-save.c | 2 +-
plug-ins/file-jpeg/jpeg.c | 29 +++++++++-------
plug-ins/file-jpeg/jpeg.h | 1 -
plug-ins/file-psd/psd-save.c | 2 +-
plug-ins/file-psd/psd.c | 18 +++++++++--
12 files changed, 155 insertions(+), 63 deletions(-)
---
diff --git a/libgimp/gimpmetadata.c b/libgimp/gimpmetadata.c
index 63aec25..dd71813 100644
--- a/libgimp/gimpmetadata.c
+++ b/libgimp/gimpmetadata.c
@@ -44,27 +44,23 @@ static gboolean gimp_image_metadata_rotate_dialog (gint32 image_ID,
/* public functions */
-void
-gimp_image_metadata_load (gint32 image_ID,
- const gchar *mime_type,
- GFile *file,
- gboolean interactive)
+GimpMetadata *
+gimp_image_metadata_load_prepare (gint32 image_ID,
+ const gchar *mime_type,
+ GFile *file,
+ GError **error)
{
GimpMetadata *metadata;
- g_return_if_fail (image_ID > 0);
- g_return_if_fail (mime_type != NULL);
- g_return_if_fail (G_IS_FILE (file));
+ g_return_val_if_fail (image_ID > 0, NULL);
+ g_return_val_if_fail (mime_type != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (file), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- metadata = gimp_metadata_load_from_file (file, NULL);
+ metadata = gimp_metadata_load_from_file (file, error);
if (metadata)
{
- gchar *comment;
- gdouble xres;
- gdouble yres;
- GimpUnit unit;
-
#if 0
{
gchar *xml = gimp_metadata_serialize (metadata);
@@ -87,6 +83,27 @@ gimp_image_metadata_load (gint32 image_ID,
}
#endif
+ gexiv2_metadata_erase_exif_thumbnail (metadata);
+ }
+
+ return metadata;
+}
+
+void
+gimp_image_metadata_load_finish (gint32 image_ID,
+ const gchar *mime_type,
+ GimpMetadata *metadata,
+ GimpMetadataLoadFlags flags,
+ gboolean interactive)
+{
+ g_return_if_fail (image_ID > 0);
+ g_return_if_fail (mime_type != NULL);
+ g_return_if_fail (GEXIV2_IS_METADATA (metadata));
+
+ if (flags & GIMP_METADATA_LOAD_COMMENT)
+ {
+ gchar *comment;
+
comment = gexiv2_metadata_get_tag_string (metadata,
"Exif.Photo.UserComment");
if (! comment)
@@ -106,22 +123,28 @@ gimp_image_metadata_load (gint32 image_ID,
gimp_image_attach_parasite (image_ID, parasite);
gimp_parasite_free (parasite);
}
+ }
+
+ if (flags & GIMP_METADATA_LOAD_RESOLUTION)
+ {
+ gdouble xres;
+ gdouble yres;
+ GimpUnit unit;
if (gimp_metadata_get_resolution (metadata, &xres, &yres, &unit))
{
gimp_image_set_resolution (image_ID, xres, yres);
gimp_image_set_unit (image_ID, unit);
}
+ }
+ if (flags & GIMP_METADATA_LOAD_ORIENTATION)
+ {
gimp_image_metadata_rotate_query (image_ID, mime_type,
metadata, interactive);
-
- gexiv2_metadata_erase_exif_thumbnail (metadata);
-
- gimp_image_set_metadata (image_ID, metadata);
-
- g_object_unref (metadata);
}
+
+ gimp_image_set_metadata (image_ID, metadata);
}
GimpMetadata *
@@ -255,8 +278,8 @@ gboolean
gimp_image_metadata_save_finish (gint32 image_ID,
const gchar *mime_type,
GimpMetadata *metadata,
- GFile *file,
GimpMetadataSaveFlags flags,
+ GFile *file,
GError **error)
{
GExiv2Metadata *new_metadata;
diff --git a/libgimp/gimpmetadata.h b/libgimp/gimpmetadata.h
index a2f9574..2c3d51a 100644
--- a/libgimp/gimpmetadata.h
+++ b/libgimp/gimpmetadata.h
@@ -30,18 +30,24 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
-void gimp_image_metadata_load (gint32 image_ID,
- const gchar *mime_type,
- GFile *file,
- gboolean interactive);
-GimpMetadata * gimp_image_metadata_save_prepare (gint32 image_ID,
- const gchar *mime_type);
-gboolean gimp_image_metadata_save_finish (gint32 image_ID,
- const gchar *mime_type,
- GimpMetadata *metadata,
- GFile *file,
- GimpMetadataSaveFlags flags,
- GError **error);
+GimpMetadata * gimp_image_metadata_load_prepare (gint32 image_ID,
+ const gchar *mime_type,
+ GFile *file,
+ GError **error);
+void gimp_image_metadata_load_finish (gint32 image_ID,
+ const gchar *mime_type,
+ GimpMetadata *metadata,
+ GimpMetadataLoadFlags flags,
+ gboolean interactive);
+
+GimpMetadata * gimp_image_metadata_save_prepare (gint32 image_ID,
+ const gchar *mime_type);
+gboolean gimp_image_metadata_save_finish (gint32 image_ID,
+ const gchar *mime_type,
+ GimpMetadata *metadata,
+ GimpMetadataSaveFlags flags,
+ GFile *file,
+ GError **error);
G_END_DECLS
diff --git a/libgimp/gimpui.def b/libgimp/gimpui.def
index 0105e31..4fe8fe1 100644
--- a/libgimp/gimpui.def
+++ b/libgimp/gimpui.def
@@ -38,7 +38,8 @@ EXPORTS
gimp_image_combo_box_get_type
gimp_image_combo_box_new
gimp_image_menu_new
- gimp_image_metadata_load
+ gimp_image_metadata_load_finish
+ gimp_image_metadata_load_prepare
gimp_image_metadata_save_finish
gimp_image_metadata_save_prepare
gimp_layer_combo_box_get_type
diff --git a/libgimpbase/gimpmetadata.h b/libgimpbase/gimpmetadata.h
index aefab9f..fb83c76 100644
--- a/libgimpbase/gimpmetadata.h
+++ b/libgimpbase/gimpmetadata.h
@@ -24,6 +24,16 @@
G_BEGIN_DECLS
+typedef enum
+{
+ GIMP_METADATA_LOAD_COMMENT = 1 << 0,
+ GIMP_METADATA_LOAD_RESOLUTION = 1 << 1,
+ GIMP_METADATA_LOAD_ORIENTATION = 1 << 2,
+
+ GIMP_METADATA_LOAD_ALL = (GIMP_METADATA_LOAD_COMMENT |
+ GIMP_METADATA_LOAD_RESOLUTION |
+ GIMP_METADATA_LOAD_ORIENTATION)
+} GimpMetadataLoadFlags;
typedef enum
{
@@ -38,6 +48,7 @@ typedef enum
GIMP_METADATA_SAVE_THUMBNAIL)
} GimpMetadataSaveFlags;
+
GimpMetadata * gimp_metadata_new (void);
GimpMetadata * gimp_metadata_duplicate (GimpMetadata *metadata);
diff --git a/plug-ins/common/file-jp2-load.c b/plug-ins/common/file-jp2-load.c
index f346c29..261142b 100644
--- a/plug-ins/common/file-jp2-load.c
+++ b/plug-ins/common/file-jp2-load.c
@@ -157,10 +157,22 @@ run (const gchar *name,
if (image_ID != -1)
{
- GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GimpMetadata *metadata;
- gimp_image_metadata_load (image_ID, "image/jp2", file,
- interactive);
+ metadata = gimp_image_metadata_load_prepare (image_ID, "image/jp2",
+ file, NULL);
+
+ if (metadata)
+ {
+ GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
+
+ gimp_image_metadata_load_finish (image_ID, "image/jp2",
+ metadata, flags,
+ interactive);
+
+ g_object_unref (metadata);
+ }
g_object_unref (file);
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 2bbd7cd..d1926a5 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -452,10 +452,22 @@ run (const gchar *name,
if (image_ID != -1)
{
- GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GimpMetadata *metadata;
- gimp_image_metadata_load (image_ID, "image/png", file,
- interactive);
+ metadata = gimp_image_metadata_load_prepare (image_ID, "image/png",
+ file, NULL);
+
+ if (metadata)
+ {
+ GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
+
+ gimp_image_metadata_load_finish (image_ID, "image/png",
+ metadata, flags,
+ interactive);
+
+ g_object_unref (metadata);
+ }
g_object_unref (file);
@@ -603,7 +615,7 @@ run (const gchar *name,
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (image_ID,
"image/png",
- metadata, file, flags,
+ metadata, flags, file,
NULL);
g_object_unref (file);
diff --git a/plug-ins/common/file-tiff-load.c b/plug-ins/common/file-tiff-load.c
index f0eb875..2f21d06 100644
--- a/plug-ins/common/file-tiff-load.c
+++ b/plug-ins/common/file-tiff-load.c
@@ -280,10 +280,23 @@ run (const gchar *name,
if (image != -1)
{
- GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GimpMetadata *metadata;
- gimp_image_metadata_load (image, "image/tiff", file,
- run_mode == GIMP_RUN_INTERACTIVE);
+ metadata = gimp_image_metadata_load_prepare (image,
+ "image/tiff",
+ file, NULL);
+
+ if (metadata)
+ {
+ GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
+
+ gimp_image_metadata_load_finish (image, "image/tiff",
+ metadata, flags,
+ run_mode == GIMP_RUN_INTERACTIVE);
+
+ g_object_unref (metadata);
+ }
g_object_unref (file);
diff --git a/plug-ins/common/file-tiff-save.c b/plug-ins/common/file-tiff-save.c
index 7e5e029..03c36ad 100644
--- a/plug-ins/common/file-tiff-save.c
+++ b/plug-ins/common/file-tiff-save.c
@@ -381,7 +381,7 @@ run (const gchar *name,
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (image,
"image/tiff",
- metadata, file, flags,
+ metadata, flags, file,
NULL);
g_object_unref (file);
diff --git a/plug-ins/file-jpeg/jpeg.c b/plug-ins/file-jpeg/jpeg.c
index 94e8a1e..176485a 100644
--- a/plug-ins/file-jpeg/jpeg.c
+++ b/plug-ins/file-jpeg/jpeg.c
@@ -51,7 +51,6 @@ gint32 display_ID;
JpegSaveVals jsvals;
gint32 orig_image_ID_global;
gint32 drawable_ID_global;
-gboolean has_metadata;
gint orig_quality;
JpegSubsampling orig_subsmp;
gint num_quant_tables;
@@ -193,7 +192,6 @@ run (const gchar *name,
preview_image_ID = -1;
preview_layer_ID = -1;
- has_metadata = FALSE;
orig_quality = 0;
orig_subsmp = JPEG_SUBSAMPLING_2x2_1x1_1x1;
num_quant_tables = 0;
@@ -216,10 +214,22 @@ run (const gchar *name,
if (image_ID != -1)
{
- GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GimpMetadata *metadata;
+
+ metadata = gimp_image_metadata_load_prepare (image_ID, "image/jpeg",
+ file, NULL);
- gimp_image_metadata_load (image_ID, "image/jpeg", file,
- load_interactive);
+ if (metadata)
+ {
+ GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
+
+ gimp_image_metadata_load_finish (image_ID, "image/jpeg",
+ metadata, flags,
+ load_interactive);
+
+ g_object_unref (metadata);
+ }
g_object_unref (file);
@@ -323,13 +333,6 @@ run (const gchar *name,
gimp_parasite_free (parasite);
}
- parasite = gimp_image_get_parasite (orig_image_ID, "gimp-metadata");
- if (parasite)
- {
- has_metadata = TRUE;
- gimp_parasite_free (parasite);
- }
-
/* load defaults from gimp parasite */
load_defaults ();
@@ -529,7 +532,7 @@ run (const gchar *name,
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (image_ID,
"image/jpeg",
- metadata, file, flags,
+ metadata, flags, file,
NULL);
g_object_unref (file);
diff --git a/plug-ins/file-jpeg/jpeg.h b/plug-ins/file-jpeg/jpeg.h
index 5cc0651..8d4ad08 100644
--- a/plug-ins/file-jpeg/jpeg.h
+++ b/plug-ins/file-jpeg/jpeg.h
@@ -57,7 +57,6 @@ extern gboolean undo_touched;
extern gboolean load_interactive;
extern gint32 display_ID;
extern gchar *image_comment;
-extern gboolean has_metadata;
extern gint orig_quality;
extern JpegSubsampling orig_subsmp;
extern gint num_quant_tables;
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index ce7ae57..c5bf4e7 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -313,7 +313,7 @@ run (const gchar *name,
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (image_id,
"image/x-psd",
- metadata, file, flags,
+ metadata, flags, file,
NULL);
g_object_unref (file);
diff --git a/plug-ins/file-psd/psd.c b/plug-ins/file-psd/psd.c
index b2bfc3e..1eca3d4 100644
--- a/plug-ins/file-psd/psd.c
+++ b/plug-ins/file-psd/psd.c
@@ -210,10 +210,22 @@ run (const gchar *name,
if (image_ID != -1)
{
- GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GFile *file = g_file_new_for_path (param[1].data.d_string);
+ GimpMetadata *metadata;
- gimp_image_metadata_load (image_ID, "image/x-psd", file,
- interactive);
+ metadata = gimp_image_metadata_load_prepare (image_ID, "image/x-psd",
+ file, NULL);
+
+ if (metadata)
+ {
+ GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
+
+ gimp_image_metadata_load_finish (image_ID, "image/x-psd",
+ metadata, flags,
+ interactive);
+
+ g_object_unref (metadata);
+ }
g_object_unref (file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]