Changeset 6127 in josm for trunk/src/org
- Timestamp:
- 2013-08-09T18:05:11+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r6106 r6127 65 65 import com.drew.imaging.jpeg.JpegMetadataReader; 66 66 import com.drew.lang.CompoundException; 67 import com.drew.lang.GeoLocation; 67 68 import com.drew.lang.Rational; 68 69 import com.drew.metadata.Directory; 69 70 import com.drew.metadata.Metadata; 70 71 import com.drew.metadata.MetadataException; 71 import com.drew.metadata.exif.Exif Directory;72 import com.drew.metadata.exif.ExifIFD0Directory; 72 73 import com.drew.metadata.exif.GpsDirectory; 73 74 … … 508 509 private static void extractExif(ImageEntry e) { 509 510 510 double deg; 511 double min, sec; 512 double lon, lat; 513 Metadata metadata = null; 514 Directory dirExif = null, dirGps = null; 511 Metadata metadata; 512 Directory dirExif; 513 GpsDirectory dirGps; 515 514 516 515 try { 517 516 metadata = JpegMetadataReader.readMetadata(e.getFile()); 518 dirExif = metadata.getDirectory(Exif Directory.class);517 dirExif = metadata.getDirectory(ExifIFD0Directory.class); 519 518 dirGps = metadata.getDirectory(GpsDirectory.class); 520 519 } catch (CompoundException p) { … … 522 521 e.setPos(null); 523 522 return; 523 } catch (IOException p) { 524 e.setExifCoor(null); 525 e.setPos(null); 526 return; 524 527 } 525 528 526 529 try { 527 int orientation = dirExif.getInt(Exif Directory.TAG_ORIENTATION);530 int orientation = dirExif.getInt(ExifIFD0Directory.TAG_ORIENTATION); 528 531 e.setExifOrientation(orientation); 529 532 } catch (MetadataException ex) { 533 } 534 535 if (dirGps == null) { 536 e.setExifCoor(null); 537 e.setPos(null); 538 return; 530 539 } 531 540 … … 541 550 542 551 try { 543 // longitude 544 545 Rational[] components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE); 546 547 deg = components[0].doubleValue(); 548 min = components[1].doubleValue(); 549 sec = components[2].doubleValue(); 550 551 if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec)) 552 throw new IllegalArgumentException(); 553 554 lon = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600))); 555 556 if (dirGps.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') { 557 lon = -lon; 558 } 559 560 // latitude 561 562 components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE); 563 564 deg = components[0].doubleValue(); 565 min = components[1].doubleValue(); 566 sec = components[2].doubleValue(); 567 568 if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec)) 569 throw new IllegalArgumentException(); 570 571 lat = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600))); 572 573 if (Double.isNaN(lat)) 574 throw new IllegalArgumentException(); 575 576 if (dirGps.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') { 577 lat = -lat; 578 } 579 580 // Store values 581 582 e.setExifCoor(new LatLon(lat, lon)); 583 e.setPos(e.getExifCoor()); 584 585 } catch (CompoundException p) { 586 // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220) 587 try { 588 Double longitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LONGITUDE); 589 Double latitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LATITUDE); 590 if (longitude == null || latitude == null) 591 throw new CompoundException(""); 592 593 // Store values 594 595 e.setExifCoor(new LatLon(latitude, longitude)); 552 GeoLocation location = dirGps.getGeoLocation(); 553 if (location != null) { 554 e.setExifCoor(new LatLon(location.getLatitude(), location.getLongitude())); 596 555 e.setPos(e.getExifCoor()); 597 } catch (CompoundException ex) { 598 e.setExifCoor(null); 599 e.setPos(null); 556 } else { 557 // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220) 558 try { 559 Double longitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LONGITUDE); 560 Double latitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LATITUDE); 561 562 // Store values 563 564 e.setExifCoor(new LatLon(latitude, longitude)); 565 e.setPos(e.getExifCoor()); 566 } catch (CompoundException ex) { 567 e.setExifCoor(null); 568 e.setPos(null); 569 } 600 570 } 601 571 } catch (Exception ex) { // (other exceptions, e.g. #5271) -
trunk/src/org/openstreetmap/josm/tools/ExifReader.java
r5610 r6127 3 3 4 4 import java.io.File; 5 import java.io.IOException; 5 6 import java.text.ParseException; 6 7 import java.util.Date; 7 import java.util.Iterator;8 8 9 9 import com.drew.imaging.jpeg.JpegMetadataReader; … … 13 13 import com.drew.metadata.MetadataException; 14 14 import com.drew.metadata.Tag; 15 import com.drew.metadata.exif.ExifDirectory; 15 import com.drew.metadata.exif.ExifIFD0Directory; 16 import com.drew.metadata.exif.ExifSubIFDDirectory; 16 17 17 18 /** … … 26 27 String dateStr = null; 27 28 OUTER: 28 for (Iterator<Directory> dirIt = metadata.getDirectoryIterator(); dirIt.hasNext();) { 29 for (Iterator<Tag> tagIt = dirIt.next().getTagIterator(); tagIt.hasNext();) { 30 Tag tag = tagIt.next(); 31 if (tag.getTagType() == ExifDirectory.TAG_DATETIME_ORIGINAL /* 0x9003 */) { 29 for (Directory dirIt : metadata.getDirectories()) { 30 for (Tag tag : dirIt.getTags()) { 31 if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL /* 0x9003 */) { 32 32 dateStr = tag.getDescription(); 33 33 break OUTER; // prefer this tag 34 34 } 35 if (tag.getTagType() == Exif Directory.TAG_DATETIME /* 0x0132 */ ||36 tag.getTagType() == Exif Directory.TAG_DATETIME_DIGITIZED /* 0x9004 */) {35 if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */ || 36 tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) { 37 37 dateStr = tag.getDescription(); 38 38 } … … 55 55 try { 56 56 final Metadata metadata = JpegMetadataReader.readMetadata(filename); 57 final Directory dir = metadata.getDirectory(Exif Directory.class);58 orientation = dir.getInt(Exif Directory.TAG_ORIENTATION);57 final Directory dir = metadata.getDirectory(ExifIFD0Directory.class); 58 orientation = dir.getInt(ExifIFD0Directory.TAG_ORIENTATION); 59 59 } catch (JpegProcessingException e) { 60 60 e.printStackTrace(); 61 61 } catch (MetadataException e) { 62 e.printStackTrace(); 63 } catch (IOException e) { 62 64 e.printStackTrace(); 63 65 }
Note:
See TracChangeset
for help on using the changeset viewer.