Ignore:
Timestamp:
2011-07-14T17:00:22+02:00 (13 years ago)
Author:
bastiK
Message:

applied #5605 - Geotagged image viewer should rotate images according to EXIF orientation tag (patch by m.zdila, some modifications)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r4010 r4241  
    6363import com.drew.metadata.Directory;
    6464import com.drew.metadata.Metadata;
     65import com.drew.metadata.MetadataException;
     66import com.drew.metadata.exif.ExifDirectory;
    6567import com.drew.metadata.exif.GpsDirectory;
    6668
     
    509511        double lon, lat;
    510512        Metadata metadata = null;
    511         Directory dir = null;
     513        Directory dirExif = null, dirGps = null;
    512514
    513515        try {
    514516            metadata = JpegMetadataReader.readMetadata(e.getFile());
    515             dir = metadata.getDirectory(GpsDirectory.class);
     517            dirExif = metadata.getDirectory(ExifDirectory.class);
     518            dirGps = metadata.getDirectory(GpsDirectory.class);
    516519        } catch (CompoundException p) {
    517520            e.setExifCoor(null);
     
    521524
    522525        try {
     526            int orientation = dirExif.getInt(ExifDirectory.TAG_ORIENTATION);
     527            e.setExifOrientation(orientation);
     528        } catch (MetadataException ex) {
     529        }
     530       
     531        try {
    523532            // longitude
    524533
    525             Rational[] components = dir.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
     534            Rational[] components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
    526535
    527536            deg = components[0].doubleValue();
     
    534543            lon = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600)));
    535544
    536             if (dir.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') {
     545            if (dirGps.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') {
    537546                lon = -lon;
    538547            }
     
    540549            // latitude
    541550
    542             components = dir.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
     551            components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
    543552
    544553            deg = components[0].doubleValue();
     
    554563                throw new IllegalArgumentException();
    555564
    556             if (dir.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') {
     565            if (dirGps.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') {
    557566                lat = -lat;
    558567            }
     
    566575            // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220)
    567576            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);
    570579                if (longitude == null || latitude == null)
    571580                    throw new CompoundException("");
     
    590599
    591600        try {
    592             direction = dir.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION);
     601            direction = dirGps.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION);
    593602            if (direction != null) {
    594603                e.setExifImgDir(direction.doubleValue());
Note: See TracChangeset for help on using the changeset viewer.