diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-06-02 16:47:56 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-06-02 16:47:56 +0200 |
| commit | e2b0092be00ebcb129a7f75230f76f52901b07b1 (patch) | |
| tree | 7da551c580c24bc1aa9433ab6b8ba6fdcbfee1ee /src/transfer_function.cc | |
| parent | f2d6161203f8b5c50b021dbe65a9109ea1577fd7 (diff) | |
Use an integer LUT for the rgb->xyz output instead of doing
multiplies and rounding in the loop.
Diffstat (limited to 'src/transfer_function.cc')
| -rw-r--r-- | src/transfer_function.cc | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/transfer_function.cc b/src/transfer_function.cc index ea71818e..0dfdb338 100644 --- a/src/transfer_function.cc +++ b/src/transfer_function.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> This file is part of libdcp. @@ -56,7 +56,13 @@ double const * TransferFunction::lut (int bit_depth, bool inverse) const { boost::mutex::scoped_lock lm (_mutex); + return lut_unlocked (bit_depth, inverse); +} + +double const * +TransferFunction::lut_unlocked (int bit_depth, bool inverse) const +{ map<pair<int, bool>, double*>::const_iterator i = _luts.find (make_pair (bit_depth, inverse)); if (i != _luts.end ()) { return i->second; @@ -65,3 +71,29 @@ TransferFunction::lut (int bit_depth, bool inverse) const _luts[make_pair(bit_depth, inverse)] = make_lut (bit_depth, inverse); return _luts[make_pair(bit_depth, inverse)]; } + + +int const * +TransferFunction::lut_int (int bit_depth, bool inverse, int multiplier) const +{ + IntDescription desc (bit_depth, inverse, multiplier); + + boost::mutex::scoped_lock lm (_mutex); + + map<IntDescription, int*>::const_iterator i = _luts_int.find (desc); + if (i != _luts_int.end()) { + return i->second; + } + + double const* lut_double = lut_unlocked (bit_depth, inverse); + + int size = lrint(pow(2.0f, bit_depth)); + int* lut_int = new int[size]; + for (int i = 0; i < size; ++i) { + lut_int[i] = lrint (lut_double[i] * multiplier); + } + + _luts_int[desc] = lut_int; + return lut_int; +} + |
