X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fjpeg%2FExternalExifLibrary.java;h=0d94f038479b829f3393ffc1fcbfc76fc795954c;hb=649c5da6ee1bbc590699e11a92316ece2ea8512d;hp=b9cd1fdadf33bb739868d98c716c8d8b4d44fc16;hpb=c0387c124840c9407e040600fda88f3c3e8f6aa6;p=GpsPrune.git diff --git a/tim/prune/jpeg/ExternalExifLibrary.java b/tim/prune/jpeg/ExternalExifLibrary.java index b9cd1fd..0d94f03 100644 --- a/tim/prune/jpeg/ExternalExifLibrary.java +++ b/tim/prune/jpeg/ExternalExifLibrary.java @@ -5,6 +5,7 @@ import java.io.File; import com.drew.lang.Rational; 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.ExifReader; import com.drew.metadata.exif.GpsDirectory; @@ -12,7 +13,7 @@ import com.drew.metadata.exif.GpsDirectory; /** * Class to act as a gateway into the external exif library functions. * This should be the only class with dependence on the lib-metadata-extractor-java - * classes (which are NOT delivered with Prune). + * classes (which are NOT delivered with GpsPrune). * This class will not compile without this extra dependency (but is not required if * the ExifGateway uses the InternalExifLibrary instead). * Should not be included if the internal library will be used (from jpeg.drew package). @@ -42,12 +43,14 @@ public class ExternalExifLibrary implements ExifLibrary { data.setLatitudeRef(gpsdir.getString(GpsDirectory.TAG_GPS_LATITUDE_REF)); Rational[] latRats = gpsdir.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE); + double seconds = ExifGateway.convertToPositiveValue(latRats[2].getNumerator(), latRats[2].getDenominator()); data.setLatitude(new double[] {latRats[0].doubleValue(), - latRats[1].doubleValue(), latRats[2].doubleValue()}); + latRats[1].doubleValue(), seconds}); data.setLongitudeRef(gpsdir.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF)); Rational[] lonRats = gpsdir.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE); + seconds = ExifGateway.convertToPositiveValue(lonRats[2].getNumerator(), lonRats[2].getDenominator()); data.setLongitude(new double[] {lonRats[0].doubleValue(), - lonRats[1].doubleValue(), lonRats[2].doubleValue()}); + lonRats[1].doubleValue(), seconds}); } // Altitude (if present) @@ -58,15 +61,30 @@ public class ExternalExifLibrary implements ExifLibrary data.setAltitudeRef(altRef); } - // Timestamp and datestamp (if present) - final int TAG_GPS_DATESTAMP = 0x001d; - if (gpsdir.containsTag(GpsDirectory.TAG_GPS_TIME_STAMP) && gpsdir.containsTag(TAG_GPS_DATESTAMP)) + try { - Rational[] times = gpsdir.getRationalArray(GpsDirectory.TAG_GPS_TIME_STAMP); - data.setGpsTimestamp(new int[] {times[0].intValue(), times[1].intValue(), - times[2].intValue()}); - Rational[] dates = gpsdir.getRationalArray(TAG_GPS_DATESTAMP); - data.setGpsDatestamp(new int[] {dates[0].intValue(), dates[1].intValue(), dates[2].intValue()}); + // Timestamp and datestamp (if present) + final int TAG_GPS_DATESTAMP = 0x001d; + if (gpsdir.containsTag(GpsDirectory.TAG_GPS_TIME_STAMP) && gpsdir.containsTag(TAG_GPS_DATESTAMP)) + { + Rational[] times = gpsdir.getRationalArray(GpsDirectory.TAG_GPS_TIME_STAMP); + data.setGpsTimestamp(new int[] {times[0].intValue(), times[1].intValue(), + times[2].intValue()}); + Rational[] dates = gpsdir.getRationalArray(TAG_GPS_DATESTAMP); + if (dates != null) { + data.setGpsDatestamp(new int[] {dates[0].intValue(), dates[1].intValue(), dates[2].intValue()}); + } + } + } + catch (MetadataException me) {} // ignore, use other tags instead + + // Image bearing (if present) + if (gpsdir.containsTag(GpsDirectory.TAG_GPS_IMG_DIRECTION) && gpsdir.containsTag(GpsDirectory.TAG_GPS_IMG_DIRECTION_REF)) + { + Rational bearing = gpsdir.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION); + if (bearing != null) { + data.setBearing(bearing.doubleValue()); + } } } @@ -75,10 +93,14 @@ public class ExternalExifLibrary implements ExifLibrary { Directory exifdir = metadata.getDirectory(ExifDirectory.class); - // Take time and date from exif tags if haven't got it already from GPS - if (data.getGpsDatestamp() == null && exifdir.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)) { + // Take time and date from exif tags + if (exifdir.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)) { data.setOriginalTimestamp(exifdir.getString(ExifDirectory.TAG_DATETIME_ORIGINAL)); } + // Also take "digitized" timestamp + if (exifdir.containsTag(ExifDirectory.TAG_DATETIME_DIGITIZED)) { + data.setDigitizedTimestamp(exifdir.getString(ExifDirectory.TAG_DATETIME_DIGITIZED)); + } // Photo rotation code if (exifdir.containsTag(ExifDirectory.TAG_ORIENTATION)) { @@ -100,10 +122,12 @@ public class ExternalExifLibrary implements ExifLibrary } catch (Exception e) { // Exception reading metadata, just ignore it + //System.err.println("Error: " + e.getClass().getName() + " - " + e.getMessage()); } return data; } + /** * Check whether the exifreader class can be correctly resolved * @return true if it looks ok