[Scipy-svn] r2880 - trunk/Lib/ndimage/src

scipy-svn@scip... scipy-svn@scip...
Wed Mar 28 09:57:30 CDT 2007


Author: stefan
Date: 2007-03-28 09:57:22 -0500 (Wed, 28 Mar 2007)
New Revision: 2880

Modified:
   trunk/Lib/ndimage/src/ni_interpolation.c
Log:
ndimage: clip values according to the output type.


Modified: trunk/Lib/ndimage/src/ni_interpolation.c
===================================================================
--- trunk/Lib/ndimage/src/ni_interpolation.c	2007-03-28 14:46:04 UTC (rev 2879)
+++ trunk/Lib/ndimage/src/ni_interpolation.c	2007-03-28 14:57:22 UTC (rev 2880)
@@ -328,15 +328,19 @@
   *(_type*)_po = (_type)_t;             \
   break;
 
-#define CASE_INTERP_OUT_UINT(_po, _t, _type) \
+#define CASE_INTERP_OUT_UINT(_po, _t, _type, type_min, type_max) \
 case t ## _type:                             \
   _t = _t > 0 ? _t + 0.5 : 0;                \
+  _t = _t > type_max ? type_max : t;         \
+  _t = _t < type_min ? type_min : t;         \
   *(_type*)_po = (_type)_t;                  \
   break;
 
-#define CASE_INTERP_OUT_INT(_po, _t, _type) \
+#define CASE_INTERP_OUT_INT(_po, _t, _type, type_min, type_max) \
 case t ## _type:                            \
   _t = _t > 0 ? _t + 0.5 : _t - 0.5;        \
+  _t = _t > type_max ? type_max : t;        \
+  _t = _t < type_min ? type_min : t;        \
   *(_type*)_po = (_type)_t;                 \
   break;
 
@@ -602,16 +606,16 @@
     /* store output value: */
     switch (output->descr->type_num) {
       CASE_INTERP_OUT(po, t, Bool);
-      CASE_INTERP_OUT_UINT(po, t, UInt8);
-      CASE_INTERP_OUT_UINT(po, t, UInt16);
-      CASE_INTERP_OUT_UINT(po, t, UInt32);
+      CASE_INTERP_OUT_UINT(po, t, UInt8, 0, MAX_UINT8);
+      CASE_INTERP_OUT_UINT(po, t, UInt16, 0, MAX_UINT16);
+      CASE_INTERP_OUT_UINT(po, t, UInt32, 0, MAX_UINT32);
 #if HAS_UINT64
       CASE_INTERP_OUT_UINT(po, t, UInt64);
 #endif
-      CASE_INTERP_OUT_INT(po, t, Int8);
-      CASE_INTERP_OUT_INT(po, t, Int16);
-      CASE_INTERP_OUT_INT(po, t, Int32);
-      CASE_INTERP_OUT_INT(po, t, Int64);
+      CASE_INTERP_OUT_INT(po, t, Int8, MIN_INT8, MAX_INT8);
+      CASE_INTERP_OUT_INT(po, t, Int16, MIN_INT16, MAX_INT16);
+      CASE_INTERP_OUT_INT(po, t, Int32, MIN_INT32, MAX_INT32);
+      CASE_INTERP_OUT_INT(po, t, Int64, MIN_INT64, MAX_INT64);
       CASE_INTERP_OUT(po, t, Float32);
       CASE_INTERP_OUT(po, t, Float64);
     default:
@@ -896,16 +900,16 @@
     /* store output: */
     switch (output->descr->type_num) {
       CASE_INTERP_OUT(po, t, Bool);
-      CASE_INTERP_OUT_UINT(po, t, UInt8);
-      CASE_INTERP_OUT_UINT(po, t, UInt16);
-      CASE_INTERP_OUT_UINT(po, t, UInt32);
+      CASE_INTERP_OUT_UINT(po, t, UInt8, 0, MAX_UINT8);
+      CASE_INTERP_OUT_UINT(po, t, UInt16, 0, MAX_UINT16);
+      CASE_INTERP_OUT_UINT(po, t, UInt32, 0, MAX_UINT32);
 #if HAS_UINT64
-      CASE_INTERP_OUT_UINT(po, t, UInt64);
+      CASE_INTERP_OUT_UINT(po, t, UInt64, 0, MAX_UINT64);
 #endif
-      CASE_INTERP_OUT_INT(po, t, Int8);
-      CASE_INTERP_OUT_INT(po, t, Int16);
-      CASE_INTERP_OUT_INT(po, t, Int32);
-      CASE_INTERP_OUT_INT(po, t, Int64);
+      CASE_INTERP_OUT_INT(po, t, Int8, MIN_INT8, MAX_INT8);
+      CASE_INTERP_OUT_INT(po, t, Int16, MIN_INT16, MAX_INT16);
+      CASE_INTERP_OUT_INT(po, t, Int32, MIN_INT32, MAX_INT32);
+      CASE_INTERP_OUT_INT(po, t, Int64, MIN_INT64, MAX_INT64);
       CASE_INTERP_OUT(po, t, Float32);
       CASE_INTERP_OUT(po, t, Float64);
     default:



More information about the Scipy-svn mailing list