Changeset 15219 in josm for trunk


Ignore:
Timestamp:
2019-07-07T02:23:14+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #17848 - read and display IPTC metadata from jpeg/tiff images (caption, headline, keywords, object name)

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageEntry.java

    r14624 r15219  
    55import java.io.IOException;
    66import java.util.Date;
     7import java.util.List;
    78import java.util.Objects;
    89import java.util.function.Consumer;
     
    2122import com.drew.metadata.exif.ExifIFD0Directory;
    2223import com.drew.metadata.exif.GpsDirectory;
     24import com.drew.metadata.iptc.IptcDirectory;
    2325import com.drew.metadata.jpeg.JpegDirectory;
    2426
     
    4143    /** Temporary source of GPS time if not correlated with GPX track. */
    4244    private Date exifGpsTime;
     45
     46    private String iptcCaption;
     47    private String iptcHeadline;
     48    private List<String> iptcKeywords;
     49    private String iptcObjectName;
    4350
    4451    /**
     
    333340    public void setExifImgDir(Double exifDir) {
    334341        this.exifImgDir = exifDir;
     342    }
     343
     344    /**
     345     * Sets the IPTC caption.
     346     * @param iptcCaption the IPTC caption
     347     * @since 15219
     348     */
     349    public void setIptcCaption(String iptcCaption) {
     350        this.iptcCaption = iptcCaption;
     351    }
     352
     353    /**
     354     * Sets the IPTC headline.
     355     * @param iptcHeadline the IPTC headline
     356     * @since 15219
     357     */
     358    public void setIptcHeadline(String iptcHeadline) {
     359        this.iptcHeadline = iptcHeadline;
     360    }
     361
     362    /**
     363     * Sets the IPTC keywords.
     364     * @param iptcKeywords the IPTC keywords
     365     * @since 15219
     366     */
     367    public void setIptcKeywords(List<String> iptcKeywords) {
     368        this.iptcKeywords = iptcKeywords;
     369    }
     370
     371    /**
     372     * Sets the IPTC object name.
     373     * @param iptcObjectName the IPTC object name
     374     * @since 15219
     375     */
     376    public void setIptcObjectName(String iptcObjectName) {
     377        this.iptcObjectName = iptcObjectName;
     378    }
     379
     380    /**
     381     * Returns the IPTC caption.
     382     * @return the IPTC caption
     383     * @since 15219
     384     */
     385    public String getIptcCaption() {
     386        return iptcCaption;
     387    }
     388
     389    /**
     390     * Returns the IPTC headline.
     391     * @return the IPTC headline
     392     * @since 15219
     393     */
     394    public String getIptcHeadline() {
     395        return iptcHeadline;
     396    }
     397
     398    /**
     399     * Returns the IPTC keywords.
     400     * @return the IPTC keywords
     401     * @since 15219
     402     */
     403    public List<String> getIptcKeywords() {
     404        return iptcKeywords;
     405    }
     406
     407    /**
     408     * Returns the IPTC object name.
     409     * @return the IPTC object name
     410     * @since 15219
     411     */
     412    public String getIptcObjectName() {
     413        return iptcObjectName;
    335414    }
    336415
     
    556635
    557636        ifNotNull(dirGps.getGpsDate(), this::setExifGpsTime);
     637
     638        IptcDirectory dirIptc = metadata.getFirstDirectoryOfType(IptcDirectory.class);
     639        if (dirIptc != null) {
     640            ifNotNull(ExifReader.readCaption(dirIptc), this::setIptcCaption);
     641            ifNotNull(ExifReader.readHeadline(dirIptc), this::setIptcHeadline);
     642            ifNotNull(ExifReader.readKeywords(dirIptc), this::setIptcKeywords);
     643            ifNotNull(ExifReader.readObjectName(dirIptc), this::setIptcObjectName);
     644        }
    558645    }
    559646
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r14903 r15219  
    1414import java.text.DateFormat;
    1515import java.text.SimpleDateFormat;
     16import java.util.Optional;
    1617
    1718import javax.swing.Box;
     
    473474                osd.append(tr("\nGPS time: {0}", dtf.format(entry.getGpsTime())));
    474475            }
     476            Optional.ofNullable(entry.getIptcCaption()).map(s -> tr("\nCaption: {0}", s)).ifPresent(osd::append);
     477            Optional.ofNullable(entry.getIptcHeadline()).map(s -> tr("\nHeadline: {0}", s)).ifPresent(osd::append);
     478            Optional.ofNullable(entry.getIptcKeywords()).map(s -> tr("\nKeywords: {0}", s)).ifPresent(osd::append);
     479            Optional.ofNullable(entry.getIptcObjectName()).map(s -> tr("\nObject name: {0}", s)).ifPresent(osd::append);
    475480
    476481            imgDisplay.setOsdText(osd.toString());
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r14159 r15219  
    77import java.time.DateTimeException;
    88import java.util.Date;
     9import java.util.List;
    910import java.util.concurrent.TimeUnit;
    1011
     
    2425import com.drew.metadata.exif.ExifSubIFDDirectory;
    2526import com.drew.metadata.exif.GpsDirectory;
     27import com.drew.metadata.iptc.IptcDirectory;
    2628
    2729/**
     
    327329
    328330    /**
     331     * Returns the caption of the given IPTC directory.
     332     * @param dirIptc The IPTC directory
     333     * @return The caption entered, or {@code null} if missing or if {@code dirIptc} is null
     334     * @since 15219
     335     */
     336    public static String readCaption(IptcDirectory dirIptc) {
     337        return dirIptc == null ? null : dirIptc.getDescription(IptcDirectory.TAG_CAPTION);
     338    }
     339
     340    /**
     341     * Returns the headline of the given IPTC directory.
     342     * @param dirIptc The IPTC directory
     343     * @return The headline entered, or {@code null} if missing or if {@code dirIptc} is null
     344     * @since 15219
     345     */
     346    public static String readHeadline(IptcDirectory dirIptc) {
     347        return dirIptc == null ? null : dirIptc.getDescription(IptcDirectory.TAG_HEADLINE);
     348    }
     349
     350    /**
     351     * Returns the keywords of the given IPTC directory.
     352     * @param dirIptc The IPTC directory
     353     * @return The keywords entered, or {@code null} if missing or if {@code dirIptc} is null
     354     * @since 15219
     355     */
     356    public static List<String> readKeywords(IptcDirectory dirIptc) {
     357        return dirIptc == null ? null : dirIptc.getKeywords();
     358    }
     359
     360    /**
     361     * Returns the object name of the given IPTC directory.
     362     * @param dirIptc The IPTC directory
     363     * @return The object name entered, or {@code null} if missing or if {@code dirIptc} is null
     364     * @since 15219
     365     */
     366    public static String readObjectName(IptcDirectory dirIptc) {
     367        return dirIptc == null ? null : dirIptc.getDescription(IptcDirectory.TAG_OBJECT_NAME);
     368    }
     369
     370    /**
    329371     * Returns a Transform that fixes the image orientation.
    330372     *
Note: See TracChangeset for help on using the changeset viewer.