Changeset 35933 in osm for applications/editors
- Timestamp:
- 2022-03-22T19:06:39+01:00 (3 years ago)
- Location:
- applications/editors/josm/plugins/photo_geotagging
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/photo_geotagging/build.xml
r35594 r35933 5 5 <property name="commit.message" value=""/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="1 4153"/>7 <property name="plugin.main.version" value="17715"/> 8 8 9 9 <property name="plugin.author" value="Paul Hartmann"/> -
applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTagger.java
r35738 r35933 9 9 import java.io.IOException; 10 10 import java.text.DecimalFormat; 11 import java.time.Instant; 11 12 import java.util.Calendar; 12 13 import java.util.Date; … … 43 44 * @throws IOException in case of I/O error 44 45 */ 45 public static void setExifGPSTag(File imageFile, File dst, double lat, double lon, DategpsTime, Double speed, Double ele, Double imgDir, boolean lossy) throws IOException {46 public static void setExifGPSTag(File imageFile, File dst, double lat, double lon, Instant gpsTime, Double speed, Double ele, Double imgDir, boolean lossy) throws IOException { 46 47 try { 47 48 setExifGPSTagWorker(imageFile, dst, lat, lon, gpsTime, speed, ele, imgDir, lossy); … … 53 54 } 54 55 55 public static void setExifGPSTagWorker(File imageFile, File dst, double lat, double lon, DategpsTime, Double speed, Double ele, Double imgDir, boolean lossy)56 public static void setExifGPSTagWorker(File imageFile, File dst, double lat, double lon, Instant gpsTime, Double speed, Double ele, Double imgDir, boolean lossy) 56 57 throws IOException, ImageReadException, ImageWriteException { 57 58 … … 78 79 if (gpsTime != null) { 79 80 Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); 80 calendar.setTime (gpsTime);81 calendar.setTimeInMillis(gpsTime.toEpochMilli()); 81 82 82 83 final int year = calendar.get(Calendar.YEAR); -
applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingAction.java
r35783 r35933 15 15 import java.nio.file.NoSuchFileException; 16 16 import java.text.DecimalFormat; 17 import java.time.Instant; 17 18 import java.util.ArrayList; 18 19 import java.util.Date; … … 56 57 class GeotaggingAction extends AbstractAction implements LayerAction { 57 58 58 final static boolean debug = false;59 59 final static String KEEP_BACKUP = "plugins.photo_geotagging.keep_backup"; 60 60 final static String CHANGE_MTIME = "plugins.photo_geotagging.change-mtime"; … … 169 169 int result = new ExtendedDialog( 170 170 MainApplication.getMainFrame(), 171 tr("Photo Geotagging Plugin"), 172 new String[] {tr("OK"), tr("Cancel")}) 173 .setButtonIcons(new String[] {"ok", "cancel"}) 171 tr("Photo Geotagging Plugin"), tr("OK"), tr("Cancel")) 172 .setButtonIcons("ok", "cancel") 174 173 .setContent(cont) 175 174 .setCancelButton(2) … … 285 284 return exifFailedEntries; 286 285 ImageEntry e = entries.get(currentIndex); 287 if (debug) { 288 System.err.print("i:" + currentIndex + " " + e.getFile().getName() + " "); 289 } 286 Logging.trace("photo_geotagging: GeotaggingAction: i: {0} {1} ", currentIndex, e.getFile().getName()); 290 287 try { 291 288 processEntry(e, lossy); … … 336 333 progressMonitor.subTask(tr("Writing position information to image files... Estimated time left: {0}", timeLeft)); 337 334 338 if (debug) { 339 System.err.println("finished " + e.getFile()); 340 } 335 Logging.trace("photo_geotagging: GeotaggingAction: finished {0}", e.getFile()); 341 336 currentIndex++; 342 337 } … … 353 348 } 354 349 355 LongmTime = null;350 Instant mTime = null; 356 351 if (mTimeMode == MTIME_MODE_GPS) { 357 352 // check GPS time fields, do nothing if all fails 358 Date time;359 353 if (e.hasGpsTime()) { 360 time = e.getGpsTime(); 361 } else { 362 time = e.getExifGpsTime(); 363 } 364 if (time != null) { 365 mTime = time.getTime(); 354 mTime = e.getGpsInstant(); 355 } else if (e.hasExifGpsTime()) { 356 mTime = e.getExifGpsInstant(); 366 357 } 367 358 } … … 370 361 // modes failed to determine the modification time 371 362 || (mTimeMode != 0 && mTime == null)) { 372 mTime = e.getFile().lastModified();373 if ( mTime.equals(0L))363 mTime = Instant.ofEpochMilli(e.getFile().lastModified()); 364 if (Instant.EPOCH.equals(mTime)) 374 365 throw new IOException(tr("Could not read mtime.")); 375 366 } … … 378 369 if (canceled) return; 379 370 ExifGPSTagger.setExifGPSTag(fileFrom, fileTo, e.getPos().lat(), e.getPos().lon(), 380 e.getGps Time(), e.getSpeed(), e.getElevation(), e.getExifImgDir(), lossy);371 e.getGpsInstant(), e.getSpeed(), e.getElevation(), e.getExifImgDir(), lossy); 381 372 382 373 if (mTime != null) { 383 if (!fileTo.setLastModified(mTime ))374 if (!fileTo.setLastModified(mTime.toEpochMilli())) 384 375 throw new IOException(tr("Could not write mtime.")); 385 376 } … … 390 381 391 382 private void chooseFiles(File file) throws IOException { 392 if (debug) { 393 System.err.println("f: "+file.getAbsolutePath()); 394 } 383 Logging.trace("photo_geotagging: GeotaggingAction: f: "+file.getAbsolutePath()); 395 384 396 385 if (!keep_backup) { … … 432 421 fileTmp = new File(file.getParentFile(), "img" + UUID.randomUUID() + ".tmp"); 433 422 } while (fileTmp.exists()); 434 if (debug) { 435 System.err.println("TMP: "+fileTmp.getAbsolutePath()); 436 } 423 Logging.trace("photo_geotagging: GeotaggingAction: TMP: {0}", fileTmp.getAbsolutePath()); 437 424 try { 438 425 Files.move(file.toPath(), fileTmp.toPath()); … … 455 442 int override = new ExtendedDialog( 456 443 progressMonitor.getWindowParent(), 457 tr("Override old backup files?"), 458 new String[] {tr("Cancel"), tr("Keep old backups and continue"), tr("Override")})459 .setButtonIcons( new String[] {"cancel", "ok", "dialogs/delete"})444 tr("Override old backup files?"), tr("Cancel"), tr("Keep old backups and continue"), 445 tr("Override")) 446 .setButtonIcons("cancel", "ok", "dialogs/delete") 460 447 .setContent(l) 461 448 .setCancelButton(1) … … 472 459 }); 473 460 } catch (Exception e) { 474 System.err.println(e);461 Logging.error(e); 475 462 canceled = true; 476 463 } -
applications/editors/josm/plugins/photo_geotagging/test/unit/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTaggerTest.java
r35738 r35933 1 1 package org.openstreetmap.josm.plugins.photo_geotagging; 2 2 3 import static org.junit.Assert.assertFalse; 3 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 4 6 5 7 import java.io.ByteArrayOutputStream; 6 8 import java.io.File; 7 import java. util.Date;9 import java.time.Instant; 8 10 import java.util.Scanner; 9 11 … … 13 15 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; 14 16 import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; 15 import org.junit.Ignore; 16 import org.junit.Rule; 17 import org.junit.Test; 18 import org.junit.rules.TemporaryFolder; 17 import org.junit.jupiter.api.Disabled; 18 import org.junit.jupiter.api.Test; 19 import org.junit.jupiter.api.io.TempDir; 19 20 import org.openstreetmap.josm.TestUtils; 20 21 21 publicclass ExifGPSTaggerTest {22 class ExifGPSTaggerTest { 22 23 23 @ Rule24 public final TemporaryFolder tempFolder = new TemporaryFolder();24 @TempDir 25 File tempFolder; 25 26 26 27 @Test 27 public void testTicket11757() throws Exception{28 void testTicket11757() { 28 29 final File in = new File(TestUtils.getTestDataRoot(), "_DSC1234.jpg"); 29 ExifGPSTagger.setExifGPSTag(in, tempFolder.newFile(), 12, 34, new Date(), 12.34, Math.E, Math.PI, true); 30 final File out = new File(tempFolder, in.getName()); 31 assertDoesNotThrow(() -> ExifGPSTagger.setExifGPSTag(in, out, 12, 34, Instant.now(), 12.34, Math.E, Math.PI, true)); 30 32 } 31 33 32 34 @Test 33 publicvoid testTicket11757WriteWithoutChange() throws Exception {35 void testTicket11757WriteWithoutChange() throws Exception { 34 36 final File in = new File(TestUtils.getTestDataRoot(), "_DSC1234.jpg"); 37 final long lastModified = in.lastModified(); 35 38 final TiffImageMetadata exif = ((JpegImageMetadata) Imaging.getMetadata(in)).getExif(); 36 39 final TiffOutputSet outputSet = exif.getOutputSet(); 37 40 new ExifRewriter().updateExifMetadataLossless(in, new ByteArrayOutputStream(), outputSet); 41 assertEquals(lastModified, in.lastModified()); 38 42 } 39 43 40 44 @Test 41 @ Ignore("To enable after https://josm.openstreetmap.de/ticket/11902 is fixed")42 publicvoid testTicket11902() throws Exception {45 @Disabled("To enable after https://josm.openstreetmap.de/ticket/11902 is fixed") 46 void testTicket11902() throws Exception { 43 47 final File in = new File(TestUtils.getTestDataRoot(), "IMG_7250_small.JPG"); 44 final File out = tempFolder.newFile();45 ExifGPSTagger.setExifGPSTag(in, out, 12, 34, new Date(), 12.34, Math.E, Math.PI, false);48 final File out = new File(tempFolder, in.getName()); 49 ExifGPSTagger.setExifGPSTag(in, out, 12, 34, Instant.now(), 12.34, Math.E, Math.PI, false); 46 50 final Process jhead = Runtime.getRuntime().exec(new String[]{"jhead", out.getAbsolutePath()}); 47 51 final String stdout = new Scanner(jhead.getErrorStream()).useDelimiter("\\A").next(); -
applications/editors/josm/plugins/photo_geotagging/test/unit/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingActionTest.java
r35777 r35933 1 1 package org.openstreetmap.josm.plugins.photo_geotagging; 2 2 3 import static org.junit.Assert.assertEquals;4 import static org.junit.Assert.assertTrue;5 3 6 4 import java.io.File; … … 11 9 import java.util.List; 12 10 13 import org.junit. Test;11 import org.junit.jupiter.api.Test; 14 12 import org.openstreetmap.josm.TestUtils; 15 13 import org.openstreetmap.josm.data.coor.LatLon; … … 17 15 import org.openstreetmap.josm.plugins.photo_geotagging.GeotaggingAction.GeoTaggingRunnable; 18 16 19 public class GeotaggingActionTest { 17 import static org.junit.jupiter.api.Assertions.assertEquals; 18 import static org.junit.jupiter.api.Assertions.assertTrue; 19 20 class GeotaggingActionTest { 20 21 21 22 @Test 22 publicvoid testProcessEntries() throws IOException {23 void testProcessEntries() throws IOException { 23 24 File original = new File(TestUtils.getTestDataRoot(), "_DSC1234.jpg"); 24 25 assertTrue(original.exists());
Note:
See TracChangeset
for help on using the changeset viewer.