Stephan Knauss wrote:
Hi,

as Potlatch2 provides the option to sharpen the image I thought this should be possible in JOSM as well.

Unfortunately my 5 minute hack is not working. First I thought it might be no BufferedImage, but it is one.

It throws an exception being unable to convolve the Image. It does not tell why it's unable. Javadoc also does not tell.

As I'm no expert in this area I hope someone more experienced with ConvolveOp can improve the imagery plugin.

Some sun bug reports suggest that you have to sanitize the image. This is a poor solution, but if the sharpened image is cached, it could be acceptable.

Index: src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java
===================================================================
--- src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java (revision 24571) +++ src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java (working copy)
@@ -15,7 +15,11 @@
 import java.awt.event.MouseEvent;
 import java.awt.font.TextAttribute;
 import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.BufferedImageOp;
+import java.awt.image.ConvolveOp;
 import java.awt.image.ImageObserver;
+import java.awt.image.Kernel;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -685,10 +689,31 @@
int img_x_end = img_x_offset + (int)(target.getWidth() * imageXScaling); int img_y_end = img_y_offset + (int)(target.getHeight() * imageYScaling);

+        boolean sharpen=true;
+        Image myImg;
+        if (sharpen && sourceImg instanceof BufferedImage) {
+ Kernel kernel = new Kernel(3, 3, new float[] { -1, -1, -1, -1, 9, -1, -1, -1, -1});
+            BufferedImageOp op = new ConvolveOp(kernel);
+
+            int w = sourceImg.getWidth(null);
+            int h = sourceImg.getHeight(null);
+ BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
+
+            for (int i=0; i<w; i++) {
+                for (int j = 0; j < h; j++) {
+ tmp.setRGB(i, j, ((BufferedImage)sourceImg).getRGB(i, j));
+                }
+            }
+            myImg = op.filter(tmp, null);
+        } else {
+            myImg = sourceImg;
+            out("can not sharpen "+sourceImg.toString());
+        }
+
         if (debug) {
             out("drawing image into target rect: " + target);
         }
-        g.drawImage(sourceImg,
+        g.drawImage(myImg,
                         target.x, target.y,
                         target.x + target.width, target.y + target.height,
                         img_x_offset, img_y_offset,



Sharpening could be an option in the context menu.

This is the patch to reproduce as well as the exception text.


Index: src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java
===================================================================
--- src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java (revision 24542) +++ src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java (working copy)
@@ -15,7 +15,11 @@
 import java.awt.event.MouseEvent;
 import java.awt.font.TextAttribute;
 import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.BufferedImageOp;
+import java.awt.image.ConvolveOp;
 import java.awt.image.ImageObserver;
+import java.awt.image.Kernel;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -672,10 +676,21 @@
int img_x_end = img_x_offset + (int)(target.getWidth() * imageXScaling); int img_y_end = img_y_offset + (int)(target.getHeight() * imageYScaling);

+        boolean sharpen=true;
+        Image myImg;
+        if (sharpen && sourceImg instanceof BufferedImage) {
+ Kernel kernel = new Kernel(3, 3, new float[] { -1, -1, -1, -1, 9, -1, -1, -1, -1});
+            BufferedImageOp op = new ConvolveOp(kernel);
+            myImg = op.filter((BufferedImage)sourceImg, null);
+        } else {
+            myImg = sourceImg;
+            out("can not sharpen "+sourceImg.toString());
+        }
+
         if (debug) {
             out("drawing image into target rect: " + target);
         }
-        g.drawImage(sourceImg,
+        g.drawImage(myImg,
                         target.x, target.y,
                         target.x + target.width, target.y + target.height,
                         img_x_offset, img_y_offset,



java.awt.image.ImagingOpException: Unable to convolve src image
        at java.awt.image.ConvolveOp.filter(Unknown Source)
at org.openstreetmap.josm.plugins.imagery.tms.TMSLayer.drawImageInside(T
MSLayer.java:684)
at org.openstreetmap.josm.plugins.imagery.tms.TMSLayer.paintTileImages(T
MSLayer.java:735)
at org.openstreetmap.josm.plugins.imagery.tms.TMSLayer.paint(TMSLayer.ja
va:993)
        at org.openstreetmap.josm.gui.MapView.paint(MapView.java:516)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JSplitPane.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown S
ource)
        at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
        at javax.swing.RepaintManager.paint(Unknown Source)
        at javax.swing.JComponent._paintImmediately(Unknown Source)
        at javax.swing.JComponent.paintImmediately(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknow
n Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

_______________________________________________
josm-dev mailing list
josm-dev@openstreetmap.org
http://lists.openstreetmap.org/listinfo/josm-dev



_______________________________________________
josm-dev mailing list
josm-dev@openstreetmap.org
http://lists.openstreetmap.org/listinfo/josm-dev

Reply via email to