2013-10-20 00:38:01 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
2015-09-25 06:40:57 +08:00
|
|
|
* gimpimagemetadata.c
|
2013-10-20 00:38:01 +08:00
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2017-07-06 07:24:54 +08:00
|
|
|
#include <sys/time.h>
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gexiv2/gexiv2.h>
|
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimpui.h"
|
2015-09-25 06:40:57 +08:00
|
|
|
#include "gimpimagemetadata.h"
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
#include "libgimp-intl.h"
|
|
|
|
|
2017-07-08 00:25:56 +08:00
|
|
|
|
2017-07-06 07:24:54 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gchar *tag;
|
|
|
|
gint type;
|
2017-07-08 00:25:56 +08:00
|
|
|
} XmpStructs;
|
2017-07-06 07:24:54 +08:00
|
|
|
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
static void gimp_image_metadata_rotate (gint32 image_ID,
|
|
|
|
GExiv2Orientation orientation);
|
|
|
|
static GdkPixbuf * gimp_image_metadata_rotate_pixbuf (GdkPixbuf *pixbuf,
|
|
|
|
GExiv2Orientation orientation);
|
|
|
|
static void gimp_image_metadata_rotate_query (gint32 image_ID,
|
|
|
|
const gchar *mime_type,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
gboolean interactive);
|
|
|
|
static gboolean gimp_image_metadata_rotate_dialog (gint32 image_ID,
|
|
|
|
GExiv2Orientation orientation,
|
|
|
|
const gchar *parasite_name);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
|
2013-10-20 00:38:01 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2013-10-28 02:42:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_image_metadata_load_prepare:
|
|
|
|
* @image_ID: The image
|
|
|
|
* @mime_type: The loaded file's mime-type
|
|
|
|
* @file: The file to load the metadata from
|
|
|
|
* @error: Return location for error
|
|
|
|
*
|
|
|
|
* Loads and returns metadata from @file to be passed into
|
|
|
|
* gimp_image_metadata_load_finish().
|
|
|
|
*
|
|
|
|
* Returns: The file's metadata.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2013-10-28 02:42:48 +08:00
|
|
|
*/
|
2013-10-27 22:22:35 +08:00
|
|
|
GimpMetadata *
|
|
|
|
gimp_image_metadata_load_prepare (gint32 image_ID,
|
|
|
|
const gchar *mime_type,
|
|
|
|
GFile *file,
|
|
|
|
GError **error)
|
2013-10-20 00:38:01 +08:00
|
|
|
{
|
2017-01-04 02:36:22 +08:00
|
|
|
GimpMetadata *metadata;
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2013-10-27 22:22:35 +08:00
|
|
|
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);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2013-10-27 22:22:35 +08:00
|
|
|
metadata = gimp_metadata_load_from_file (file, error);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
if (metadata)
|
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_erase_exif_thumbnail (GEXIV2_METADATA (metadata));
|
2013-10-27 22:22:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:42:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_image_metadata_load_finish:
|
|
|
|
* @image_ID: The image
|
|
|
|
* @mime_type: The loaded file's mime-type
|
|
|
|
* @metadata: The metadata to set on the image
|
|
|
|
* @flags: Flags to specify what of the metadata to apply to the image
|
|
|
|
* @interactive: Whether this function is allowed to query info with dialogs
|
|
|
|
*
|
|
|
|
* Applies the @metadata previously loaded with
|
|
|
|
* gimp_image_metadata_load_prepare() to the image, taking into account
|
|
|
|
* the passed @flags.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2013-10-28 02:42:48 +08:00
|
|
|
*/
|
2013-10-27 22:22:35 +08:00
|
|
|
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);
|
2017-01-04 02:36:22 +08:00
|
|
|
g_return_if_fail (GEXIV2_IS_METADATA (metadata));
|
2013-10-27 22:22:35 +08:00
|
|
|
|
|
|
|
if (flags & GIMP_METADATA_LOAD_COMMENT)
|
|
|
|
{
|
2017-01-04 02:36:22 +08:00
|
|
|
gchar *comment;
|
2013-10-27 22:22:35 +08:00
|
|
|
|
2017-01-30 23:42:27 +08:00
|
|
|
comment = gexiv2_metadata_get_tag_interpreted_string (GEXIV2_METADATA (metadata),
|
2017-01-04 02:36:22 +08:00
|
|
|
"Exif.Photo.UserComment");
|
|
|
|
if (! comment)
|
2017-01-30 23:42:27 +08:00
|
|
|
comment = gexiv2_metadata_get_tag_interpreted_string (GEXIV2_METADATA (metadata),
|
2017-01-04 02:36:22 +08:00
|
|
|
"Exif.Image.ImageDescription");
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
if (comment)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
parasite = gimp_parasite_new ("gimp-comment",
|
|
|
|
GIMP_PARASITE_PERSISTENT,
|
|
|
|
strlen (comment) + 1,
|
|
|
|
comment);
|
|
|
|
g_free (comment);
|
|
|
|
|
|
|
|
gimp_image_attach_parasite (image_ID, parasite);
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
2013-10-27 22:22:35 +08:00
|
|
|
}
|
2017-01-04 02:36:22 +08:00
|
|
|
|
2013-10-27 22:22:35 +08:00
|
|
|
if (flags & GIMP_METADATA_LOAD_RESOLUTION)
|
|
|
|
{
|
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
|
|
|
GimpUnit unit;
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
if (gimp_metadata_get_resolution (metadata, &xres, &yres, &unit))
|
|
|
|
{
|
|
|
|
gimp_image_set_resolution (image_ID, xres, yres);
|
|
|
|
gimp_image_set_unit (image_ID, unit);
|
|
|
|
}
|
2013-10-27 22:22:35 +08:00
|
|
|
}
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
if (flags & GIMP_METADATA_LOAD_ORIENTATION)
|
|
|
|
{
|
|
|
|
gimp_image_metadata_rotate_query (image_ID, mime_type,
|
|
|
|
metadata, interactive);
|
|
|
|
}
|
|
|
|
|
2015-08-20 21:05:04 +08:00
|
|
|
if (flags & GIMP_METADATA_LOAD_COLORSPACE)
|
|
|
|
{
|
2015-09-29 01:54:18 +08:00
|
|
|
GimpColorProfile *profile = gimp_image_get_color_profile (image_ID);
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
/* only look for colorspace information from metadata if the
|
|
|
|
* image didn't contain an embedded color profile
|
|
|
|
*/
|
2015-09-29 01:54:18 +08:00
|
|
|
if (! profile)
|
|
|
|
{
|
2015-10-01 02:47:52 +08:00
|
|
|
GimpMetadataColorspace colorspace;
|
2015-09-29 01:54:18 +08:00
|
|
|
|
2015-10-01 02:47:52 +08:00
|
|
|
colorspace = gimp_metadata_get_colorspace (metadata);
|
2015-09-29 01:54:18 +08:00
|
|
|
|
2015-10-01 02:47:52 +08:00
|
|
|
switch (colorspace)
|
2015-09-29 01:54:18 +08:00
|
|
|
{
|
2015-10-01 02:47:52 +08:00
|
|
|
case GIMP_METADATA_COLORSPACE_UNSPECIFIED:
|
|
|
|
case GIMP_METADATA_COLORSPACE_UNCALIBRATED:
|
|
|
|
case GIMP_METADATA_COLORSPACE_SRGB:
|
|
|
|
/* use sRGB, a NULL profile will do the right thing */
|
|
|
|
break;
|
2015-08-20 21:05:04 +08:00
|
|
|
|
2015-10-01 02:47:52 +08:00
|
|
|
case GIMP_METADATA_COLORSPACE_ADOBERGB:
|
2015-12-16 03:42:21 +08:00
|
|
|
profile = gimp_color_profile_new_rgb_adobe ();
|
2015-10-01 02:47:52 +08:00
|
|
|
break;
|
2015-08-20 21:05:04 +08:00
|
|
|
}
|
|
|
|
|
2015-09-29 01:54:18 +08:00
|
|
|
if (profile)
|
|
|
|
gimp_image_set_color_profile (image_ID, profile);
|
2015-08-20 21:05:04 +08:00
|
|
|
}
|
|
|
|
|
2015-09-29 01:54:18 +08:00
|
|
|
if (profile)
|
|
|
|
g_object_unref (profile);
|
2015-08-20 21:05:04 +08:00
|
|
|
}
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
gimp_image_set_metadata (image_ID, metadata);
|
2013-10-20 00:38:01 +08:00
|
|
|
}
|
|
|
|
|
2013-10-28 02:42:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_image_metadata_save_prepare:
|
2014-06-05 21:50:05 +08:00
|
|
|
* @image_ID: The image
|
|
|
|
* @mime_type: The saved file's mime-type
|
2018-01-11 12:17:59 +08:00
|
|
|
* @suggested_flags: Suggested default values for the @flags passed to
|
2014-06-05 21:50:05 +08:00
|
|
|
* gimp_image_metadata_save_finish()
|
2013-10-28 02:42:48 +08:00
|
|
|
*
|
2017-01-04 02:36:22 +08:00
|
|
|
* Gets the image metadata for saving it using
|
2013-10-28 02:42:48 +08:00
|
|
|
* gimp_image_metadata_save_finish().
|
|
|
|
*
|
2018-01-11 12:17:59 +08:00
|
|
|
* The @suggested_flags are determined from what kind of metadata
|
|
|
|
* (Exif, XMP, ...) is actually present in the image and the preferences
|
|
|
|
* for metadata exporting.
|
|
|
|
* The calling application may still update @available_flags, for
|
|
|
|
* instance to follow the settings from a previous export in the same
|
|
|
|
* session, or a previous export of the same image. But it should not
|
|
|
|
* override the preferences without a good reason since it is a data
|
|
|
|
* leak.
|
|
|
|
*
|
|
|
|
* The suggested value for GIMP_METADATA_SAVE_THUMBNAIL is determined by
|
|
|
|
* whether there was a thumbnail in the previously imported image.
|
2014-06-05 21:50:05 +08:00
|
|
|
*
|
2017-01-04 02:36:22 +08:00
|
|
|
* Returns: The image's metadata, prepared for saving.
|
2013-10-28 02:42:48 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2013-10-28 02:42:48 +08:00
|
|
|
*/
|
2013-10-20 00:38:01 +08:00
|
|
|
GimpMetadata *
|
2014-06-05 08:07:13 +08:00
|
|
|
gimp_image_metadata_save_prepare (gint32 image_ID,
|
|
|
|
const gchar *mime_type,
|
|
|
|
GimpMetadataSaveFlags *suggested_flags)
|
2013-10-20 00:38:01 +08:00
|
|
|
{
|
2017-01-04 02:36:22 +08:00
|
|
|
GimpMetadata *metadata;
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (image_ID > 0, NULL);
|
|
|
|
g_return_val_if_fail (mime_type != NULL, NULL);
|
2014-06-05 08:07:13 +08:00
|
|
|
g_return_val_if_fail (suggested_flags != NULL, NULL);
|
|
|
|
|
|
|
|
*suggested_flags = GIMP_METADATA_SAVE_ALL;
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
metadata = gimp_image_get_metadata (image_ID);
|
|
|
|
|
|
|
|
if (metadata)
|
|
|
|
{
|
2017-01-04 02:36:22 +08:00
|
|
|
GDateTime *datetime;
|
|
|
|
const GimpParasite *comment_parasite;
|
|
|
|
const gchar *comment = NULL;
|
|
|
|
gint image_width;
|
|
|
|
gint image_height;
|
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
|
|
|
gchar buffer[32];
|
2017-01-30 23:42:27 +08:00
|
|
|
GExiv2Metadata *g2metadata = GEXIV2_METADATA (metadata);
|
2017-01-04 02:36:22 +08:00
|
|
|
|
|
|
|
image_width = gimp_image_width (image_ID);
|
|
|
|
image_height = gimp_image_height (image_ID);
|
|
|
|
|
|
|
|
datetime = g_date_time_new_now_local ();
|
|
|
|
|
|
|
|
comment_parasite = gimp_image_get_parasite (image_ID, "gimp-comment");
|
|
|
|
if (comment_parasite)
|
|
|
|
comment = gimp_parasite_data (comment_parasite);
|
|
|
|
|
2013-10-30 05:48:46 +08:00
|
|
|
/* Exif */
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2018-01-11 12:17:59 +08:00
|
|
|
if (! gimp_export_exif () ||
|
|
|
|
! gexiv2_metadata_has_exif (g2metadata))
|
2014-06-05 08:07:13 +08:00
|
|
|
*suggested_flags &= ~GIMP_METADATA_SAVE_EXIF;
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
if (comment)
|
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Exif.Photo.UserComment",
|
|
|
|
comment);
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Exif.Image.ImageDescription",
|
|
|
|
comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer),
|
|
|
|
"%d:%02d:%02d %02d:%02d:%02d",
|
|
|
|
g_date_time_get_year (datetime),
|
|
|
|
g_date_time_get_month (datetime),
|
|
|
|
g_date_time_get_day_of_month (datetime),
|
|
|
|
g_date_time_get_hour (datetime),
|
|
|
|
g_date_time_get_minute (datetime),
|
|
|
|
g_date_time_get_second (datetime));
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Exif.Image.DateTime",
|
|
|
|
buffer);
|
|
|
|
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Exif.Image.Software",
|
|
|
|
PACKAGE_STRING);
|
|
|
|
|
|
|
|
gimp_metadata_set_pixel_size (metadata,
|
|
|
|
image_width, image_height);
|
|
|
|
|
|
|
|
gimp_image_get_resolution (image_ID, &xres, &yres);
|
|
|
|
gimp_metadata_set_resolution (metadata, xres, yres,
|
|
|
|
gimp_image_get_unit (image_ID));
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
/* XMP */
|
|
|
|
|
2018-01-11 12:17:59 +08:00
|
|
|
if (! gimp_export_xmp () ||
|
|
|
|
! gexiv2_metadata_has_xmp (g2metadata))
|
2014-06-05 08:07:13 +08:00
|
|
|
*suggested_flags &= ~GIMP_METADATA_SAVE_XMP;
|
|
|
|
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Xmp.dc.Format",
|
|
|
|
mime_type);
|
|
|
|
|
|
|
|
if (! g_strcmp0 (mime_type, "image/tiff"))
|
|
|
|
{
|
|
|
|
/* TIFF specific XMP data */
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer), "%d", image_width);
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Xmp.tiff.ImageWidth",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer), "%d", image_height);
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Xmp.tiff.ImageLength",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer),
|
|
|
|
"%d:%02d:%02d %02d:%02d:%02d",
|
|
|
|
g_date_time_get_year (datetime),
|
|
|
|
g_date_time_get_month (datetime),
|
|
|
|
g_date_time_get_day_of_month (datetime),
|
|
|
|
g_date_time_get_hour (datetime),
|
|
|
|
g_date_time_get_minute (datetime),
|
|
|
|
g_date_time_get_second (datetime));
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Xmp.tiff.DateTime",
|
|
|
|
buffer);
|
|
|
|
}
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
/* IPTC */
|
|
|
|
|
2018-01-11 12:17:59 +08:00
|
|
|
if (! gimp_export_xmp () ||
|
|
|
|
! gexiv2_metadata_has_iptc (g2metadata))
|
2014-06-05 08:07:13 +08:00
|
|
|
*suggested_flags &= ~GIMP_METADATA_SAVE_IPTC;
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer),
|
|
|
|
"%d-%d-%d",
|
|
|
|
g_date_time_get_year (datetime),
|
|
|
|
g_date_time_get_month (datetime),
|
|
|
|
g_date_time_get_day_of_month (datetime));
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Iptc.Application2.DateCreated",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer),
|
|
|
|
"%02d:%02d:%02d-%02d:%02d",
|
|
|
|
g_date_time_get_hour (datetime),
|
|
|
|
g_date_time_get_minute (datetime),
|
|
|
|
g_date_time_get_second (datetime),
|
|
|
|
g_date_time_get_hour (datetime),
|
|
|
|
g_date_time_get_minute (datetime));
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (g2metadata,
|
2017-01-04 02:36:22 +08:00
|
|
|
"Iptc.Application2.TimeCreated",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
g_date_time_unref (datetime);
|
2014-06-05 08:07:13 +08:00
|
|
|
|
|
|
|
/* Thumbnail */
|
|
|
|
|
|
|
|
if (FALSE /* FIXME if (original image had a thumbnail) */)
|
|
|
|
*suggested_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
|
2013-10-20 00:38:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
|
2017-07-06 07:24:54 +08:00
|
|
|
|
2013-10-28 02:42:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_image_metadata_save_finish:
|
|
|
|
* @image_ID: The image
|
|
|
|
* @mime_type: The saved file's mime-type
|
|
|
|
* @metadata: The metadata to set on the image
|
|
|
|
* @flags: Flags to specify what of the metadata to save
|
|
|
|
* @file: The file to load the metadata from
|
|
|
|
* @error: Return location for error message
|
|
|
|
*
|
|
|
|
* Saves the @metadata retrieved from the image with
|
|
|
|
* gimp_image_metadata_save_prepare() to @file, taking into account
|
|
|
|
* the passed @flags.
|
|
|
|
*
|
|
|
|
* Return value: Whether the save was successful.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2013-10-28 02:42:48 +08:00
|
|
|
*/
|
2013-10-20 00:38:01 +08:00
|
|
|
gboolean
|
|
|
|
gimp_image_metadata_save_finish (gint32 image_ID,
|
|
|
|
const gchar *mime_type,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataSaveFlags flags,
|
2013-10-27 22:22:35 +08:00
|
|
|
GFile *file,
|
2013-10-20 00:38:01 +08:00
|
|
|
GError **error)
|
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
GimpMetadata *new_metadata;
|
|
|
|
GExiv2Metadata *new_g2metadata;
|
2013-10-20 00:38:01 +08:00
|
|
|
gboolean support_exif;
|
|
|
|
gboolean support_xmp;
|
|
|
|
gboolean support_iptc;
|
2017-01-04 02:36:22 +08:00
|
|
|
gchar *value;
|
|
|
|
gboolean success = FALSE;
|
|
|
|
gint i;
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (image_ID > 0, FALSE);
|
|
|
|
g_return_val_if_fail (mime_type != NULL, FALSE);
|
2017-01-04 02:36:22 +08:00
|
|
|
g_return_val_if_fail (GEXIV2_IS_METADATA (metadata), FALSE);
|
2013-10-20 00:38:01 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2014-05-01 01:46:13 +08:00
|
|
|
if (! (flags & (GIMP_METADATA_SAVE_EXIF |
|
|
|
|
GIMP_METADATA_SAVE_XMP |
|
|
|
|
GIMP_METADATA_SAVE_IPTC |
|
2013-11-12 06:31:58 +08:00
|
|
|
GIMP_METADATA_SAVE_THUMBNAIL)))
|
|
|
|
return TRUE;
|
|
|
|
|
2013-10-20 00:38:01 +08:00
|
|
|
/* read metadata from saved file */
|
2017-01-04 02:36:22 +08:00
|
|
|
new_metadata = gimp_metadata_load_from_file (file, error);
|
2017-01-30 23:42:27 +08:00
|
|
|
new_g2metadata = GEXIV2_METADATA (new_metadata);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
if (! new_metadata)
|
2013-10-20 00:38:01 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2017-01-30 23:42:27 +08:00
|
|
|
support_exif = gexiv2_metadata_get_supports_exif (new_g2metadata);
|
|
|
|
support_xmp = gexiv2_metadata_get_supports_xmp (new_g2metadata);
|
|
|
|
support_iptc = gexiv2_metadata_get_supports_iptc (new_g2metadata);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
if ((flags & GIMP_METADATA_SAVE_EXIF) && support_exif)
|
2013-10-20 00:38:01 +08:00
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
gchar **exif_data = gexiv2_metadata_get_exif_tags (GEXIV2_METADATA (metadata));
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
for (i = 0; exif_data[i] != NULL; i++)
|
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
if (! gexiv2_metadata_has_tag (new_g2metadata, exif_data[i]) &&
|
2013-10-20 00:38:01 +08:00
|
|
|
gimp_metadata_is_tag_supported (exif_data[i], mime_type))
|
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
|
|
|
|
exif_data[i]);
|
|
|
|
gexiv2_metadata_set_tag_string (new_g2metadata, exif_data[i],
|
2013-10-20 00:38:01 +08:00
|
|
|
value);
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (exif_data);
|
|
|
|
}
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
if ((flags & GIMP_METADATA_SAVE_XMP) && support_xmp)
|
2013-10-20 00:38:01 +08:00
|
|
|
{
|
2017-07-08 00:25:56 +08:00
|
|
|
static const XmpStructs structlist[] =
|
|
|
|
{
|
|
|
|
{ "Xmp.iptcExt.LocationCreated", GEXIV2_STRUCTURE_XA_BAG },
|
|
|
|
{ "Xmp.iptcExt.LocationShown", GEXIV2_STRUCTURE_XA_BAG },
|
|
|
|
{ "Xmp.iptcExt.ArtworkOrObject", GEXIV2_STRUCTURE_XA_BAG },
|
|
|
|
{ "Xmp.iptcExt.RegistryId", GEXIV2_STRUCTURE_XA_BAG },
|
|
|
|
{ "Xmp.xmpMM.History", GEXIV2_STRUCTURE_XA_SEQ },
|
|
|
|
{ "Xmp.plus.ImageSupplier", GEXIV2_STRUCTURE_XA_SEQ },
|
|
|
|
{ "Xmp.plus.ImageCreator", GEXIV2_STRUCTURE_XA_SEQ },
|
|
|
|
{ "Xmp.plus.CopyrightOwner", GEXIV2_STRUCTURE_XA_SEQ },
|
|
|
|
{ "Xmp.plus.Licensor", GEXIV2_STRUCTURE_XA_SEQ }
|
|
|
|
};
|
|
|
|
|
2017-07-06 07:24:54 +08:00
|
|
|
gchar **xmp_data;
|
|
|
|
struct timeval timer_usec;
|
2017-07-08 00:25:56 +08:00
|
|
|
gint64 timestamp_usec;
|
|
|
|
gchar ts[128];
|
2017-07-06 07:24:54 +08:00
|
|
|
|
2017-07-08 00:25:56 +08:00
|
|
|
gettimeofday (&timer_usec, NULL);
|
|
|
|
timestamp_usec = ((gint64) timer_usec.tv_sec) * 1000000ll +
|
|
|
|
(gint64) timer_usec.tv_usec;
|
|
|
|
g_snprintf (ts, sizeof (ts), "%" G_GINT64_FORMAT, timestamp_usec);
|
|
|
|
|
|
|
|
gimp_metadata_add_xmp_history (metadata, "");
|
2017-07-06 07:24:54 +08:00
|
|
|
|
|
|
|
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
|
|
|
|
"Xmp.GIMP.TimeStamp",
|
|
|
|
ts);
|
|
|
|
|
|
|
|
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
|
|
|
|
"Xmp.xmp.CreatorTool",
|
2018-04-26 22:06:32 +08:00
|
|
|
N_("GIMP 2.10"));
|
2017-07-06 07:24:54 +08:00
|
|
|
|
|
|
|
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
|
|
|
|
"Xmp.GIMP.Version",
|
|
|
|
GIMP_VERSION);
|
|
|
|
|
|
|
|
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
|
|
|
|
"Xmp.GIMP.API",
|
|
|
|
GIMP_API_VERSION);
|
|
|
|
|
|
|
|
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
|
|
|
|
"Xmp.GIMP.Platform",
|
|
|
|
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
|
|
|
|
"Windows");
|
|
|
|
#elif defined(__linux__)
|
|
|
|
"Linux");
|
|
|
|
#elif defined(__APPLE__) && defined(__MACH__)
|
|
|
|
"Mac OS");
|
|
|
|
#elif defined(unix) || defined(__unix__) || defined(__unix)
|
|
|
|
"Unix");
|
|
|
|
#else
|
|
|
|
"Unknown");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
xmp_data = gexiv2_metadata_get_xmp_tags (GEXIV2_METADATA (metadata));
|
|
|
|
|
|
|
|
/* Patch necessary structures */
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
{
|
2017-07-08 00:25:56 +08:00
|
|
|
gexiv2_metadata_set_xmp_tag_struct (GEXIV2_METADATA (new_g2metadata),
|
|
|
|
structlist[i].tag,
|
|
|
|
structlist[i].type);
|
2017-07-06 07:24:54 +08:00
|
|
|
}
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
for (i = 0; xmp_data[i] != NULL; i++)
|
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
if (! gexiv2_metadata_has_tag (new_g2metadata, xmp_data[i]) &&
|
2013-10-20 00:38:01 +08:00
|
|
|
gimp_metadata_is_tag_supported (xmp_data[i], mime_type))
|
|
|
|
{
|
2017-07-08 00:25:56 +08:00
|
|
|
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
|
|
|
|
xmp_data[i]);
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (new_g2metadata, xmp_data[i],
|
2017-01-04 02:36:22 +08:00
|
|
|
value);
|
|
|
|
g_free (value);
|
2013-10-20 00:38:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (xmp_data);
|
|
|
|
}
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
if ((flags & GIMP_METADATA_SAVE_IPTC) && support_iptc)
|
2013-10-20 00:38:01 +08:00
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
gchar **iptc_data = gexiv2_metadata_get_iptc_tags (GEXIV2_METADATA (metadata));
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
for (i = 0; iptc_data[i] != NULL; i++)
|
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
if (! gexiv2_metadata_has_tag (new_g2metadata, iptc_data[i]) &&
|
2013-10-20 00:38:01 +08:00
|
|
|
gimp_metadata_is_tag_supported (iptc_data[i], mime_type))
|
|
|
|
{
|
2017-01-30 23:42:27 +08:00
|
|
|
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
|
|
|
|
iptc_data[i]);
|
|
|
|
gexiv2_metadata_set_tag_string (new_g2metadata, iptc_data[i],
|
2017-01-04 02:36:22 +08:00
|
|
|
value);
|
|
|
|
g_free (value);
|
2013-10-20 00:38:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (iptc_data);
|
|
|
|
}
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
if (flags & GIMP_METADATA_SAVE_THUMBNAIL)
|
2013-10-20 00:38:01 +08:00
|
|
|
{
|
|
|
|
GdkPixbuf *thumb_pixbuf;
|
|
|
|
gchar *thumb_buffer;
|
|
|
|
gint image_width;
|
|
|
|
gint image_height;
|
|
|
|
gsize count;
|
|
|
|
gint thumbw;
|
|
|
|
gint thumbh;
|
|
|
|
|
|
|
|
#define EXIF_THUMBNAIL_SIZE 256
|
|
|
|
|
|
|
|
image_width = gimp_image_width (image_ID);
|
|
|
|
image_height = gimp_image_height (image_ID);
|
|
|
|
|
|
|
|
if (image_width > image_height)
|
|
|
|
{
|
|
|
|
thumbw = EXIF_THUMBNAIL_SIZE;
|
|
|
|
thumbh = EXIF_THUMBNAIL_SIZE * image_height / image_width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
thumbh = EXIF_THUMBNAIL_SIZE;
|
2014-05-03 00:44:45 +08:00
|
|
|
thumbw = EXIF_THUMBNAIL_SIZE * image_width / image_height;
|
2013-10-20 00:38:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
thumb_pixbuf = gimp_image_get_thumbnail (image_ID, thumbw, thumbh,
|
|
|
|
GIMP_PIXBUF_KEEP_ALPHA);
|
|
|
|
|
|
|
|
if (gdk_pixbuf_save_to_buffer (thumb_pixbuf, &thumb_buffer, &count,
|
|
|
|
"jpeg", NULL,
|
|
|
|
"quality", "75",
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
gchar buffer[32];
|
|
|
|
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_exif_thumbnail_from_buffer (new_g2metadata,
|
2013-10-20 00:38:01 +08:00
|
|
|
(guchar *) thumb_buffer,
|
|
|
|
count);
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer), "%d", thumbw);
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (new_g2metadata,
|
2013-10-20 00:38:01 +08:00
|
|
|
"Exif.Thumbnail.ImageWidth",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer), "%d", thumbh);
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (new_g2metadata,
|
2013-10-20 00:38:01 +08:00
|
|
|
"Exif.Thumbnail.ImageLength",
|
|
|
|
buffer);
|
|
|
|
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (new_g2metadata,
|
2013-10-20 00:38:01 +08:00
|
|
|
"Exif.Thumbnail.BitsPerSample",
|
|
|
|
"8 8 8");
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (new_g2metadata,
|
2013-10-20 00:38:01 +08:00
|
|
|
"Exif.Thumbnail.SamplesPerPixel",
|
|
|
|
"3");
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_set_tag_string (new_g2metadata,
|
2013-10-20 00:38:01 +08:00
|
|
|
"Exif.Thumbnail.PhotometricInterpretation",
|
|
|
|
"6");
|
|
|
|
|
|
|
|
g_free (thumb_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (thumb_pixbuf);
|
|
|
|
}
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
success = gimp_metadata_save_to_file (new_metadata, file, error);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
g_object_unref (new_metadata);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2013-10-30 07:04:36 +08:00
|
|
|
gint32
|
|
|
|
gimp_image_metadata_load_thumbnail (GFile *file,
|
|
|
|
GError **error)
|
|
|
|
{
|
2017-01-04 02:36:22 +08:00
|
|
|
GimpMetadata *metadata;
|
|
|
|
GInputStream *input_stream;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
guint8 *thumbnail_buffer;
|
|
|
|
gint thumbnail_size;
|
|
|
|
gint32 image_ID = -1;
|
2013-10-30 07:04:36 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), -1);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, -1);
|
|
|
|
|
|
|
|
metadata = gimp_metadata_load_from_file (file, error);
|
|
|
|
if (! metadata)
|
|
|
|
return -1;
|
|
|
|
|
2017-01-30 23:42:27 +08:00
|
|
|
if (! gexiv2_metadata_get_exif_thumbnail (GEXIV2_METADATA (metadata),
|
2013-10-30 07:04:36 +08:00
|
|
|
&thumbnail_buffer,
|
|
|
|
&thumbnail_size))
|
|
|
|
{
|
|
|
|
g_object_unref (metadata);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_stream = g_memory_input_stream_new_from_data (thumbnail_buffer,
|
|
|
|
thumbnail_size,
|
|
|
|
(GDestroyNotify) g_free);
|
|
|
|
pixbuf = gdk_pixbuf_new_from_stream (input_stream, NULL, error);
|
|
|
|
g_object_unref (input_stream);
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
{
|
|
|
|
gint32 layer_ID;
|
|
|
|
|
|
|
|
image_ID = gimp_image_new (gdk_pixbuf_get_width (pixbuf),
|
|
|
|
gdk_pixbuf_get_height (pixbuf),
|
|
|
|
GIMP_RGB);
|
|
|
|
gimp_image_undo_disable (image_ID);
|
|
|
|
|
|
|
|
layer_ID = gimp_layer_new_from_pixbuf (image_ID, _("Background"),
|
|
|
|
pixbuf,
|
2017-02-26 23:26:34 +08:00
|
|
|
100.0,
|
2017-08-22 02:04:25 +08:00
|
|
|
gimp_image_get_default_new_layer_mode (image_ID),
|
2013-10-30 07:04:36 +08:00
|
|
|
0.0, 0.0);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
|
|
|
gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
|
|
|
|
|
|
|
|
gimp_image_metadata_rotate (image_ID,
|
2017-01-30 23:42:27 +08:00
|
|
|
gexiv2_metadata_get_orientation (GEXIV2_METADATA (metadata)));
|
2013-10-30 07:04:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (metadata);
|
|
|
|
|
|
|
|
return image_ID;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_image_metadata_rotate (gint32 image_ID,
|
|
|
|
GExiv2Orientation orientation)
|
|
|
|
{
|
|
|
|
switch (orientation)
|
|
|
|
{
|
|
|
|
case GEXIV2_ORIENTATION_UNSPECIFIED:
|
|
|
|
case GEXIV2_ORIENTATION_NORMAL: /* standard orientation, do nothing */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_HFLIP:
|
|
|
|
gimp_image_flip (image_ID, GIMP_ORIENTATION_HORIZONTAL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_180:
|
|
|
|
gimp_image_rotate (image_ID, GIMP_ROTATE_180);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_VFLIP:
|
|
|
|
gimp_image_flip (image_ID, GIMP_ORIENTATION_VERTICAL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90_HFLIP: /* flipped diagonally around '\' */
|
|
|
|
gimp_image_rotate (image_ID, GIMP_ROTATE_90);
|
|
|
|
gimp_image_flip (image_ID, GIMP_ORIENTATION_HORIZONTAL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90: /* 90 CW */
|
|
|
|
gimp_image_rotate (image_ID, GIMP_ROTATE_90);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90_VFLIP: /* flipped diagonally around '/' */
|
|
|
|
gimp_image_rotate (image_ID, GIMP_ROTATE_90);
|
|
|
|
gimp_image_flip (image_ID, GIMP_ORIENTATION_VERTICAL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_270: /* 90 CCW */
|
|
|
|
gimp_image_rotate (image_ID, GIMP_ROTATE_270);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* shouldn't happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
static GdkPixbuf *
|
|
|
|
gimp_image_metadata_rotate_pixbuf (GdkPixbuf *pixbuf,
|
|
|
|
GExiv2Orientation orientation)
|
|
|
|
{
|
|
|
|
GdkPixbuf *rotated = NULL;
|
|
|
|
GdkPixbuf *temp;
|
|
|
|
|
|
|
|
switch (orientation)
|
|
|
|
{
|
|
|
|
case GEXIV2_ORIENTATION_UNSPECIFIED:
|
|
|
|
case GEXIV2_ORIENTATION_NORMAL: /* standard orientation, do nothing */
|
2014-06-06 02:38:38 +08:00
|
|
|
rotated = g_object_ref (pixbuf);
|
2014-05-31 02:51:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_HFLIP:
|
|
|
|
rotated = gdk_pixbuf_flip (pixbuf, TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_180:
|
|
|
|
rotated = gdk_pixbuf_rotate_simple (pixbuf, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_VFLIP:
|
|
|
|
rotated = gdk_pixbuf_flip (pixbuf, FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90_HFLIP: /* flipped diagonally around '\' */
|
|
|
|
temp = gdk_pixbuf_rotate_simple (pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
|
|
|
|
rotated = gdk_pixbuf_flip (temp, TRUE);
|
|
|
|
g_object_unref (temp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90: /* 90 CW */
|
|
|
|
rotated = gdk_pixbuf_rotate_simple (pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90_VFLIP: /* flipped diagonally around '/' */
|
|
|
|
temp = gdk_pixbuf_rotate_simple (pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
|
|
|
|
rotated = gdk_pixbuf_flip (temp, FALSE);
|
|
|
|
g_object_unref (temp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_270: /* 90 CCW */
|
|
|
|
rotated = gdk_pixbuf_rotate_simple (pixbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* shouldn't happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rotated;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:38:01 +08:00
|
|
|
static void
|
|
|
|
gimp_image_metadata_rotate_query (gint32 image_ID,
|
|
|
|
const gchar *mime_type,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
gboolean interactive)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite;
|
|
|
|
gchar *parasite_name;
|
|
|
|
GExiv2Orientation orientation;
|
|
|
|
gboolean query = interactive;
|
|
|
|
|
2017-01-30 23:42:27 +08:00
|
|
|
orientation = gexiv2_metadata_get_orientation (GEXIV2_METADATA (metadata));
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
if (orientation <= GEXIV2_ORIENTATION_NORMAL ||
|
|
|
|
orientation > GEXIV2_ORIENTATION_MAX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
parasite_name = g_strdup_printf ("gimp-metadata-exif-rotate(%s)", mime_type);
|
|
|
|
|
|
|
|
parasite = gimp_get_parasite (parasite_name);
|
|
|
|
|
|
|
|
if (parasite)
|
|
|
|
{
|
|
|
|
if (strncmp (gimp_parasite_data (parasite), "yes",
|
|
|
|
gimp_parasite_data_size (parasite)) == 0)
|
|
|
|
{
|
|
|
|
query = FALSE;
|
|
|
|
}
|
|
|
|
else if (strncmp (gimp_parasite_data (parasite), "no",
|
|
|
|
gimp_parasite_data_size (parasite)) == 0)
|
|
|
|
{
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
g_free (parasite_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query && ! gimp_image_metadata_rotate_dialog (image_ID,
|
2014-05-31 02:51:39 +08:00
|
|
|
orientation,
|
2013-10-20 00:38:01 +08:00
|
|
|
parasite_name))
|
|
|
|
{
|
|
|
|
g_free (parasite_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (parasite_name);
|
|
|
|
|
|
|
|
gimp_image_metadata_rotate (image_ID, orientation);
|
2017-02-20 08:30:19 +08:00
|
|
|
gexiv2_metadata_set_orientation (GEXIV2_METADATA (metadata),
|
|
|
|
GEXIV2_ORIENTATION_NORMAL);
|
2013-10-20 00:38:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-05-31 02:51:39 +08:00
|
|
|
gimp_image_metadata_rotate_dialog (gint32 image_ID,
|
|
|
|
GExiv2Orientation orientation,
|
|
|
|
const gchar *parasite_name)
|
2013-10-20 00:38:01 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2014-05-31 02:51:39 +08:00
|
|
|
GtkWidget *main_vbox;
|
2013-10-20 00:38:01 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *toggle;
|
|
|
|
GdkPixbuf *pixbuf;
|
2014-05-31 02:51:39 +08:00
|
|
|
gchar *name;
|
|
|
|
gchar *title;
|
2013-10-20 00:38:01 +08:00
|
|
|
gint response;
|
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
name = gimp_image_get_name (image_ID);
|
|
|
|
title = g_strdup_printf (_("Rotate %s?"), name);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
dialog = gimp_dialog_new (title, "gimp-metadata-rotate-dialog",
|
2013-10-20 00:38:01 +08:00
|
|
|
NULL, 0, NULL, NULL,
|
|
|
|
|
2017-02-12 23:10:50 +08:00
|
|
|
_("_Keep Original"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Rotate"), GTK_RESPONSE_OK,
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
g_free (title);
|
|
|
|
|
2018-05-10 23:04:37 +08:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2013-10-20 00:38:01 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
2013-10-20 00:38:01 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
2014-05-31 02:51:39 +08:00
|
|
|
main_vbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (main_vbox);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
#define THUMBNAIL_SIZE 128
|
|
|
|
|
|
|
|
pixbuf = gimp_image_get_thumbnail (image_ID,
|
|
|
|
THUMBNAIL_SIZE, THUMBNAIL_SIZE,
|
|
|
|
GIMP_PIXBUF_SMALL_CHECKS);
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
{
|
2014-05-31 02:51:39 +08:00
|
|
|
GdkPixbuf *rotated;
|
|
|
|
GtkWidget *hbox;
|
2013-10-20 00:38:01 +08:00
|
|
|
GtkWidget *image;
|
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
label = gtk_label_new (_("Original"));
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_MIDDLE);
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (label),
|
|
|
|
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
|
|
|
|
-1);
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
image = gtk_image_new_from_pixbuf (pixbuf);
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), image, FALSE, FALSE, 0);
|
2013-10-20 00:38:01 +08:00
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
label = gtk_label_new (_("Rotated"));
|
2013-10-20 00:38:01 +08:00
|
|
|
gimp_label_set_attributes (GTK_LABEL (label),
|
|
|
|
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
|
|
|
|
-1);
|
2014-05-31 02:51:39 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
2013-10-20 00:38:01 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
rotated = gimp_image_metadata_rotate_pixbuf (pixbuf, orientation);
|
|
|
|
g_object_unref (pixbuf);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2014-05-31 02:51:39 +08:00
|
|
|
image = gtk_image_new_from_pixbuf (rotated);
|
|
|
|
g_object_unref (rotated);
|
|
|
|
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), image, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (image);
|
|
|
|
}
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
label = g_object_new (GTK_TYPE_LABEL,
|
2014-05-31 02:51:39 +08:00
|
|
|
"label", _("This image contains Exif orientation "
|
|
|
|
"metadata."),
|
2013-10-20 00:38:01 +08:00
|
|
|
"wrap", TRUE,
|
|
|
|
"justify", GTK_JUSTIFY_LEFT,
|
|
|
|
"xalign", 0.0,
|
|
|
|
"yalign", 0.5,
|
|
|
|
NULL);
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (label),
|
|
|
|
PANGO_ATTR_SCALE, PANGO_SCALE_LARGE,
|
|
|
|
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
|
|
|
|
-1);
|
2014-05-31 02:51:39 +08:00
|
|
|
/* eek */
|
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (label),
|
|
|
|
2 * THUMBNAIL_SIZE + 12, -1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, FALSE, 0);
|
2013-10-20 00:38:01 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
label = g_object_new (GTK_TYPE_LABEL,
|
2014-05-31 02:51:39 +08:00
|
|
|
"label", _("Would you like to rotate the image?"),
|
2013-10-20 00:38:01 +08:00
|
|
|
"wrap", TRUE,
|
|
|
|
"justify", GTK_JUSTIFY_LEFT,
|
|
|
|
"xalign", 0.0,
|
|
|
|
"yalign", 0.5,
|
|
|
|
NULL);
|
2014-05-31 02:51:39 +08:00
|
|
|
/* eek */
|
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (label),
|
|
|
|
2 * THUMBNAIL_SIZE + 12, -1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, FALSE, 0);
|
2013-10-20 00:38:01 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("_Don't ask me again"));
|
2014-05-31 02:51:39 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (main_vbox), toggle, FALSE, FALSE, 0);
|
2013-10-20 00:38:01 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), FALSE);
|
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
|
|
|
response = gimp_dialog_run (GIMP_DIALOG (dialog));
|
|
|
|
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle)))
|
|
|
|
{
|
|
|
|
GimpParasite *parasite;
|
|
|
|
const gchar *str = (response == GTK_RESPONSE_OK) ? "yes" : "no";
|
|
|
|
|
|
|
|
parasite = gimp_parasite_new (parasite_name,
|
|
|
|
GIMP_PARASITE_PERSISTENT,
|
|
|
|
strlen (str), str);
|
|
|
|
gimp_attach_parasite (parasite);
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
|
|
|
|
return (response == GTK_RESPONSE_OK);
|
|
|
|
}
|