Changeset 9499 in josm for trunk/src


Ignore:
Timestamp:
2016-01-17T13:10:38+01:00 (8 years ago)
Author:
simon04
Message:

fix #11685 - Use sub-second exif/xmp data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r9383 r9499  
    4242            Metadata metadata = JpegMetadataReader.readMetadata(filename);
    4343            String dateStr = null;
    44             OUTER:
     44            String subSeconds = null;
    4545            for (Directory dirIt : metadata.getDirectories()) {
    4646                for (Tag tag : dirIt.getTags()) {
     
    4848                            !tag.getDescription().matches("\\[[0-9]+ .+\\]")) {
    4949                        dateStr = tag.getDescription();
    50                         break OUTER; // prefer this tag if known
    5150                    }
    5251                    if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */ ||
    5352                        tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) {
    54                         dateStr = tag.getDescription();
     53                        if (dateStr != null) {
     54                            // prefer TAG_DATETIME_ORIGINAL
     55                            dateStr = tag.getDescription();
     56                        }
     57                    }
     58                    if (tag.getTagType() == ExifIFD0Directory.TAG_SUBSECOND_TIME_ORIGINAL) {
     59                        subSeconds = tag.getDescription();
    5560                    }
    5661                }
     
    5863            if (dateStr != null) {
    5964                dateStr = dateStr.replace('/', ':'); // workaround for HTC Sensation bug, see #7228
    60                 return DateUtils.fromString(dateStr);
     65                final Date date = DateUtils.fromString(dateStr);
     66                if (subSeconds != null) {
     67                    try {
     68                        date.setTime(date.getTime() + Integer.parseInt(subSeconds));
     69                    } catch (NumberFormatException e) {
     70                        Main.warn("Failed parsing sub seconds from [{0}]", subSeconds);
     71                        Main.warn(e);
     72                    }
     73                }
     74                return date;
    6175            }
    6276        } catch (Exception e) {
Note: See TracChangeset for help on using the changeset viewer.