Changeset 17144 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-10-10T18:41:23+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java
r16252 r17144 190 190 img = noIcon == null ? null : noIcon.getImage(); 191 191 } else { 192 img = rescale(result.getImageIcon(new Dimension(width, height)).getImage()); 192 img = result.getImageIcon(new Dimension(width, height)).getImage(); 193 if (img != null && mustRescale(img)) { 194 // Scale down large images to 16x16 pixels if no size is explicitly specified 195 img = result.getImageIconBounded(ImageProvider.ImageSizes.MAP.getImageDimension()).getImage(); 196 } 193 197 } 194 198 if (temporary) { … … 301 305 } 302 306 303 /**304 * Rescale excessively large images.305 * @param image the unscaled image306 * @return The scaled down version to 16x16 pixels if the image height and width exceeds 48 pixels and no size has been explicitly specified307 */308 private Image rescale(Image image) {309 if (image == null) return null;310 // Scale down large (.svg) images to 16x16 pixels if no size is explicitly specified311 if (mustRescale(image)) {312 return ImageProvider.createBoundedImage(image, 16);313 } else {314 return image;315 }316 }317 318 307 private boolean mustRescale(Image image) { 319 308 return autoRescale && width == -1 && image.getWidth(null) > MAX_SIZE -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r16998 r17144 661 661 } 662 662 if (virtualMaxWidth != -1 || virtualMaxHeight != -1) 663 return ir.getImageIcon(new Dimension(virtualMaxWidth, virtualMaxHeight), multiResolution, ImageResizeMode.BOUNDED);663 return ir.getImageIcon(new Dimension(virtualMaxWidth, virtualMaxHeight), multiResolution, null); 664 664 else 665 665 return ir.getImageIcon(new Dimension(virtualWidth, virtualHeight), multiResolution, ImageResizeMode.AUTO); … … 1489 1489 Logging.error("createImageFromSvg: {0} {1} sourceWidth={2} sourceHeight={3}", svg.getXMLBase(), dim, sourceWidth, sourceHeight); 1490 1490 return null; 1491 }1492 if (resizeMode == ImageResizeMode.BOUNDED) {1493 resizeMode = ImageResizeMode.BOUNDED_UPSCALE;1494 1491 } 1495 1492 return resizeMode.createBufferedImage(dim, new Dimension((int) sourceWidth, (int) sourceHeight), g -> { -
trunk/src/org/openstreetmap/josm/tools/ImageResizeMode.java
r17074 r17144 14 14 enum ImageResizeMode { 15 15 16 /** 17 * Calculate proportional dimensions that best fit into the target width and height, retain aspect ratio 18 */ 16 19 AUTO { 17 20 @Override … … 25 28 } else if (dim.height == -1) { 26 29 return new Dimension(dim.width, Math.max(1, icon.height * dim.width / icon.width)); 30 } else if (icon.getWidth() / dim.getWidth() > icon.getHeight() / dim.getHeight()) { 31 return computeDimension(new Dimension(dim.width, -1), icon); 27 32 } else { 28 return dim;33 return computeDimension(new Dimension(-1, dim.height), icon); 29 34 } 30 35 } 31 36 }, 32 37 38 /** 39 * Calculate dimensions for the largest image that fit within the bounding box, retain aspect ratio 40 */ 33 41 BOUNDED { 34 @Override35 Dimension computeDimension(Dimension dim, Dimension icon) {36 final int maxWidth = Math.min(dim.width, icon.width);37 final int maxHeight = Math.min(dim.height, icon.height);38 return BOUNDED_UPSCALE.computeDimension(new Dimension(maxWidth, maxHeight), icon);39 }40 },41 42 BOUNDED_UPSCALE {43 42 @Override 44 43 Dimension computeDimension(Dimension dim, Dimension icon) { 45 44 CheckParameterUtil.ensureThat((dim.width > 0 || dim.width == -1) && (dim.height > 0 || dim.height == -1), 46 45 () -> dim + " is invalid"); 47 final int maxWidth = dim.width; 48 final int maxHeight = dim.height; 49 final Dimension spec; 50 if (maxWidth == -1 || maxHeight == -1) { 51 spec = dim; 52 } else if (icon.getWidth() / maxWidth > icon.getHeight() / maxHeight) { 53 spec = new Dimension(maxWidth, -1); 54 } else { 55 spec = new Dimension(-1, maxHeight); 56 } 57 return AUTO.computeDimension(spec, icon); 46 final int maxWidth = Math.min(dim.width, icon.width); 47 final int maxHeight = Math.min(dim.height, icon.height); 48 return AUTO.computeDimension(new Dimension(maxWidth, maxHeight), icon); 58 49 } 59 50 }, 60 51 52 /** 53 * Position an appropriately scaled image within the bounding box, retain aspect ratio 54 */ 61 55 PADDED { 62 56 @Override -
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r16998 r17144 102 102 public void attachImageIcon(AbstractAction a) { 103 103 Dimension iconDimension = ImageProvider.ImageSizes.SMALLICON.getImageDimension(); 104 ImageIcon icon = getImageIcon Bounded(iconDimension);104 ImageIcon icon = getImageIcon(iconDimension); 105 105 a.putValue(Action.SMALL_ICON, icon); 106 106 107 107 iconDimension = ImageProvider.ImageSizes.LARGEICON.getImageDimension(); 108 icon = getImageIcon Bounded(iconDimension);108 icon = getImageIcon(iconDimension); 109 109 a.putValue(Action.LARGE_ICON_KEY, icon); 110 110 } … … 141 141 */ 142 142 public ImageIcon getImageIcon(Dimension dim) { 143 return getImageIcon(dim, true, ImageResizeMode.AUTO);143 return getImageIcon(dim, true, null); 144 144 } 145 145 … … 175 175 () -> dim + " is invalid"); 176 176 177 if (resizeMode == null && svg != null) { 178 // upscale SVG icons 179 resizeMode = ImageResizeMode.AUTO; 180 } else if (resizeMode == null) { 181 resizeMode = ImageResizeMode.BOUNDED; 182 } 177 183 final int cacheKey = resizeMode.cacheKey(dim); 178 184 BufferedImage img = imgCache.get(cacheKey);
Note:
See TracChangeset
for help on using the changeset viewer.