From caf3a9f24c8ebb83fa42b71991c9860a8294b503 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 7 Oct 2015 16:52:11 -0700 Subject: [PATCH] PfmFile::apply_1d_lut() --- panda/src/pnmimage/pfmFile.cxx | 26 ++++++++++++++++++++++++++ panda/src/pnmimage/pfmFile.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/panda/src/pnmimage/pfmFile.cxx b/panda/src/pnmimage/pfmFile.cxx index 3cad7c7e99..287a569ebf 100644 --- a/panda/src/pnmimage/pfmFile.cxx +++ b/panda/src/pnmimage/pfmFile.cxx @@ -1439,6 +1439,32 @@ reverse_distort(const PfmFile &dist, PN_float32 scale_factor) { _table.swap(result._table); } +//////////////////////////////////////////////////////////////////// +// Function: PfmFile::apply_1d_lut +// Access: Published +// Description: Assumes that lut is an X by 1, 1-component PfmFile +// whose X axis maps points to target points. For each +// point in this pfm file, computes: p(u, v)[channel] = +// lut(p(u, v)[channel] * x_scale, 0)[0] +//////////////////////////////////////////////////////////////////// +void PfmFile:: +apply_1d_lut(int channel, const PfmFile &lut, PN_float32 x_scale) { + for (int yi = 0; yi < _y_size; ++yi) { + for (int xi = 0; xi < _x_size; ++xi) { + if (!has_point(xi, yi)) { + continue; + } + + PN_float32 v = get_channel(xi, yi, channel); + LPoint3f p; + if (!lut.calc_bilinear_point(p, v * x_scale, 0.5)) { + continue; + } + set_channel(xi, yi, channel, p[0]); + } + } +} + //////////////////////////////////////////////////////////////////// // Function: PfmFile::merge // Access: Published diff --git a/panda/src/pnmimage/pfmFile.h b/panda/src/pnmimage/pfmFile.h index ab0347f739..1b82f91d65 100644 --- a/panda/src/pnmimage/pfmFile.h +++ b/panda/src/pnmimage/pfmFile.h @@ -122,6 +122,8 @@ PUBLISHED: INLINE BLOCKING void xform(const LMatrix4d &transform); BLOCKING void forward_distort(const PfmFile &dist, PN_float32 scale_factor = 1.0); BLOCKING void reverse_distort(const PfmFile &dist, PN_float32 scale_factor = 1.0); + BLOCKING void apply_1d_lut(int channel, const PfmFile &lut, PN_float32 x_scale = 1.0); + BLOCKING void merge(const PfmFile &other); BLOCKING void apply_mask(const PfmFile &other); BLOCKING void copy_channel(int to_channel, const PfmFile &other, int from_channel);