Changeset 8723 in josm for trunk/src/org


Ignore:
Timestamp:
2015-09-03T16:57:32+02:00 (5 years ago)
Author:
simon04
Message:

see #11713 - use new interface ImageProcessor where applicable

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

Legend:

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

    r8715 r8723  
    208208            tile.setImage(null);
    209209        }
    210         if (sharpenLevel != 0 && success) {
    211             tile.setImage(sharpenImage(tile.getImage()));
    212         }
    213210        tile.setLoaded(success);
    214211        needRedraw = true;
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r8625 r8723  
    7575    protected double dy = 0.0;
    7676
    77     protected int sharpenLevel;
    78 
    7977    private final ImageryAdjustAction adjustAction = new ImageryAdjustAction(this);
    8078
     
    9391            icon = ImageProvider.get("imagery_small");
    9492        }
    95         this.sharpenLevel = PROP_SHARPEN_LEVEL.get();
     93        addImageProcessor(createSharpener(PROP_SHARPEN_LEVEL.get()));
    9694    }
    9795
     
    238236    }
    239237
    240     public BufferedImage sharpenImage(BufferedImage img) {
    241         if (sharpenLevel <= 0) return img;
    242         int width = img.getWidth(null);
    243         int height = img.getHeight(null);
    244         BufferedImage tmp = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    245         tmp.getGraphics().drawImage(img, 0, 0, null);
    246         Kernel kernel;
     238    public ImageProcessor createSharpener(int sharpenLevel) {
     239        final Kernel kernel;
    247240        if (sharpenLevel == 1) {
    248             kernel = new Kernel(3, 3, new float[] {-0.25f, -0.5f, -0.25f, -0.5f, 4, -0.5f, -0.25f, -0.5f, -0.25f});
     241            kernel = new Kernel(3, 3, new float[]{-0.25f, -0.5f, -0.25f, -0.5f, 4, -0.5f, -0.25f, -0.5f, -0.25f});
     242        } else if (sharpenLevel == 2) {
     243            kernel = new Kernel(3, 3, new float[]{-0.5f, -1, -0.5f, -1, 7, -1, -0.5f, -1, -0.5f});
    249244        } else {
    250             kernel = new Kernel(3, 3, new float[] {-0.5f, -1, -0.5f, -1, 7, -1, -0.5f, -1, -0.5f});
     245            return null;
    251246        }
    252247        BufferedImageOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    253         return op.filter(tmp, null);
    254     }
    255 
    256     /**
    257      * This method adds the {@link ImageProcessor} to this Layer
     248        return createImageProcessor(op, false);
     249    }
     250
     251    /**
     252     * This method adds the {@link ImageProcessor} to this Layer if it is not {@code null}.
    258253     *
    259254     * @param processor that processes the image
     
    262257     */
    263258    public boolean addImageProcessor(ImageProcessor processor) {
    264         return imageProcessors.add(processor);
     259        return processor != null && imageProcessors.add(processor);
    265260    }
    266261
     
    274269    public boolean removeImageProcessor(ImageProcessor processor) {
    275270        return imageProcessors.remove(processor);
     271    }
     272
     273    /**
     274     * Wraps a {@link BufferedImageOp} to be used as {@link ImageProcessor}.
     275     * @param op the {@link BufferedImageOp}
     276     * @param inPlace true to apply filter in place, i.e., not create a new {@link BufferedImage} for the result
     277     *                (the {@code op} needs to support this!)
     278     * @return the {@link ImageProcessor} wrapper
     279     */
     280    public static ImageProcessor createImageProcessor(final BufferedImageOp op, final boolean inPlace) {
     281        return new ImageProcessor() {
     282            @Override
     283            public BufferedImage process(BufferedImage image) {
     284                return op.filter(image, inPlace ? image : null);
     285            }
     286        };
    276287    }
    277288
  • trunk/src/org/openstreetmap/josm/tools/ImageOverlay.java

    r8722 r8723  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import org.openstreetmap.josm.gui.layer.ImageProcessor;
    35
    46import java.awt.Dimension;
     
    1012 * @since 8095
    1113 */
    12 public class ImageOverlay {
     14public class ImageOverlay implements ImageProcessor {
    1315    /** the image resource to use as overlay */
    1416    public ImageProvider image;
     
    6567     * @since 8095
    6668     */
    67     public BufferedImage apply(BufferedImage ground) {
     69    @Override
     70    public BufferedImage process(BufferedImage ground) {
    6871        /* get base dimensions for calculation */
    6972        int w = ground.getWidth();
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r8095 r8723  
    115115            if (overlayInfo != null) {
    116116                for (ImageOverlay o : overlayInfo) {
    117                     o.apply(bimg);
     117                    o.process(bimg);
    118118                }
    119119            }
     
    139139            if (overlayInfo != null) {
    140140                for (ImageOverlay o : overlayInfo) {
    141                     o.apply(bimg);
     141                    o.process(bimg);
    142142                }
    143143            }
Note: See TracChangeset for help on using the changeset viewer.