Color shifts using QUANTIZE_COLORS=256

thomas bonfort thomas.bonfort at GMAIL.COM
Fri Nov 30 13:12:05 PST 2007


Mapserver relies on a gd library function to do the actual
quantization, so there's little we can do about the color shifting
you're experiencing
another solution is to use a precomputed palette

OUTPUTFORMAT
     [... snip...]
     FORMATOPTION "PALETTE_FORCE=TRUE"
     FORMATOPTION "PALETTE=/path/to/my/palette.txt"
 END

where palette.txt contains 1 rgb triplet per line

cheers

On Nov 30, 2007 9:09 PM, rich.fromm <nospam420 at yahoo.com> wrote:
> Stephen Woodbridge wrote:
> >
> > Thanks for the pointer to the bug. I will add some comments to it even
> > though it is closed.
> >
> > Bart van den Eijnden (OSGIS) wrote:
> >> there is some info by Frank in the following bug report (assuming it is
> >> not outdated):
> >>
> >> http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=684
> >
>
> I think this may be just a rehashing of this same issue, which I think is
> further covered in the following (the URL has moved):
>
> http://trac.osgeo.org/mapserver/ticket/684
> Trouble tricking Mapserver colors in 8-bit mode
> Ticket #684 (closed defect: wontfix)
>
> Although since that was opened 4 years ago, last modified more than 1 year
> ago, and this thread is from the time (>1 year ago) of that last
> modification,
> I want to make sure that this is valid and I'm understanding things
> properly.
>
> I've narrowed this down to a very simple test case (see below).  ALL that
> I'm
> attempting to displaying here is an 80% grey background.  This works fine
> with
> both the AGG and GD rendering backends, as long as quantization is not
> enabled.  However, if I enable quantization, instead of getting a uniform
> background of (204,204,204), I get (204,206,204).  And I'm quite surprised
> at
> how visually noticeable such a small green shift is.  I can preserve the
> proper color if I use IMAGEMODE PC256 rather than IMAGEMODE RGB, but that is
> only valid with GD.  If I try to use it with AGG, I get the following error
> message:
>
> ---
> msDrawMap(): Image handling error. Unable to initialize
> image. msPrepareImage(): GD library error. Unable to initialize
> image. msImageCreateAGG(): AGG library error. AGG driver only supports RGB
> or
> RGBA pixel models.
> ---
>
> I have a very strong preference for using AGG instead of GD.  And I would
> prefer to make my PNG's smaller by not using full 24bit color.  I realize a
> plain background is a bit of an extreme case, but in this case the size
> difference is dramatic:
>
> -rw-r--r--  1 rich engr 2809 2007-11-30 11:14 agg.png
> -rw-r--r--  1 rich engr  133 2007-11-30 11:15 agg_q.png
> -rw-r--r--  1 rich engr 2809 2007-11-30 11:14 gd.png
> -rw-r--r--  1 rich engr  133 2007-11-30 11:37 gd_q.png
> -rw-r--r--  1 rich engr  133 2007-11-30 11:47 gd_256.png
>
> And here are the color distributions within the images:
>
> agg.png --------
> 0: (204,204,204)        grey80
> agg_q.png --------
> 0: (204,206,204)        #CCCECC
> gd.png --------
> 0: (204,204,204)        grey80
> gd_q.png --------
> 0: (204,206,204)        #CCCECC
> gd_256.png --------
> 0: (204,204,204)        grey80
>
> I realize that sometimes quantization will by its very nature need to change
> colors, but I had not expected this if the input image already had a
> sufficiently small number of colors.
>
> Is this indeed still recognized as a known issue that is not going to be
> fixed?  One of the replies here suggested the possibility of reserving
> colors
> via a PALETTE option, but I can find no mention of this anywhere in the
> docs.
>
> I suppose another option would be to have mapserver output 24bit color PNG
> images and use some external program (like ImageMagick) to convert to 8bit
> PNG.
>
> I am running mapserver-5.0.0, compiled with gd-2.0.35 and agg-2.5.
>
> Complete map files to reproduce my testcases are included below.
>
> - Rich Fromm
>
> --- begin agg.map ---
> MAP
>     NAME                agg
>
>     IMAGETYPE   AGG
>     OUTPUTFORMAT
>         NAME 'AGG'
>         DRIVER AGG/PNG
>         IMAGEMODE RGB
>     END
>
>     EXTENT  -122.293878 37.838295 -122.288122 37.841705
>
>     SIZE                640 480
>     IMAGECOLOR  204 204 204    # background
> END
> --- end agg.map ---
>
> --- begin agg_q.map ---
> MAP
>     NAME                agg_q
>
>     IMAGETYPE   AGG_Q
>     OUTPUTFORMAT
>         NAME 'AGG_Q'
>         DRIVER AGG/PNG
>         IMAGEMODE RGB
>         FORMATOPTION "QUANTIZE_FORCE=ON"
>         FORMATOPTION "QUANTIZE_DITHER=OFF"
>         FORMATOPTION "QUANTIZE_COLORS=256"
>     END
>
>     EXTENT  -122.293878 37.838295 -122.288122 37.841705
>
>     SIZE                640 480
>     IMAGECOLOR  204 204 204    # background
> END
> --- end agg_q.map ---
>
> --- begin gd.map ---
> MAP
>     NAME                gd
>
>     IMAGETYPE   PNG
>     OUTPUTFORMAT
>         NAME 'PNG'
>         DRIVER GD/PNG
>         IMAGEMODE RGB
>     END
>
>     EXTENT  -122.293878 37.838295 -122.288122 37.841705
>
>     SIZE                640 480
>     IMAGECOLOR  204 204 204    # background
> END
> --- end gd.map ---
>
> --- begin gd_q.map ---
> MAP
>     NAME                gd
>
>     IMAGETYPE   PNG_Q
>     OUTPUTFORMAT
>         NAME 'PNG_Q'
>         DRIVER GD/PNG
>         IMAGEMODE RGB
>         FORMATOPTION "QUANTIZE_FORCE=ON"
>         FORMATOPTION "QUANTIZE_DITHER=OFF"
>         FORMATOPTION "QUANTIZE_COLORS=256"
>     END
>
>     EXTENT  -122.293878 37.838295 -122.288122 37.841705
>
>     SIZE                640 480
>     IMAGECOLOR  204 204 204    # background
>
> END
> --- end gd_q.map ---
>
> --- begin gd_256.map ---
> MAP
>     NAME                gd_256
>
>     IMAGETYPE   PNG_256
>     OUTPUTFORMAT
>         NAME 'PNG_256'
>         DRIVER GD/PNG
>         IMAGEMODE PC256
>     END
>
>     EXTENT  -122.293878 37.838295 -122.288122 37.841705
>
>     SIZE                640 480
>     IMAGECOLOR  204 204 204    # background
> END
> --- end gd_256.map ---
>
> --
> View this message in context: http://www.nabble.com/Color-shifts-using-QUANTIZE_COLORS%3D256-tf2080351.html#a14092078
> Sent from the Mapserver - User mailing list archive at Nabble.com.
>



More information about the MapServer-users mailing list