[GRASS-SVN] r61380 - in grass/trunk/lib: gis init raster

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 23 14:06:07 PDT 2014


Author: glynn
Date: 2014-07-23 14:06:07 -0700 (Wed, 23 Jul 2014)
New Revision: 61380

Modified:
   grass/trunk/lib/gis/G.h
   grass/trunk/lib/gis/flate.c
   grass/trunk/lib/gis/gisinit.c
   grass/trunk/lib/init/variables.html
   grass/trunk/lib/raster/init.c
Log:
Enable zlib compression by default (set GRASS_INT_ZLIB=0 to use RLE)
Allow zlib compression to be set via GRASS_ZLIB_LEVEL environment variable


Modified: grass/trunk/lib/gis/G.h
===================================================================
--- grass/trunk/lib/gis/G.h	2014-07-23 19:11:04 UTC (rev 61379)
+++ grass/trunk/lib/gis/G.h	2014-07-23 21:06:07 UTC (rev 61380)
@@ -6,6 +6,7 @@
     struct Cell_head window;	/* Contains the current window          */
     int window_set;		/* Flag: window set?                    */
     int little_endian;          /* Flag denoting little-endian architecture */
+    int compression_level;	/* zlib compression level               */
 };
 
 extern struct G__ G__;		/* allocated in gisinit */

Modified: grass/trunk/lib/gis/flate.c
===================================================================
--- grass/trunk/lib/gis/flate.c	2014-07-23 19:11:04 UTC (rev 61379)
+++ grass/trunk/lib/gis/flate.c	2014-07-23 21:06:07 UTC (rev 61380)
@@ -123,6 +123,8 @@
 #include <unistd.h>
 #include <grass/gis.h>
 
+#include "G.h"
+
 #define G_ZLIB_COMPRESSED_NO (unsigned char)'0'
 #define G_ZLIB_COMPRESSED_YES (unsigned char)'1'
 
@@ -327,7 +329,9 @@
     c_stream.next_out = buf;
 
     /* Initialize using default compression (usually 6) */
-    err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
+    err = deflateInit(&c_stream, G__.compression_level < 0
+		      ? Z_DEFAULT_COMPRESSION
+		      : G__.compression_level);
 
     /* If there was an error initializing, return -1 */
     if (err != Z_OK) {

Modified: grass/trunk/lib/gis/gisinit.c
===================================================================
--- grass/trunk/lib/gis/gisinit.c	2014-07-23 19:11:04 UTC (rev 61379)
+++ grass/trunk/lib/gis/gisinit.c	2014-07-23 21:06:07 UTC (rev 61380)
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -105,6 +106,8 @@
 
 static int gisinit(void)
 {
+    char *zlib;
+
 #ifdef __MINGW32__
     _fmode = O_BINARY;
 #endif
@@ -114,6 +117,9 @@
     /* byte order */
     G__.little_endian = G_is_little_endian();
 
+    zlib = getenv("GRASS_ZLIB_LEVEL");
+    G__.compression_level = (zlib && *zlib && isdigit(*zlib)) ? atoi(zlib) : -1;
+
     initialized = 1;
 
     setlocale(LC_NUMERIC, "C");

Modified: grass/trunk/lib/init/variables.html
===================================================================
--- grass/trunk/lib/init/variables.html	2014-07-23 19:11:04 UTC (rev 61379)
+++ grass/trunk/lib/init/variables.html	2014-07-23 21:06:07 UTC (rev 61380)
@@ -161,13 +161,24 @@
     <key>, without the bracketing <string> tags.</dd>
 
   <dt>GRASS_INT_ZLIB</dt>
-  <dd>[libgis]<br> if the environment variable GRASS_INT_ZLIB exists,
+  <dd>[libraster]<br> if the environment variable GRASS_INT_ZLIB exists and has the value 0,
     new compressed <i>integer</i> (CELL type) raster maps will be compressed
-    using zlib instead of RLE compression. Such rasters will have a <tt>compressed</tt>
+    using RLE compression.
+    <br><br>
+    If the variable doesn't exist, or the value is non-zero, zlib compression
+    will be used instead. Such rasters will have a <tt>compressed</tt>
     value of 2 in the cellhd file.
     <br><br>
     Obviously, decompression is controlled by the
     raster's <tt>compressed</tt> value, not the environment variable.</dd>
+
+  <dt>GRASS_ZLIB_LEVEL</dt>
+  <dd>[libgis]<br> if the environment variable GRASS_ZLIB_LEVEL exists and its value can
+    be parsed as an integer, it determines the compression level used when new compressed
+    <i>integer</i> (CELL type) raster maps are compressed using zlib compression.
+    <br><br>
+    If the variable doesn't exist, or the value cannot be parsed as an
+    integer, zlib's default compression level will be used.</dd>
   
   <dt>GRASS_MESSAGE_FORMAT</dt>
   <dd>[various modules, wxGUI]<br>

Modified: grass/trunk/lib/raster/init.c
===================================================================
--- grass/trunk/lib/raster/init.c	2014-07-23 19:11:04 UTC (rev 61379)
+++ grass/trunk/lib/raster/init.c	2014-07-23 21:06:07 UTC (rev 61380)
@@ -77,6 +77,8 @@
 
 static int init(void)
 {
+    char *zlib;
+
     Rast__init_window();
 
     /* no histograms */
@@ -90,8 +92,10 @@
     R__.mask_fd = -1;
 
     R__.nbytes = sizeof(CELL);
-    R__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
 
+    zlib = getenv("GRASS_INT_ZLIB");
+    R__.compression_type = (!zlib || atoi(zlib)) ? 2 : 1;
+
     G_add_error_handler(Rast__error_handler, NULL);
 
     initialized = 1;



More information about the grass-commit mailing list