]> granicus.if.org Git - postgis/commitdiff
Fix raster regression on Raspberry Pi.
authorDarafei Praliaskouski <me@komzpa.net>
Mon, 23 Jul 2018 00:17:50 +0000 (00:17 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Mon, 23 Jul 2018 00:17:50 +0000 (00:17 +0000)
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
raster/rt_core/rt_serialize.c
raster/rt_core/rt_wkb.c
raster/test/regress/tickets.sql
raster/test/regress/tickets_expected

index 68c907a1299cba98f1dfa9b659387d19187e3b93..382adda307fd801a3cf48233e386a645d1d5a77d 100644 (file)
@@ -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;
index eb5a87715dd9f9ae2ea0589e05863d8df361e4f4..8d2c520707dfaae0923da73b2e3df6476aa820b1 100644 (file)
@@ -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);
index 9c9da3fe9cb49044b0f15e5da7381a0094cf7a08..98cbc8359e5dbfa35dfe2421041abffd66b818ea 100644 (file)
@@ -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);
index 4a62cb3b320f2b514c196c2c2e035675a1d1b916..dd4fe7af8933301b3628240c30c36b0a084afc87 100644 (file)
@@ -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;
index de6373b22e03f438c4be8be96375a906f1118b68..1b1d14ab3c0e4743730871f01cda49fcda38baa2 100644 (file)
@@ -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