Changeset 7956 in josm for trunk/src/org


Ignore:
Timestamp:
2015-01-11T20:03:18+01:00 (9 years ago)
Author:
bastiK
Message:

fixed #10962 - Photo orientation should not be ignored for thumbnails

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

Legend:

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

    r7912 r7956  
    2727
    2828import org.openstreetmap.josm.Main;
     29import org.openstreetmap.josm.tools.ExifReader;
    2930
    3031public class ImageDisplay extends JComponent {
     
    103104                    final int h = (int) visibleRect.getHeight();
    104105
    105                     outer: {
    106                         final int hh, ww, q;
    107                         final double ax, ay;
    108                         switch (orientation) {
    109                         case 8:
    110                             q = -1;
    111                             ax = w / 2;
    112                             ay = w / 2;
     106                    if (ExifReader.orientationNeedsCorrection(orientation)) {
     107                        final int hh, ww;
     108                        if (ExifReader.orientationSwitchesDimensions(orientation)) {
    113109                            ww = h;
    114110                            hh = w;
    115                             break;
    116                         case 3:
    117                             q = 2;
    118                             ax = w / 2;
    119                             ay = h / 2;
     111                        } else {
    120112                            ww = w;
    121113                            hh = h;
    122                             break;
    123                         case 6:
    124                             q = 1;
    125                             ax = h / 2;
    126                             ay = h / 2;
    127                             ww = h;
    128                             hh = w;
    129                             break;
    130                         default:
    131                             break outer;
    132114                        }
    133 
    134115                        final BufferedImage rot = new BufferedImage(ww, hh, BufferedImage.TYPE_INT_RGB);
    135                         final AffineTransform xform = AffineTransform.getQuadrantRotateInstance(q, ax, ay);
     116                        final AffineTransform xform = ExifReader.getRestoreOrientationTransform(orientation, w, h);
    136117                        final Graphics2D g = rot.createGraphics();
    137118                        g.drawImage(image, xform, null);
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java

    r7935 r7956  
    77import java.awt.Rectangle;
    88import java.awt.Toolkit;
     9import java.awt.geom.AffineTransform;
    910import java.awt.image.BufferedImage;
    1011import java.util.ArrayList;
     
    1314import org.openstreetmap.josm.Main;
    1415import org.openstreetmap.josm.io.CacheFiles;
     16import org.openstreetmap.josm.tools.ExifReader;
    1517
    1618public class ThumbsLoader implements Runnable {
     
    7981            return null;
    8082        }
     83
     84        final int w = img.getWidth(null);
     85        final int h = img.getHeight(null);
     86        final int hh, ww;
     87        if (ExifReader.orientationSwitchesDimensions(entry.getExifOrientation())) {
     88            ww = h;
     89            hh = w;
     90        } else {
     91            ww = w;
     92            hh = h;
     93        }
     94
    8195        Rectangle targetSize = ImageDisplay.calculateDrawImageRectangle(
    82                 new Rectangle(0, 0, img.getWidth(null), img.getHeight(null)),
     96                new Rectangle(0, 0, ww, hh),
    8397                new Rectangle(0, 0, maxSize, maxSize));
    8498        BufferedImage scaledBI = new BufferedImage(targetSize.width, targetSize.height, BufferedImage.TYPE_INT_RGB);
    8599        Graphics2D g = scaledBI.createGraphics();
    86         while (!g.drawImage(img, 0, 0, targetSize.width, targetSize.height, null)) {
     100
     101        final AffineTransform restoreOrientation = ExifReader.getRestoreOrientationTransform(entry.getExifOrientation(), w, h);
     102        final AffineTransform scale = AffineTransform.getScaleInstance((double) targetSize.width / ww, (double) targetSize.height / hh);
     103        scale.concatenate(restoreOrientation);
     104
     105        while (!g.drawImage(img, scale, null)) {
    87106            try {
    88107                Thread.sleep(10);
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CustomProjectionChoice.java

    r7937 r7956  
    188188            s.append(listKeys(Projections.nadgrids)+"<br>");
    189189            s.append("<b>+bounds=</b>minlon,minlat,maxlon,maxlat - <i>"+tr("Projection bounds (in degrees)")+"</i><br>");
    190             s.append("<b>+wmssrs=</b>EPSG:123456 - <i>"+tr("WMS SRS (EPSG code)")+"</i><br>");
     190            s.append("<b>+wmssrs=</b>EPSG:123456 - <i>"+tr("Sets the SRS=... parameter in the WMS request")+"</i><br>");
    191191
    192192            return new HtmlPanel(s.toString());
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r7434 r7956  
    10841084            }
    10851085        }
    1086         return;
    10871086    }
    10881087
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r7864 r7956  
    2121import com.drew.metadata.exif.ExifSubIFDDirectory;
    2222import com.drew.metadata.exif.GpsDirectory;
     23import java.awt.geom.AffineTransform;
    2324
    2425/**
     
    188189        return value;
    189190    }
     191
     192    /**
     193     * Returns a Transform that fixes the image orientation.
     194     *
     195     * Only orientation 1, 3, 6 and 8 are supported. Everything else is treated
     196     * as 1.
     197     * @param orientation the exif-orientation of the image
     198     * @param width the original width of the image
     199     * @param height the original height of the image
     200     * @return a transform that rotates the image, so it is upright
     201     */
     202    public static AffineTransform getRestoreOrientationTransform(final int orientation, final int width, final int height) {
     203        final int q;
     204        final double ax, ay;
     205        switch (orientation) {
     206        case 8:
     207            q = -1;
     208            ax = width / 2;
     209            ay = width / 2;
     210            break;
     211        case 3:
     212            q = 2;
     213            ax = width / 2;
     214            ay = height / 2;
     215            break;
     216        case 6:
     217            q = 1;
     218            ax = height / 2;
     219            ay = height / 2;
     220            break;
     221        default:
     222            q = 0;
     223            ax = 0;
     224            ay = 0;
     225        }
     226        return AffineTransform.getQuadrantRotateInstance(q, ax, ay);
     227    }
     228
     229    /**
     230     * Check, if the given orientation switches width and height of the image.
     231     * E.g. 90 degree rotation
     232     *
     233     * Only orientation 1, 3, 6 and 8 are supported. Everything else is treated
     234     * as 1.
     235     * @param orientation the exif-orientation of the image
     236     * @return true, if it switches width and height
     237     */
     238    public static boolean orientationSwitchesDimensions(int orientation) {
     239        return orientation == 6 || orientation == 8;
     240    }
     241
     242    /**
     243     * Check, if the given orientation requires any correction to the image.
     244     *
     245     * Only orientation 1, 3, 6 and 8 are supported. Everything else is treated
     246     * as 1.
     247     * @param orientation the exif-orientation of the image
     248     * @return true, unless the orientation value is 1 or unsupported.
     249     */
     250    public static boolean orientationNeedsCorrection(int orientation) {
     251        return orientation == 3 || orientation == 6 || orientation == 8;
     252    }
    190253}
Note: See TracChangeset for help on using the changeset viewer.