[josm-dev] Sharpen imagery layer
Stephan Knauss
osm at stephans-server.de
Mon Dec 6 00:21:02 GMT 2010
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.
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)
More information about the josm-dev
mailing list