From 6f248198e7f015240ca16138498da40f18d22f37 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 20 Nov 2012 19:36:08 +0000 Subject: [PATCH] clip to bounds in make_displacement() --- panda/src/grutil/pfmVizzer.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/panda/src/grutil/pfmVizzer.cxx b/panda/src/grutil/pfmVizzer.cxx index e1f91be43d..b209c5b6bf 100644 --- a/panda/src/grutil/pfmVizzer.cxx +++ b/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);