From 7b9283b824853aa040dfd263eb418c0bf24beb07 Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Mon, 23 Jul 2018 00:17:50 +0000 Subject: [PATCH] Fix raster regression on Raspberry Pi. A signed NODATA value was assigned to unsigned variable. On Intel that was reversible, on ARM and PPC it replaced all negatives with 0. Thanks to Alina Dolgikh for supporting me: https://www.patreon.com/komzpa Closes #4102 Closes https://github.com/postgis/postgis/pull/276 git-svn-id: http://svn.osgeo.org/postgis/trunk@16661 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_pixel.c | 10 +++++----- raster/rt_core/rt_serialize.c | 14 ++++++++++++-- raster/rt_core/rt_wkb.c | 14 ++++++++++++-- raster/test/regress/tickets.sql | 4 ++++ raster/test/regress/tickets_expected | 2 ++ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/raster/rt_core/rt_pixel.c b/raster/rt_core/rt_pixel.c index 68c907a12..382adda30 100644 --- a/raster/rt_core/rt_pixel.c +++ b/raster/rt_core/rt_pixel.c @@ -151,13 +151,13 @@ rt_pixtype_get_min_value(rt_pixtype pixtype) { return (double) rt_util_clamp_to_1BB((double) CHAR_MIN); } case PT_2BUI: { - return (double) rt_util_clamp_to_2BUI((double) CHAR_MIN); + return 0; } case PT_4BUI: { - return (double) rt_util_clamp_to_4BUI((double) CHAR_MIN); + return 0; } case PT_8BUI: { - return (double) rt_util_clamp_to_8BUI((double) CHAR_MIN); + return 0; } case PT_8BSI: { return (double) rt_util_clamp_to_8BSI((double) SCHAR_MIN); @@ -166,13 +166,13 @@ rt_pixtype_get_min_value(rt_pixtype pixtype) { return (double) rt_util_clamp_to_16BSI((double) SHRT_MIN); } case PT_16BUI: { - return (double) rt_util_clamp_to_16BUI((double) SHRT_MIN); + return 0; } case PT_32BSI: { return (double) rt_util_clamp_to_32BSI((double) INT_MIN); } case PT_32BUI: { - return (double) rt_util_clamp_to_32BUI((double) INT_MIN); + return 0; } case PT_32BF: { return (double) -FLT_MAX; diff --git a/raster/rt_core/rt_serialize.c b/raster/rt_core/rt_serialize.c index eb5a87715..8d2c52070 100644 --- a/raster/rt_core/rt_serialize.c +++ b/raster/rt_core/rt_serialize.c @@ -629,14 +629,24 @@ rt_raster_serialize(rt_raster raster) { ptr += 1; break; } - case PT_16BSI: + case PT_16BSI: { + int16_t v = band->nodataval; + memcpy(ptr, &v, 2); + ptr += 2; + break; + } case PT_16BUI: { uint16_t v = band->nodataval; memcpy(ptr, &v, 2); ptr += 2; break; } - case PT_32BSI: + case PT_32BSI: { + int32_t v = band->nodataval; + memcpy(ptr, &v, 4); + ptr += 4; + break; + } case PT_32BUI: { uint32_t v = band->nodataval; memcpy(ptr, &v, 4); diff --git a/raster/rt_core/rt_wkb.c b/raster/rt_core/rt_wkb.c index 9c9da3fe9..98cbc8359 100644 --- a/raster/rt_core/rt_wkb.c +++ b/raster/rt_core/rt_wkb.c @@ -592,14 +592,24 @@ rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize) { ptr += 1; break; } - case PT_16BSI: + case PT_16BSI: { + int16_t v = band->nodataval; + memcpy(ptr, &v, 2); + ptr += 2; + break; + } case PT_16BUI: { uint16_t v = band->nodataval; memcpy(ptr, &v, 2); ptr += 2; break; } - case PT_32BSI: + case PT_32BSI: { + int32_t v = band->nodataval; + memcpy(ptr, &v, 4); + ptr += 4; + break; + } case PT_32BUI: { uint32_t v = band->nodataval; memcpy(ptr, &v, 4); diff --git a/raster/test/regress/tickets.sql b/raster/test/regress/tickets.sql index 4a62cb3b3..dd4fe7af8 100644 --- a/raster/test/regress/tickets.sql +++ b/raster/test/regress/tickets.sql @@ -117,3 +117,7 @@ SET client_min_messages TO DEFAULT; #3055 ST_Clip() on a raster without band crashes the server ******************************************************************************/ SELECT ST_SummaryStats(ST_Clip(ST_MakeEmptyRaster(42, 42, 0, 0, 1.0, 1.0, 0, 0, 4269), ST_MakeEnvelope(0, 0, 20, 20, 4269))); + +-- #4102 negative nodata values don't apply on Raspberry Pi +SELECT '#4102.1', ST_BandNoDataValue(ST_AddBand(ST_MakeEmptyRaster(2, 2, 0, 0, 1, -1, 0, 0, 0), 1, '16BSI', 0, -10), 1) AS rast; +SELECT '#4102.2', ST_BandNoDataValue(ST_AddBand(ST_MakeEmptyRaster(2, 2, 0, 0, 1, -1, 0, 0, 0), 1, '32BSI', 0, -10), 1) AS rast; diff --git a/raster/test/regress/tickets_expected b/raster/test/regress/tickets_expected index de6373b22..1b1d14ab3 100644 --- a/raster/test/regress/tickets_expected +++ b/raster/test/regress/tickets_expected @@ -14,3 +14,5 @@ test_raster_scale_small|rast||1 ERROR: new row for relation "test_raster_scale_small" violates check constraint "enforce_scaley_rast" NOTICE: Input raster is empty or has no bands. Returning empty raster NOTICE: Invalid band index (must use 1-based). Returning NULL +#4102.1|-10 +#4102.2|-10 -- 2.40.0