[GRASS-SVN] r61797 - in grass/branches/releasebranch_7_0: . lib/gis lib/init lib/raster raster/r.compress

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 4 21:27:41 PDT 2014


Author: neteler
Date: 2014-09-04 21:27:41 -0700 (Thu, 04 Sep 2014)
New Revision: 61797

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/lib/gis/G.h
   grass/branches/releasebranch_7_0/lib/gis/flate.c
   grass/branches/releasebranch_7_0/lib/gis/gisinit.c
   grass/branches/releasebranch_7_0/lib/init/variables.html
   grass/branches/releasebranch_7_0/lib/raster/init.c
   grass/branches/releasebranch_7_0/raster/r.compress/r.compress.html
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; libgis: -1 is a valid compression level (Z_DEFAULT_COMPRESSION) (backport from trunk, r61380 + r61420 + r61422 + r61500)


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:61764
   + /grass/trunk:61380,61420,61422,61500,61764

Modified: grass/branches/releasebranch_7_0/lib/gis/G.h
===================================================================
--- grass/branches/releasebranch_7_0/lib/gis/G.h	2014-09-05 04:24:55 UTC (rev 61796)
+++ grass/branches/releasebranch_7_0/lib/gis/G.h	2014-09-05 04:27:41 UTC (rev 61797)
@@ -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/branches/releasebranch_7_0/lib/gis/flate.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/gis/flate.c	2014-09-05 04:24:55 UTC (rev 61796)
+++ grass/branches/releasebranch_7_0/lib/gis/flate.c	2014-09-05 04:27:41 UTC (rev 61797)
@@ -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,10 +329,12 @@
     c_stream.next_out = buf;
 
     /* Initialize */
-    /* Compression levels 0 - 9 */
-    /* zlib default: Z_DEFAULT_COMPRESSION (-1), equivalent to 6 
+    /* Valid zlib compression levels -1 - 9 */
+    /* zlib default: Z_DEFAULT_COMPRESSION = -1, equivalent to 6 
      * as used here, 1 gives the best compromise between speed and compression */
-    err = deflateInit(&c_stream, 1);
+    err = deflateInit(&c_stream,
+                      (G__.compression_level < -1 || G__.compression_level > 9) 
+		      ? 1 : G__.compression_level);
 
     /* If there was an error initializing, return -1 */
     if (err != Z_OK) {

Modified: grass/branches/releasebranch_7_0/lib/gis/gisinit.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/gis/gisinit.c	2014-09-05 04:24:55 UTC (rev 61796)
+++ grass/branches/releasebranch_7_0/lib/gis/gisinit.c	2014-09-05 04:27:41 UTC (rev 61797)
@@ -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) : -2;
+
     initialized = 1;
 
     setlocale(LC_NUMERIC, "C");

Modified: grass/branches/releasebranch_7_0/lib/init/variables.html
===================================================================
--- grass/branches/releasebranch_7_0/lib/init/variables.html	2014-09-05 04:24:55 UTC (rev 61796)
+++ grass/branches/releasebranch_7_0/lib/init/variables.html	2014-09-05 04:27:41 UTC (rev 61797)
@@ -161,13 +161,25 @@
     <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
+    raster maps are compressed using zlib compression. This applies to all 
+    raster map types (CELL, FCELL, DCELL).
+    <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/branches/releasebranch_7_0/lib/raster/init.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/raster/init.c	2014-09-05 04:24:55 UTC (rev 61796)
+++ grass/branches/releasebranch_7_0/lib/raster/init.c	2014-09-05 04:27:41 UTC (rev 61797)
@@ -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;

Modified: grass/branches/releasebranch_7_0/raster/r.compress/r.compress.html
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.compress/r.compress.html	2014-09-05 04:24:55 UTC (rev 61796)
+++ grass/branches/releasebranch_7_0/raster/r.compress/r.compress.html	2014-09-05 04:27:41 UTC (rev 61797)
@@ -49,10 +49,10 @@
 Floating point (FCELL, DCELL) raster maps never use RLE compression;
 they are either compressed with ZLIB or uncompressed.
 <p>
-Integer (CELL) raster maps by default RLE compressed or may remain
+Integer (CELL) raster maps are by default ZLIB compressed or may remain
 uncompressed. If the environment variable <tt>GRASS_INT_ZLIB</tt>
-exists, newly generated compressed integer (CELL type) raster maps will
-be compressed using ZLIB instead of RLE compression. In the internal
+exists and has the value 0, newly generated compressed integer (CELL type) raster maps will
+be compressed using RLE compression instead of ZLIB. In the internal
 cellhd file, the value for "compressed" is 1 for RLE and 2 for ZLIB.
 <p>
 Obviously, decompression is controlled by the raster map's compression,



More information about the grass-commit mailing list