From 7299a150c3b4855da46014420fb7f27c81ab24f7 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 2 Nov 2012 01:14:51 +0000 Subject: [PATCH] raise precision of 16-bit image processing --- panda/src/grutil/pfmVizzer.cxx | 28 ++++++++++++------------- panda/src/grutil/pfmVizzer.h | 6 +++--- panda/src/pnmimage/pnm-image-filter.cxx | 4 ++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/panda/src/grutil/pfmVizzer.cxx b/panda/src/grutil/pfmVizzer.cxx index 9ba8d32a35..a9193614e6 100644 --- a/panda/src/grutil/pfmVizzer.cxx +++ b/panda/src/grutil/pfmVizzer.cxx @@ -312,12 +312,12 @@ generate_vis_mesh(MeshFace face) const { // map. This can be passed to make_displacement(); see // that function for more information. //////////////////////////////////////////////////////////////////// -int PfmVizzer:: +double PfmVizzer:: calc_max_u_displacement() const { int x_size = _pfm.get_x_size(); int y_size = _pfm.get_y_size(); - int max_u = 0; + double max_u = 0; for (int yi = 0; yi < y_size; ++yi) { for (int xi = 0; xi < x_size; ++xi) { @@ -326,10 +326,9 @@ calc_max_u_displacement() const { } const LPoint3f &point = _pfm.get_point(xi, yi); - double nxi = point[0] * (double)(x_size - 1) + 0.5; - double nyi = point[1] * (double)(y_size - 1) + 0.5; + double nxi = point[0] * (double)(x_size - 1); - max_u = max(max_u, (int)cceil(cabs(nxi - (double)xi))); + max_u = max(max_u, cabs(nxi - (double)xi)); } } @@ -344,12 +343,12 @@ calc_max_u_displacement() const { // map. This can be passed to make_displacement(); see // that function for more information. //////////////////////////////////////////////////////////////////// -int PfmVizzer:: +double PfmVizzer:: calc_max_v_displacement() const { int x_size = _pfm.get_x_size(); int y_size = _pfm.get_y_size(); - int max_v = 0; + double max_v = 0; for (int yi = 0; yi < y_size; ++yi) { for (int xi = 0; xi < x_size; ++xi) { @@ -358,9 +357,9 @@ calc_max_v_displacement() const { } const LPoint3f &point = _pfm.get_point(xi, yi); - double nyi = point[1] * (double)(y_size - 1) + 0.5; + double nyi = point[1] * (double)(y_size - 1); - max_v = max(max_v, (int)cceil(cabs(nyi - (double)yi))); + max_v = max(max_v, cabs(nyi - (double)yi)); } } @@ -386,13 +385,12 @@ calc_max_v_displacement() const { // for max_u and max_v. //////////////////////////////////////////////////////////////////// void PfmVizzer:: -make_displacement(PNMImage &result, int max_u, int max_v) const { +make_displacement(PNMImage &result, double max_u, double max_v) const { int x_size = _pfm.get_x_size(); int y_size = _pfm.get_y_size(); result.clear(x_size, y_size, 3, PNM_MAXMAXVAL); result.fill(0.5); - for (int yi = 0; yi < y_size; ++yi) { for (int xi = 0; xi < x_size; ++xi) { if (!_pfm.has_point(xi, yi)) { @@ -400,11 +398,11 @@ make_displacement(PNMImage &result, int max_u, int max_v) const { } const LPoint3f &point = _pfm.get_point(xi, yi); - double nxi = point[0] * (double)(x_size - 1) + 0.5; - double nyi = point[1] * (double)(y_size - 1) + 0.5; + double nxi = point[0] * (double)(x_size - 1); + double nyi = point[1] * (double)(y_size - 1); - double u_shift = (nxi - (double)xi) / (double)max_u; - double v_shift = (nyi - (double)yi) / (double)max_v; + double u_shift = (nxi - (double)xi) / max_u; + double v_shift = (nyi - (double)yi) / max_v; result.set_red(xi, yi, u_shift * 0.5 + 0.5); result.set_green(xi, yi, v_shift * 0.5 + 0.5); diff --git a/panda/src/grutil/pfmVizzer.h b/panda/src/grutil/pfmVizzer.h index 0c80658a20..e33af79c5b 100644 --- a/panda/src/grutil/pfmVizzer.h +++ b/panda/src/grutil/pfmVizzer.h @@ -74,9 +74,9 @@ PUBLISHED: }; BLOCKING NodePath generate_vis_mesh(MeshFace face = MF_front) const; - BLOCKING int calc_max_u_displacement() const; - BLOCKING int calc_max_v_displacement() const; - BLOCKING void make_displacement(PNMImage &result, int max_u, int max_v) const; + BLOCKING double calc_max_u_displacement() const; + BLOCKING double calc_max_v_displacement() const; + BLOCKING void make_displacement(PNMImage &result, double max_u, double max_v) const; private: void make_vis_mesh_geom(GeomNode *gnode, bool inverted) const; diff --git a/panda/src/pnmimage/pnm-image-filter.cxx b/panda/src/pnmimage/pnm-image-filter.cxx index d08906f30e..a54a936595 100644 --- a/panda/src/pnmimage/pnm-image-filter.cxx +++ b/panda/src/pnmimage/pnm-image-filter.cxx @@ -62,19 +62,19 @@ // are usually 8 bits per channel), it doesn't cost any precision at all to // use shorts, and not very much to use chars. -/* // To use double-precision floating point, 8 bytes: (strictly for the neurotic) typedef double WorkType; typedef double StoreType; static const WorkType source_max = 1.0; static const WorkType filter_max = 1.0; -*/ +/* // To use single-precision floating point, 4 bytes: typedef double WorkType; typedef float StoreType; static const WorkType source_max = 1.0; static const WorkType filter_max = 1.0; +*/ /* // To use 16-bit integer arithmetic, 2 bytes: