]> granicus.if.org Git - postgis/commitdiff
Added rt_pixtype_compare_clamped_values() for comparing two doubles in
authorBborie Park <bkpark at ucdavis.edu>
Wed, 25 Jul 2012 19:31:34 +0000 (19:31 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 25 Jul 2012 19:31:34 +0000 (19:31 +0000)
the context of a pixeltype.

git-svn-id: http://svn.osgeo.org/postgis/trunk@10127 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_core/rt_api.h

index f8ea315f5d09d409eb5625e73e1ec2b6c7868b7e..3b31d2de171c40ea92a7324b78b2d5e775a231f3 100644 (file)
@@ -1069,6 +1069,71 @@ rt_pixtype_get_min_value(rt_pixtype pixtype) {
        }
 }
 
+/**
+ * Returns 1 if clamped values are equal, 0 if not equal, -1 if error
+ *
+ * @param pixtype: the pixel type to clamp the provided values
+ * @param val: value to compare to reference value
+ * @param refval: reference value to be compared with
+ *
+ * @return 1 if clamped values are equal, 0 if not equal, -1 if error
+ */
+int rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double refval) {
+       int rtn = 0;
+
+       switch (pixtype) {
+               case PT_1BB:
+                       if (rt_util_clamp_to_1BB(val) == rt_util_clamp_to_1BB(refval))
+                               rtn = 1;
+                       break;
+               case PT_2BUI:
+                       if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(refval))
+                               rtn = 1;
+                       break;
+               case PT_4BUI:
+                       if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(refval))
+                               rtn = 1;
+                       break;
+               case PT_8BSI:
+                       if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(refval))
+                               rtn = 1;
+                       break;
+               case PT_8BUI:
+                       if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(refval))
+                               rtn = 1;
+                       break;
+               case PT_16BSI:
+                       if (rt_util_clamp_to_16BSI(val) == rt_util_clamp_to_16BSI(refval))
+                               rtn = 1;
+                       break;
+               case PT_16BUI:
+                       if (rt_util_clamp_to_16BUI(val) == rt_util_clamp_to_16BUI(refval))
+                               rtn = 1;
+                       break;
+               case PT_32BSI:
+                       if (rt_util_clamp_to_32BSI(val) == rt_util_clamp_to_32BSI(refval))
+                               rtn = 1;
+                       break;
+               case PT_32BUI:
+                       if (rt_util_clamp_to_32BUI(val) == rt_util_clamp_to_32BUI(refval))
+                               rtn = 1;
+                       break;
+               case PT_32BF:
+                       if (FLT_EQ(rt_util_clamp_to_32F(val), rt_util_clamp_to_32F(refval)))
+                               rtn = 1;
+                       break;
+               case PT_64BF:
+                       if (FLT_EQ(val, refval))
+                               rtn = 1;
+                       break;
+               default:
+                       rterror("rt_pixtype_compare_clamped_values: Unknown pixeltype %d", pixtype);
+                       rtn = -1;
+       }
+
+       return rtn;
+}
+
 /*- rt_pixel ----------------------------------------------------------*/
 
 /*
@@ -2641,63 +2706,21 @@ rt_band_clamped_value_is_nodata(rt_band band, double val) {
                return -1;
 
        /* value is exactly NODATA */
-       if (FLT_EQ(val, band->nodataval))
+       if (FLT_EQ(val, band->nodataval)) {
                return -1;
-
-       switch (band->pixtype) {
-               case PT_1BB:
-                       if (rt_util_clamp_to_1BB(val) == rt_util_clamp_to_1BB(band->nodataval))
-                               return 1;
-                       break;
-               case PT_2BUI:
-                       if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(band->nodataval))
-                               return 1;
-                       break;
-               case PT_4BUI:
-                       if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(band->nodataval))
-                               return 1;
-                       break;
-               case PT_8BSI:
-                       if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(band->nodataval))
-                               return 1;
-                       break;
-               case PT_8BUI:
-                       if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(band->nodataval))
-                               return 1;
-                       break;
-               case PT_16BSI:
-                       if (rt_util_clamp_to_16BSI(val) == rt_util_clamp_to_16BSI(band->nodataval))
-                               return 1;
-                       break;
-               case PT_16BUI:
-                       if (rt_util_clamp_to_16BUI(val) == rt_util_clamp_to_16BUI(band->nodataval))
-                               return 1;
-                       break;
-               case PT_32BSI:
-                       if (rt_util_clamp_to_32BSI(val) == rt_util_clamp_to_32BSI(band->nodataval))
-                               return 1;
-                       break;
-               case PT_32BUI:
-                       if (rt_util_clamp_to_32BUI(val) == rt_util_clamp_to_32BUI(band->nodataval))
-                               return 1;
-                       break;
-               case PT_32BF:
-                       if (FLT_EQ(rt_util_clamp_to_32F(val), rt_util_clamp_to_32F(band->nodataval)))
-                               return 1;
-                       break;
-               case PT_64BF:
-                       break;
-               default:
-                       rterror("rt_band_clamped_value_is_nodata: Unknown pixeltype %d", band->pixtype);
-                       return -1;
        }
 
-       return 0;
+       return rt_pixtype_compare_clamped_values(
+               band->pixtype,
+               val,
+               band->nodataval
+       );
 }
 
 /**
- * Correct value when clamped value is clamped NODATA value.  Correction
- * does NOT occur if unclamped value is exactly unclamped NODATA value.
+ * Correct value when clamped value is equal to clamped NODATA value.
+ * Correction does NOT occur if unclamped value is exactly unclamped
+ * NODATA value.
  * 
  * @param band: the band whose NODATA value will be used for comparison
  * @param val: the value to compare to the NODATA value and correct
index cec8752a7d0f80fce53237f2b7be08510374383c..144d8ec07fa2186e8a1b6af3ff94f2e2b8b5c4be 100644 (file)
@@ -325,6 +325,17 @@ rt_pixtype rt_pixtype_index_from_name(const char* pixname);
  */
 double rt_pixtype_get_min_value(rt_pixtype pixtype);
 
+/**
+ * Returns 1 if clamped values are equal, 0 if not equal, -1 if error
+ *
+ * @param pixtype: the pixel type to clamp the provided values
+ * @param val: value to compare to reference value
+ * @param refval: reference value to be compared with
+ *
+ * @return 1 if clamped values are equal, 0 if not equal, -1 if error
+ */
+int rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double refval);
+
 /*- rt_pixel ----------------------------------------------------------*/
 
 /*
@@ -637,13 +648,14 @@ int rt_band_check_is_nodata(rt_band band);
  *
  * @return 1 if clamped value is clamped NODATA
  *         0 if clamped value is NOT clamped NODATA
- *         -1 otherwise
+ *         -1 if error
  */
 int rt_band_clamped_value_is_nodata(rt_band band, double val);
 
 /**
- * Correct value when clamped value is clamped NODATA value.  Correction
- * does NOT occur if unclamped value is exactly unclamped NODATA value.
+ * Correct value when clamped value is equal to clamped NODATA value.
+ * Correction does NOT occur if unclamped value is exactly unclamped
+ * NODATA value.
  * 
  * @param band: the band whose NODATA value will be used for comparison
  * @param val: the value to compare to the NODATA value and correct