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
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2013-10-20 00:38:01 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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 <gexiv2/gexiv2.h>
|
|
|
|
|
|
|
|
#include "gimp.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
|
|
|
|
2021-03-23 04:06:54 +08:00
|
|
|
static gchar * gimp_image_metadata_interpret_comment (gchar *comment);
|
2013-10-20 00:38:01 +08:00
|
|
|
|
2021-03-23 04:06:54 +08:00
|
|
|
static void gimp_image_metadata_rotate (GimpImage *image,
|
|
|
|
GExiv2Orientation orientation);
|
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:
|
2019-08-11 23:12:20 +08:00
|
|
|
* @image: The image
|
2013-10-28 02:42:48 +08:00
|
|
|
* @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
|
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
|
|
|
* gimp_image_metadata_load_finish().
|
2013-10-28 02:42:48 +08:00
|
|
|
*
|
2019-08-01 07:52:07 +08:00
|
|
|
* Returns: (transfer full): The file's metadata.
|
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-27 22:22:35 +08:00
|
|
|
GimpMetadata *
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_metadata_load_prepare (GimpImage *image,
|
2013-10-27 22:22:35 +08:00
|
|
|
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
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2013-10-27 22:22:35 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-23 04:06:54 +08:00
|
|
|
static gchar *
|
|
|
|
gimp_image_metadata_interpret_comment (gchar *comment)
|
|
|
|
{
|
|
|
|
/* Exiv2 can return unwanted text at the start of a comment
|
|
|
|
* taken from Exif.Photo.UserComment since 0.27.3.
|
|
|
|
* Let's remove that part and return NULL if there
|
|
|
|
* is nothing else left as comment. */
|
|
|
|
|
|
|
|
if (comment && g_str_has_prefix (comment, "charset=Ascii "))
|
|
|
|
{
|
|
|
|
gchar *real_comment;
|
|
|
|
|
|
|
|
/* Skip "charset=Ascii " (length 14) to find the real comment */
|
|
|
|
real_comment = comment + 14;
|
|
|
|
if (real_comment[0] == '\0' ||
|
|
|
|
! g_strcmp0 (real_comment, "binary comment"))
|
|
|
|
{
|
|
|
|
g_free (comment);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
real_comment = g_strdup (real_comment);
|
|
|
|
g_free (comment);
|
|
|
|
return real_comment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:42:48 +08:00
|
|
|
/**
|
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
|
|
|
* gimp_image_metadata_load_finish:
|
2019-08-11 23:12:20 +08:00
|
|
|
* @image: The image
|
2013-10-28 02:42:48 +08:00
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* Applies the @metadata previously loaded with
|
|
|
|
* gimp_image_metadata_load_prepare() to the image, taking into account
|
|
|
|
* the passed @flags.
|
|
|
|
*
|
2020-09-13 19:09:59 +08:00
|
|
|
* Since: 3.0
|
2013-10-28 02:42:48 +08:00
|
|
|
*/
|
2013-10-27 22:22:35 +08:00
|
|
|
void
|
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
|
|
|
gimp_image_metadata_load_finish (GimpImage *image,
|
|
|
|
const gchar *mime_type,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags flags)
|
2013-10-27 22:22:35 +08:00
|
|
|
{
|
2019-08-11 23:12:20 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2013-10-27 22:22:35 +08:00
|
|
|
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");
|
2021-03-23 04:06:54 +08:00
|
|
|
comment = gimp_image_metadata_interpret_comment (comment);
|
|
|
|
|
2017-01-04 02:36:22 +08:00
|
|
|
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);
|
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_attach_parasite (image, parasite);
|
2013-10-20 00:38:01 +08:00
|
|
|
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))
|
|
|
|
{
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_set_resolution (image, xres, yres);
|
|
|
|
gimp_image_set_unit (image, unit);
|
2013-10-20 00:38:01 +08:00
|
|
|
}
|
2013-10-27 22:22:35 +08:00
|
|
|
}
|
2013-10-20 00:38:01 +08:00
|
|
|
|
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
|
|
|
if (! (flags & GIMP_METADATA_LOAD_ORIENTATION))
|
2017-01-04 02:36:22 +08:00
|
|
|
{
|
2020-09-13 19:09:59 +08:00
|
|
|
gexiv2_metadata_set_orientation (GEXIV2_METADATA (metadata),
|
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
|
|
|
GEXIV2_ORIENTATION_UNSPECIFIED);
|
2017-01-04 02:36:22 +08:00
|
|
|
}
|
|
|
|
|
2015-08-20 21:05:04 +08:00
|
|
|
if (flags & GIMP_METADATA_LOAD_COLORSPACE)
|
|
|
|
{
|
2019-08-11 23:12:20 +08:00
|
|
|
GimpColorProfile *profile = gimp_image_get_color_profile (image);
|
2015-09-29 01:54:18 +08:00
|
|
|
|
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)
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_set_color_profile (image, 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
|
|
|
}
|
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_set_metadata (image, metadata);
|
2013-10-20 00:38:01 +08:00
|
|
|
}
|
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
/**
|
|
|
|
* gimp_image_metadata_load_thumbnail:
|
|
|
|
* @file: A #GFile image
|
|
|
|
* @error: Return location for error message
|
|
|
|
*
|
|
|
|
* Retrieves a thumbnail from metadata if present.
|
|
|
|
*
|
2019-08-15 16:01:08 +08:00
|
|
|
* Returns: (transfer none) (nullable): a #GimpImage of the @file thumbnail.
|
2019-08-27 22:32:25 +08:00
|
|
|
*
|
|
|
|
* Since: 2.10
|
2019-08-11 23:12:20 +08:00
|
|
|
*/
|
|
|
|
GimpImage *
|
2013-10-30 07:04:36 +08:00
|
|
|
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;
|
2019-08-11 23:12:20 +08:00
|
|
|
GimpImage *image = NULL;
|
2013-10-30 07:04:36 +08:00
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2013-10-30 07:04:36 +08:00
|
|
|
|
|
|
|
metadata = gimp_metadata_load_from_file (file, error);
|
|
|
|
if (! metadata)
|
2019-08-11 23:12:20 +08:00
|
|
|
return NULL;
|
2013-10-30 07:04:36 +08:00
|
|
|
|
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);
|
2019-08-11 23:12:20 +08:00
|
|
|
return NULL;
|
2013-10-30 07:04:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
GimpLayer *layer;
|
2013-10-30 07:04:36 +08:00
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
image = gimp_image_new (gdk_pixbuf_get_width (pixbuf),
|
2019-08-15 16:01:08 +08:00
|
|
|
gdk_pixbuf_get_height (pixbuf),
|
|
|
|
GIMP_RGB);
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_undo_disable (image);
|
2013-10-30 07:04:36 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
layer = gimp_layer_new_from_pixbuf (image, _("Background"),
|
|
|
|
pixbuf,
|
|
|
|
100.0,
|
|
|
|
gimp_image_get_default_new_layer_mode (image),
|
|
|
|
0.0, 0.0);
|
2013-10-30 07:04:36 +08:00
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_image_insert_layer (image, layer, NULL, 0);
|
2013-10-30 07:04:36 +08:00
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_metadata_rotate (image,
|
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);
|
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
return image;
|
2013-10-30 07:04:36 +08:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:38:01 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_metadata_rotate (GimpImage *image,
|
2013-10-20 00:38:01 +08:00
|
|
|
GExiv2Orientation orientation)
|
|
|
|
{
|
|
|
|
switch (orientation)
|
|
|
|
{
|
|
|
|
case GEXIV2_ORIENTATION_UNSPECIFIED:
|
|
|
|
case GEXIV2_ORIENTATION_NORMAL: /* standard orientation, do nothing */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_HFLIP:
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_flip (image, GIMP_ORIENTATION_HORIZONTAL);
|
2013-10-20 00:38:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_180:
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_rotate (image, GIMP_ROTATE_180);
|
2013-10-20 00:38:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_VFLIP:
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_flip (image, GIMP_ORIENTATION_VERTICAL);
|
2013-10-20 00:38:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90_HFLIP: /* flipped diagonally around '\' */
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_rotate (image, GIMP_ROTATE_90);
|
|
|
|
gimp_image_flip (image, GIMP_ORIENTATION_HORIZONTAL);
|
2013-10-20 00:38:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90: /* 90 CW */
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_rotate (image, GIMP_ROTATE_90);
|
2013-10-20 00:38:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_90_VFLIP: /* flipped diagonally around '/' */
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_rotate (image, GIMP_ROTATE_90);
|
|
|
|
gimp_image_flip (image, GIMP_ORIENTATION_VERTICAL);
|
2013-10-20 00:38:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GEXIV2_ORIENTATION_ROT_270: /* 90 CCW */
|
2019-08-11 23:12:20 +08:00
|
|
|
gimp_image_rotate (image, GIMP_ROTATE_270);
|
2013-10-20 00:38:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* shouldn't happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|