Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
fxri authored and raveit65 committed Jul 14, 2018
1 parent 7eec54c commit 017f7e5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/eom-image-private.h
Expand Up @@ -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
Expand Down
45 changes: 34 additions & 11 deletions src/eom-image.c
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -767,7 +786,6 @@ eom_image_autorotate (EomImage *img)
/* Schedule auto orientation */
img->priv->autorotate = TRUE;
}
#endif

#ifdef HAVE_EXEMPI
static void
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/eom-image.h
Expand Up @@ -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);
Expand Down

0 comments on commit 017f7e5

Please sign in to comment.