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

Eichner, Andreas - SID Andreas.Eichner at sid.sachsen.de
Thu May 20 01:58:25 PDT 2021


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
	
	



More information about the MapServer-users mailing list