Index: src/dlg-jpegtran.c
===================================================================
RCS file: /cvs/gnome/gthumb/src/dlg-jpegtran.c,v
retrieving revision 1.38
diff -u -p -r1.38 dlg-jpegtran.c
--- src/dlg-jpegtran.c	10 Oct 2006 20:29:27 -0000	1.38
+++ src/dlg-jpegtran.c	11 Oct 2006 12:41:44 -0000
@@ -258,42 +258,20 @@ apply_transformation (DialogData *data,
 
 	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)) {
-
-                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_ROTATE_RESET_EXIF_ORIENTATION, 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 
+	if ((image_is_jpeg (path) && get_exif_tag_short(path,EXIF_TAG_ORIENTATION)) &&
+			!eel_gconf_get_boolean (PREF_ROTATE_RESET_EXIF_ORIENTATION, TRUE)) {
+		// Exif transform.
+		update_orientation_field (path, data->rot_data);
+	} else if (image_is_jpeg (path)) {
+		// Lossless jpeg transform.
+		update_rotation_from_exif_data (path, data->rot_data);
+		apply_transformation_jpeg (window, path, data->rot_data);
+	} else {
+		// Generic transform.
+		update_rotation_from_exif_data (path, data->rot_data);
 		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);
 
 	notify_file_changed (data, path, notify_soon);
Index: src/dlg-photo-importer.c
===================================================================
RCS file: /cvs/gnome/gthumb/src/dlg-photo-importer.c,v
retrieving revision 1.40
diff -u -p -r1.40 dlg-photo-importer.c
--- src/dlg-photo-importer.c	10 Oct 2006 20:29:27 -0000	1.40
+++ src/dlg-photo-importer.c	11 Oct 2006 12:41:46 -0000
@@ -1372,7 +1372,7 @@ adjust_orientation__step (AsyncOperation
 		FileData     *fd = file_data_new (filepath, &info);
 		RotationData *rot_data = rotation_data_new ();
 
-		update_rotation_from_exif_data (fd->path, rot_data);
+		read_rotation_from_exif_data (fd->path, rot_data);
 		if (image_is_jpeg (filepath))
 			apply_transformation_jpeg (window, fd->path, rot_data);
 		else
Index: src/rotation-utils.c
===================================================================
RCS file: /cvs/gnome/gthumb/src/rotation-utils.c,v
retrieving revision 1.8
diff -u -p -r1.8 rotation-utils.c
--- src/rotation-utils.c	10 Oct 2006 20:29:27 -0000	1.8
+++ src/rotation-utils.c	11 Oct 2006 12:41:46 -0000
@@ -49,7 +49,7 @@ rotation_data_new ()
 
 
 void
-update_rotation_from_exif_data (const char   *path,
+read_rotation_from_exif_data (const char   *path,
 				RotationData *rot_data)
 {
 	GthExifOrientation orientation;
@@ -61,6 +61,88 @@ update_rotation_from_exif_data (const ch
 	if (path == NULL)
 		return;
 	orientation = get_exif_tag_short (path, EXIF_TAG_ORIENTATION);
+
+	switch (orientation) {
+	case GTH_EXIF_ORIENTATION_TOP_LEFT:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_0;
+		rot_data->tran_type = GTH_TRANSFORM_NONE;
+		break;
+	case GTH_EXIF_ORIENTATION_TOP_RIGHT:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_0;
+		rot_data->tran_type = GTH_TRANSFORM_MIRROR;
+		break;
+	case GTH_EXIF_ORIENTATION_BOTTOM_RIGHT:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_180;
+		rot_data->tran_type = GTH_TRANSFORM_NONE;
+		break;
+	case GTH_EXIF_ORIENTATION_BOTTOM_LEFT:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_180;
+		rot_data->tran_type = GTH_TRANSFORM_MIRROR;
+		break;
+	case GTH_EXIF_ORIENTATION_LEFT_TOP:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_90;
+		rot_data->tran_type = GTH_TRANSFORM_MIRROR;
+		break;
+	case GTH_EXIF_ORIENTATION_RIGHT_TOP:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_90;
+		rot_data->tran_type = GTH_TRANSFORM_NONE;
+		break;
+	case GTH_EXIF_ORIENTATION_RIGHT_BOTTOM:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_90;
+		rot_data->tran_type = GTH_TRANSFORM_FLIP;
+		break;
+	case GTH_EXIF_ORIENTATION_LEFT_BOTTOM:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_270;
+		rot_data->tran_type = GTH_TRANSFORM_NONE;
+		break;
+	default:
+		rot_data->rot_type = GTH_TRANSFORM_ROTATE_0;
+		rot_data->tran_type = GTH_TRANSFORM_NONE;
+		break;
+	}
+}
+
+
+void
+update_rotation_from_exif_data (const char   *path,
+				RotationData *rot_data)
+{
+	GthExifOrientation orientation;
+
+	path = get_file_path_from_uri (path);
+	if (path == NULL)
+		return;
+	orientation = get_exif_tag_short (path, EXIF_TAG_ORIENTATION);
+
+	switch (rot_data->rot_type) {
+	case GTH_TRANSFORM_ROTATE_90:
+		orientation = get_next_value_rotation_90 (orientation);
+		break;
+	case GTH_TRANSFORM_ROTATE_180:
+		orientation = get_next_value_rotation_90 (orientation);
+		orientation = get_next_value_rotation_90 (orientation);
+		break;
+	case GTH_TRANSFORM_ROTATE_270:
+		orientation = get_next_value_rotation_90 (orientation);
+		orientation = get_next_value_rotation_90 (orientation);
+		orientation = get_next_value_rotation_90 (orientation);
+		break;
+	default:
+		orientation = GTH_EXIF_ORIENTATION_TOP_LEFT;
+		break;
+	}
+	
+	switch (rot_data->tran_type) {
+	case GTH_TRANSFORM_MIRROR:
+		orientation = get_next_value_mirror (orientation);
+		break;
+	case GTH_TRANSFORM_FLIP:
+		orientation = get_next_value_flip (orientation);
+		break;
+	default:
+		orientation = GTH_EXIF_ORIENTATION_TOP_LEFT;
+		break;
+	}
 
 	switch (orientation) {
 	case GTH_EXIF_ORIENTATION_TOP_LEFT:
Index: src/rotation-utils.h
===================================================================
RCS file: /cvs/gnome/gthumb/src/rotation-utils.h,v
retrieving revision 1.3
diff -u -p -r1.3 rotation-utils.h
--- src/rotation-utils.h	8 Oct 2006 08:45:17 -0000	1.3
+++ src/rotation-utils.h	11 Oct 2006 12:41:46 -0000
@@ -39,6 +39,8 @@ RotationData*	        rotation_data_new 
 
 void			update_rotation_from_exif_data (const char      *filename,
 							RotationData 	*rot_data);
+void			read_rotation_from_exif_data (const char      *filename,
+							RotationData 	*rot_data);
 void			apply_transformation_exif      (GtkWindow       *win,
 							const char      *filename,
 							RotationData 	*rot_data);
