]> granicus.if.org Git - postgis/commitdiff
Make sure new bands when added using ST_AddBand are correctly clamping NODATA values...
authorBborie Park <bkpark at ucdavis.edu>
Mon, 6 Feb 2012 23:14:21 +0000 (23:14 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Mon, 6 Feb 2012 23:14:21 +0000 (23:14 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9055 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c

index 6d1ab75924e73903bb7936ff27b34582dcd2100d..36a7f11afa4ff4a97269dd8f3fbac1932f820eda 100644 (file)
@@ -981,12 +981,18 @@ rt_band_new_inline(
        band->width = width;
        band->height = height;
        band->hasnodata = hasnodata;
-       band->nodataval = nodataval;
        band->data.mem = data;
        band->ownsData = 0;
        band->isnodata = FALSE;
        band->raster = NULL;
 
+       /* properly set nodataval as it may need to be constrained to the data type */
+       if (hasnodata && rt_band_set_nodata(band, nodataval) < 0) {
+               rterror("rt_band_new_inline: Unable to set NODATA value");
+               rtdealloc(band);
+               return NULL;
+       }
+
        return band;
 }
 
@@ -1035,10 +1041,16 @@ rt_band_new_offline(
        band->width = width;
        band->height = height;
        band->hasnodata = hasnodata;
-       band->nodataval = nodataval;
        band->isnodata = FALSE;
        band->raster = NULL;
 
+       /* properly set nodataval as it may need to be constrained to the data type */
+       if (hasnodata && rt_band_set_nodata(band, nodataval) < 0) {
+               rterror("rt_band_new_offline: Unable to set NODATA value");
+               rtdealloc(band);
+               return NULL;
+       }
+
        /* XXX QUESTION (jorgearevalo): What does exactly ownsData mean?? I think that
         * ownsData = 0 ==> the memory for band->data is externally owned
         * ownsData = 1 ==> the memory for band->data is internally owned
@@ -1628,7 +1640,7 @@ rt_band_set_pixel_line(
 
        /* make sure len of values to copy don't exceed end of data */
        if (len > (band->width * band->height) - offset) {
-               rterror("rt_band_set_pixel_line: Unable to apply pixel values as values length exceeds the ");
+               rterror("rt_band_set_pixel_line: Unable to apply pixels as values length exceeds end of data");
                return 0;
        }