Index: /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java	(revision 12965)
+++ /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java	(revision 12966)
@@ -5,12 +5,8 @@
 
 import java.awt.Color;
-import java.util.List;
-import java.util.Optional;
 
 import org.openstreetmap.josm.data.preferences.CachingProperty;
 import org.openstreetmap.josm.data.preferences.ColorProperty;
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
-import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener;
-import org.openstreetmap.josm.gui.mappaint.StyleSource;
 
 /**
@@ -91,23 +87,4 @@
     private final CachingProperty<Color> property;
 
-    private static volatile Color backgroundColorCache;
-
-    private static final MapPaintSylesUpdateListener STYLE_OVERRIDE_LISTENER = new MapPaintSylesUpdateListener() {
-        //TODO: Listen to wireframe map mode changes.
-        @Override
-        public void mapPaintStylesUpdated() {
-            backgroundColorCache = null;
-        }
-
-        @Override
-        public void mapPaintStyleEntryUpdated(int idx) {
-            mapPaintStylesUpdated();
-        }
-    };
-
-    static {
-        MapPaintStyles.addMapPaintSylesUpdateListener(STYLE_OVERRIDE_LISTENER);
-    }
-
     PaintColors(String name, Color defaultColor) {
         baseProperty = new ColorProperty(name, defaultColor);
@@ -138,17 +115,5 @@
      */
     public static Color getBackgroundColor() {
-        if (backgroundColorCache != null)
-            return backgroundColorCache;
-        List<StyleSource> sources = MapPaintStyles.getStyles().getStyleSources();
-        for (StyleSource s : sources) {
-            if (!s.active) {
-                continue;
-            }
-            Color backgroundColorOverride = s.getBackgroundColorOverride();
-            if (backgroundColorOverride != null) {
-                backgroundColorCache = backgroundColorOverride;
-            }
-        }
-        return Optional.ofNullable(backgroundColorCache).orElseGet(BACKGROUND::get);
+        return MapPaintStyles.getStyles().getBackgroundColor();
     }
 
Index: /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 12965)
+++ /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 12966)
@@ -1372,5 +1372,5 @@
         super.getColors();
         this.highlightColorTransparent = new Color(highlightColor.getRed(), highlightColor.getGreen(), highlightColor.getBlue(), 100);
-        this.backgroundColor = PaintColors.getBackgroundColor();
+        this.backgroundColor = styles.getBackgroundColor();
     }
 
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java	(revision 12965)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java	(revision 12966)
@@ -10,4 +10,5 @@
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 
 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
@@ -17,4 +18,5 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
@@ -69,4 +71,6 @@
     private final Map<String, String> preferenceCache = new HashMap<>();
 
+    private static volatile Color backgroundColorCache;
+
     /**
      * Constructs a new {@code ElemStyles}.
@@ -75,4 +79,16 @@
         styleSources = new ArrayList<>();
         Config.getPref().addPreferenceChangeListener(this);
+        MapPaintStyles.addMapPaintSylesUpdateListener(new MapPaintStyles.MapPaintSylesUpdateListener() {
+            //TODO: Listen to wireframe map mode changes.
+            @Override
+            public void mapPaintStylesUpdated() {
+                backgroundColorCache = null;
+            }
+
+            @Override
+            public void mapPaintStyleEntryUpdated(int idx) {
+                mapPaintStylesUpdated();
+            }
+        });
     }
 
@@ -94,4 +110,19 @@
     public List<StyleSource> getStyleSources() {
         return Collections.<StyleSource>unmodifiableList(styleSources);
+    }
+
+    public Color getBackgroundColor() {
+        if (backgroundColorCache != null)
+            return backgroundColorCache;
+        for (StyleSource s : styleSources) {
+            if (!s.active) {
+                continue;
+            }
+            Color backgroundColorOverride = s.getBackgroundColorOverride();
+            if (backgroundColorOverride != null) {
+                backgroundColorCache = backgroundColorOverride;
+            }
+        }
+        return Optional.ofNullable(backgroundColorCache).orElseGet(PaintColors.BACKGROUND::get);
     }
 
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java	(revision 12965)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java	(revision 12966)
@@ -5,4 +5,6 @@
 
 import java.awt.Dimension;
+import java.awt.image.BufferedImage;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -14,4 +16,6 @@
 import java.util.function.Supplier;
 import java.util.logging.Level;
+
+import javax.imageio.ImageIO;
 
 import org.openstreetmap.gui.jmapviewer.OsmMercator;
@@ -155,7 +159,7 @@
             RenderingArea area = determineRenderingArea(ds);
             RenderingHelper rh = new RenderingHelper(ds, area.bounds, area.scale, argStyles);
-            rh.setOutputFile(argOutput);
             checkPreconditions(rh);
-            rh.render();
+            BufferedImage image = rh.render();
+            writeImageToFile(image);
         } catch (FileNotFoundException e) {
             if (Logging.isDebugEnabled()) {
@@ -562,3 +566,8 @@
         }
     }
+
+    private void writeImageToFile(BufferedImage image) throws IOException {
+        String output = Optional.ofNullable(argOutput).orElse("out.png");
+        ImageIO.write(image, "png", new File(output));
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java	(revision 12965)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java	(revision 12966)
@@ -4,9 +4,10 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
+import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics2D;
 import java.awt.Point;
+import java.awt.RenderingHints;
 import java.awt.image.BufferedImage;
-import java.io.File;
 import java.io.IOException;
 import java.util.Collection;
@@ -15,11 +16,8 @@
 import java.util.Optional;
 
-import javax.imageio.ImageIO;
-
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.ProjectionBounds;
 import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
 import org.openstreetmap.josm.data.projection.Projection;
@@ -41,5 +39,6 @@
     private final double scale;
     private final Collection<StyleData> styles;
-    private String outputFile;
+    private Color backgroundColor;
+    private boolean fillBackground = true;
 
     /**
@@ -73,11 +72,23 @@
 
     /**
-     * Set the output file for rendering.
+     * Set the background color to use for rendering.
      *
-     * Default is {@code out.png}.
-     * @param outputFile the output file for rendering
+     * @param backgroundColor the background color to use, {@code} means
+     * to determine the background color automatically from the style
+     * @see #setFillBackground(boolean)
+     * @since 12966
      */
-    public void setOutputFile(String outputFile) {
-        this.outputFile = outputFile;
+    public void setBackgroundColor(Color backgroundColor) {
+        this.backgroundColor = backgroundColor;
+    }
+
+    /**
+     * Decide if background should be filled or left transparent.
+     * @param fillBackground true, if background should be filled
+     * @see #setBackgroundColor(java.awt.Color)
+     * @since 12966
+     */
+    public void setFillBackground(boolean fillBackground) {
+        this.fillBackground = fillBackground;
     }
 
@@ -93,8 +104,9 @@
      * Invoke the renderer.
      *
+     * @return the rendered image
      * @throws IOException in case of an IOException
      * @throws IllegalDataException when illegal data is encountered (style has errors, etc.)
      */
-    public void render() throws IOException, IllegalDataException {
+    public BufferedImage render() throws IOException, IllegalDataException {
         // load the styles
         ElemStyles elemStyles = new ElemStyles();
@@ -152,13 +164,24 @@
         BufferedImage image = new BufferedImage(imgDimPx.width, imgDimPx.height, BufferedImage.TYPE_INT_ARGB);
         Graphics2D g = image.createGraphics();
-        g.setColor(PaintColors.getBackgroundColor());
-        g.fillRect(0, 0, imgDimPx.width, imgDimPx.height);
+
+        // Force all render hints to be defaults - do not use platform values
+        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+        g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
+        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
+        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+        if (fillBackground) {
+            g.setColor(Optional.ofNullable(backgroundColor).orElse(elemStyles.getBackgroundColor()));
+            g.fillRect(0, 0, imgDimPx.width, imgDimPx.height);
+        }
         StyledMapRenderer smr = new StyledMapRenderer(g, nc, false);
         smr.setStyles(elemStyles);
         smr.render(ds, false, bounds);
-
-        // write to file
-        String output = Optional.ofNullable(outputFile).orElse("out.png");
-        ImageIO.write(image, "png", new File(output));
+        return image;
     }
 
Index: /trunk/test/functional/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java
===================================================================
--- /trunk/test/functional/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java	(revision 12965)
+++ /trunk/test/functional/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java	(revision 12966)
@@ -5,8 +5,6 @@
 import static org.junit.Assert.fail;
 
-import java.awt.Graphics2D;
 import java.awt.GraphicsEnvironment;
 import java.awt.Point;
-import java.awt.RenderingHints;
 import java.awt.image.BufferedImage;
 import java.io.File;
@@ -18,4 +16,5 @@
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -38,8 +37,4 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
-import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
-import org.openstreetmap.josm.data.preferences.sources.SourceType;
-import org.openstreetmap.josm.gui.NavigatableComponent;
-import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
 import org.openstreetmap.josm.io.IllegalDataException;
 import org.openstreetmap.josm.io.OsmReader;
@@ -163,62 +158,17 @@
         // load the data
         DataSet dataSet = testConfig.getOsmDataSet();
-
-        // load the style
-        MapCSSStyleSource.STYLE_SOURCE_LOCK.writeLock().lock();
-        try {
-            MapPaintStyles.getStyles().clear();
-
-            MapCSSStyleSource source = new MapCSSStyleSource(testConfig.getStyleSourceEntry());
-            source.loadStyleSource();
-            if (!source.getErrors().isEmpty()) {
-                fail("Failed to load style file. Errors: " + source.getErrors());
-            }
-            MapPaintStyles.getStyles().setStyleSources(Arrays.asList(source));
-            MapPaintStyles.fireMapPaintSylesUpdated();
-            MapPaintStyles.getStyles().clearCached();
-
-        } finally {
-            MapCSSStyleSource.STYLE_SOURCE_LOCK.writeLock().unlock();
-        }
-
-        // create the renderer
-        BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB);
-        NavigatableComponent nc = new NavigatableComponent() {
-            {
-                setBounds(0, 0, IMAGE_SIZE, IMAGE_SIZE);
-                updateLocationState();
-            }
-
-            @Override
-            protected boolean isVisibleOnScreen() {
-                return true;
-            }
-
-            @Override
-            public Point getLocationOnScreen() {
-                return new Point(0, 0);
-            }
-        };
+        dataSet.allPrimitives().stream().forEach(this::loadPrimitiveStyle);
+        dataSet.setSelected(dataSet.allPrimitives().stream().filter(n -> n.isKeyTrue("selected")).collect(Collectors.toList()));
+
         ProjectionBounds pb = new ProjectionBounds();
         pb.extend(Main.getProjection().latlon2eastNorth(testConfig.testArea.getMin()));
         pb.extend(Main.getProjection().latlon2eastNorth(testConfig.testArea.getMax()));
         double scale = (pb.maxEast - pb.minEast) / IMAGE_SIZE;
-        nc.zoomTo(pb.getCenter(), scale);
-
-        dataSet.allPrimitives().stream().forEach(this::loadPrimitiveStyle);
-        dataSet.setSelected(dataSet.allPrimitives().stream().filter(n -> n.isKeyTrue("selected")).collect(Collectors.toList()));
-
-        Graphics2D g = image.createGraphics();
-        // Force all render hints to be defaults - do not use platform values
-        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
-        g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
-        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
-        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
-        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
-        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
-        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
-        new StyledMapRenderer(g, nc, false).render(dataSet, false, testConfig.testArea);
+
+        RenderingHelper.StyleData sd = new RenderingHelper.StyleData();
+        sd.styleUrl = testConfig.getStyleSourceUrl();
+        RenderingHelper rh = new RenderingHelper(dataSet, testConfig.testArea, scale, Collections.singleton(sd));
+        rh.setFillBackground(false);
+        BufferedImage image = rh.render();
 
         if (UPDATE_ALL) {
@@ -317,8 +267,6 @@
         }
 
-        public SourceEntry getStyleSourceEntry() {
-            return new SourceEntry(SourceType.MAP_PAINT_STYLE, getTestDirectory() + "/style.mapcss",
-                    "test style", "a test style", true // active
-            );
+        public String getStyleSourceUrl() {
+            return getTestDirectory() + "/style.mapcss";
         }
 
