Browse Source

PfmFile::store_mask()

David Rose 13 years ago
parent
commit
267e02c3d3
2 changed files with 25 additions and 0 deletions
  1. 24 0
      panda/src/pnmimage/pfmFile.cxx
  2. 1 0
      panda/src/pnmimage/pfmFile.h

+ 24 - 0
panda/src/pnmimage/pfmFile.cxx

@@ -446,6 +446,30 @@ store(PNMImage &pnmimage) const {
   return true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::store_mask
+//       Access: Published
+//  Description: Stores 1 or 0 values into the indicated PNMImage,
+//               according to has_point() for each pixel.  Each valid
+//               point gets a 1 value; each nonexistent point gets a 0
+//               value.
+////////////////////////////////////////////////////////////////////
+bool PfmFile::
+store_mask(PNMImage &pnmimage) const {
+  if (!is_valid()) {
+    pnmimage.clear();
+    return false;
+  }
+
+  pnmimage.clear(get_x_size(), get_y_size(), 1, 255);
+  for (int yi = 0; yi < get_y_size(); ++yi) {
+    for (int xi = 0; xi < get_x_size(); ++xi) {
+      pnmimage.set_gray(xi, yi, has_point(xi, yi));
+    }
+  }
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::calc_average_point
 //       Access: Published

+ 1 - 0
panda/src/pnmimage/pfmFile.h

@@ -49,6 +49,7 @@ PUBLISHED:
 
   BLOCKING bool load(const PNMImage &pnmimage);
   BLOCKING bool store(PNMImage &pnmimage) const;
+  BLOCKING bool store_mask(PNMImage &pnmimage) const;
 
   INLINE bool is_valid() const;