Skip to content

Commit 017f7e5

Browse files
fxriraveit65
authored andcommitted
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
1 parent 7eec54c commit 017f7e5

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/eom-image-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ struct _EomImagePrivate {
6363
gboolean modified;
6464
gboolean file_is_changed;
6565

66-
#ifdef HAVE_EXIF
6766
gboolean autorotate;
6867
gint orientation;
68+
#ifdef HAVE_EXIF
6969
ExifData *exif;
7070
#endif
7171
#ifdef HAVE_EXEMPI

src/eom-image.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,19 @@ eom_image_set_icc_data (EomImage *img, EomMetadataReader *md_reader)
693693
}
694694
#endif
695695

696-
#ifdef HAVE_EXIF
697696
static void
698697
eom_image_set_orientation (EomImage *img)
699698
{
700699
EomImagePrivate *priv;
700+
#ifdef HAVE_EXIF
701701
ExifData* exif;
702+
#endif
702703

703704
g_return_if_fail (EOM_IS_IMAGE (img));
704705

705706
priv = img->priv;
706707

708+
#ifdef HAVE_EXIF
707709
exif = (ExifData*) eom_image_get_exif_info (img);
708710

709711
if (exif != NULL) {
@@ -715,10 +717,27 @@ eom_image_set_orientation (EomImage *img)
715717
if (entry && entry->data != NULL) {
716718
priv->orientation = exif_get_short (entry->data, o);
717719
}
718-
}
720+
exif_data_unref (exif);
721+
} else
722+
#endif
723+
{
724+
GdkPixbuf *pbuf;
725+
726+
pbuf = eom_image_get_pixbuf (img);
719727

720-
/* exif_data_unref handles NULL values like g_free */
721-
exif_data_unref (exif);
728+
if (pbuf) {
729+
const gchar *o_str;
730+
731+
o_str = gdk_pixbuf_get_option (pbuf, "orientation");
732+
if (o_str) {
733+
short t = (short) g_ascii_strtoll (o_str,
734+
NULL, 10);
735+
if (t >= 0 && t < 9)
736+
priv->orientation = t;
737+
}
738+
g_object_unref (pbuf);
739+
}
740+
}
722741

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

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

11391157
priv->file_is_changed = FALSE;
1158+
1159+
/* Set orientation again for safety, eg. if we don't
1160+
* have Exif data or HAVE_EXIF is undefined. */
1161+
eom_image_set_orientation (img);
1162+
11401163
} else {
11411164
/* Some loaders don't report errors correctly.
11421165
* Error will be set below. */
@@ -1233,16 +1256,16 @@ eom_image_load (EomImage *img, EomImageData data2read, EomJob *job, GError **err
12331256

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

1236-
#ifdef HAVE_EXIF
12371259
/* Check that the metadata was loaded at least once before
12381260
* trying to autorotate. Also only an imatge load job should try to
12391261
* autorotate and image */
1240-
if (priv->autorotate &&
1241-
priv->metadata_status == EOM_IMAGE_METADATA_READY &&
1242-
data2read & EOM_IMAGE_DATA_IMAGE) {
1243-
eom_image_real_autorotate (img);
1244-
}
1262+
if (priv->autorotate &&
1263+
#ifdef HAVE_EXIF
1264+
priv->metadata_status != EOM_IMAGE_METADATA_NOT_READ &&
12451265
#endif
1266+
data2read & EOM_IMAGE_DATA_IMAGE) {
1267+
eom_image_real_autorotate (img);
1268+
}
12461269

12471270
if (success && eom_image_needs_transformation (img)) {
12481271
success = eom_image_apply_transformations (img, error);

src/eom-image.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ void eom_image_transform (EomImage *img,
187187
EomTransform *trans,
188188
EomJob *job);
189189

190-
#ifdef HAVE_EXIF
191190
void eom_image_autorotate (EomImage *img);
192-
#endif
193191

194192
#ifdef HAVE_LCMS
195193
cmsHPROFILE eom_image_get_profile (EomImage *img);

0 commit comments

Comments
 (0)