Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/VectorImageModifier.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/VectorImageModifier.java	(revision 19947)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/VectorImageModifier.java	(revision 19948)
@@ -16,9 +16,5 @@
     public static int cadastreBackgroundTransp = 1; // original white but transparent
 
-    private boolean withBackground = false;
-
     private int backgroundPixel = 0;
-
-    private int backgroundSampleX, backgroundSampleY;
 
     public VectorImageModifier(BufferedImage bi) {
@@ -44,11 +40,9 @@
                 if (pixel == cadastreBackground) {
                     bufferedImage.setRGB(x, y, josmBackgroundColor);
-                    if (!withBackground)
-                        withBackground = true;
-                    backgroundSampleX = x;
-                    backgroundSampleY = y;
                 }
             }
         }
+        // The cadastre has now a new background (for invertGrey())
+        cadastreBackground = josmBackgroundColor;
     }
 
@@ -81,6 +75,9 @@
         int b = col.getBlue();
         if ((b == r) && (b == g)) {
-            pixel = (0x00 << 32) + ((byte) (255 - r) << 16) + ((byte) (255 - r) << 8) + ((byte) (255 - r));
+            pixel = ((byte) col.getAlpha() << 24) + ((byte) (255 - r) << 16) + ((byte) (255 - r) << 8) + ((byte) (255 - r));
         }
+        // Maybe we should try to find a better formula to avoid discontinuity when text is drawn on a colored item
+        // (building, ...). One could use the conversion to and from HSB to only change the brightness not the color.
+        // Note: the color palette does not have the inverse colors so it may be very weird!
         return pixel;
     }
@@ -93,8 +90,5 @@
             WritableRaster raster = bufferedImage.getRaster();
             // pixel is offset in ICM's palette
-            if (withBackground)
-                backgroundPixel = raster.getSample(backgroundSampleX, backgroundSampleY, 0);
-            else
-                backgroundPixel = 1; // default Cadastre background sample
+            backgroundPixel = 1; // default Cadastre background sample
             int size = icm.getMapSize();
             byte[] reds = new byte[size];
@@ -104,4 +98,6 @@
             icm.getGreens(greens);
             icm.getBlues(blues);
+            // The cadastre background has now an alpha to 0 (for invertGrey())
+            cadastreBackground = 0x00ffffff;
             IndexColorModel icm2 = new IndexColorModel(colorModel.getPixelSize(), size, reds, greens, blues,
                     backgroundPixel);
