From edd731b232ebb518eb173b4d3429402383587f04 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 29 Jan 2014 17:30:40 +0000 Subject: [PATCH] copy_channel_masked() --- panda/src/pnmimage/pfmFile.cxx | 23 +++++++++++++++++++++++ panda/src/pnmimage/pfmFile.h | 1 + 2 files changed, 24 insertions(+) diff --git a/panda/src/pnmimage/pfmFile.cxx b/panda/src/pnmimage/pfmFile.cxx index b78a3dcbab..06e13106bd 100644 --- a/panda/src/pnmimage/pfmFile.cxx +++ b/panda/src/pnmimage/pfmFile.cxx @@ -1467,6 +1467,29 @@ copy_channel(int to_channel, const PfmFile &other, int from_channel) { } } +//////////////////////////////////////////////////////////////////// +// Function: PfmFile::copy_channel_masked +// Access: Published +// Description: Copies just the specified channel values from the +// indicated PfmFile, but only where the other file has +// a data point. +//////////////////////////////////////////////////////////////////// +void PfmFile:: +copy_channel_masked(int to_channel, const PfmFile &other, int from_channel) { + nassertv(is_valid() && other.is_valid()); + nassertv(other._x_size == _x_size && other._y_size == _y_size); + nassertv(to_channel >= 0 && to_channel < get_num_channels() && + from_channel >= 0 && from_channel < other.get_num_channels()); + + for (int yi = 0; yi < _y_size; ++yi) { + for (int xi = 0; xi < _x_size; ++xi) { + if (other.has_point(xi, yi)) { + set_channel(xi, yi, to_channel, other.get_channel(xi, yi, from_channel)); + } + } + } +} + //////////////////////////////////////////////////////////////////// // Function: PfmFile::apply_crop // Access: Published diff --git a/panda/src/pnmimage/pfmFile.h b/panda/src/pnmimage/pfmFile.h index 723940ce5b..9a3cd444c4 100644 --- a/panda/src/pnmimage/pfmFile.h +++ b/panda/src/pnmimage/pfmFile.h @@ -121,6 +121,7 @@ PUBLISHED: BLOCKING void reverse_distort(const PfmFile &dist, PN_float32 scale_factor = 1.0); BLOCKING void merge(const PfmFile &other); BLOCKING void copy_channel(int to_channel, const PfmFile &other, int from_channel); + BLOCKING void copy_channel_masked(int to_channel, const PfmFile &other, int from_channel); BLOCKING void apply_crop(int x_begin, int x_end, int y_begin, int y_end); BLOCKING void clear_to_texcoords(int x_size, int y_size);