Index: src/dlg-jpegtran.c
===================================================================
RCS file: /cvs/gnome/gthumb/src/dlg-jpegtran.c,v
retrieving revision 1.37
diff -u -r1.37 dlg-jpegtran.c
--- src/dlg-jpegtran.c	8 Oct 2006 08:45:17 -0000	1.37
+++ src/dlg-jpegtran.c	8 Oct 2006 11:12:55 -0000
@@ -239,7 +239,9 @@
 	char             *dir;
 	GnomeVFSFileInfo  info;
 	GtkWindow  	 *window = GTK_WINDOW (data->dialog);
-        
+	gint		  width = 0;
+	gint		  height = 0;
+	
 	/* Check directory permissions. */
 
 	dir = remove_level_from_path (path);
@@ -255,14 +257,41 @@
 	g_free (dir);
 
 	gnome_vfs_get_file_info (path, &info, GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS|GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
-	if (image_is_jpeg (path)) {
-		apply_transformation_exif (window, path, data->rot_data);
-		if (eel_gconf_get_boolean (PREF_RESET_EXIF_ORIENTATION_ROTATE, TRUE)) {
-			update_rotation_from_exif_data (path, data->rot_data);
+
+        if (image_is_jpeg (path)) {
+
+                if (!get_exif_tag_short(path,EXIF_TAG_ORIENTATION)) {
+                        /* If no exif orientation tag is present, simply
+                           transform the data using the "lossless" jpeg
+                           mathematical transform (only really lossless if
+                           dimensions are multiples of 8 */
                         apply_transformation_jpeg (window, path, data->rot_data);
-		}
+                }
+                else {
+                        /* Calculate a new orientation tag, based on the
+                           input tag and the requested rotation. This saves
+			   the jpeg, so no further action is required if
+			   "adjust photo orientation" is not selected. */
+                        update_orientation_field (path, data->rot_data);
+
+                        /* if "adjust photo orientation" is selected mathematically transform
+			   the data so that the viewed image remains the same, but the 
+			   orientation tag can be set to "top left" */
+
+                        if (eel_gconf_get_boolean (PREF_RESET_EXIF_ORIENTATION_ROTATE, TRUE)) {
+
+				gdk_pixbuf_get_file_info(get_file_path_from_uri (path),&width,&height);
+				
+				if (!(height%8) && !(width%8)) {
+					/* Don't do this if the dimensions are not multiples
+					   of the jpeg minimum coding unit (iMCU = 8) */
+	                		update_rotation_from_exif_data (path, data->rot_data);
+					apply_transformation_jpeg (window, path, data->rot_data);
+				}
+                        }
+                }
 
-	}
+        }
 	else 
 		apply_transformation_generic (window, path, data->rot_data);
 	gnome_vfs_set_file_info (path, &info, GNOME_VFS_SET_FILE_INFO_PERMISSIONS|GNOME_VFS_SET_FILE_INFO_OWNER);
Index: src/rotation-utils.c
===================================================================
RCS file: /cvs/gnome/gthumb/src/rotation-utils.c,v
retrieving revision 1.7
diff -u -r1.7 rotation-utils.c
--- src/rotation-utils.c	8 Oct 2006 08:45:17 -0000	1.7
+++ src/rotation-utils.c	8 Oct 2006 11:12:55 -0000
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 
+#include <glib/gi18n.h>
 #include <libgnomevfs/gnome-vfs-mime.h>
 #include "file-utils.h"
 #include "gtk-utils.h"
@@ -101,18 +102,6 @@
 	}
 }
 
-void
-apply_transformation_exif (GtkWindow    *win,
-			   const char   *path,
-			   RotationData *rot_data)
-
-{
-	if (get_exif_tag_short(path,EXIF_TAG_ORIENTATION)) 
-		update_orientation_field (path, rot_data);
-	else 
-		apply_transformation_jpeg(win, path, rot_data);
-}
-
 
 void
 reset_orientation_field (const char *path)
@@ -323,7 +312,11 @@
 					&error, 
 					NULL))
 			_gtk_error_dialog_from_gerror_run (win, &error);
-	}
+	} else
+		_gtk_error_dialog_run (win,
+				       _("Image type not supported: %s"),
+				       mime_type);
+
 	g_object_unref (pixbuf1);
 }
 
