From d52335621b0cb612a9fc709b835bebd46e7bb7fc Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 6 Mar 2013 02:41:40 +0000 Subject: [PATCH] More pfm enhancements --- panda/src/grutil/pfmVizzer.cxx | 10 ++++++ panda/src/pnmimage/pfmFile.I | 50 +++++++++++++++++++++++++++ panda/src/pnmimage/pfmFile.cxx | 62 ++++++++++++++++++++++++++++++++++ panda/src/pnmimage/pfmFile.h | 8 +++++ 4 files changed, 130 insertions(+) diff --git a/panda/src/grutil/pfmVizzer.cxx b/panda/src/grutil/pfmVizzer.cxx index 44ab51cede..338479cc86 100644 --- a/panda/src/grutil/pfmVizzer.cxx +++ b/panda/src/grutil/pfmVizzer.cxx @@ -806,7 +806,17 @@ make_array_format(const VisColumns &vis_columns) const { break; case CT_vertex1: + num_components = 1; + numeric_type = GeomEnums::NT_float32; + contents = GeomEnums::C_point; + break; + case CT_vertex2: + num_components = 2; + numeric_type = GeomEnums::NT_float32; + contents = GeomEnums::C_point; + break; + case CT_vertex3: num_components = 3; numeric_type = GeomEnums::NT_float32; diff --git a/panda/src/pnmimage/pfmFile.I b/panda/src/pnmimage/pfmFile.I index b985cda877..7fc18a5528 100644 --- a/panda/src/pnmimage/pfmFile.I +++ b/panda/src/pnmimage/pfmFile.I @@ -548,3 +548,53 @@ void PfmFile:: swap_table(vector_float &table) { _table.swap(table); } + +//////////////////////////////////////////////////////////////////// +// Function: PfmFile::setup_sub_image +// Access: Private +// Description: Computes xmin, ymin, xmax, and ymax, based on the +// input parameters for copy_sub_image() and related +// methods. +//////////////////////////////////////////////////////////////////// +INLINE void PfmFile:: +setup_sub_image(const PfmFile ©, int &xto, int &yto, + int &xfrom, int &yfrom, int &x_size, int &y_size, + int &xmin, int &ymin, int &xmax, int &ymax) { + if (x_size < 0) { + x_size = copy.get_x_size() - xfrom; + } + if (y_size < 0) { + y_size = copy.get_y_size() - yfrom; + } + + if (xfrom < 0) { + xto += -xfrom; + x_size -= -xfrom; + xfrom = 0; + } + if (yfrom < 0) { + yto += -yfrom; + y_size -= -yfrom; + yfrom = 0; + } + + if (xto < 0) { + xfrom += -xto; + x_size -= -xto; + xto = 0; + } + if (yto < 0) { + yfrom += -yto; + y_size -= -yto; + yto = 0; + } + + x_size = min(x_size, copy.get_x_size() - xfrom); + y_size = min(y_size, copy.get_y_size() - yfrom); + + xmin = xto; + ymin = yto; + + xmax = min(xmin + x_size, get_x_size()); + ymax = min(ymin + y_size, get_y_size()); +} diff --git a/panda/src/pnmimage/pfmFile.cxx b/panda/src/pnmimage/pfmFile.cxx index 739108c0b5..7e13d21b22 100644 --- a/panda/src/pnmimage/pfmFile.cxx +++ b/panda/src/pnmimage/pfmFile.cxx @@ -1554,6 +1554,68 @@ compute_sample_point(LPoint3f &result, } } +//////////////////////////////////////////////////////////////////// +// Function: PfmFile::copy_sub_image +// Access: Published +// Description: Copies a rectangular area of another image into a +// rectangular area of this image. Both images must +// already have been initialized. The upper-left corner +// of the region in both images is specified, and the +// size of the area; if the size is omitted, it defaults +// to the entire other image, or the largest piece that +// will fit. +//////////////////////////////////////////////////////////////////// +void PfmFile:: +copy_sub_image(const PfmFile ©, int xto, int yto, + int xfrom, int yfrom, int x_size, int y_size) { + int xmin, ymin, xmax, ymax; + setup_sub_image(copy, xto, yto, xfrom, yfrom, x_size, y_size, + xmin, ymin, xmax, ymax); + + int x, y; + switch (_num_channels) { + case 1: + { + for (y = ymin; y < ymax; y++) { + for (x = xmin; x < xmax; x++) { + set_point1(x, y, copy.get_point1(x - xmin + xfrom, y - ymin + yfrom)); + } + } + } + break; + + case 2: + { + for (y = ymin; y < ymax; y++) { + for (x = xmin; x < xmax; x++) { + set_point2(x, y, copy.get_point2(x - xmin + xfrom, y - ymin + yfrom)); + } + } + } + break; + + case 3: + { + for (y = ymin; y < ymax; y++) { + for (x = xmin; x < xmax; x++) { + set_point(x, y, copy.get_point(x - xmin + xfrom, y - ymin + yfrom)); + } + } + } + break; + + case 4: + { + for (y = ymin; y < ymax; y++) { + for (x = xmin; x < xmax; x++) { + set_point4(x, y, copy.get_point4(x - xmin + xfrom, y - ymin + yfrom)); + } + } + } + break; + } +} + //////////////////////////////////////////////////////////////////// // Function: PfmFile::output // Access: Published diff --git a/panda/src/pnmimage/pfmFile.h b/panda/src/pnmimage/pfmFile.h index 08a2ac2c80..99f1fed955 100644 --- a/panda/src/pnmimage/pfmFile.h +++ b/panda/src/pnmimage/pfmFile.h @@ -118,6 +118,10 @@ PUBLISHED: void compute_sample_point(LPoint3f &result, PN_float32 x, PN_float32 y, PN_float32 sample_radius) const; + void copy_sub_image(const PfmFile ©, int xto, int yto, + int xfrom = 0, int yfrom = 0, + int x_size = -1, int y_size = -1); + void output(ostream &out) const; public: @@ -125,6 +129,10 @@ public: INLINE void swap_table(vector_float &table); private: + INLINE void setup_sub_image(const PfmFile ©, int &xto, int &yto, + int &xfrom, int &yfrom, int &x_size, int &y_size, + int &xmin, int &ymin, int &xmax, int &ymax); + void box_filter_region(PN_float32 &result, PN_float32 x0, PN_float32 y0, PN_float32 x1, PN_float32 y1) const; void box_filter_region(LPoint3f &result,