[GRASS-SVN] r71891 - grass/trunk/lib/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 4 10:18:02 PST 2017


Author: mmetz
Date: 2017-12-04 10:18:02 -0800 (Mon, 04 Dec 2017)
New Revision: 71891

Modified:
   grass/trunk/lib/raster/init.c
   grass/trunk/lib/raster/put_row.c
Log:
libraster: update for ZSTD,  use new G_compress_bound()

Modified: grass/trunk/lib/raster/init.c
===================================================================
--- grass/trunk/lib/raster/init.c	2017-12-04 18:17:17 UTC (rev 71890)
+++ grass/trunk/lib/raster/init.c	2017-12-04 18:18:02 UTC (rev 71891)
@@ -93,32 +93,37 @@
 
     R__.nbytes = sizeof(CELL);
 
-    zlib = getenv("GRASS_INT_ZLIB");
-    R__.compression_type = (!zlib || atoi(zlib)) ? 2 : 1;
+    R__.compression_type = G_default_compressor();
 
     cname = getenv("GRASS_COMPRESSOR");
     /* 1: RLE
      * 2: ZLIB (DEFLATE)
      * 3: LZ4
-     * 4: BZIP2 */
-    if (cname) {
+     * 4: BZIP2
+     * 5: ZSTD */
+    if (cname && *cname) {
 	/* ask gislib */
 	R__.compression_type = G_compressor_number(cname);
 	if (R__.compression_type < 1) {
 	    if (R__.compression_type < 0) {
-		G_warning(_("Unknown compression method <%s>, using default ZLIB"),
-		    cname);
+		G_warning(_("Unknown compression method <%s>, using default %s"),
+		    cname, G_compressor_name(G_default_compressor()));
 	    }
 	    if (R__.compression_type == 0) {
-		G_warning(_("No compression is not supported for GRASS raster maps, using default ZLIB"));
+		G_warning(_("No compression is not supported for GRASS raster maps, using default %s"),
+		          G_compressor_name(G_default_compressor()));
 	    }
-	    R__.compression_type = 2; /* default to ZLIB */
+	    /* use default */
+	    R__.compression_type = G_default_compressor();
 	}
 	if (G_check_compressor(R__.compression_type) != 1) {
-	    G_warning(_("This GRASS version does not support %s compression, using default ZLIB"),
-		cname);
-	    R__.compression_type = 2; /* default to ZLIB */
+	    G_warning(_("This GRASS version does not support %s compression, using default %s"),
+		cname, G_compressor_name(G_default_compressor()));
+	    /* use default */
+	    R__.compression_type = G_default_compressor();
 	}
+	G_debug(1, "Using %s compression",
+	           G_compressor_name(R__.compression_type));
     }
 
     nulls = getenv("GRASS_COMPRESS_NULLS");

Modified: grass/trunk/lib/raster/put_row.c
===================================================================
--- grass/trunk/lib/raster/put_row.c	2017-12-04 18:17:17 UTC (rev 71890)
+++ grass/trunk/lib/raster/put_row.c	2017-12-04 18:18:02 UTC (rev 71891)
@@ -354,7 +354,7 @@
     if (compressed) {
 	int nbytes = count_bytes(wk, n, len);
 	unsigned char *compressed_buf;
-	int total;
+	int total, cmax;
 
 	if (fcb->nbytes < nbytes)
 	    fcb->nbytes = nbytes;
@@ -364,7 +364,12 @@
 	    trim_bytes(wk, n, len, len - nbytes);
 
 	total = nbytes * n;
-	compressed_buf = G_malloc(total + 1);
+	/* get upper bound of compressed size */
+	if (fcb->cellhd.compressed == 1)
+	    cmax = total;
+	else
+	    cmax = G_compress_bound(total, fcb->cellhd.compressed);
+	compressed_buf = G_malloc(cmax + 1);
 
 	compressed_buf[0] = work_buf[0] = nbytes;
 
@@ -372,7 +377,7 @@
 	if (fcb->cellhd.compressed == 1)
 	    nwrite = rle_compress(compressed_buf + 1, work_buf + 1, n, nbytes);
 	else {
-	    nwrite = G_compress(work_buf + 1, total, compressed_buf + 1, total,
+	    nwrite = G_compress(work_buf + 1, total, compressed_buf + 1, cmax,
 	                        fcb->cellhd.compressed);
 	}
 
@@ -500,13 +505,16 @@
     struct fileinfo *fcb = &R__.fileinfo[fd];
     unsigned char *compressed_buf;
     ssize_t nwrite;
+    size_t cmax;
 
     fcb->null_row_ptr[row] = lseek(fcb->null_fd, 0L, SEEK_CUR);
 
-    compressed_buf = G_malloc(size + 1);
+    /* get upper bound of compressed size */
+    cmax = G_compress_bound(size, 3);
+    compressed_buf = G_malloc(cmax);
 
     /* compress null bits file with LZ4, see lib/gis/compress.h */
-    nwrite = G_lz4_compress(flags, size, compressed_buf, size);
+    nwrite = G_compress(flags, size, compressed_buf, cmax, 3);
 
     if (nwrite > 0 && nwrite < size) {
 	if (write(fcb->null_fd, compressed_buf, nwrite) != nwrite)



More information about the grass-commit mailing list