New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support of paletted rgba output #2436

Closed
mapserver-bot opened this Issue Apr 3, 2012 · 8 comments

Comments

Projects
None yet
2 participants
@mapserver-bot

mapserver-bot commented Apr 3, 2012

Reporter: tbonfort
Date: 2007/12/14 - 10:46
Trac URL: http://trac.osgeo.org/mapserver/ticket/2436
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.

@mapserver-bot

This comment has been minimized.

Show comment
Hide comment
@mapserver-bot

mapserver-bot Apr 3, 2012

Author: tbonfort
Date: 2007/12/29 - 12:07
committed in 3e064bb (r7221)

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

leaving open until documentation is updated

mapserver-bot commented Apr 3, 2012

Author: tbonfort
Date: 2007/12/29 - 12:07
committed in 3e064bb (r7221)

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

leaving open until documentation is updated

@mapserver-bot

This comment has been minimized.

Show comment
Hide comment
@mapserver-bot

mapserver-bot Apr 3, 2012

Author: tbonfort
Date: 2008/05/29 - 07:37
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?

mapserver-bot commented Apr 3, 2012

Author: tbonfort
Date: 2008/05/29 - 07:37
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?

@mapserver-bot

This comment has been minimized.

Show comment
Hide comment
@mapserver-bot

mapserver-bot Apr 3, 2012

Author: diletant
Date: 2008/06/24 - 17:40
This optional feature seems to be great.
Is it possible to enable it into the next final build for windows users ?
Thks

mapserver-bot commented Apr 3, 2012

Author: diletant
Date: 2008/06/24 - 17:40
This optional feature seems to be great.
Is it possible to enable it into the next final build for windows users ?
Thks

@mapserver-bot

This comment has been minimized.

Show comment
Hide comment
@mapserver-bot

mapserver-bot Apr 3, 2012

Author: rbranson
Date: 2009/04/18 - 00:56
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")'

mapserver-bot commented Apr 3, 2012

Author: rbranson
Date: 2009/04/18 - 00:56
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")'
@mapserver-bot

This comment has been minimized.

Show comment
Hide comment
@mapserver-bot

mapserver-bot Apr 3, 2012

Author: tbonfort
Date: 2009/10/15 - 10:55
closing as this is implemented and documented. further bugs should be opened in new tickets

mapserver-bot commented Apr 3, 2012

Author: tbonfort
Date: 2009/10/15 - 10:55
closing as this is implemented and documented. further bugs should be opened in new tickets

@mapserver-bot

This comment has been minimized.

Show comment
Hide comment
@mapserver-bot

mapserver-bot Apr 5, 2012

attachment http://trac.osgeo.org/mapserver/attachment/ticket/2436/rgba.png :

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

mapserver-bot commented Apr 5, 2012

attachment http://trac.osgeo.org/mapserver/attachment/ticket/2436/rgba.png :

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

This comment has been minimized.

Show comment
Hide comment
@mapserver-bot

mapserver-bot commented Apr 5, 2012

attachment http://trac.osgeo.org/mapserver/attachment/ticket/2436/palette.png :

   same image but with an 8bit rgba palette
@mapserver-bot

This comment has been minimized.

Show comment
Hide comment
@mapserver-bot

mapserver-bot Apr 5, 2012

attachment http://trac.osgeo.org/mapserver/attachment/ticket/2436/rgbapalettegd.png :

   current output when using rgba and quantization

mapserver-bot commented Apr 5, 2012

attachment http://trac.osgeo.org/mapserver/attachment/ticket/2436/rgbapalettegd.png :

   current output when using rgba and quantization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment