[josm-dev] [PATCH] Image Direction / Compass Camera images

Florian Lohoff f at zz.de
Mon May 17 16:11:58 BST 2010


On Sat, May 15, 2010 at 11:30:01PM +0200, Sebastian Klein wrote:
> Sure, if you donate a camera, I'll fully implement it. ;)
> 
> Seriously, there is a lot to do and we cannot add each extension that is 
> used by a single hardware model. But it's a damn cool feature. 
> Hopefully, there will be other vendors and models supporting this!

Don't tell anyone i touched java - I have something rudimentary working
which draws a little triangle arrow below the camera icon when activating it 
e.g. clicking on the picture icon - It does only so when there is a
GPS Image Direction tag in the exif header. I had no clue about java but
someone might hint me through some design/style issues ... Especially
i think there is some overhead in the exception reading the exif tags as
this 

	+            Metadata metadata = JpegMetadataReader.readMetadata(e.getFile());
	+            Directory directory = metadata.getDirectory(GpsDirectory.class);

is called twice ... Probably unnecessary ....

Here is a small screenshot how it will look:

http://silicon-verl.de/home/flo/tmp/screenshot-josm3260-imgdir1.png


diff --git a/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java b/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
index eb56404..28a06b3 100644
--- a/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
+++ b/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
@@ -467,9 +468,36 @@ public class GeoImageLayer extends Layer implements PropertyChangeListener {
                     g.setColor(new Color(128, 0, 0, 122));
                     g.fillRect(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
                 } else {
+			if (e.getExifImgDir() != null) {
+				double arrowlength = 25;
+				double arrowwidth = 18;
+
+				double dir = e.getExifImgDir();
+				// Rotate 90° CCW 
+				double headdir = ( dir < 90 ) ? dir + 270 : dir - 90;
+				double leftdir = ( headdir < 90 ) ? headdir + 270 : headdir - 90;
+				double rightdir = ( headdir > 270 ) ? headdir - 270 : headdir + 90;
+
+				double ptx = p.x + Math.cos(Math.toRadians(headdir)) * arrowlength;
+				double pty = p.y + Math.sin(Math.toRadians(headdir)) * arrowlength;
+
+				double ltx = p.x + Math.cos(Math.toRadians(leftdir)) * arrowwidth/2;
+				double lty = p.y + Math.sin(Math.toRadians(leftdir)) * arrowwidth/2;
+
+				double rtx = p.x + Math.cos(Math.toRadians(rightdir)) * arrowwidth/2;
+				double rty = p.y + Math.sin(Math.toRadians(rightdir)) * arrowwidth/2;
+
+				g.setColor(Color.white);
+				int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx};
+				int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty};
+				g.fillPolygon(xar, yar, 4);
+			}
+
                     selectedIcon.paintIcon(mv, g,
                             p.x - selectedIcon.getIconWidth() / 2,
                             p.y - selectedIcon.getIconHeight() / 2);
+
+		  
                 }
             }
         }
@@ -536,6 +564,15 @@ public class GeoImageLayer extends Layer implements PropertyChangeListener {
             e.setExifCoor(null);
             e.setPos(null);
         }
+
+	try {
+            Metadata metadata = JpegMetadataReader.readMetadata(e.getFile());
+            Directory directory = metadata.getDirectory(GpsDirectory.class);
+            Rational direction = directory.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION);
+
+	    e.setExifImgDir(direction.doubleValue());
+	} catch (CompoundException p) {
+	}
     }
 
     public void showNextPhoto() {
diff --git a/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java b/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java
index 2b199e9..a73297a 100644
--- a/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java
+++ b/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java
@@ -19,6 +19,7 @@ import org.openstreetmap.josm.data.coor.LatLon;
 final public class ImageEntry implements Comparable<ImageEntry>, Cloneable {
     private File file;
     private LatLon exifCoor;
+    private Double exifImgDir;
     private Date exifTime;
     Image thumbnail;
 
@@ -77,6 +78,10 @@ final public class ImageEntry implements Comparable<ImageEntry>, Cloneable {
     LatLon getExifCoor() {
         return exifCoor;
     }
+    public Double getExifImgDir() {
+    	return exifImgDir;
+    }
+
     /**
      * setter methods
      */
@@ -104,6 +109,9 @@ final public class ImageEntry implements Comparable<ImageEntry>, Cloneable {
     void setExifCoor(LatLon exifCoor) {
         this.exifCoor = exifCoor;
     }
+    void setExifImgDir(double exifDir) {
+        this.exifImgDir = exifDir;
+    } 
 
     @Override
     public ImageEntry clone() {
diff --git a/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java b/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
index 02db2d6..7d99186 100644
--- a/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
+++ b/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
@@ -238,6 +238,9 @@ public class ImageViewerDialog extends ToggleDialog {
             if (entry.getSpeed() != null) {
                 osd.append(tr("\n{0} km/h", Math.round(entry.getSpeed())));
             }
+	    if (entry.getExifImgDir() != null) {
+                osd.append(tr("\nDirection {0}°", Math.round(entry.getExifImgDir())));
+	    }
             //if (entry.getPos()  != null) {
             //    osd.append(tr("\nlat: {0}, lon: {1}", Double.toString(entry.getPos().lat()), Double.toString(entry.getPos().lon())));
             //}

Flo
-- 
Florian Lohoff                                                 f at zz.de
"Es ist ein grobes Missverständnis und eine Fehlwahrnehmung, dem Staat
im Internet Zensur- und Überwachungsabsichten zu unterstellen."
- - Bundesminister Dr. Wolfgang Schäuble -- 10. Juli in Berlin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
URL: <http://lists.openstreetmap.org/pipermail/josm-dev/attachments/20100517/322ba3e5/attachment.pgp>


More information about the josm-dev mailing list