[mapserver-commits] r11577 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Thu Apr 14 11:47:05 EDT 2011


Author: tbonfort
Date: 2011-04-14 08:47:05 -0700 (Thu, 14 Apr 2011)
New Revision: 11577

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapimageio.c
Log:
add configurable PNG/ZLIB compression level (#3841)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2011-04-14 14:45:02 UTC (rev 11576)
+++ trunk/mapserver/HISTORY.TXT	2011-04-14 15:47:05 UTC (rev 11577)
@@ -20,6 +20,8 @@
 Version 6.0.0-beta6 (2011-04-13)
 --------------------------------
 
+- add configurable PNG/ZLIB compression level (#3841)
+
 - SLD: use pixmap size when parameter size is not specified (#2305)
 
 - fix memory leaks in mapgraticule.c (#3831)

Modified: trunk/mapserver/mapimageio.c
===================================================================
--- trunk/mapserver/mapimageio.c	2011-04-14 14:45:02 UTC (rev 11576)
+++ trunk/mapserver/mapimageio.c	2011-04-14 15:47:05 UTC (rev 11577)
@@ -32,6 +32,7 @@
 #include "setjmp.h"
 #include <assert.h>
 #include "jpeglib.h"
+#include <stdlib.h>
 
 #ifdef USE_GIF
 #include "gif_lib.h"
@@ -237,7 +238,7 @@
    return MS_SUCCESS;
 }
 
-int savePalettePNG(rasterBufferObj *rb, streamInfo *info) {
+int savePalettePNG(rasterBufferObj *rb, streamInfo *info, int compression) {
    png_infop info_ptr;
    rgbPixel rgb[256];
    unsigned char a[256];
@@ -269,8 +270,7 @@
    else
       png_set_write_fn(png_ptr,info, png_write_data_to_buffer, png_flush_data);
    
-   /* set max compression (writing a palette image is to gain size anyways */
-   png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
+   png_set_compression_level(png_ptr, compression);
    
    if (rb->data.palette.num_entries <= 2)
     sample_depth = 1;
@@ -355,9 +355,21 @@
     int force_palette = MS_FALSE;
    
     int ret = MS_FAILURE;
-    const char *force_string;
+
+    const char *force_string,*zlib_compression;
+    int compression = -1;
+
+    zlib_compression = msGetOutputFormatOption( format, "COMPRESSION", NULL);
+    if(zlib_compression && *zlib_compression) {
+      char *endptr;
+      compression = strtol(zlib_compression,&endptr,10);
+      if(*endptr || compression<-1 || compression>9) {
+         msSetError(MS_MISCERR,"failed to parse FORMATOPTION \"COMPRESSION=%s\", expecting integer from 0 to 9.","saveAsPNG()",zlib_compression);
+         return MS_FAILURE;
+      }
+    }
+
    
-   
     force_string = msGetOutputFormatOption( format, "QUANTIZE_FORCE", NULL );
     if( force_string && (strcasecmp(force_string,"on") == 0  || strcasecmp(force_string,"yes") == 0 || strcasecmp(force_string,"true") == 0) )
         force_pc256 = MS_TRUE;
@@ -407,7 +419,7 @@
         }
         if(ret != MS_FAILURE) {
             ret = msClassifyRasterBuffer(rb,&qrb);
-            ret = savePalettePNG(&qrb,info);  
+            ret = savePalettePNG(&qrb,info,compression);  
         }
         //msFreeRasterBuffer(&qrb);
         return ret;
@@ -446,6 +458,7 @@
         else
             color_type = PNG_COLOR_TYPE_RGB;
 	
+        png_set_compression_level(png_ptr, compression);
         png_set_IHDR(png_ptr, info_ptr, rb->width, rb->height,
                      8, color_type, PNG_INTERLACE_NONE,
                      PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);



More information about the mapserver-commits mailing list