Changeset 36466 in osm for applications
- Timestamp:
- 2026-01-05T14:20:42+01:00 (13 days ago)
- Location:
- applications/editors/josm/plugins/photo_geotagging
- Files:
-
- 6 edited
-
data/el.lang (modified) ( previous)
-
data/zh_CN.lang (modified) ( previous)
-
src/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTagger.java (modified) (4 diffs)
-
src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingAction.java (modified) (9 diffs)
-
test/unit/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTaggerTest.java (modified) (7 diffs)
-
test/unit/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingActionTest.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTagger.java
r36436 r36466 42 42 * @param dst The output file. 43 43 * @param imageEntry the image object from Josm core 44 * @param writeGpsTime write the EXIF tags GPSDateStamp and GPSTimeStamp 44 45 * @param lossy whether to use lossy approach when writing metadata (overwriting unknown tags) 45 46 * @throws IOException in case of I/O error 46 47 * @since 36436 separate image parameters (lat, lon, gpsTime, speed, ele, imgDir), replaced by the whole ImageEntry object. 48 * @since xxx added writeGpsTime parameter 47 49 */ 48 50 49 51 public static void setExifGPSTag(File imageFile, File dst, ImageEntry imageEntry, 50 boolean lossy) throws IOException { 52 boolean writeGpsTime, boolean lossy) throws IOException { 51 53 try { 52 setExifGPSTagWorker(imageFile, dst, imageEntry, lossy); 54 setExifGPSTagWorker(imageFile, dst, imageEntry, writeGpsTime, lossy); 53 55 } catch (ImagingException ire) { 54 56 // This used to be two separate exceptions; ImageReadException and imageWriteException … … 58 60 59 61 public static void setExifGPSTagWorker(File imageFile, File dst, ImageEntry imageEntry, 60 boolean lossy) throws IOException { 62 boolean writeGpsTime, boolean lossy) throws IOException { 61 63 62 64 TiffOutputSet outputSet = null; … … 80 82 gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_VERSION_ID, (byte) 2, (byte) 3, (byte) 0, (byte) 0); 81 83 82 if (imageEntry.getGpsInstant() != null) { 84 if (writeGpsTime && imageEntry.getGpsInstant() != null) { 83 85 Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); 84 86 calendar.setTimeInMillis(imageEntry.getGpsInstant().toEpochMilli()); … … 202 204 /** 203 205 * Normalizes an angle to the range [0.0, 360.0[ degrees. 204 * This will fix any angle value <0 and >= 360206 * This will fix any angle value < 0 and >= 360 205 207 * @param angle the angle to normalize (in degrees) 206 208 * @return the equivalent angle value in the range [0.0, 360.0[ -
applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingAction.java
r36436 r36466 56 56 /** 57 57 * The action to ask the user for confirmation and then do the tagging. 58 * @since xxx added checkbox option to write GPS date and time 58 59 */ 59 60 class GeotaggingAction extends AbstractAction implements LayerAction { … … 137 138 cont.add(settingsPanel, GBC.eol().insets(3, 10, 3, 0)); 138 139 139 final JCheckBox backups = new JCheckBox(tr("keep backup files"), Config.getPref().getBoolean(KEEP_BACKUP, true)); 140 settingsPanel.add(backups, GBC.eol().insets(3, 3, 0, 0)); 141 142 final JCheckBox setMTime = new JCheckBox(tr("change file modification time:"), Config.getPref().getBoolean(CHANGE_MTIME, false)); 143 settingsPanel.add(setMTime, GBC.std().insets(3, 3, 5, 3)); 144 145 final String[] mTimeModeArray = {"----", tr("to gps time"), tr("to previous value (unchanged mtime)")}; 140 final JCheckBox cbWriteGpsTime = new JCheckBox(tr("Write EXIF GPS date and time"), false); 141 settingsPanel.add(cbWriteGpsTime, GBC.eol().insets(3, 3, 0, 0)); 142 143 final JCheckBox cbBackups = new JCheckBox(tr("Keep backup files"), Config.getPref().getBoolean(KEEP_BACKUP, true)); 144 settingsPanel.add(cbBackups, GBC.eol().insets(3, 3, 0, 0)); 145 146 final JCheckBox cbSetMTime = new JCheckBox(tr("Change file modification time:"), Config.getPref().getBoolean(CHANGE_MTIME, false)); 147 settingsPanel.add(cbSetMTime, GBC.std().insets(3, 3, 5, 3)); 148 149 final String[] mTimeModeArray = {"----", tr("to GPS time"), tr("to previous value (unchanged mtime)")}; 146 150 final JComboBox<String> mTimeMode = new JComboBox<>(mTimeModeArray); 147 151 … … 153 157 mTimeIdx = 2; 154 158 } 155 mTimeMode.setSelectedIndex( setMTime.isSelected() ? mTimeIdx : 0);159 mTimeMode.setSelectedIndex(cbSetMTime.isSelected() ? mTimeIdx : 0); 156 160 157 161 settingsPanel.add(mTimeMode, GBC.eol().insets(3, 3, 3, 3)); 158 162 159 setMTime.addActionListener(e -> {160 if ( setMTime.isSelected()) {163 cbSetMTime.addActionListener(e -> { 164 if (cbSetMTime.isSelected()) { 161 165 mTimeMode.setEnabled(true); 162 166 } else { … … 167 171 168 172 // Toggle the checkbox to fire actionListener 169 setMTime.setSelected(!setMTime.isSelected());170 setMTime.doClick();173 cbSetMTime.setSelected(!cbSetMTime.isSelected()); 174 cbSetMTime.doClick(); 171 175 172 176 int result = new ExtendedDialog( … … 183 187 return; 184 188 185 final boolean keep_backup = backups.isSelected(); 186 final boolean change_mtime = setMTime.isSelected(); 189 final boolean write_gpstime = cbWriteGpsTime.isSelected(); 190 final boolean keep_backup = cbBackups.isSelected(); 191 final boolean change_mtime = cbSetMTime.isSelected(); 187 192 Config.getPref().putBoolean(KEEP_BACKUP, keep_backup); 188 193 Config.getPref().putBoolean(CHANGE_MTIME, change_mtime); … … 202 207 } 203 208 204 MainApplication.worker.execute(new GeoTaggingRunnable(images, keep_backup, mTimeMode.getSelectedIndex())); 209 MainApplication.worker.execute(new GeoTaggingRunnable(images, write_gpstime, keep_backup, mTimeMode.getSelectedIndex())); 205 210 } 206 211 207 212 static class GeoTaggingRunnable extends PleaseWaitRunnable { 208 213 private final List<ImageEntry> images; 214 private final boolean write_gpstime; 209 215 private final boolean keep_backup; 210 216 private final int mTimeMode; … … 219 225 private int currentIndex; 220 226 221 GeoTaggingRunnable(List<ImageEntry> images, boolean keep_backup, int mTimeMode) { 227 GeoTaggingRunnable(List<ImageEntry> images, boolean write_gpstime, boolean keep_backup, int mTimeMode) { 222 228 super(tr("Photo Geotagging Plugin")); 223 229 this.images = images; 230 this.write_gpstime = write_gpstime; 224 231 this.keep_backup = keep_backup; 225 232 this.mTimeMode = mTimeMode; … … 371 378 chooseFiles(e.getFile()); 372 379 if (canceled) return; 373 ExifGPSTagger.setExifGPSTag(fileFrom, fileTo, e, lossy); 380 ExifGPSTagger.setExifGPSTag(fileFrom, fileTo, e, write_gpstime, lossy); 374 381 375 382 if (mTime != null) { … … 538 545 } 539 546 } 540 -
applications/editors/josm/plugins/photo_geotagging/test/unit/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTaggerTest.java
r36450 r36466 3 3 package org.openstreetmap.josm.plugins.photo_geotagging; 4 4 5 import static org.junit.Assert.assertThrows; 5 6 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 6 7 import static org.junit.jupiter.api.Assertions.assertEquals; … … 23 24 import org.openstreetmap.josm.gui.layer.geoimage.ImageEntry; 24 25 import org.openstreetmap.josm.tools.ExifReader; 26 import org.openstreetmap.josm.tools.date.DateUtils; 25 27 26 28 class ExifGPSTaggerTest { … … 45 47 final File out = new File(tempFolder, in.getName()); 46 48 final ImageEntry image = newImageEntry("test", 12d, 34d, Instant.now(), 12.34d, Math.E, Math.PI); 47 assertDoesNotThrow(() -> ExifGPSTagger.setExifGPSTag(in, out, image, true)); 49 assertDoesNotThrow(() -> ExifGPSTagger.setExifGPSTag(in, out, image, true, true)); 48 50 } 49 51 … … 63 65 final File out = new File(tempFolder, in.getName()); 64 66 final ImageEntry image = newImageEntry("test", 12d, 34d, Instant.now(), 12.34d, Math.E, Math.PI); 65 ExifGPSTagger.setExifGPSTag(in, out, image, true); 67 ExifGPSTagger.setExifGPSTag(in, out, image, true, true); 66 68 try { 67 69 final Process jhead = Runtime.getRuntime().exec(new String[]{"jhead", out.getAbsolutePath()}); … … 74 76 75 77 @Test 76 public void testTicket24278() throws Exception{ 78 public void testTicket24278() throws Exception { 77 79 final File in = new File(TestUtils.getTestDataRoot(), "_DSC1234.jpg"); 78 80 final File out = new File(tempFolder, in.getName()); … … 85 87 image.setExifGpsDop(2.5d); 86 88 image.setExifGpsDatum("WGS84"); 87 ExifGPSTagger.setExifGPSTag(in, out, image, true); 89 ExifGPSTagger.setExifGPSTag(in, out, image, true, true); 88 90 assertEquals(Math.PI, ExifReader.readDirection(out), 0.001); 89 91 assertEquals(97.99, ExifReader.readGpsTrackDirection(out)); … … 95 97 assertEquals("WGS84", ExifReader.readGpsDatum(out)); 96 98 } 99 100 @Test 101 public void testTicket24458() throws Exception { 102 final File in = new File(TestUtils.getTestDataRoot(), "_DSC1234.jpg"); 103 final File out = new File(tempFolder, in.getName()); 104 final ImageEntry image = newImageEntry("test", 12d, 34d, Instant.now(), 12.34d, Math.E, Math.PI); 105 image.setGpsTime(DateUtils.parseInstant("2025:10:26 12:00:00")); 106 // Test writing EXIF GPSDateStamp and GPSTimeStamp 107 ExifGPSTagger.setExifGPSTag(in, out, image, true, true); 108 assertEquals(DateUtils.parseInstant("2025:10:26 12:00:00"), ExifReader.readGpsInstant(out)); 109 // Test not writing GPSDateStamp and GPSTimeStamp 110 ExifGPSTagger.setExifGPSTag(in, out, image, false, true); 111 assertThrows(NullPointerException.class, () -> ExifReader.readGpsInstant(out)); 112 } 97 113 } -
applications/editors/josm/plugins/photo_geotagging/test/unit/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingActionTest.java
r36436 r36466 35 35 List<ImageEntry> list = Arrays.asList(entry); 36 36 37 GeoTaggingRunnable runnable = new GeotaggingAction.GeoTaggingRunnable(list, true, 0); 37 GeoTaggingRunnable runnable = new GeotaggingAction.GeoTaggingRunnable(list, true, true, 0); 38 38 //this causes some warnings from the PleaseWaitRunnable because not all resources are available 39 39 //but that's irrelevant to the test … … 45 45 assertEquals(0, runnable.processEntries(list, true).size()); 46 46 47 runnable = new GeotaggingAction.GeoTaggingRunnable(list, false, 0); 47 runnable = new GeotaggingAction.GeoTaggingRunnable(list, true, false, 0); 48 48 runnable.getProgressMonitor().beginTask("test"); 49 49 //file is now "repaired" from operation above and lossless writing should work:
Note:
See TracChangeset
for help on using the changeset viewer.
