From 96720d55257b6a26eb1e3d5f46396a6936e2174b Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Mon, 6 Feb 2012 23:14:21 +0000 Subject: [PATCH] Make sure new bands when added using ST_AddBand are correctly clamping NODATA values. Ticket is #1546. git-svn-id: http://svn.osgeo.org/postgis/trunk@9055 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_api.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 6d1ab7592..36a7f11af 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -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; } -- 2.50.0