Skip to content
Permalink
Browse files

Use GdkPixbuf's "orientation" feature as fallback for autorotation

Useful for formats where we don't support extracting the needed data
ourselves (e.g TIFF) and if eog is compiled without libexif.

https://bugzilla.gnome.org/show_bug.cgi?id=548474
https://bugzilla.gnome.org/show_bug.cgi?id=615114

origin commit:
https://gitlab.gnome.org/GNOME/eog/commit/8ac825b
  • Loading branch information...
Felix Riemann authored and raveit65 committed Jun 8, 2011
1 parent 7eec54c commit 017f7e5ff65081068cb504c5d4561ab685a66fa7
Showing with 35 additions and 14 deletions.
  1. +1 −1 src/eom-image-private.h
  2. +34 −11 src/eom-image.c
  3. +0 −2 src/eom-image.h
@@ -63,9 +63,9 @@ struct _EomImagePrivate {
gboolean modified;
gboolean file_is_changed;

#ifdef HAVE_EXIF
gboolean autorotate;
gint orientation;
#ifdef HAVE_EXIF
ExifData *exif;
#endif
#ifdef HAVE_EXEMPI
@@ -693,17 +693,19 @@ eom_image_set_icc_data (EomImage *img, EomMetadataReader *md_reader)
}
#endif

#ifdef HAVE_EXIF
static void
eom_image_set_orientation (EomImage *img)
{
EomImagePrivate *priv;
#ifdef HAVE_EXIF
ExifData* exif;
#endif

g_return_if_fail (EOM_IS_IMAGE (img));

priv = img->priv;

#ifdef HAVE_EXIF
exif = (ExifData*) eom_image_get_exif_info (img);

if (exif != NULL) {
@@ -715,10 +717,27 @@ eom_image_set_orientation (EomImage *img)
if (entry && entry->data != NULL) {
priv->orientation = exif_get_short (entry->data, o);
}
}
exif_data_unref (exif);
} else
#endif
{
GdkPixbuf *pbuf;

pbuf = eom_image_get_pixbuf (img);

/* exif_data_unref handles NULL values like g_free */
exif_data_unref (exif);
if (pbuf) {
const gchar *o_str;

o_str = gdk_pixbuf_get_option (pbuf, "orientation");
if (o_str) {
short t = (short) g_ascii_strtoll (o_str,
NULL, 10);
if (t >= 0 && t < 9)
priv->orientation = t;
}
g_object_unref (pbuf);
}
}

if (priv->orientation > 4 &&
priv->orientation < 9) {
@@ -767,7 +786,6 @@ eom_image_autorotate (EomImage *img)
/* Schedule auto orientation */
img->priv->autorotate = TRUE;
}
#endif

#ifdef HAVE_EXEMPI
static void
@@ -1137,6 +1155,11 @@ eom_image_real_load (EomImage *img,
}

priv->file_is_changed = FALSE;

/* Set orientation again for safety, eg. if we don't
* have Exif data or HAVE_EXIF is undefined. */
eom_image_set_orientation (img);

} else {
/* Some loaders don't report errors correctly.
* Error will be set below. */
@@ -1233,16 +1256,16 @@ eom_image_load (EomImage *img, EomImageData data2read, EomJob *job, GError **err

success = eom_image_real_load (img, data2read, job, error);

#ifdef HAVE_EXIF
/* Check that the metadata was loaded at least once before
* trying to autorotate. Also only an imatge load job should try to
* autorotate and image */
if (priv->autorotate &&
priv->metadata_status == EOM_IMAGE_METADATA_READY &&
data2read & EOM_IMAGE_DATA_IMAGE) {
eom_image_real_autorotate (img);
}
if (priv->autorotate &&
#ifdef HAVE_EXIF
priv->metadata_status != EOM_IMAGE_METADATA_NOT_READ &&
#endif
data2read & EOM_IMAGE_DATA_IMAGE) {
eom_image_real_autorotate (img);
}

if (success && eom_image_needs_transformation (img)) {
success = eom_image_apply_transformations (img, error);
@@ -187,9 +187,7 @@ void eom_image_transform (EomImage *img,
EomTransform *trans,
EomJob *job);

#ifdef HAVE_EXIF
void eom_image_autorotate (EomImage *img);
#endif

#ifdef HAVE_LCMS
cmsHPROFILE eom_image_get_profile (EomImage *img);

0 comments on commit 017f7e5

Please sign in to comment.
You can’t perform that action at this time.