Ignore:
Timestamp:
2017-12-18T00:46:58+01:00 (8 years ago)
Author:
Don-vip
Message:

see #15574:

  • additionally refactors ImageDisplay to use ImageEntry instead; stores width and height info while metadata of images are read; might break plugin code (patch by cmuelle8, minor changes)
  • remove double semicolon causing https://github.com/pmd/pmd/issues/785
  • enable PMD rule DoNotCallGarbageCollectionExplicitly
  • disable SpotBugs rule ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java

    r13060 r13220  
    2121import com.drew.metadata.exif.ExifIFD0Directory;
    2222import com.drew.metadata.exif.GpsDirectory;
     23import com.drew.metadata.jpeg.JpegDirectory;
    2324
    2425/**
     
    5354    private Date gpsTime;
    5455
     56    private int width;
     57    private int height;
     58
    5559    /**
    5660     * When the correlation dialog is open, we like to show the image position
     
    7781
    7882    /**
     83     * Returns width of the image this ImageEntry represents.
     84     * @return width of the image this ImageEntry represents
     85     * @since 13220
     86     */
     87    public int getWidth() {
     88        return width;
     89    }
     90
     91    /**
     92     * Returns height of the image this ImageEntry represents.
     93     * @return height of the image this ImageEntry represents
     94     * @since 13220
     95     */
     96    public int getHeight() {
     97        return height;
     98    }
     99
     100    /**
    79101     * Returns the position value. The position value from the temporary copy
    80102     * is returned if that copy exists.
     
    142164     */
    143165    public Integer getExifOrientation() {
    144         return exifOrientation;
     166        return exifOrientation != null ? exifOrientation : 1;
    145167    }
    146168
     
    228250            new ThumbsLoader(Collections.singleton(this)).run();
    229251        }
     252    }
     253
     254    /**
     255     * Sets the width of this ImageEntry.
     256     * @param width set the width of this ImageEntry
     257     * @since 13220
     258     */
     259    public void setWidth(int width) {
     260        this.width = width;
     261    }
     262
     263    /**
     264     * Sets the height of this ImageEntry.
     265     * @param height set the height of this ImageEntry
     266     * @since 13220
     267     */
     268    public void setHeight(int height) {
     269        this.height = height;
    230270    }
    231271
     
    457497        }
    458498
     499        final Directory dir = metadata.getFirstDirectoryOfType(JpegDirectory.class);
    459500        final Directory dirExif = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
    460501        final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     
    464505                int orientation = dirExif.getInt(ExifIFD0Directory.TAG_ORIENTATION);
    465506                setExifOrientation(orientation);
     507            }
     508        } catch (MetadataException ex) {
     509            Logging.debug(ex);
     510        }
     511
     512        try {
     513            if (dir != null) {
     514                // there are cases where these do not match width and height stored in dirExif
     515                int width = dir.getInt(JpegDirectory.TAG_IMAGE_WIDTH);
     516                int height = dir.getInt(JpegDirectory.TAG_IMAGE_HEIGHT);
     517                setWidth(width);
     518                setHeight(height);
    466519            }
    467520        } catch (MetadataException ex) {
Note: See TracChangeset for help on using the changeset viewer.