diff --git a/panda/src/pnmimage/pnmImage.cxx b/panda/src/pnmimage/pnmImage.cxx index 6a8502f36e..87d431af33 100644 --- a/panda/src/pnmimage/pnmImage.cxx +++ b/panda/src/pnmimage/pnmImage.cxx @@ -1007,6 +1007,44 @@ add_sub_image(const PNMImage ©, int xto, int yto, } } +//////////////////////////////////////////////////////////////////// +// Function: PNMImage::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. Unlike +// blend_sub_image(), the alpha channel is not treated +// specially. +//////////////////////////////////////////////////////////////////// +void PNMImage:: +mult_sub_image(const PNMImage ©, 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; + if (has_alpha() && copy.has_alpha()) { + for (y = ymin; y < ymax; y++) { + for (x = xmin; x < xmax; x++) { + set_alpha(x, y, get_alpha(x, y) * copy.get_alpha(x, y) * pixel_scale); + } + } + } + + for (y = ymin; y < ymax; y++) { + for (x = xmin; x < xmax; x++) { + LRGBColord rgb1 = get_xel(x, y); + LRGBColord rgb2 = copy.get_xel(x, y); + set_xel(x, y, + rgb1[0] * rgb2[0] * pixel_scale, + rgb1[1] * rgb2[1] * pixel_scale, + rgb1[2] * rgb2[2] * pixel_scale); + } + } +} + //////////////////////////////////////////////////////////////////// // Function: PNMImage::darken_sub_image // Access: Published diff --git a/panda/src/pnmimage/pnmImage.h b/panda/src/pnmimage/pnmImage.h index 803dc1b09e..5f690f0835 100644 --- a/panda/src/pnmimage/pnmImage.h +++ b/panda/src/pnmimage/pnmImage.h @@ -204,6 +204,10 @@ PUBLISHED: int xfrom = 0, int yfrom = 0, int x_size = -1, int y_size = -1, double pixel_scale = 1.0); + void mult_sub_image(const PNMImage ©, int xto, int yto, + int xfrom = 0, int yfrom = 0, + int x_size = -1, int y_size = -1, + double pixel_scale = 1.0); void darken_sub_image(const PNMImage ©, int xto, int yto, int xfrom = 0, int yfrom = 0, int x_size = -1, int y_size = -1,