Opened 13 years ago

Closed 11 years ago

#2436 closed enhancement (fixed)

support of paletted rgba output

Reported by: tbonfort Owned by: tbonfort
Priority: normal Milestone: 5.6 release
Component: Documentation - MapServer 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 (3)

rgba.png (129.4 KB) - added by tbonfort 13 years ago.
typical rgba output - this is the reference file in 32-bit RGB+alpha
palette.png (38.9 KB) - added by tbonfort 13 years ago.
same image but with an 8bit rgba palette
rgbapalettegd.png (30.0 KB) - added by tbonfort 13 years ago.
current output when using rgba and quantization

Download all attachments as: .zip

Change History (10)

Changed 13 years ago by tbonfort

Attachment: rgba.png added

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

Changed 13 years ago by tbonfort

Attachment: palette.png added

same image but with an 8bit rgba palette

Changed 13 years ago by tbonfort

Attachment: rgbapalettegd.png added

current output when using rgba and quantization

comment:1 Changed 13 years ago by tbonfort

committed in r7221

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

leaving open until documentation is updated

comment:2 Changed 13 years ago by tbonfort

Component: MapServer C LibraryMapServer Documentation

comment:3 Changed 13 years ago by tbonfort

Cc: jmckenna added

comment:4 Changed 13 years ago 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?

comment:5 Changed 13 years ago by diletant

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

comment:6 Changed 12 years ago 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")'

comment:7 Changed 11 years ago by tbonfort

Resolution: fixed
Status: newclosed

closing as this is implemented and documented. further bugs should be opened in new tickets

Note: See TracTickets for help on using tickets.