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.
This commit is contained in:
Michael Natterer 2013-10-27 15:22:35 +01:00
parent 605144ff57
commit 7cbe83d911
12 changed files with 155 additions and 63 deletions

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;
gimp_image_metadata_load (image_ID, "image/jpeg", file,
load_interactive);
metadata = gimp_image_metadata_load_prepare (image_ID, "image/jpeg",
file, NULL);
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);

View File

@ -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;

View File

@ -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);

View File

@ -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);