From fb6637ddacfc102e890dd0c591662b0d155d6675 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 29 Aug 2016 16:43:13 -0700 Subject: [PATCH] expand PfmFile::merge() to support other than 3 channels, and not to fuss about NaN's in the result --- panda/src/pnmimage/pfmFile.cxx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/panda/src/pnmimage/pfmFile.cxx b/panda/src/pnmimage/pfmFile.cxx index 75bb06682f..214c028dd7 100644 --- a/panda/src/pnmimage/pfmFile.cxx +++ b/panda/src/pnmimage/pfmFile.cxx @@ -1449,17 +1449,20 @@ apply_1d_lut(int channel, const PfmFile &lut, PN_float32 x_scale) { void PfmFile:: merge(const PfmFile &other) { nassertv(is_valid() && other.is_valid()); - nassertv(other._x_size == _x_size && other._y_size == _y_size); + nassertv(other._x_size == _x_size && other._y_size == _y_size && other._num_channels == _num_channels); if (!_has_no_data_value) { // Trivial no-op. return; } - for (int yi = 0; yi < _y_size; ++yi) { - for (int xi = 0; xi < _x_size; ++xi) { - if (!has_point(xi, yi) && other.has_point(xi, yi)) { - set_point(xi, yi, other.get_point(xi, yi)); + size_t point_size = _num_channels * sizeof(PN_float32); + for (int y = 0; y < _y_size; ++y) { + for (int x = 0; x < _x_size; ++x) { + if (!has_point(x, y) && other.has_point(x, y)) { + memcpy(&_table[(y * _x_size + x) * _num_channels], + &other._table[(y * _x_size + x) * _num_channels], + point_size); } } }