From: Bborie Park Date: Thu, 5 Jan 2012 21:18:56 +0000 (+0000) Subject: Added shortcut mechanism for copying data in rt_raster_from_gdal_dataset() when the... X-Git-Tag: 2.0.0alpha1~191 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e75260f5767c83a450ebc2b6de6dab79fb5c147;p=postgis Added shortcut mechanism for copying data in rt_raster_from_gdal_dataset() when the natural block width is the raster width. Enhanced testing in testapi.c. git-svn-id: http://svn.osgeo.org/postgis/trunk@8684 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index a12a688fc..2e1a2d73b 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -7032,14 +7032,24 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) { return NULL; } - ptr = values; - for (iY = 0; iY < nYValid; iY++) { + /* if block width is same as raster width, shortcut */ + if (nXBlocks == 1 && nYBlockSize > 1 && nXValid == width) { + x = 0; + y = nYBlockSize * iYBlock; + + RASTER_DEBUGF(4, "Setting set of pixel lines at (%d, %d) for %d pixels", x, y, nXValid * nYValid); + rt_band_set_pixel_line(band, x, y, values, nXValid * nYValid); + } + else { + ptr = values; x = nXBlockSize * iXBlock; - y = iY + (nYBlockSize * iYBlock); + for (iY = 0; iY < nYValid; iY++) { + y = iY + (nYBlockSize * iYBlock); - RASTER_DEBUGF(4, "Setting pixel line at (%d, %d) for %d pixels", x, y, nXValid); - rt_band_set_pixel_line(band, x, y, ptr, nXValid); - ptr += (nXValid * ptlen); + RASTER_DEBUGF(4, "Setting pixel line at (%d, %d) for %d pixels", x, y, nXValid); + rt_band_set_pixel_line(band, x, y, ptr, nXValid); + ptr += (nXValid * ptlen); + } } } } diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index fd5228047..56a6e61f8 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -1430,10 +1430,11 @@ static void testGDALToRaster() { rt_raster raster; rt_raster rast; rt_band band; + const uint32_t xmax = 100; + const uint32_t ymax = 100; uint32_t x; - uint32_t xmax = 100; uint32_t y; - uint32_t ymax = 100; + double values[xmax][ymax]; int rtn = 0; double value; @@ -1448,7 +1449,8 @@ static void testGDALToRaster() { for (x = 0; x < xmax; x++) { for (y = 0; y < ymax; y++) { - rtn = rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1)); + values[x][y] = (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1); + rtn = rt_band_set_pixel(band, x, y, values[x][y]); CHECK((rtn != -1)); } } @@ -1466,17 +1468,13 @@ static void testGDALToRaster() { band = rt_raster_get_band(rast, 0); CHECK(band); - rtn = rt_band_get_pixel(band, 0, 3, &value); - CHECK((rtn != -1)); - CHECK(FLT_EQ(value, 0.75)); - - rtn = rt_band_get_pixel(band, 99, 0, &value); - CHECK((rtn != -1)); - CHECK(FLT_EQ(value, 1.98)); - - rtn = rt_band_get_pixel(band, 95, 4, &value); - CHECK((rtn != -1)); - CHECK(FLT_EQ(value, 9.54)); + for (x = 0; x < xmax; x++) { + for (y = 0; y < ymax; y++) { + rtn = rt_band_get_pixel(band, x, y, &value); + CHECK((rtn != -1)); + CHECK(FLT_EQ(value, values[x][y])); + } + } GDALClose(gdds); GDALDeregisterDriver(gddrv);