Browse Source

clip to bounds in make_displacement()

David Rose 13 years ago
parent
commit
6f248198e7
1 changed files with 8 additions and 2 deletions
  1. 8 2
      panda/src/grutil/pfmVizzer.cxx

+ 8 - 2
panda/src/grutil/pfmVizzer.cxx

@@ -421,7 +421,10 @@ make_displacement(PNMImage &result, double max_u, double max_v) const {
 
       // We use the blue channel to mark holes, so we can fill them in
       // later.
-      result.set_xel_val(xi, yi, u_val, v_val, 0);
+      result.set_xel_val(xi, yi, 
+                         min(max(u_val, 0), PNM_MAXMAXVAL), 
+                         min(max(v_val, 0), PNM_MAXMAXVAL), 
+                         0);
     }
   }
 
@@ -483,7 +486,10 @@ r_fill_displacement(PNMImage &result, int xi, int yi,
     double y_shift = (nyi - (double)yi);
     int u_val = midval + (int)cfloor(x_shift * u_scale + 0.5);
     int v_val = midval + (int)cfloor(y_shift * v_scale + 0.5);
-    result.set_xel_val(xi, yi, u_val, v_val, distance);
+    result.set_xel_val(xi, yi, 
+                       min(max(u_val, 0), PNM_MAXMAXVAL), 
+                       min(max(v_val, 0), PNM_MAXMAXVAL), 
+                       min(distance, PNM_MAXMAXVAL));
 
     r_fill_displacement(result, xi - 1, yi, nxi, nyi, u_scale, v_scale, distance + 1);
     r_fill_displacement(result, xi + 1, yi, nxi, nyi, u_scale, v_scale, distance + 1);