Parcourir la source

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, https://trac.osgeo.org/grass/changeset/61380 + https://trac.osgeo.org/grass/changeset/61420 + https://trac.osgeo.org/grass/changeset/61422 + https://trac.osgeo.org/grass/changeset/61500)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@61797 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler il y a 10 ans
Parent
commit
fd25af5813
6 fichiers modifiés avec 36 ajouts et 9 suppressions
  1. 1 0
      lib/gis/G.h
  2. 7 3
      lib/gis/flate.c
  3. 6 0
      lib/gis/gisinit.c
  4. 14 2
      lib/init/variables.html
  5. 5 1
      lib/raster/init.c
  6. 3 3
      raster/r.compress/r.compress.html

+ 1 - 0
lib/gis/G.h

@@ -6,6 +6,7 @@ struct G__			/*  Structure of library globals */
     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 */

+ 7 - 3
lib/gis/flate.c

@@ -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 @@ G_zlib_compress(const unsigned char *src, int src_sz, unsigned char *dst,
     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) {

+ 6 - 0
lib/gis/gisinit.c

@@ -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 @@ void G__check_gisinit(void)
 
 static int gisinit(void)
 {
+    char *zlib;
+
 #ifdef __MINGW32__
     _fmode = O_BINARY;
 #endif
@@ -114,6 +117,9 @@ static int gisinit(void)
     /* 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");

+ 14 - 2
lib/init/variables.html

@@ -161,13 +161,25 @@ PERMANENT
     &lt;key&gt;, without the bracketing &lt;string&gt; 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>

+ 5 - 1
lib/raster/init.c

@@ -77,6 +77,8 @@ void Rast__error_handler(void *p)
 
 static int init(void)
 {
+    char *zlib;
+
     Rast__init_window();
 
     /* no histograms */
@@ -90,7 +92,9 @@ static int init(void)
     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);
 

+ 3 - 3
raster/r.compress/r.compress.html

@@ -49,10 +49,10 @@ the user the map is already (de)compressed and exits.
 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,