Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java	(revision 4240)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java	(revision 4241)
@@ -33,9 +33,7 @@
 import java.util.Comparator;
 import java.util.Date;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.TimeZone;
-import java.util.Vector;
 import java.util.zip.GZIPInputStream;
 
@@ -348,5 +346,10 @@
                 public void valueChanged(ListSelectionEvent arg0) {
                     int index = imgList.getSelectedIndex();
-                    imgDisp.setImage(yLayer.data.get(index).getFile());
+                    Integer orientation = null;
+                    try {
+                        orientation = ExifReader.readOrientation(yLayer.data.get(index).getFile());
+                    } catch (Exception e) {
+                    }
+                    imgDisp.setImage(yLayer.data.get(index).getFile(), orientation);
                     Date date = yLayer.data.get(index).getExifTime();
                     if (date != null) {
@@ -380,5 +383,10 @@
                         return;
 
-                    imgDisp.setImage(sel);
+                    Integer orientation = null;
+                    try {
+                        orientation = ExifReader.readOrientation(sel);
+                    } catch (Exception e) {
+                    }
+                    imgDisp.setImage(sel, orientation);
 
                     Date date = null;
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(revision 4240)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(revision 4241)
@@ -63,4 +63,6 @@
 import com.drew.metadata.Directory;
 import com.drew.metadata.Metadata;
+import com.drew.metadata.MetadataException;
+import com.drew.metadata.exif.ExifDirectory;
 import com.drew.metadata.exif.GpsDirectory;
 
@@ -509,9 +511,10 @@
         double lon, lat;
         Metadata metadata = null;
-        Directory dir = null;
+        Directory dirExif = null, dirGps = null;
 
         try {
             metadata = JpegMetadataReader.readMetadata(e.getFile());
-            dir = metadata.getDirectory(GpsDirectory.class);
+            dirExif = metadata.getDirectory(ExifDirectory.class);
+            dirGps = metadata.getDirectory(GpsDirectory.class);
         } catch (CompoundException p) {
             e.setExifCoor(null);
@@ -521,7 +524,13 @@
 
         try {
+            int orientation = dirExif.getInt(ExifDirectory.TAG_ORIENTATION);
+            e.setExifOrientation(orientation);
+        } catch (MetadataException ex) {
+        }
+        
+        try {
             // longitude
 
-            Rational[] components = dir.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
+            Rational[] components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
 
             deg = components[0].doubleValue();
@@ -534,5 +543,5 @@
             lon = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600)));
 
-            if (dir.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') {
+            if (dirGps.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') {
                 lon = -lon;
             }
@@ -540,5 +549,5 @@
             // latitude
 
-            components = dir.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
+            components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
 
             deg = components[0].doubleValue();
@@ -554,5 +563,5 @@
                 throw new IllegalArgumentException();
 
-            if (dir.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') {
+            if (dirGps.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') {
                 lat = -lat;
             }
@@ -566,6 +575,6 @@
             // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220)
             try {
-                Double longitude = dir.getDouble(GpsDirectory.TAG_GPS_LONGITUDE);
-                Double latitude = dir.getDouble(GpsDirectory.TAG_GPS_LATITUDE);
+                Double longitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LONGITUDE);
+                Double latitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LATITUDE);
                 if (longitude == null || latitude == null)
                     throw new CompoundException("");
@@ -590,5 +599,5 @@
 
         try {
-            direction = dir.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION);
+            direction = dirGps.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION);
             if (direction != null) {
                 e.setExifImgDir(direction.doubleValue());
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java	(revision 4240)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java	(revision 4241)
@@ -10,4 +10,5 @@
 import java.awt.FontMetrics;
 import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.MediaTracker;
@@ -20,5 +21,7 @@
 import java.awt.event.MouseWheelEvent;
 import java.awt.event.MouseWheelListener;
+import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
 import java.io.File;
 
@@ -34,5 +37,5 @@
     /** The image currently displayed */
     private Image image = null;
-
+    
     /** The image currently displayed */
     private boolean errorLoading = false;
@@ -56,8 +59,10 @@
     private class LoadImageRunnable implements Runnable {
 
-        File file = null;
-
-        public LoadImageRunnable(File file) {
+        private File file;
+        private int orientation;
+
+        public LoadImageRunnable(File file, Integer orientation) {
             this.file = file;
+            this.orientation = orientation == null ? -1 : orientation;
         }
 
@@ -90,6 +95,51 @@
                     return;
                 }
+
                 ImageDisplay.this.image = img;
                 visibleRect = new Rectangle(0, 0, img.getWidth(null), img.getHeight(null));
+
+                final int w = (int) visibleRect.getWidth();
+                final int h = (int) visibleRect.getHeight();
+
+                outer: {
+                    final int hh, ww, q;
+                    final double ax, ay;
+                    switch (orientation) {
+                    case 8:
+                        q = -1;
+                        ax = w / 2;
+                        ay = w / 2;
+                        ww = h;
+                        hh = w;
+                        break;
+                    case 3:
+                        q = 2;
+                        ax = w / 2;
+                        ay = h / 2;
+                        ww = w;
+                        hh = h;
+                        break;
+                    case 6:
+                        q = 1;
+                        ax = h / 2;
+                        ay = h / 2;
+                        ww = h;
+                        hh = w;
+                        break;
+                    default:
+                        break outer;
+                    }
+
+                    final BufferedImage rot = new BufferedImage(ww, hh, BufferedImage.TYPE_INT_RGB);
+                    final AffineTransform xform = AffineTransform.getQuadrantRotateInstance(q, ax, ay);
+                    final Graphics2D g = rot.createGraphics();
+                    g.drawImage(image, xform, null);
+                    g.dispose();
+
+                    visibleRect.setSize(ww, hh);
+                    image.flush();
+                    ImageDisplay.this.image = rot;
+                }
+
                 selectedRect = null;
                 errorLoading = error;
@@ -394,5 +444,5 @@
     }
 
-    public void setImage(File file) {
+    public void setImage(File file, Integer orientation) {
         synchronized(this) {
             this.file = file;
@@ -403,5 +453,5 @@
         repaint();
         if (file != null) {
-            new Thread(new LoadImageRunnable(file)).start();
+            new Thread(new LoadImageRunnable(file, orientation)).start();
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java	(revision 4240)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java	(revision 4241)
@@ -19,4 +19,5 @@
 final public class ImageEntry implements Comparable<ImageEntry>, Cloneable {
     private File file;
+    private Integer exifOrientation;
     private LatLon exifCoor;
     private Double exifImgDir;
@@ -73,4 +74,7 @@
         return file;
     }
+    public Integer getExifOrientation() {
+        return exifOrientation;
+    }
     public Date getExifTime() {
         return exifTime;
@@ -100,4 +104,7 @@
     void setFile(File file) {
         this.file = file;
+    }
+    void setExifOrientation(Integer exifOrientation) {
+        this.exifOrientation = exifOrientation;
     }
     void setExifTime(Date exifTime) {
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 4240)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 4241)
@@ -230,5 +230,5 @@
 
         if (entry != null) {
-            imgDisplay.setImage(entry.getFile());
+            imgDisplay.setImage(entry.getFile(), entry.getExifOrientation());
             setTitle("Geotagged Images" + (entry.getFile() != null ? " - " + entry.getFile().getName() : ""));
             StringBuffer osd = new StringBuffer(entry.getFile() != null ? entry.getFile().getName() : "");
@@ -253,5 +253,5 @@
             imgDisplay.setOsdText(osd.toString());
         } else {
-            imgDisplay.setImage(null);
+            imgDisplay.setImage(null, null);
             imgDisplay.setOsdText("");
         }
Index: trunk/src/org/openstreetmap/josm/tools/ExifReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/ExifReader.java	(revision 4240)
+++ trunk/src/org/openstreetmap/josm/tools/ExifReader.java	(revision 4241)
@@ -8,7 +8,10 @@
 
 import com.drew.imaging.jpeg.JpegMetadataReader;
+import com.drew.imaging.jpeg.JpegProcessingException;
 import com.drew.metadata.Directory;
 import com.drew.metadata.Metadata;
+import com.drew.metadata.MetadataException;
 import com.drew.metadata.Tag;
+import com.drew.metadata.exif.ExifDirectory;
 
 /**
@@ -38,3 +41,18 @@
         return date;
     }
+
+    @SuppressWarnings("unchecked") public static Integer readOrientation(File filename) throws ParseException {
+        Integer orientation = null;
+        try {
+            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
+            final Directory dir = metadata.getDirectory(ExifDirectory.class);
+            orientation = dir.getInt(ExifDirectory.TAG_ORIENTATION);
+        } catch (JpegProcessingException e) {
+            e.printStackTrace();
+        } catch (MetadataException e) {
+            e.printStackTrace();
+        }
+        return orientation;
+    }
+
 }
