Ticket #2436 (new enhancement)

Opened 2 years ago

Last modified 3 months ago

support of paletted rgba output

Reported by: tbonfort Assigned to: tbonfort
Priority: normal Milestone: 5.2.1 release
Component: MapServer Documentation Version: unspecified
Severity: normal Keywords: png palette quantize rgba
Cc: jmckenna

Description

mapserver currently supports writing a palette based png image, either by automatic quantization or by a user supplied palette. This functionality is supplied by the GD function gdImageCreatePaletteFromTrueColor which does not support creating a palette for images where the alpha channel is significant.

this ticket tracks the addition of paletted png output for rgba images, using the same OUTPUTFORMAT options as for rgb images, i.e QUANTIZE_FORCE and PALETTE_FORCE.

Attachments

rgba.png (129.4 kB) - added by tbonfort on 12/14/07 04:50:46.
typical rgba output - this is the reference file in 32-bit RGB+alpha
palette.png (38.9 kB) - added by tbonfort on 12/14/07 04:53:39.
same image but with an 8bit rgba palette
rgbapalettegd.png (30.0 kB) - added by tbonfort on 12/14/07 05:20:00.
current output when using rgba and quantization

Change History

12/14/07 04:50:46 changed by tbonfort

  • attachment rgba.png added.

typical rgba output - this is the reference file in 32-bit RGB+alpha

12/14/07 04:53:39 changed by tbonfort

  • attachment palette.png added.

same image but with an 8bit rgba palette

12/14/07 05:20:00 changed by tbonfort

  • attachment rgbapalettegd.png added.

current output when using rgba and quantization

12/29/07 06:07:47 changed by tbonfort

committed in r7221

functionality is enabled if configure is run with the --with-experimental-png flag

leaving open until documentation is updated

04/17/08 04:09:21 changed by tbonfort

  • component changed from MapServer C Library to MapServer Documentation.

04/17/08 04:10:43 changed by tbonfort

  • cc set to jmckenna.

05/29/08 01:37:03 changed by tbonfort

it is activated when the ./configure script is run with the --with-experimental-png switch, which checks for the libpng headers. this means that the libpng headers have to be installed and accessible on your system (apt-get install libpng-dev or the equivalent with yum/yast/etc...)

to activate these outputs in your mapfiles you'll need to set some FORMATOPTION entries to the wanted OUTPUTFORMATs, eg

to force quantization

(creates a paletted png, with the palette automatically created/selected for each rendered image)

OUTPUTFORMAT
    NAME 'AGGAQ'
    DRIVER AGG/PNG # not AGG specific, also works with GD. PNG is mandatory though
    IMAGEMODE RGBA  # only for rgba imagemodes
    MIMETYPE "image/png"
# this is the important part
    FORMATOPTION "QUANTIZE_FORCE=ON"
# this specifies the number of colors wanted in the final image
# 256 is the typically wanted value
# values 17 to 255 are possible but don't really make sense as there's
# little reduction in file size compared to 256 (each pixel is still
# stored with 8 bits, only the palette is smaller)
# 16 greatly reduces image size (and quality, no magic)
    FORMATOPTION "QUANTIZE_COLORS=256"
END

to use a specified precomputed palette

(faster than quantization, and guarantees colors are consistent whatever the image created, but less flexible as the palette has to be precomputed and is fixed whatever is in the image)

OUTPUTFORMAT
    NAME 'AGGAP'
    DRIVER AGG/PNG
    IMAGEMODE RGBA
    MIMETYPE "image/png"

# the important part
    FORMATOPTION "PALETTE_FORCE=TRUE"
    FORMATOPTION "PALETTE=/path/to/palette.txt"
END

here the palette file must be specified with an absolute path, and contains at most 256 lines, each consisting of an r,g,b,a quadruplet, eg:

0,0,0,0
127,127,127,2
196,226,251,237
170,170,170,2
191,191,191,4
196,225,251,233
...
snip
...
163,189,242,57
137,158,242,56
118,137,241,48
184,213,245,75

to obtain this palette, take a typical (32bit rgba png) image you will want to display, use your favorite image editor to reduce the number of colors (photoshop using "save web image" and selecting png, or the commandline utilities pngquant http://libpng.org/pub/png/apps/pngquant.html or neuquant http://members.ozemail.com.au/~dekker/NEUQUANT.HTML, etc ) and then extract (and transform to the required r,g,b,a format) the computed palette to the palette file. ( pngcheck http://www.libpng.org/pub/png/apps/pngcheck.html with its -p option and some scripting can be used for this )

Jef, I can update the online docs with this. What's best, a specific howto or an update to the official documentation?

06/24/08 11:40:39 changed by diletant

This optional feature seems to be great. Is it possible to enable it into the next final build for windows users ? Thks

04/17/09 18:56:16 changed by rbranson

Here's a quick hack of a script to get the output for the palette file from pngcheck.

pngcheck -p input.png | ruby -n -e 'next if !/=/; puts $_.gsub(/^.*?\(\s*?(\d+),\s*?(\d+),\s*?(\d+)\) =.*?$/, "\\1,\\2,\\3")'