From 267e02c3d3b3a3258571ee1671756d256cf22615 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 7 Nov 2012 19:08:32 +0000 Subject: [PATCH] PfmFile::store_mask() --- panda/src/pnmimage/pfmFile.cxx | 24 ++++++++++++++++++++++++ panda/src/pnmimage/pfmFile.h | 1 + 2 files changed, 25 insertions(+) diff --git a/panda/src/pnmimage/pfmFile.cxx b/panda/src/pnmimage/pfmFile.cxx index e96c3f4fb9..b88d707b58 100644 --- a/panda/src/pnmimage/pfmFile.cxx +++ b/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 diff --git a/panda/src/pnmimage/pfmFile.h b/panda/src/pnmimage/pfmFile.h index 7af3ab0fda..5a8e3e6a28 100644 --- a/panda/src/pnmimage/pfmFile.h +++ b/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;