Explorar el Código

rasterlib: more tests for raster compression

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67296 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz hace 9 años
padre
commit
b90f709936
Se han modificado 2 ficheros con 24 adiciones y 8 borrados
  1. 18 5
      lib/raster/init.c
  2. 6 3
      lib/raster/open.c

+ 18 - 5
lib/raster/init.c

@@ -77,7 +77,7 @@ void Rast__error_handler(void *p)
 
 static int init(void)
 {
-    char *zlib, *nulls, *ctype;
+    char *zlib, *nulls, *cname;
 
     Rast__init_window();
 
@@ -96,16 +96,29 @@ static int init(void)
     zlib = getenv("GRASS_INT_ZLIB");
     R__.compression_type = (!zlib || atoi(zlib)) ? 2 : 1;
 
-    ctype = getenv("GRASS_COMPRESSOR");
+    cname = getenv("GRASS_COMPRESSOR");
     /* 1: RLE
      * 2: ZLIB (DEFLATE)
      * 3: LZ4
      * 4: BZIP2 */
-    if (ctype) {
+    if (cname) {
 	/* ask gislib */
-	R__.compression_type = G_get_compressor(ctype);
-	if (R__.compression_type < 1)
+	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);
+	    }
+	    if (R__.compression_type == 0) {
+		G_warning(_("No compression is not supported for GRASS raster maps, using default ZLIB"));
+	    }
 	    R__.compression_type = 2; /* default to ZLIB */
+	}
+	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 */
+	}
     }
 
     nulls = getenv("GRASS_COMPRESS_NULLS");

+ 6 - 3
lib/raster/open.c

@@ -230,7 +230,10 @@ int Rast__open_old(const char *name, const char *mapset)
 	if (cellhd.compressed == 1)
 	    cellhd.compressed = 2;
     }
-    /* TODO: test if compressor type is supported */
+    /* test if compressor type is supported */
+    if (!G_check_compressor(cellhd.compressed)) {
+	G_fatal_error(_("Compression with %s is not supported"), G_compressor_name(cellhd.compressed));
+    }
 
     if (cellhd.proj != R__.rd_window.proj)
 	G_fatal_error(_("Raster map <%s> is in different projection than current region. "
@@ -648,8 +651,8 @@ static int open_raster_new(const char *name, int open_mode,
      *   allocate space to hold the row address array
      */
     fcb->cellhd = R__.wr_window;
-
-    /* TODO: test if compressor type is supported */
+    
+    /* change open_mode to OPEN_NEW_UNCOMPRESSED if R__.compression_type == 0 ? */
 
     if (open_mode == OPEN_NEW_COMPRESSED && fcb->map_type == CELL_TYPE) {
 	fcb->row_ptr = G_calloc(fcb->cellhd.rows + 1, sizeof(off_t));