[mapserver-users] anti-aliasing (was differing image size with different mapserver versions)

Steve Lime sdlime at gmail.com
Wed May 19 09:24:11 PDT 2021


Worth adding to main?

On Wed, May 19, 2021 at 10: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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20210519/562151ab/attachment.html>


More information about the mapserver-users mailing list