PfmFile::add_sub_image(), mult_sub_image()
This commit is contained in:
parent
7bce2d6124
commit
5dad10cf78
|
|
@ -1899,7 +1899,9 @@ copy_sub_image(const PfmFile ©, int xto, int yto,
|
|||
{
|
||||
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));
|
||||
if (copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point1(x, y, copy.get_point1(x - xmin + xfrom, y - ymin + yfrom));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1909,7 +1911,9 @@ copy_sub_image(const PfmFile ©, int xto, int yto,
|
|||
{
|
||||
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));
|
||||
if (copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point2(x, y, copy.get_point2(x - xmin + xfrom, y - ymin + yfrom));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1919,7 +1923,9 @@ copy_sub_image(const PfmFile ©, int xto, int yto,
|
|||
{
|
||||
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));
|
||||
if (copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point(x, y, copy.get_point(x - xmin + xfrom, y - ymin + yfrom));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1929,7 +1935,9 @@ copy_sub_image(const PfmFile ©, int xto, int yto,
|
|||
{
|
||||
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));
|
||||
if (copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point4(x, y, copy.get_point4(x - xmin + xfrom, y - ymin + yfrom));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1937,6 +1945,206 @@ copy_sub_image(const PfmFile ©, int xto, int yto,
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PfmFile::add_sub_image
|
||||
// Access: Published
|
||||
// Description: Behaves like copy_sub_image(), except the copy pixels
|
||||
// are added to the pixels of the destination, after
|
||||
// scaling by the specified pixel_scale.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PfmFile::
|
||||
add_sub_image(const PfmFile ©, int xto, int yto,
|
||||
int xfrom, int yfrom, int x_size, int y_size,
|
||||
double pixel_scale) {
|
||||
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++) {
|
||||
if (has_point(x, y) && copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point1(x, y, get_point1(x, y) + copy.get_point1(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
if (has_point(x, y) && copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point2(x, y, get_point2(x, y) + copy.get_point2(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
if (has_point(x, y) && copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point3(x, y, get_point3(x, y) + copy.get_point3(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
{
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
if (has_point(x, y) && copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point4(x, y, get_point4(x, y) + copy.get_point4(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PfmFile::mult_sub_image
|
||||
// Access: Published
|
||||
// Description: Behaves like copy_sub_image(), except the copy pixels
|
||||
// are multiplied to the pixels of the destination, after
|
||||
// scaling by the specified pixel_scale.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PfmFile::
|
||||
mult_sub_image(const PfmFile ©, int xto, int yto,
|
||||
int xfrom, int yfrom, int x_size, int y_size,
|
||||
double pixel_scale) {
|
||||
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++) {
|
||||
if (has_point(x, y) && copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
set_point1(x, y, get_point1(x, y) * (copy.get_point1(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
if (has_point(x, y) && copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
modify_point2(x, y).componentwise_mult(copy.get_point2(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
if (has_point(x, y) && copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
modify_point3(x, y).componentwise_mult(copy.get_point3(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
{
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
if (has_point(x, y) && copy.has_point(x - xmin + xfrom, y - ymin + yfrom)) {
|
||||
modify_point4(x, y).componentwise_mult(copy.get_point4(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PfmFile::operator *=
|
||||
// Access: Published
|
||||
// Description: Multiplies every point value in the image by
|
||||
// a constant floating-point multiplier value.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PfmFile::
|
||||
operator *= (double multiplier) {
|
||||
nassertv(is_valid());
|
||||
|
||||
switch (_num_channels) {
|
||||
case 1:
|
||||
{
|
||||
for (int y = 0; y < _y_size; ++y) {
|
||||
for (int x = 0; x < _x_size; ++x) {
|
||||
if (has_point(x, y)) {
|
||||
PN_float32 p = get_point1(x, y);
|
||||
p *= multiplier;
|
||||
set_point1(x, y, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
for (int y = 0; y < _y_size; ++y) {
|
||||
for (int x = 0; x < _x_size; ++x) {
|
||||
if (has_point(x, y)) {
|
||||
LPoint2f &p = modify_point2(x, y);
|
||||
p *= multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
for (int y = 0; y < _y_size; ++y) {
|
||||
for (int x = 0; x < _x_size; ++x) {
|
||||
if (has_point(x, y)) {
|
||||
LPoint3f &p = modify_point3(x, y);
|
||||
p *= multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
{
|
||||
for (int y = 0; y < _y_size; ++y) {
|
||||
for (int x = 0; x < _x_size; ++x) {
|
||||
if (has_point(x, y)) {
|
||||
LPoint4f &p = modify_point4(x, y);
|
||||
p *= multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PfmFile::output
|
||||
// Access: Published
|
||||
|
|
|
|||
|
|
@ -140,6 +140,16 @@ PUBLISHED:
|
|||
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 add_sub_image(const PfmFile ©, int xto, int yto,
|
||||
int xfrom = 0, int yfrom = 0,
|
||||
int x_size = -1, int y_size = -1,
|
||||
double pixel_scale = 1.0);
|
||||
void mult_sub_image(const PfmFile ©, int xto, int yto,
|
||||
int xfrom = 0, int yfrom = 0,
|
||||
int x_size = -1, int y_size = -1,
|
||||
double pixel_scale = 1.0);
|
||||
|
||||
void operator *= (double multiplier);
|
||||
|
||||
void output(ostream &out) const;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue