Commit 7979f76d authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Fix EXIF orientation tag after lossless rotate

parent 3a1b0727
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
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:
+13 −1
Original line number Diff line number Diff line
@@ -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.
.
+30 −2
Original line number Diff line number Diff line
@@ -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);
}