Changeset 16998 in josm for trunk


Ignore:
Timestamp:
2020-09-02T19:58:39+02:00 (4 years ago)
Author:
simon04
Message:

see #19706, see #19725 - ImageProvider: improve resize quality for raster images

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r16997 r16998  
    15011501                Logging.log(Logging.LEVEL_ERROR, "Unable to load svg:", ex);
    15021502            }
    1503         });
     1503        }, null);
    15041504    }
    15051505
  • trunk/src/org/openstreetmap/josm/tools/ImageResizeMode.java

    r16997 r16998  
    44import java.awt.Dimension;
    55import java.awt.Graphics2D;
     6import java.awt.Image;
    67import java.awt.RenderingHints;
    78import java.awt.image.BufferedImage;
     
    8788     * @param icon the dimensions of the image to resize
    8889     * @param renderer the rendering function
     90     * @param sourceIcon the source icon to draw
    8991     * @return a new buffered image
    9092     */
    91     BufferedImage createBufferedImage(Dimension dim, Dimension icon, Consumer<Graphics2D> renderer) {
     93    BufferedImage createBufferedImage(Dimension dim, Dimension icon, Consumer<Graphics2D> renderer, Image sourceIcon) {
    9294        final Dimension real = computeDimension(dim, icon);
    9395        final BufferedImage bufferedImage = new BufferedImage(real.width, real.height, BufferedImage.TYPE_INT_ARGB);
    9496        final Graphics2D g = bufferedImage.createGraphics();
    9597        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    96         prepareGraphics(icon, bufferedImage, g);
    97         renderer.accept(g);
     98        if (renderer != null) {
     99            prepareGraphics(icon, bufferedImage, g);
     100            renderer.accept(g);
     101        } else if (sourceIcon != null) {
     102            sourceIcon = sourceIcon.getScaledInstance(real.width, real.height, Image.SCALE_SMOOTH);
     103            g.drawImage(sourceIcon, 0, 0, null);
     104        } else {
     105            throw new NullPointerException("renderer or sourceIcon");
     106        }
    98107        return bufferedImage;
    99108    }
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r16946 r16998  
    187187                ImageIcon icon = new ImageIcon(baseImage);
    188188                img = resizeMode.createBufferedImage(dim, new Dimension(icon.getIconWidth(), icon.getIconHeight()),
    189                         g -> g.drawImage(icon.getImage(), 0, 0, null));
     189                        null, icon.getImage());
    190190            }
    191191            if (overlayInfo != null) {
Note: See TracChangeset for help on using the changeset viewer.