From cbbb9e63b7ec7a5c34f186ceafe5da6be8faa739 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 5 May 2022 20:56:14 +0200 Subject: Allow LUTs to be created with a particular range. --- src/modified_gamma_transfer_function.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/modified_gamma_transfer_function.cc') diff --git a/src/modified_gamma_transfer_function.cc b/src/modified_gamma_transfer_function.cc index e2cc1e86..991e642e 100644 --- a/src/modified_gamma_transfer_function.cc +++ b/src/modified_gamma_transfer_function.cc @@ -59,7 +59,7 @@ ModifiedGammaTransferFunction::ModifiedGammaTransferFunction (double power, doub vector -ModifiedGammaTransferFunction::make_lut (int bit_depth, bool inverse) const +ModifiedGammaTransferFunction::make_lut (double from, double to, int bit_depth, bool inverse) const { int const bit_length = int(std::pow(2.0f, bit_depth)); auto lut = vector(bit_length); @@ -67,19 +67,21 @@ ModifiedGammaTransferFunction::make_lut (int bit_depth, bool inverse) const double const threshold = _threshold / _B; for (int i = 0; i < bit_length; ++i) { double const p = static_cast(i) / (bit_length - 1); - if (p > threshold) { - lut[i] = (1 + _A) * pow (p, 1 / _power) - _A; + double const q = (p * (to - from)) + from; + if (q > threshold) { + lut[i] = (1 + _A) * pow (q, 1 / _power) - _A; } else { - lut[i] = p * _B; + lut[i] = q * _B; } } } else { for (int i = 0; i < bit_length; ++i) { double const p = static_cast(i) / (bit_length - 1); - if (p > _threshold) { - lut[i] = pow ((p + _A) / (1 + _A), _power); + double const q = (p * (to - from)) + from; + if (q > _threshold) { + lut[i] = pow ((q + _A) / (1 + _A), _power); } else { - lut[i] = p / _B; + lut[i] = q / _B; } } } -- cgit v1.2.3