Index: trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 4819)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 4820)
@@ -16,4 +16,5 @@
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;
 import org.openstreetmap.josm.tools.Utils;
 
@@ -45,9 +46,6 @@
         IconReference iconRef = c.get("fill-image", null, IconReference.class);
         if (iconRef != null) {
-            ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, false);
+            ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, SanitizeMode.MAKE_BUFFEREDIMAGE);
             if (icon != null) {
-                if (!(icon.getImage() instanceof BufferedImage)) {
-                    icon = MapPaintStyles.getIcon(iconRef, -1, -1, true);
-                }
                 if (!(icon.getImage() instanceof BufferedImage))
                     throw new RuntimeException();
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java	(revision 4819)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java	(revision 4820)
@@ -28,5 +28,5 @@
         if (iconRef == null)
             return null;
-        ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, false);
+        ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1);
         if (icon == null)
             return null;
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 4819)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 4820)
@@ -27,4 +27,5 @@
 import org.openstreetmap.josm.io.MirroredInputStream;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;
 
 /**
@@ -87,5 +88,9 @@
     }
 
-    public static ImageIcon getIcon(IconReference ref, int width, int height, boolean sanitize) {
+    public static ImageIcon getIcon(IconReference ref, int width, int height) {
+        return getIcon(ref, width, height, SanitizeMode.OFF);
+    }
+
+    public static ImageIcon getIcon(IconReference ref, int width, int height, SanitizeMode sanitize) {
         final String namespace = ref.source.getPrefName();
         ImageIcon i = new ImageProvider(ref.iconName)
@@ -105,4 +110,8 @@
     }
 
+    public static ImageIcon getNoIcon_Icon(StyleSource source) {
+        return getNoIcon_Icon(source, SanitizeMode.OFF);
+    }
+
     /**
      * No icon with the given name was found, show a dummy icon instead
@@ -113,5 +122,5 @@
      *  can be null if the defaults are turned off by user
      */
-    public static ImageIcon getNoIcon_Icon(StyleSource source, boolean sanitize) {
+    public static ImageIcon getNoIcon_Icon(StyleSource source, SanitizeMode sanitize) {
         return new ImageProvider("misc/no_icon.png")
                 .setDirs(getIconSourceDirs(source))
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 4819)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 4820)
@@ -150,7 +150,7 @@
         int height = heightF == null ? -1 : Math.round(heightF);
 
-        ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height, false);
+        ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height);
         if (icon == null)
-            return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source, false), 255);
+            return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source), 255);
         int iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
         Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java	(revision 4819)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java	(revision 4820)
@@ -74,5 +74,5 @@
         if (imageIcon == null) {
             if (icon != null) {
-                imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1, false);
+                imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1);
             }
             if (imageIcon == null) {
Index: trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 4819)
+++ trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 4820)
@@ -35,6 +35,8 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
+
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
+
 import org.apache.commons.codec.binary.Base64;
 import org.openstreetmap.josm.Main;
@@ -81,4 +83,10 @@
     }
 
+    public static enum SanitizeMode {
+        OFF,                // never sanitize the image
+        ALWAYS,             // always copy to a new BufferedImage
+        MAKE_BUFFEREDIMAGE  // make sure the returned image is instance of BufferedImage
+    }
+
     protected Collection<String> dirs;
     protected String id;
@@ -90,5 +98,5 @@
     protected int maxWidth = -1;
     protected int maxHeight = -1;
-    protected boolean sanitize;
+    protected SanitizeMode sanitize;
     protected boolean optional;
 
@@ -200,5 +208,5 @@
      * Set true, if the image should be repainted to a new BufferedImage in order to work around certain issues.
      */
-    public ImageProvider setSanitize(boolean sanitize) {
+    public ImageProvider setSanitize(SanitizeMode sanitize) {
         this.sanitize = sanitize;
         return this;
@@ -276,14 +284,14 @@
     @Deprecated
     public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive) {
-        return getIfAvailable(dirs, id, subdir, name, archive, false);
+        return getIfAvailable(dirs, id, subdir, name, archive, SanitizeMode.OFF);
     }
 
     @Deprecated
-    public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, boolean sanitize) {
+    public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, SanitizeMode sanitize) {
         return getIfAvailable(dirs, id, subdir, name, archive, null, sanitize);
     }
 
     @Deprecated
-    public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, Dimension dim, boolean sanitize) {
+    public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, Dimension dim, SanitizeMode sanitize) {
         return getIfAvailable(dirs, id, subdir, name, archive, dim, null, sanitize);
     }
@@ -312,5 +320,5 @@
     @Deprecated
     public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name,
-            File archive, Dimension dim, Dimension maxSize, boolean sanitize) {
+            File archive, Dimension dim, Dimension maxSize, SanitizeMode sanitize) {
         ImageProvider p = new ImageProvider(subdir, name).setDirs(dirs).setId(id).setArchive(archive).setSanitize(sanitize).setOptional(true);
         if (dim != null) {
Index: trunk/src/org/openstreetmap/josm/tools/ImageResource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/ImageResource.java	(revision 4819)
+++ trunk/src/org/openstreetmap/josm/tools/ImageResource.java	(revision 4820)
@@ -6,6 +6,9 @@
 import java.awt.Dimension;
 import java.awt.Image;
+import java.awt.image.BufferedImage;
 import java.util.HashMap;
 import javax.swing.ImageIcon;
+
+import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;
 
 /**
@@ -50,5 +53,5 @@
 
     public ImageIcon getImageIcon() {
-        return getImageIcon(DEFAULT_DIMENSION, false);
+        return getImageIcon(DEFAULT_DIMENSION, SanitizeMode.OFF);
     }
 
@@ -58,15 +61,17 @@
      *          and (width, -1) to set the width, but otherwise scale the image
      *          proportionally.
-     * @param sanitized Whether the returned image should be copied to a BufferedImage
+     * @param sanitize Whether the returned image should be copied to a BufferedImage
      *          to avoid certain problem with native image formats.
      */
-    public ImageIcon getImageIcon(Dimension dim, boolean sanitized) {
+    public ImageIcon getImageIcon(Dimension dim, SanitizeMode sanitize) {
         if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0)
             throw new IllegalArgumentException();
         ImageWrapper iw = imgCache.get(dim);
         if (iw != null) {
-            if (sanitized && !iw.sanitized) {
-                iw.img = ImageProvider.sanitize(iw.img);
-                iw.sanitized = true;
+            if (!iw.sanitized) {
+                if (sanitize == SanitizeMode.ALWAYS || (sanitize == SanitizeMode.MAKE_BUFFEREDIMAGE && !(iw.img instanceof BufferedImage))) {
+                    iw.img = ImageProvider.sanitize(iw.img);
+                    iw.sanitized = true;
+                }
             }
             return new ImageIcon(iw.img);
@@ -88,7 +93,14 @@
                 height = icon.getIconHeight() * width / icon.getIconWidth();
             }
-            Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
-            if (sanitized) {
+            Image img;
+            if (width == dim.width && height == dim.height) {
+                img = icon.getImage();
+            } else {
+                img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
+            }
+            boolean sanitized = false;
+            if (sanitize == SanitizeMode.ALWAYS || (sanitize == SanitizeMode.MAKE_BUFFEREDIMAGE && !(img instanceof BufferedImage))) {
                 img = ImageProvider.sanitize(img);
+                sanitized = true;
             }
             imgCache.put(dim, new ImageWrapper(img, sanitized));
@@ -104,5 +116,5 @@
      * which means it is not bounded.
      */
-    public ImageIcon getImageIconBounded(Dimension maxSize, boolean sanitized) {
+    public ImageIcon getImageIconBounded(Dimension maxSize, SanitizeMode sanitize) {
         if (maxSize.width < -1 || maxSize.width == 0 || maxSize.height < -1 || maxSize.height == 0)
             throw new IllegalArgumentException();
@@ -130,14 +142,14 @@
 
         if (maxWidth == -1 && maxHeight == -1)
-            return getImageIcon(DEFAULT_DIMENSION, sanitized);
+            return getImageIcon(DEFAULT_DIMENSION, sanitize);
         else if (maxWidth == -1)
-            return getImageIcon(new Dimension(-1, maxHeight), sanitized);
+            return getImageIcon(new Dimension(-1, maxHeight), sanitize);
         else if (maxHeight == -1)
-            return getImageIcon(new Dimension(maxWidth, -1), sanitized);
+            return getImageIcon(new Dimension(maxWidth, -1), sanitize);
         else
             if (realWidth / maxWidth > realHeight / maxHeight)
-                return getImageIcon(new Dimension(maxWidth, -1), sanitized);
+                return getImageIcon(new Dimension(maxWidth, -1), sanitize);
             else
-                return getImageIcon(new Dimension(-1, maxHeight), sanitized);
+                return getImageIcon(new Dimension(-1, maxHeight), sanitize);
    }
 }
