From c707de06614d3d183c942e562f0dd88bcc79fd69 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 1 May 2012 17:12:20 +0000 Subject: [PATCH] add add_sub_image() --- panda/src/pnmimage/pnmImage.cxx | 38 +++++++++++++++++++++++++++++++++ panda/src/pnmimage/pnmImage.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/panda/src/pnmimage/pnmImage.cxx b/panda/src/pnmimage/pnmImage.cxx index 9638bfa824..42b5296b9e 100644 --- a/panda/src/pnmimage/pnmImage.cxx +++ b/panda/src/pnmimage/pnmImage.cxx @@ -816,6 +816,44 @@ blend_sub_image(const PNMImage ©, int xto, int yto, } } +//////////////////////////////////////////////////////////////////// +// Function: PNMImage::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. Unlike +// blend_sub_image(), the alpha channel is not treated +// specially. +//////////////////////////////////////////////////////////////////// +void PNMImage:: +add_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 ce723e1e12..34d7bdd0fb 100644 --- a/panda/src/pnmimage/pnmImage.h +++ b/panda/src/pnmimage/pnmImage.h @@ -199,6 +199,10 @@ PUBLISHED: int xfrom = 0, int yfrom = 0, int x_size = -1, int y_size = -1, double pixel_scale = 1.0); + void add_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,