Colors, PNGs

Ed McNierney ed at TOPOZONE.COM
Mon Sep 6 10:01:53 EDT 2004


Titus -

As the others have suggested, this is a matter of running out of colors.
Your photo layer is not "black and white" (two colors), but grayscale,
and probably has 256 different shades of gray.  MapServer processes
layers one at a time, allocating available colors as needed.  If you
draw the first layer in your map using 256 different shades of gray,
MapServer will create a palette with 256 gray shades in it, so that
first layer is drawn accurately.  If you then try to draw another layer,
there are no new colors left and MapServer will use the shade of gray
that's closest to each color (which won't be very close, of course).

You don't say what outputformat DOES work, but I suspect that you're
using JPEG, which is a 24-bit output format and therefore doesn't have
this problem.  It's a limitation of the color depth, not the format
itself.

If you reverse the order of those two layers so the color layer is drawn
first, you'll see you get a different result.

As Steve suggests, you can use the PROCESSING= option (from GDAL) to
have GDAL use a near match rather than exact match when drawing the
grayscale layer.  This will use fewer colors, and will leave some left
over for your other layer.  You can also create an OUTPUTFORMAT block to
define your PNG output to be a 24-bit PNG rather than 8-bit PNG, and
that will fix the problem, too.

        - Ed

Ed McNierney
President and Chief Mapmaker
TopoZone.com / Maps a la carte, Inc.
73 Princeton Street, Suite 305
North Chelmsford, MA  01863
Phone: +1 978 251-4242   Fax: +1 978 251-1396 

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Titus von der Malsburg
Sent: Monday, September 06, 2004 7:28 AM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] Colors, PNGs

Hi,

I have a problem with colors in maps rendererd by Mapserver when using
png as the outputformat.  I have two layers: a raster layer with
black&white ortho imagery and a shape showing buildings in different
colors.  The layers a look as expected when rendered individually.  See:

 * http://www.cl.uni-heidelberg.de/~malsburg/temp/mapserv03.png
 * http://www.cl.uni-heidelberg.de/~malsburg/temp/mapserv01.png

But if I switch them both on, it looks like

 * http://www.cl.uni-heidelberg.de/~malsburg/temp/mapserv02.png

Everything is black&white.  The problem does only appear with
outputformat set to png.

Does anyone know how to solve this problem?

Thanks,
        Titus

$ mapserv -v
MapServer version 4.0.1 OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP SUPPORTS=PROJ
SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT
SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT INPUT=TIFF INPUT=EPPL7
INPUT=JPEG INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE

On Debian unstable.



More information about the mapserver-users mailing list