Changeset 4241 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2011-07-14T17:00:22+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r3408 r4241 33 33 import java.util.Comparator; 34 34 import java.util.Date; 35 import java.util.Hashtable;36 35 import java.util.Iterator; 37 36 import java.util.List; 38 37 import java.util.TimeZone; 39 import java.util.Vector;40 38 import java.util.zip.GZIPInputStream; 41 39 … … 348 346 public void valueChanged(ListSelectionEvent arg0) { 349 347 int index = imgList.getSelectedIndex(); 350 imgDisp.setImage(yLayer.data.get(index).getFile()); 348 Integer orientation = null; 349 try { 350 orientation = ExifReader.readOrientation(yLayer.data.get(index).getFile()); 351 } catch (Exception e) { 352 } 353 imgDisp.setImage(yLayer.data.get(index).getFile(), orientation); 351 354 Date date = yLayer.data.get(index).getExifTime(); 352 355 if (date != null) { … … 380 383 return; 381 384 382 imgDisp.setImage(sel); 385 Integer orientation = null; 386 try { 387 orientation = ExifReader.readOrientation(sel); 388 } catch (Exception e) { 389 } 390 imgDisp.setImage(sel, orientation); 383 391 384 392 Date date = null; -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r4010 r4241 63 63 import com.drew.metadata.Directory; 64 64 import com.drew.metadata.Metadata; 65 import com.drew.metadata.MetadataException; 66 import com.drew.metadata.exif.ExifDirectory; 65 67 import com.drew.metadata.exif.GpsDirectory; 66 68 … … 509 511 double lon, lat; 510 512 Metadata metadata = null; 511 Directory dir = null;513 Directory dirExif = null, dirGps = null; 512 514 513 515 try { 514 516 metadata = JpegMetadataReader.readMetadata(e.getFile()); 515 dir = metadata.getDirectory(GpsDirectory.class); 517 dirExif = metadata.getDirectory(ExifDirectory.class); 518 dirGps = metadata.getDirectory(GpsDirectory.class); 516 519 } catch (CompoundException p) { 517 520 e.setExifCoor(null); … … 521 524 522 525 try { 526 int orientation = dirExif.getInt(ExifDirectory.TAG_ORIENTATION); 527 e.setExifOrientation(orientation); 528 } catch (MetadataException ex) { 529 } 530 531 try { 523 532 // longitude 524 533 525 Rational[] components = dir .getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);534 Rational[] components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE); 526 535 527 536 deg = components[0].doubleValue(); … … 534 543 lon = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600))); 535 544 536 if (dir .getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') {545 if (dirGps.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') { 537 546 lon = -lon; 538 547 } … … 540 549 // latitude 541 550 542 components = dir .getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);551 components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE); 543 552 544 553 deg = components[0].doubleValue(); … … 554 563 throw new IllegalArgumentException(); 555 564 556 if (dir .getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') {565 if (dirGps.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') { 557 566 lat = -lat; 558 567 } … … 566 575 // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220) 567 576 try { 568 Double longitude = dir .getDouble(GpsDirectory.TAG_GPS_LONGITUDE);569 Double latitude = dir .getDouble(GpsDirectory.TAG_GPS_LATITUDE);577 Double longitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LONGITUDE); 578 Double latitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LATITUDE); 570 579 if (longitude == null || latitude == null) 571 580 throw new CompoundException(""); … … 590 599 591 600 try { 592 direction = dir .getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION);601 direction = dirGps.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION); 593 602 if (direction != null) { 594 603 e.setExifImgDir(direction.doubleValue()); -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
r3479 r4241 10 10 import java.awt.FontMetrics; 11 11 import java.awt.Graphics; 12 import java.awt.Graphics2D; 12 13 import java.awt.Image; 13 14 import java.awt.MediaTracker; … … 20 21 import java.awt.event.MouseWheelEvent; 21 22 import java.awt.event.MouseWheelListener; 23 import java.awt.geom.AffineTransform; 22 24 import java.awt.geom.Rectangle2D; 25 import java.awt.image.BufferedImage; 23 26 import java.io.File; 24 27 … … 34 37 /** The image currently displayed */ 35 38 private Image image = null; 36 39 37 40 /** The image currently displayed */ 38 41 private boolean errorLoading = false; … … 56 59 private class LoadImageRunnable implements Runnable { 57 60 58 File file = null; 59 60 public LoadImageRunnable(File file) { 61 private File file; 62 private int orientation; 63 64 public LoadImageRunnable(File file, Integer orientation) { 61 65 this.file = file; 66 this.orientation = orientation == null ? -1 : orientation; 62 67 } 63 68 … … 90 95 return; 91 96 } 97 92 98 ImageDisplay.this.image = img; 93 99 visibleRect = new Rectangle(0, 0, img.getWidth(null), img.getHeight(null)); 100 101 final int w = (int) visibleRect.getWidth(); 102 final int h = (int) visibleRect.getHeight(); 103 104 outer: { 105 final int hh, ww, q; 106 final double ax, ay; 107 switch (orientation) { 108 case 8: 109 q = -1; 110 ax = w / 2; 111 ay = w / 2; 112 ww = h; 113 hh = w; 114 break; 115 case 3: 116 q = 2; 117 ax = w / 2; 118 ay = h / 2; 119 ww = w; 120 hh = h; 121 break; 122 case 6: 123 q = 1; 124 ax = h / 2; 125 ay = h / 2; 126 ww = h; 127 hh = w; 128 break; 129 default: 130 break outer; 131 } 132 133 final BufferedImage rot = new BufferedImage(ww, hh, BufferedImage.TYPE_INT_RGB); 134 final AffineTransform xform = AffineTransform.getQuadrantRotateInstance(q, ax, ay); 135 final Graphics2D g = rot.createGraphics(); 136 g.drawImage(image, xform, null); 137 g.dispose(); 138 139 visibleRect.setSize(ww, hh); 140 image.flush(); 141 ImageDisplay.this.image = rot; 142 } 143 94 144 selectedRect = null; 95 145 errorLoading = error; … … 394 444 } 395 445 396 public void setImage(File file ) {446 public void setImage(File file, Integer orientation) { 397 447 synchronized(this) { 398 448 this.file = file; … … 403 453 repaint(); 404 454 if (file != null) { 405 new Thread(new LoadImageRunnable(file )).start();455 new Thread(new LoadImageRunnable(file, orientation)).start(); 406 456 } 407 457 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java
r3530 r4241 19 19 final public class ImageEntry implements Comparable<ImageEntry>, Cloneable { 20 20 private File file; 21 private Integer exifOrientation; 21 22 private LatLon exifCoor; 22 23 private Double exifImgDir; … … 73 74 return file; 74 75 } 76 public Integer getExifOrientation() { 77 return exifOrientation; 78 } 75 79 public Date getExifTime() { 76 80 return exifTime; … … 100 104 void setFile(File file) { 101 105 this.file = file; 106 } 107 void setExifOrientation(Integer exifOrientation) { 108 this.exifOrientation = exifOrientation; 102 109 } 103 110 void setExifTime(Date exifTime) { -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r3263 r4241 230 230 231 231 if (entry != null) { 232 imgDisplay.setImage(entry.getFile() );232 imgDisplay.setImage(entry.getFile(), entry.getExifOrientation()); 233 233 setTitle("Geotagged Images" + (entry.getFile() != null ? " - " + entry.getFile().getName() : "")); 234 234 StringBuffer osd = new StringBuffer(entry.getFile() != null ? entry.getFile().getName() : ""); … … 253 253 imgDisplay.setOsdText(osd.toString()); 254 254 } else { 255 imgDisplay.setImage(null );255 imgDisplay.setImage(null, null); 256 256 imgDisplay.setOsdText(""); 257 257 } -
trunk/src/org/openstreetmap/josm/tools/ExifReader.java
r1169 r4241 8 8 9 9 import com.drew.imaging.jpeg.JpegMetadataReader; 10 import com.drew.imaging.jpeg.JpegProcessingException; 10 11 import com.drew.metadata.Directory; 11 12 import com.drew.metadata.Metadata; 13 import com.drew.metadata.MetadataException; 12 14 import com.drew.metadata.Tag; 15 import com.drew.metadata.exif.ExifDirectory; 13 16 14 17 /** … … 38 41 return date; 39 42 } 43 44 @SuppressWarnings("unchecked") public static Integer readOrientation(File filename) throws ParseException { 45 Integer orientation = null; 46 try { 47 final Metadata metadata = JpegMetadataReader.readMetadata(filename); 48 final Directory dir = metadata.getDirectory(ExifDirectory.class); 49 orientation = dir.getInt(ExifDirectory.TAG_ORIENTATION); 50 } catch (JpegProcessingException e) { 51 e.printStackTrace(); 52 } catch (MetadataException e) { 53 e.printStackTrace(); 54 } 55 return orientation; 56 } 57 40 58 }
Note:
See TracChangeset
for help on using the changeset viewer.