Ignore:
Timestamp:
2024-06-06T17:48:26+02:00 (4 months ago)
Author:
taylor.smock
Message:

Update photo_geotagging to use apache commons-imaging 1.0.0-alpha5

Also convert license headers to the standard JOSM license headers + SPDX.

Location:
applications/editors/josm/plugins/photo_geotagging
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTagger.java

    r35933 r36275  
    1 // Wrapper class for sanselan library
     1// License: GPL. For details, see LICENSE file.
     2// SPDX-License-Identifier: GPL-2.0-or-later
    23package org.openstreetmap.josm.plugins.photo_geotagging;
    34
     
    1112import java.time.Instant;
    1213import java.util.Calendar;
    13 import java.util.Date;
    1414import java.util.GregorianCalendar;
    1515import java.util.TimeZone;
    1616
    17 import org.apache.commons.imaging.ImageReadException;
    18 import org.apache.commons.imaging.ImageWriteException;
    1917import org.apache.commons.imaging.Imaging;
     18import org.apache.commons.imaging.ImagingException;
    2019import org.apache.commons.imaging.common.ImageMetadata;
    2120import org.apache.commons.imaging.common.RationalNumber;
     
    2827import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
    2928
    30 public class ExifGPSTagger {
     29/**
     30 * Wrapper class for sanselan library
     31 */
     32public final class ExifGPSTagger {
     33    private ExifGPSTagger() {
     34        // Hide constructor
     35    }
     36
    3137    /**
    3238     * Set the GPS values in JPEG EXIF metadata.
     
    4450     * @throws IOException in case of I/O error
    4551     */
    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 {
     52    public static void setExifGPSTag(File imageFile, File dst, double lat, double lon, Instant gpsTime, Double speed,
     53            Double ele, Double imgDir, boolean lossy) throws IOException {
    4754        try {
    4855            setExifGPSTagWorker(imageFile, dst, lat, lon, gpsTime, speed, ele, imgDir, lossy);
    49         } catch (ImageReadException ire) {
    50             throw new IOException(tr("Read error: "+ire), ire);
    51         } catch (ImageWriteException ire2) {
    52             throw new IOException(tr("Write error: "+ire2), ire2);
     56        } catch (ImagingException ire) {
     57            // This used to be two separate exceptions; ImageReadException and imageWriteException
     58            throw new IOException(tr("Read/write error: " + ire.getMessage()), ire);
    5359        }
    5460    }
    5561
    56     public static void setExifGPSTagWorker(File imageFile, File dst, double lat, double lon, Instant gpsTime, Double speed, Double ele, Double imgDir, boolean lossy)
    57             throws IOException, ImageReadException, ImageWriteException {
     62    public static void setExifGPSTagWorker(File imageFile, File dst, double lat, double lon, Instant gpsTime, Double speed,
     63            Double ele, Double imgDir, boolean lossy) throws IOException {
    5864
    5965        TiffOutputSet outputSet = null;
     
    7379        }
    7480
    75         TiffOutputDirectory gpsDirectory = outputSet.getOrCreateGPSDirectory();
     81        TiffOutputDirectory gpsDirectory = outputSet.getOrCreateGpsDirectory();
    7682        gpsDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_VERSION_ID);
    7783        gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_VERSION_ID, (byte)2, (byte)3, (byte)0, (byte)0);
     
    112118        }
    113119
    114         outputSet.setGPSInDegrees(lon, lat);
     120        outputSet.setGpsInDegrees(lon, lat);
    115121
    116122        if (speed != null) {
  • applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingAction.java

    r35933 r36275  
    1 //License: GPL (v2 or later)
     1// License: GPL. For details, see LICENSE file.
     2// SPDX-License-Identifier: GPL-2.0-or-later
    23package org.openstreetmap.josm.plugins.photo_geotagging;
    34
     
    89import java.awt.Component;
    910import java.awt.Dimension;
     11import java.awt.GridBagConstraints;
    1012import java.awt.GridBagLayout;
    1113import java.awt.event.ActionEvent;
     
    1719import java.time.Instant;
    1820import java.util.ArrayList;
    19 import java.util.Date;
    2021import java.util.List;
     22import java.util.Locale;
    2123import java.util.UUID;
    2224
     
    3537import javax.swing.UIManager;
    3638
    37 import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter;
     39import org.apache.commons.imaging.ImagingOverflowException;
    3840import org.apache.commons.io.FilenameUtils;
    3941import org.openstreetmap.josm.gui.ExtendedDialog;
     
    5759class GeotaggingAction extends AbstractAction implements LayerAction {
    5860
    59     final static String KEEP_BACKUP = "plugins.photo_geotagging.keep_backup";
    60     final static String CHANGE_MTIME = "plugins.photo_geotagging.change-mtime";
    61     final static String MTIME_MODE = "plugins.photo_geotagging.mtime-mode";
    62     final static int MTIME_MODE_GPS = 1;
    63     final static int MTIME_MODE_PREVIOUS_VALUE = 2;
     61    static final String KEEP_BACKUP = "plugins.photo_geotagging.keep_backup";
     62    static final String CHANGE_MTIME = "plugins.photo_geotagging.change-mtime";
     63    static final String MTIME_MODE = "plugins.photo_geotagging.mtime-mode";
     64    static final int MTIME_MODE_GPS = 1;
     65    static final int MTIME_MODE_PREVIOUS_VALUE = 2;
    6466
    6567    public GeotaggingAction() {
     
    8890            if (e.getPos() != null && e.hasNewGpsData()) {
    8991                String pth = e.getFile().getAbsolutePath();
    90                 switch (FilenameUtils.getExtension(pth).toLowerCase()) {
     92                switch (FilenameUtils.getExtension(pth).toLowerCase(Locale.ENGLISH)) {
    9193                    case "tif":
    9294                    case "tiff":
     
    113115        JScrollPane scroll = new JScrollPane(entryList);
    114116        scroll.setPreferredSize(new Dimension(900, 250));
    115         cont.add(scroll, GBC.eol().fill(GBC.BOTH));
     117        cont.add(scroll, GBC.eol().fill(GridBagConstraints.BOTH));
    116118
    117119        if (notSupportedFilesCount > 0) {
     
    119121                    ? tr("The file \"{0}\" can not be updated. Only JPEG and TIFF images are supported.", notSupportedName)
    120122                    : trn("{0} file can not be updated. Only JPEG and TIFF images are supported.",
    121                           "{0} files can not be updated. Only JPEG and TIFF images are supported.", notSupportedFilesCount, notSupportedFilesCount));
     123                          "{0} files can not be updated. Only JPEG and TIFF images are supported.",
     124                    notSupportedFilesCount, notSupportedFilesCount));
    122125            warn.setForeground(Color.RED);
    123126            cont.add(warn, GBC.eol());
     
    203206
    204207    static class GeoTaggingRunnable extends PleaseWaitRunnable {
    205         final private List<ImageEntry> images;
    206         final private boolean keep_backup;
    207         final private int mTimeMode;
     208        private final List<ImageEntry> images;
     209        private final boolean keep_backup;
     210        private final int mTimeMode;
    208211
    209212        private boolean canceled = false;
     
    288291                    processEntry(e, lossy);
    289292                } catch (final IOException ioe) {
    290                     ioe.printStackTrace();
     293                    Logging.trace(ioe);
    291294                    restoreFile();
    292                     if (!lossy && ioe.getCause() instanceof ExifRewriter.ExifOverflowException) {
     295                    if (!lossy && ioe.getCause() instanceof ImagingOverflowException) {
    293296                        exifFailedEntries.add(e);
    294297                    } else {
  • applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingPlugin.java

    r35715 r36275  
    1 //License: GPL (v2 or above)
     1// License: GPL. For details, see LICENSE file.
     2// SPDX-License-Identifier: GPL-2.0-or-later
    23package org.openstreetmap.josm.plugins.photo_geotagging;
    34
     
    1112 * It extends the core geoimage feature of JOSM by adding a new entry
    1213 * to the right click menu of any image layer.
    13  *
     14 * <p>
    1415 * The real work (writing lat/lon values to file) is done by the pure Java
    1516 * sanselan library.
Note: See TracChangeset for help on using the changeset viewer.