Index: libgnomeui/gnome-thumbnail-pixbuf-utils.c
===================================================================
--- libgnomeui/gnome-thumbnail-pixbuf-utils.c	(revision 5348)
+++ libgnomeui/gnome-thumbnail-pixbuf-utils.c	(working copy)
@@ -33,10 +33,6 @@
 
 #define LOAD_BUFFER_SIZE 65536
 
-GdkPixbuf * _gnome_thumbnail_load_scaled_jpeg (const char *uri,
-					       int         target_width,
-					       int         target_height);
-
 /**
  * gnome_thumbnail_scale_down_pixbuf:
  * @pixbuf: a #GdkPixbuf
@@ -174,302 +170,3 @@
 	return dest_pixbuf;
 }
 
-
-
-#ifdef HAVE_LIBJPEG
-
-#include <setjmp.h>
-
-#include <stdio.h>
-
-/* Workaround broken libjpeg defining these that may
- * collide w/ the ones in config.h
- */
-#undef HAVE_STDDEF_H
-#undef HAVE_STDLIB_H
-#include <jpeglib.h>
-
-#include <libgnomevfs/gnome-vfs-types.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-
-#define BUFFER_SIZE 16384
-
-typedef struct {
-	struct jpeg_source_mgr pub;	/* public fields */
-	GnomeVFSHandle *handle;
-	JOCTET buffer[BUFFER_SIZE];
-} Source;
-
-typedef struct {
-	struct jpeg_error_mgr pub;
-	jmp_buf setjmp_buffer;
-} ErrorHandlerData;
-
-static void
-fatal_error_handler (j_common_ptr cinfo)
-{
-	ErrorHandlerData *data;
-
-	data = (ErrorHandlerData *) cinfo->err;
-	longjmp (data->setjmp_buffer, 1);
-}
-
-static void
-output_message_handler (j_common_ptr cinfo)
-{
-	/* If we don't supply this handler, libjpeg reports errors
-	 * directly to stderr.
-	 */
-}
-
-static void
-init_source (j_decompress_ptr cinfo)
-{
-}
-
-static gboolean
-fill_input_buffer (j_decompress_ptr cinfo)
-{
-	Source *src;
-	GnomeVFSFileSize nbytes;
-	GnomeVFSResult result;
-	
-	src = (Source *) cinfo->src;
-	result = gnome_vfs_read (src->handle,
-				 src->buffer,
-				 G_N_ELEMENTS (src->buffer),
-				 &nbytes);
-	
-	if (result != GNOME_VFS_OK || nbytes == 0) {
-		/* return a fake EOI marker so we will eventually terminate */
-		src->buffer[0] = (JOCTET) 0xFF;
-		src->buffer[1] = (JOCTET) JPEG_EOI;
-		nbytes = 2;
-	}
-	
-	src->pub.next_input_byte = src->buffer;
-	src->pub.bytes_in_buffer = nbytes;
-	
-	return TRUE;
-}
-
-static void
-skip_input_data (j_decompress_ptr cinfo, long num_bytes)
-{
-	Source *src;
-
-	src = (Source *) cinfo->src;
-	if (num_bytes > 0) {
-		while (num_bytes > (long) src->pub.bytes_in_buffer) {
-			num_bytes -= (long) src->pub.bytes_in_buffer;
-			fill_input_buffer (cinfo);
-		}
-		src->pub.next_input_byte += (size_t) num_bytes;
-		src->pub.bytes_in_buffer -= (size_t) num_bytes;
-	}
-}
-
-static void
-term_source (j_decompress_ptr cinfo)
-{
-}
-
-static void
-vfs_src (j_decompress_ptr cinfo, Source *src, GnomeVFSHandle *handle)
-{
-	cinfo->src = (struct jpeg_source_mgr *)src;
-	src->pub.init_source = init_source;
-	src->pub.fill_input_buffer = fill_input_buffer;
-	src->pub.skip_input_data = skip_input_data;
-	src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
-	src->pub.term_source = term_source;
-	src->handle = handle;
-	src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
-	src->pub.next_input_byte = NULL; /* until buffer loaded */
-}
-
-static int
-calculate_divisor (int width,
-		   int height,
-		   int target_width,
-		   int target_height)
-{
-	if (width/8 > target_width && height/8 > target_height) {
-		return 8;
-	}
-	if (width/4 > target_width && height/4 > target_height) {
-		return 4;
-	}
-	if (width/2 > target_width && height/2 > target_height) {
-		return 2;
-	}
-	return 1;
-}
-
-static void
-free_buffer (guchar *pixels, gpointer data)
-{
-	g_free (pixels);
-}
-
-static void
-convert_cmyk_to_rgb (struct jpeg_decompress_struct *cinfo,
-		     guchar *line) 
-{
-	gint j;
-	guchar *p;
-
-	g_return_if_fail (cinfo != NULL);
-	g_return_if_fail (cinfo->output_components == 4);
-	g_return_if_fail (cinfo->out_color_space == JCS_CMYK);
-
-	p = line;
-	for (j = 0; j < cinfo->output_width; j++) {
-		int c, m, y, k;
-		c = p[0];
-		m = p[1];
-		y = p[2];
-		k = p[3];
-		if (cinfo->saw_Adobe_marker) {
-			p[0] = k*c / 255;
-			p[1] = k*m / 255;
-			p[2] = k*y / 255;
-		}
-		else {
-			p[0] = (255 - k)*(255 - c) / 255;
-			p[1] = (255 - k)*(255 - m) / 255;
-			p[2] = (255 - k)*(255 - y) / 255;
-		}
-		p[3] = 255;
-		p += 4;
-	}
-}
-
-GdkPixbuf *
-_gnome_thumbnail_load_scaled_jpeg (const char *uri,
-				   int         target_width,
-				   int         target_height)
-{
-	GdkPixbuf *pixbuf;
-	struct jpeg_decompress_struct cinfo;
-	Source src;
-	ErrorHandlerData jerr;
-	GnomeVFSHandle *handle;
-	unsigned char *lines[1];
-	guchar * volatile buffer;
-	guchar * volatile pixels;
-	guchar *ptr;
-	GnomeVFSResult result;
-	unsigned int i;
-	int out_n_components;
-	
-	result = gnome_vfs_open (&handle,
-				 uri,
-				 GNOME_VFS_OPEN_READ);
-	if (result != GNOME_VFS_OK) {
-		return NULL;
-	}
-	
-	cinfo.err = jpeg_std_error (&jerr.pub);
-	jerr.pub.error_exit = fatal_error_handler;
-	jerr.pub.output_message = output_message_handler;
-
-	buffer = NULL;
-	pixels = NULL;
-	if (setjmp (jerr.setjmp_buffer)) {
-		/* Handle a JPEG error. */
-		jpeg_destroy_decompress (&cinfo);
-		gnome_vfs_close (handle);
-		g_free (buffer);
-		g_free (pixels);
-		return NULL;
-	}
-
-	jpeg_create_decompress (&cinfo);
-
-	vfs_src (&cinfo, &src, handle);
-
-	jpeg_read_header (&cinfo, TRUE);
-
-	cinfo.scale_num = 1;
-	cinfo.scale_denom = calculate_divisor (cinfo.image_width,
-					       cinfo.image_height,
-					       target_width,
-					       target_height);
-	cinfo.dct_method = JDCT_FASTEST;
-	cinfo.do_fancy_upsampling = FALSE;
-
-	jpeg_calc_output_dimensions(&cinfo);
-
-	if (cinfo.out_color_space != JCS_GRAYSCALE &&
-	    cinfo.out_color_space != JCS_RGB &&
-	    cinfo.out_color_space != JCS_CMYK) {
-		jpeg_destroy_decompress (&cinfo);
-		gnome_vfs_close (handle);
-		return NULL;
-	}
-
-	jpeg_start_decompress (&cinfo);
-
-	if (cinfo.num_components == 1)
-	  out_n_components = 3;
-	else
-	  out_n_components = cinfo.num_components;
-	
-	pixels = g_malloc (cinfo.output_width * cinfo.output_height * out_n_components);
-
-	ptr = pixels;
-	if (cinfo.num_components == 1) {
-		/* Allocate extra buffer for grayscale data */
-		buffer = g_malloc (cinfo.output_width);
-		lines[0] = buffer;
-	} else {
-		lines[0] = pixels;
-	}
-	
-	while (cinfo.output_scanline < cinfo.output_height) {
-		jpeg_read_scanlines (&cinfo, lines, 1);
-		
-		if (cinfo.num_components == 1) {
-			/* Convert grayscale to rgb */
-			for (i = 0; i < cinfo.output_width; i++) {
-				ptr[i*3] = buffer[i];
-				ptr[i*3+1] = buffer[i];
-				ptr[i*3+2] = buffer[i];
-			}
-			ptr += cinfo.output_width * 3;
-		} else {
-			if (cinfo.out_color_space == JCS_CMYK) {
-				convert_cmyk_to_rgb (&cinfo, 
-						     lines[0]);
-			}
-			lines[0] += cinfo.output_width * out_n_components;
-		}
-	}
-
-	g_free (buffer);
-	buffer = NULL;
-
-	jpeg_finish_decompress (&cinfo);
-	jpeg_destroy_decompress (&cinfo);
-	
-	gnome_vfs_close (handle);
-	
-	pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB,
-					   cinfo.out_color_components == 4 ? TRUE : FALSE,
-					   8,
-					   cinfo.output_width,
-					   cinfo.output_height,
-					   cinfo.output_width * out_n_components,
-					   free_buffer, NULL);
-
-	g_object_set_data (G_OBJECT (pixbuf), "gnome-original-width",
-			   GINT_TO_POINTER (cinfo.image_width));
-	g_object_set_data (G_OBJECT (pixbuf), "gnome-original-height",
-			   GINT_TO_POINTER (cinfo.image_height));
-
-	return pixbuf;
-}
-
-#endif /* HAVE_LIBJPEG */
-
Index: libgnomeui/gnome-thumbnail.c
===================================================================
--- libgnomeui/gnome-thumbnail.c	(revision 5348)
+++ libgnomeui/gnome-thumbnail.c	(working copy)
@@ -49,12 +49,6 @@
 #include <gconf/gconf-client.h>
 #include <glib/gstdio.h>
 
-#ifdef HAVE_LIBJPEG
-GdkPixbuf * _gnome_thumbnail_load_scaled_jpeg (const char *uri,
-					       int         target_width,
-					       int         target_height);
-#endif
-
 #define SECONDS_BETWEEN_STATS 10
 
 struct ThumbMD5Context {
@@ -942,7 +936,7 @@
 					    const char            *uri,
 					    const char            *mime_type)
 {
-  GdkPixbuf *pixbuf, *scaled;
+  GdkPixbuf *pixbuf, *scaled, *tmp_pixbuf;
   char *script, *expanded_script;
   int width, height, size;
   int original_width = 0;
@@ -996,12 +990,7 @@
   /* Fall back to gdk-pixbuf */
   if (pixbuf == NULL)
     {
-#ifdef HAVE_LIBJPEG
-      if (strcmp (mime_type, "image/jpeg") == 0)
-	pixbuf = _gnome_thumbnail_load_scaled_jpeg (uri, size, size);
-      else
-#endif
-	pixbuf = gnome_gdk_pixbuf_new_from_uri_at_scale (uri, size, size, TRUE);
+      pixbuf = gnome_gdk_pixbuf_new_from_uri_at_scale (uri, size, size, TRUE);
 
       if (pixbuf != NULL)
         {
@@ -1015,6 +1004,13 @@
   if (pixbuf == NULL)
     return NULL;
 
+  /* The pixbuf loader may attach an "orientation" option to the pixbuf,
+     if the tiff or exif jpeg file had an orientation tag. Rotate/flip
+     the pixbuf as specified by this tag, if present. */
+  tmp_pixbuf = gdk_pixbuf_transform_orientation_auto (pixbuf);
+  g_object_unref (pixbuf);
+  pixbuf = tmp_pixbuf;
+
   width = gdk_pixbuf_get_width (pixbuf);
   height = gdk_pixbuf_get_height (pixbuf);
   
