[mapserver-users] anti-aliasing (was differing image size with different mapserver versions)
Richard Greenwood
richard.greenwood at gmail.com
Wed May 19 14:12:00 PDT 2021
Andreas,
Very interesting. Your Cairo driver modifications create an image the same
size as your AGG driver modification that disables AA, but with strikingly
different appearance. Links to examples below. (The examples are pretty
ugly but with some work on the styles in the map file they could
significantly be improved) I have not tested performance yet. Again -
thank you for your suggestions.
https://greenwoodmap.com/cairo-aliased.png CAIRO/PNG ANTIALIAS=FALSE
https://greenwoodmap.com/agg-aliased.png AGG/PNG8
renderer_scanline_bin_solid
On Wed, May 19, 2021 at 9:15 AM Eichner, Andreas - SID <
Andreas.Eichner at sid.sachsen.de> wrote:
> If you want to give Cairo a try, you could modify mapcairo.c like this:
>
> diff --git a/mapcairo.c b/mapcairo.c
> index 0f4cc094..d28947d6 100644
> --- a/mapcairo.c
> +++ b/mapcairo.c
> @@ -517,6 +517,12 @@ imageObj* createImageCairo(int width, int height,
> outputFormatObj *format,colorO
>
> cairo_set_line_cap (r->cr,CAIRO_LINE_CAP_ROUND);
> cairo_set_line_join(r->cr,CAIRO_LINE_JOIN_ROUND);
> + {
> + const char* antialias = msGetOutputFormatOption(format,
> "ANTIALIAS", "TRUE");
> + if (EQUAL(antialias, "OFF") || EQUAL(antialias, "FALSE") ||
> EQUAL(antialias, "0")) {
> + cairo_set_antialias(r->cr, CAIRO_ANTIALIAS_NONE);
> + }
> + }
> image->img.plugin = (void*)r;
> } else {
> msSetError(MS_RENDERERERR, "Cannot create cairo image of size %dx%d.",
>
> This adds a FORMATOPTION "ANTIALIAS" to the CAIRO/*-Drivers that defaults
> to TRUE. But when explicitly set to 0/OFF/FALSE it calls
> cairo_set_antialias() to disable it. The raster buffer created by the CAIRO
> renderer is passed to the PNG writer which enables COMPRESSION,
> PALETTE_FORCE, QUANTIZE_FORCE. So you can combine it:
>
> OUTPUTFORMAT
> NAME "cairopng"
> DRIVER CAIRO/PNG
> MIMETYPE "image/png"
> IMAGEMODE RGB
> EXTENSION "png"
> FORMATOPTION "ANTIALIAS=FALSE"
> FORMATOPTION "QUANTIZE_FORCE=ON"
> FORMATOPTION "QUANTIZE_COLORS=256"
> FORMATOPTION "COMPRESSION=9"
> END
>
> I used the msautotest/renderers/line_simple.map example to test and that
> crushed the resulting png from 5920 bytes down to 947 bytes.
>
> HTH, Andreas
>
> -----Ursprüngliche Nachricht-----
> Von: Richard Greenwood <richard.greenwood at gmail.com>
> Gesendet: Mittwoch, 19. Mai 2021 16:12
> An: Eichner, Andreas - SID <Andreas.Eichner at sid.sachsen.de>
> Cc: mapserver <mapserver-users at lists.osgeo.org>
> Betreff: Re: [mapserver-users] anti-aliasing (was differing image size
> with different mapserver versions)
>
> Andreas,
>
> I have built a version of MapServer without AA enabled in mapagg.cpp as
> you have suggested. The reduction in file size is remarkable. In some cases
> it is 1/2 the size of a GD/GIF or an optimized AGG/PNG8. Aesthetically the
> images are pretty bad at first, but by softening the colors in the map file
> and reducing the color contrast between adjacent features I'm getting
> images that are acceptable. I will try experimenting with Cairo driver
> modifications next. Thank you very much for your suggestion and detailed
> explanation.
>
> Rich
>
> On Wed, May 19, 2021 at 5:38 AM Eichner, Andreas - SID <
> Andreas.Eichner at sid.sachsen.de <mailto:Andreas.Eichner at sid.sachsen.de> >
> wrote:
>
>
> What AGG does with it's sub-pixel accuracy can be viewed as
> computing the contribution of the pixels of a virtually larger image to the
> pixels of the final image. It uses a gamma function to translate the amount
> of virtual pixels into an amount of visual impact on the final pixel - both
> expressed as a value in the range 0..1. AGG's default is a linear function
> that proportionally maps the range 0..1 onto 0..1 (i.e. y=x). MapServer
> (where applied) uses a linear gamma function that proportionally maps the
> range 0..gamma onto 0..1. All this results in intermediate color values
> giving a smoother and visually improved result as in this example:
> https://commons.wikimedia.org/wiki/File:Antialiasing.png#/media/Datei:Antialiasing.png
>
> As PNG uses lossless compression these additional information
> enlarges the resulting files. So to reduce the size of your map image files
> it's best to turn anti-aliasing off. One way is to compile a special
> version with modified typedefs in mapagg.cpp to turn AA off. With Cairo you
> could use the method cairo_set_antialias(cairo_t*, CAIRO_ANTIALIAS_NONE) to
> switch it off. But then you would loose paletted image and compression
> control.
>
> With the modified AGG you should still apply the other suggestions
> with reduced palette and maximum compression.
>
> HTH
>
>
> -----Ursprüngliche Nachricht-----
> Von: mapserver-users <mapserver-users-bounces at lists.osgeo.org
> <mailto:mapserver-users-bounces at lists.osgeo.org> > Im Auftrag von Richard
> Greenwood
> Gesendet: Dienstag, 18. Mai 2021 18:50
> An: mapserver <mapserver-users at lists.osgeo.org <mailto:
> mapserver-users at lists.osgeo.org> >
> Betreff: [mapserver-users] anti-aliasing (was differing image size
> with different mapserver versions)
>
> Thanks to several helpful replies to my previous thread I know
> that the increased image size between MapServer 6 with the GD driver and
> MapServer 7 with the AGG driver is due to differences in anti-aliasing (and
> lack of) in the two drivers. (AGG features anti-aliasing and sub-pixel
> resolution <https://en.wikipedia.org/wiki/Anti-Grain_Geometry> ).
>
> Gamma setting from 0-1 affects the size of a filled polygon layer
> by a factor of almost 3x. But gamma has no effect on text, lines, and
> polygon outlines. So images comprised of these types of features are
> approximately 2x larger with the AGG/PNG8 driver than with the GD/GIF
> driver.
>
> Where else should I be looking to reduce my images sizes? I serve
> rural areas with poor internet so in my case, smaller image sizes are more
> important than higher quality images.
>
> Thanks,
> Rich
>
> --
>
> Richard W. Greenwood, PLS
> www.greenwoodmap.com <http://www.greenwoodmap.com> <
> http://www.greenwoodmap.com>
>
>
>
>
> --
>
> Richard W. Greenwood, PLS
> www.greenwoodmap.com <http://www.greenwoodmap.com>
>
--
Richard W. Greenwood, PLS
www.greenwoodmap.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20210519/c7bf76de/attachment.htm>
More information about the MapServer-users
mailing list