diff src/image.c @ 1567:c776b1310ca6

added an option to write image orientation to the metadata
author nadvornik
date Sun, 26 Apr 2009 09:01:35 +0000
parents 3d9f5c078521
children 1d7941c147be
line wrap: on
line diff
--- a/src/image.c	Sat Apr 25 22:08:09 2009 +0000
+++ b/src/image.c	Sun Apr 26 09:01:35 2009 +0000
@@ -401,10 +401,18 @@
 			break;
 		}
 
-	if (type != ALTER_NONE)
+	if (imd->orientation != imd->image_fd->exif_orientation ? imd->image_fd->exif_orientation : 1)
 		{
-		if (imd->image_fd->user_orientation == 0) file_data_ref(imd->image_fd);
-		imd->image_fd->user_orientation = imd->orientation;
+		if (!options->metadata.write_orientation)
+			{
+			/* user_orientation does not work together with options->metadata.write_orientation,
+			   use either one or the other.
+			   we must however handle switching metadata.write_orientation on and off, therefore
+			   we just disable referencing new fd's, not unreferencing the old ones
+			*/
+			if (imd->image_fd->user_orientation == 0) file_data_ref(imd->image_fd);
+			imd->image_fd->user_orientation = imd->orientation;
+			}
 		}
 	else
 		{
@@ -412,6 +420,18 @@
 		imd->image_fd->user_orientation = 0;
 		}
 
+	if (options->metadata.write_orientation)
+		{
+		if (type == ALTER_NONE)
+			{
+			metadata_write_revert(imd->image_fd, ORIENTATION_KEY);
+			}
+		else
+			{
+			metadata_write_int(imd->image_fd, ORIENTATION_KEY, imd->orientation);
+			}
+		}
+
 	pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
 }
 
@@ -1079,7 +1099,7 @@
 			}
 		else if (options->image.exif_rotate_enable)
 			{
-			imd->orientation = metadata_read_int(imd->image_fd, "Exif.Image.Orientation", EXIF_ORIENTATION_TOP_LEFT);
+			imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
 			imd->image_fd->exif_orientation = imd->orientation;
 			}
 		}