[mapserver-users] anti-aliasing (was differing image size with different mapserver versions)
Richard Greenwood
richard.greenwood at gmail.com
Sun May 23 13:06:25 PDT 2021
I did some testing and summarized my results in this Google spreadsheet
<https://docs.google.com/spreadsheets/d/169tfJbAciEO0ojLKkteyzfMTaueS2vHDp4tPw4l6szk/edit#gid=872662075>.
My initial goal was to switch from MapServer 6 to 7, and thus from GIF to
PNG since the GD/GIF driver is gone in MapServer 7. I'm looking for a
palleted PNG format similar in size to GIF. PNG uses sub-pixel
anti-aliasing which makes images larger than GIFs which uses color
interpolation to anti-alias. MapServer 7 does not have a built-in
mechanism to disable anti-aliasing in either the AGG or Cairo drivers but
with minor modifications to the source code it can be disabled. The
spreadsheet compares five output formats: GD/GIF, AGG/PNG8, AGG/PNG8 w/o
anti-aliasing, Cairo/PNG8, and Cairo/PNG8 w/o anti-aliasing.
I used three different source maps with significantly different content
(they're linked in the spreadsheet). Not surprisingly, the PNG8 images look
the best, GIF looks okay, and images without anti-aliasing look pretty
poor. The size of the images generally corresponds to the visual quality.
In other words, I did not find any magic way to consistently make really
nice, really small images. But depending on the content there are some ways
to significantly reduce size and still get a nice looking image.
The spreadsheet includes some timing tests. I did these with Apache Bench,
they're not especially rigorous.
Thanks to all who commented on this thread, I learned quite a bit.
Rich
On Thu, May 20, 2021 at 2:58 AM Eichner, Andreas - SID <
Andreas.Eichner at sid.sachsen.de> wrote:
> Well, anti-aliased maps look much better and are basically the way to go.
> But in some corner cases it would be great to be able to turn this feature
> off. Cairo provides a single switch to do that and a patch that enables
> control over that from within MapServer can be simple and straight forward.
> With a little more effort this can be extended to switch between all
> possible CAIRO_ANTIALIAS_* values. So IMHO integrating this option for the
> Cairo renderer seems to be a good idea. For the AGG renderer it requires
> more work to make this runtime controllable.
>
> @Richard: The difference between both renderers is impressive. Since you
> are using this with much more complex maps can you give some feedback which
> one which one looks "better" (with tuning applied) and how usable the
> result is?
>
> Regards, Andreas
>
> -----Ursprüngliche Nachricht-----
> Von: Steve Lime <sdlime at gmail.com>
> Gesendet: Mittwoch, 19. Mai 2021 18:24
> An: Eichner, Andreas - SID <Andreas.Eichner at sid.sachsen.de>
> Cc: Richard Greenwood <richard.greenwood at gmail.com>; mapserver <
> mapserver-users at lists.osgeo.org>
> Betreff: Re: [mapserver-users] anti-aliasing (was differing image size
> with different mapserver versions)
>
> Worth adding to main?
>
> On Wed, May 19, 2021 at 10:15 AM Eichner, Andreas - SID <
> Andreas.Eichner at sid.sachsen.de <mailto: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
>
>
>
>
--
Richard W. Greenwood, PLS
www.greenwoodmap.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20210523/e3a91bc4/attachment.htm>
More information about the MapServer-users
mailing list