More pfm enhancements

This commit is contained in:
David Rose 2013-03-06 02:41:40 +00:00
parent a5e6aca66d
commit d52335621b
4 changed files with 130 additions and 0 deletions

View File

@ -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;

View File

@ -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 &copy, 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());
}

View File

@ -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 &copy, 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

View File

@ -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 &copy, 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 &copy, 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,