Changeset 11514 in josm for trunk


Ignore:
Timestamp:
2017-01-30T23:21:38+01:00 (8 years ago)
Author:
Don-vip
Message:

fix #14209 - EXIF: prefer DATETIME over DATETIME_DIGITIZED

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r11484 r11514  
    4444            Metadata metadata = JpegMetadataReader.readMetadata(filename);
    4545            String dateStr = null;
     46            String dateTime = null;
    4647            String subSeconds = null;
    4748            for (Directory dirIt : metadata.getDirectories()) {
     
    5253                    if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL /* 0x9003 */ &&
    5354                            !tag.getDescription().matches("\\[[0-9]+ .+\\]")) {
     55                        // prefer DATETIME_ORIGINAL
    5456                        dateStr = tag.getDescription();
    5557                    }
    56                     if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */ ||
    57                         tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) {
    58                         if (dateStr == null) {
    59                             // prefer TAG_DATETIME_ORIGINAL
    60                             dateStr = tag.getDescription();
    61                         }
     58                    if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */) {
     59                        // prefer DATETIME over DATETIME_DIGITIZED
     60                        dateTime = tag.getDescription();
     61                    }
     62                    if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */ && dateTime == null) {
     63                        dateTime = tag.getDescription();
    6264                    }
    6365                    if (tag.getTagType() == ExifIFD0Directory.TAG_SUBSECOND_TIME_ORIGINAL) {
     
    6567                    }
    6668                }
     69            }
     70            if (dateStr == null) {
     71                dateStr = dateTime;
    6772            }
    6873            if (dateStr != null) {
  • trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java

    r11484 r11514  
    2424
    2525import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     26
    2627/**
    2728 * EXIF metadata extraction test
     
    7071    public void testReadTimeSubSecond1() throws ParseException {
    7172        Date date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg"));
    72         String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date);
    73         assertEquals("2015-07-11T19:34:19.100", dateStr);
     73        doTest("2015-07-11T19:34:19.100", date);
    7474
    7575        TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    7676        date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg"));
    7777        TimeZone.setDefault(DateUtils.UTC);
    78         dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date);
    79         assertEquals("2015-07-11T17:34:19.100", dateStr);
     78        doTest("2015-07-11T17:34:19.100", date);
     79    }
     80
     81    private static void doTest(String expectedDate, Date parsedDate) {
     82        assertEquals(expectedDate, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(parsedDate));
     83    }
     84
     85    private static void doTestFile(String expectedDate, int ticket, String filename) {
     86        doTest(expectedDate, ExifReader.readTime(new File(TestUtils.getRegressionDataFile(ticket, filename))));
    8087    }
    8188
     
    115122    @Test
    116123    public void testTicket11685() throws IOException {
    117         File file = new File(TestUtils.getRegressionDataFile(11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg"));
    118         String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(ExifReader.readTime(file));
    119         assertEquals("2015-11-08T15:33:27.500", dateStr);
     124        doTestFile("2015-11-08T15:33:27.500", 11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg");
    120125    }
    121126
     
    126131    @Test
    127132    public void testTicket14209() throws IOException {
    128         File file = new File(TestUtils.getRegressionDataFile(14209, "0MbEfj1S--.1.jpg"));
    129         String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(ExifReader.readTime(file));
    130         assertEquals("2017-01-16T18:27:00.000", dateStr);
     133        doTestFile("2017-01-16T18:27:00.000", 14209, "0MbEfj1S--.1.jpg");
     134        doTestFile("2016-08-13T19:51:13.000", 14209, "7VWFOryj--.1.jpg");
    131135    }
    132136}
Note: See TracChangeset for help on using the changeset viewer.