summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2012-09-17 15:20:47 +0200
committerDaniel Friesel <derf@finalrewind.org>2012-09-17 15:20:47 +0200
commit7979f76dcd5d5e2340956f6ec3b9009e64648fc1 (patch)
tree958e5ceca243594ba03448ecfb5afde141091856
parent3a1b07272aeff6397f74014cdeae2c129d608a94 (diff)
downloadfeh-7979f76dcd5d5e2340956f6ec3b9009e64648fc1.zip
Fix EXIF orientation tag after lossless rotate
-rw-r--r--ChangeLog7
-rw-r--r--man/feh.pre14
-rw-r--r--src/imlib.c32
3 files changed, 50 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index af57063..6cefc73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+git HEAD
+
+ * Set EXIF orientation tag to 1 ("0,0 is top left" aka normal) after
+ running jpegtran. Previously, when doing a lossless rotate, the image
+ was rotated but the corresponding EXIF tag not updated, resulting in
+ wrong image display in programs aware of this EXIF tag.
+
Thu, 13 Sep 2012 12:00:06 +0200 Daniel Friesel <derf+feh@finalrewind.org>
* Fix freedesktop.org Thumbnail Managing Standard implementation:
diff --git a/man/feh.pre b/man/feh.pre
index e047286..5199151 100644
--- a/man/feh.pre
+++ b/man/feh.pre
@@ -1106,6 +1106,16 @@ away. See
.Xr jpegtran 1
for more about lossless JPEG rotation.
.
+.Em Note:
+jpegtran does not update EXIF orientation tags. However,
+.Nm
+assumes that you use the feature to normalize image orientation and want it to
+be displayed this way everywhere. After every rotation, it will unconditionally
+set the EXIF orientation to 1
+.Pq Qq 0,0 is top left .
+Should you need to reverse this, see
+.Xr jpegexiforient 1 .
+.
.It _ Bq flip
.
In place editing - vertical flip
@@ -1487,7 +1497,9 @@ but without the flickering.
.Nm
requires the
.Cm jpegtran
-binary
+and
+.Cm jpegexiforient
+binaries
.Pq usually distributed in Qo libjpeg-progs Qc or similar
for lossless rotation.
.
diff --git a/src/imlib.c b/src/imlib.c
index b3abc8a..f247bf7 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -1137,6 +1137,7 @@ void feh_edit_inplace_lossless(winwidget w, int op)
int len = strlen(filename) + 1;
char *file_str = emalloc(len);
int pid, status;
+ int devnull = -1;
char op_name[] = "rotate"; /* message */
char op_op[] = "-rotate"; /* jpegtran option */
char op_value[] = "horizontal"; /* jpegtran option's value */
@@ -1156,14 +1157,16 @@ void feh_edit_inplace_lossless(winwidget w, int op)
if ((pid = fork()) < 0) {
im_weprintf(w, "lossless %s: fork failed:", op_name);
exit(1);
- } else if (pid == 0) {
+ }
+ else if (pid == 0) {
execlp("jpegtran", "jpegtran", "-copy", "all", op_op, op_value,
"-outfile", file_str, file_str, NULL);
im_weprintf(w, "lossless %s: Is 'jpegtran' installed? Failed to exec:", op_name);
exit(1);
- } else {
+ }
+ else {
waitpid(pid, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
@@ -1176,6 +1179,31 @@ void feh_edit_inplace_lossless(winwidget w, int op)
return;
}
}
+ if ((pid = fork()) < 0) {
+ im_weprintf(w, "lossless %s: cannot fix rotation: fork:", op_name);
+ exit(1);
+ }
+ else if (pid == 0) {
+
+ /* discard normal output */
+ devnull = open("/dev/null", O_WRONLY);
+ dup2(devnull, 1);
+
+ execlp("jpegexiforient", "jpegexiforient", "-1", file_str, NULL);
+ im_weprintf(w, "lossless %s: Failed to exec jpegexiforient:", op_name);
+ exit(1);
+ }
+ else {
+ waitpid(pid, &status, 0);
+
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ im_weprintf(w,
+ "lossless %s: Got exitcode %d from jpegexiforient",
+ status >> 8);
+ free(file_str);
+ return;
+ }
+ }
free(file_str);
}