diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-06-02 19:46:21 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-06-02 19:46:21 +0200 |
| commit | 0e910402791b27e082946d99e8f7bc333ab680a9 (patch) | |
| tree | eab9ba0606120caec5d8c4bc4468eb63067b458c | |
| parent | e2b0092be00ebcb129a7f75230f76f52901b07b1 (diff) | |
Add lut_float to TransferFunction.
| -rw-r--r-- | src/transfer_function.cc | 23 | ||||
| -rw-r--r-- | src/transfer_function.h | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/transfer_function.cc b/src/transfer_function.cc index 0dfdb338..00cd2c9c 100644 --- a/src/transfer_function.cc +++ b/src/transfer_function.cc @@ -73,6 +73,29 @@ TransferFunction::lut_unlocked (int bit_depth, bool inverse) const } +float const * +TransferFunction::lut_float (int bit_depth, bool inverse) const +{ + boost::mutex::scoped_lock lm (_mutex); + + map<pair<int, bool>, float*>::const_iterator i = _luts_float.find (make_pair(bit_depth, inverse)); + if (i != _luts_float.end()) { + return i->second; + } + + double const* lut_double = lut_unlocked (bit_depth, inverse); + + int size = lrint(pow(2.0f, bit_depth)); + float* lut_float = new float[size]; + for (int i = 0; i < size; ++i) { + lut_float[i] = static_cast<float> (lut_double[i]); + } + + _luts_float[make_pair(bit_depth, inverse)] = lut_float; + return lut_float; +} + + int const * TransferFunction::lut_int (int bit_depth, bool inverse, int multiplier) const { diff --git a/src/transfer_function.h b/src/transfer_function.h index 9d35b281..e497ae8a 100644 --- a/src/transfer_function.h +++ b/src/transfer_function.h @@ -55,6 +55,7 @@ public: /** @return A look-up table (of size 2^bit_depth) whose values range from 0 to 1 */ double const * lut (int bit_depth, bool inverse) const; + float const * lut_float (int bit_depth, bool inverse) const; int const * lut_int (int bit_depth, bool inverse, int multiplier) const; virtual bool about_equal (boost::shared_ptr<const TransferFunction> other, double epsilon) const = 0; @@ -67,6 +68,7 @@ private: double const * lut_unlocked (int bit_depth, bool inverse) const; mutable std::map<std::pair<int, bool>, double*> _luts; + mutable std::map<std::pair<int, bool>, float*> _luts_float; struct IntDescription { IntDescription (int bit_depth_, bool inverse_, int multipler_) |
