Changeset 17872 in josm for trunk/src/org
- Timestamp:
- 2021-05-06T21:47:02+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/layer/geoimage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
r17871 r17872 18 18 import java.awt.event.MouseWheelEvent; 19 19 import java.awt.event.MouseWheelListener; 20 import java.awt.geom.AffineTransform;21 20 import java.awt.geom.Rectangle2D; 22 21 import java.awt.image.BufferedImage; … … 37 36 import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener; 38 37 import org.openstreetmap.josm.tools.Destroyable; 39 import org.openstreetmap.josm.tools.ExifReader;40 38 import org.openstreetmap.josm.tools.ImageProcessor; 41 39 import org.openstreetmap.josm.tools.Logging; … … 251 249 } 252 250 253 boolean switchedDim = false;254 if (ExifReader.orientationNeedsCorrection(entry.getExifOrientation())) {255 if (ExifReader.orientationSwitchesDimensions(entry.getExifOrientation())) {256 width = img.getHeight(null);257 height = img.getWidth(null);258 switchedDim = true;259 }260 final BufferedImage rot = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);261 final AffineTransform xform = ExifReader.getRestoreOrientationTransform(262 entry.getExifOrientation(),263 img.getWidth(null),264 img.getHeight(null));265 final Graphics2D g = rot.createGraphics();266 g.drawImage(img, xform, null);267 g.dispose();268 img = rot;269 }270 271 251 ImageDisplay.this.image = img; 272 252 updateProcessedImage(); … … 274 254 ImageDisplay.this.oldEntry = ImageDisplay.this.entry; 275 255 visibleRect = new VisRect(0, 0, width, height); 276 277 Logging.debug("Loaded {0} with dimensions {1}x{2} memoryTaken={3}m exifOrientationSwitchedDimension={4}",278 entry.getFile().getPath(), width, height, width * height * 4 / 1024 / 1024, switchedDim);279 256 280 257 selectedRect = null; -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java
r17871 r17872 3 3 4 4 import java.awt.Dimension; 5 import java.awt.Graphics2D; 5 6 import java.awt.Image; 7 import java.awt.geom.AffineTransform; 6 8 import java.awt.image.BufferedImage; 7 9 import java.io.File; … … 13 15 import org.openstreetmap.josm.data.ImageData; 14 16 import org.openstreetmap.josm.data.gpx.GpxImageEntry; 17 import org.openstreetmap.josm.tools.ExifReader; 15 18 import org.openstreetmap.josm.tools.ImageProvider; 16 19 import org.openstreetmap.josm.tools.Logging; … … 139 142 public BufferedImage read(Dimension target) throws IOException { 140 143 Logging.info(tr("Loading {0}", getFile().getPath())); 141 returnImageProvider.read(getFile(), false, false,144 BufferedImage image = ImageProvider.read(getFile(), false, false, 142 145 r -> target == null ? r.getDefaultReadParam() : withSubsampling(r, target)); 146 Logging.debug("Loaded {0} with dimensions {1}x{2} memoryTaken={3}m exifOrientationSwitchedDimension={4}", 147 getFile().getPath(), image.getWidth(), image.getHeight(), image.getWidth() * image.getHeight() * 4 / 1024 / 1024, 148 ExifReader.orientationSwitchesDimensions(getExifOrientation())); 149 return applyExifRotation(image); 143 150 } 144 151 … … 158 165 } 159 166 } 167 168 private BufferedImage applyExifRotation(BufferedImage img) { 169 Integer exifOrientation = getExifOrientation(); 170 if (!ExifReader.orientationNeedsCorrection(exifOrientation)) { 171 return img; 172 } 173 boolean switchesDimensions = ExifReader.orientationSwitchesDimensions(exifOrientation); 174 int width = switchesDimensions ? img.getHeight() : img.getWidth(); 175 int height = switchesDimensions ? img.getWidth() : img.getHeight(); 176 BufferedImage rotated = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 177 AffineTransform transform = ExifReader.getRestoreOrientationTransform(exifOrientation, img.getWidth(), img.getHeight()); 178 Graphics2D g = rotated.createGraphics(); 179 g.drawImage(img, transform, null); 180 g.dispose(); 181 return rotated; 182 } 160 183 }
Note:
See TracChangeset
for help on using the changeset viewer.