*/
private static void extractExif(ImageEntry e) {
Metadata metadata;
Directory dirExif;
GpsDirectory dirGps;
try {
metadata = JpegMetadataReader.readMetadata(e.getFile());
dirExif = metadata.getDirectory(ExifIFD0Directory.class);
dirGps = metadata.getDirectory(GpsDirectory.class);
} catch (CompoundException | IOException p) {
e.setExifCoor(null);
e.setPos(null);
return;
}
try {
if (dirExif != null) {
int orientation = dirExif.getInt(ExifIFD0Directory.TAG_ORIENTATION);
e.setExifOrientation(orientation);
}
} catch (MetadataException ex) {
Main.debug(ex.getMessage());
}
if (dirGps == null) {
e.setExifCoor(null);
e.setPos(null);
return;
}
try {
double ele = dirGps.getDouble(GpsDirectory.TAG_GPS_ALTITUDE);
int d = dirGps.getInt(GpsDirectory.TAG_GPS_ALTITUDE_REF);
if (d == 1) {
ele *= -1;
}
e.setElevation(ele);
} catch (MetadataException ex) {
Main.debug(ex.getMessage());
}
try {
LatLon latlon = ExifReader.readLatLon(dirGps);
e.setExifCoor(latlon);
e.setPos(e.getExifCoor());
} catch (Exception ex) { // (other exceptions, e.g. #5271)
Main.error("Error reading EXIF from file: "+ex);
e.setExifCoor(null);
e.setPos(null);
}
try {
Double direction = ExifReader.readDirection(dirGps);
if (direction != null) {
e.setExifImgDir(direction.doubleValue());
}
} catch (Exception ex) { // (CompoundException and other exceptions, e.g. #5271)
Main.debug(ex.getMessage());
}
// Time and date. We can have these cases:
// 1) GPS_TIME_STAMP not set -> date/time will be null
// 2) GPS_DATE_STAMP not set -> use EXIF date or set to default
// 3) GPS_TIME_STAMP and GPS_DATE_STAMP are set
int[] timeStampComps = dirGps.getIntArray(GpsDirectory.TAG_GPS_TIME_STAMP);
if (timeStampComps != null) {
int gpsHour = timeStampComps[0];
int gpsMin = timeStampComps[1];
int gpsSec = timeStampComps[2];
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
// We have the time. Next step is to check if the GPS date stamp is set.
// dirGps.getString() always succeeds, but the return value might be null.
String dateStampStr = dirGps.getString(GpsDirectory.TAG_GPS_DATE_STAMP);
if (dateStampStr != null && dateStampStr.matches("^\\d+:\\d+:\\d+$")) {
String[] dateStampComps = dateStampStr.split(":");
cal.set(Calendar.YEAR, Integer.parseInt(dateStampComps[0]));
cal.set(Calendar.MONTH, Integer.parseInt(dateStampComps[1]) - 1);
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStampComps[2]));