Browse Source

Added remix_channels

Josh Yelon 19 years ago
parent
commit
fbd72a9000
2 changed files with 22 additions and 0 deletions
  1. 20 0
      panda/src/pnmimage/pnmImage.cxx
  2. 2 0
      panda/src/pnmimage/pnmImage.h

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

@@ -191,6 +191,26 @@ alpha_fill_val(xelval alpha) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PNMImage::remix_channels
+//       Access: Published
+//  Description: Transforms every pixel using the operation
+//               (Ro,Go,Bo) = conv.xform_point(Ri,Gi,Bi);
+//               Input must be a color image.
+////////////////////////////////////////////////////////////////////
+void PNMImage::
+remix_channels(LMatrix4f &conv) {
+  int nchannels = get_num_channels();
+  nassertv((nchannels >= 3) && (nchannels <= 4));
+  for (int y = 0; y < get_y_size(); y++) {
+    for (int x = 0; x < get_x_size(); x++) {
+      LVector3f inv(get_red(x,y),get_green(x,y),get_blue(x,y));
+      LVector3f outv(conv.xform_point(inv));
+      set_xel(x,y,outv[0],outv[1],outv[2]);
+    }
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PNMImage::read
 //       Access: Published

+ 2 - 0
panda/src/pnmimage/pnmImage.h

@@ -83,6 +83,8 @@ PUBLISHED:
   INLINE void fill(double red, double green, double blue);
   INLINE void fill(double gray = 0.0);
 
+  void remix_channels(LMatrix4f &conv);
+
   void fill_val(xelval red, xelval green, xelval blue);
   INLINE void fill_val(xelval gray = 0);