Changeset 9499 in josm


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

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

Location:
trunk
Files:
2 added
2 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) {
  • trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java

    r9394 r9499  
    88import java.text.DecimalFormat;
    99import java.text.ParseException;
     10import java.text.SimpleDateFormat;
    1011import java.util.Calendar;
    1112import java.util.Date;
     
    4748
    4849    /**
     50     * Tests reading sub-seconds from the EXIF header
     51     * @throws ParseException  if {@link ExifReader#readTime} fails to parse date/time of sample file
     52     */
     53    @Test
     54    public void testReadTimeSubSecond1() throws ParseException {
     55        Date date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg"));
     56        String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date);
     57        assertEquals("2015-07-11T19:34:19.100", dateStr);
     58    }
     59
     60    /**
    4961     * Test orientation extraction
    5062     */
Note: See TracChangeset for help on using the changeset viewer.