David Rose 13 роки тому
батько
коміт
c707de0661
2 змінених файлів з 42 додано та 0 видалено
  1. 38 0
      panda/src/pnmimage/pnmImage.cxx
  2. 4 0
      panda/src/pnmimage/pnmImage.h

+ 38 - 0
panda/src/pnmimage/pnmImage.cxx

@@ -816,6 +816,44 @@ blend_sub_image(const PNMImage &copy, 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 &copy, 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

+ 4 - 0
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 &copy, 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 &copy, int xto, int yto,
                         int xfrom = 0, int yfrom = 0,
                         int x_size = -1, int y_size = -1,