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/s_gamut3_transfer_function.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/s_gamut3_transfer_function.cc') diff --git a/src/s_gamut3_transfer_function.cc b/src/s_gamut3_transfer_function.cc index b2e82b51..512a2951 100644 --- a/src/s_gamut3_transfer_function.cc +++ b/src/s_gamut3_transfer_function.cc @@ -49,26 +49,28 @@ using namespace dcp; vector -SGamut3TransferFunction::make_lut (int bit_depth, bool inverse) const +SGamut3TransferFunction::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); if (inverse) { for (int i = 0; i < bit_length; ++i) { auto const p = static_cast(i) / (bit_length - 1); - if (p >= (0.01125 / 1023)) { - lut[i] = (420 + log10((p + 0.01) / (0.18 + 0.01)) * 261.5) / 1023; + auto const q = (p * (to - from)) + from; + if (q >= (0.01125 / 1023)) { + lut[i] = (420 + log10((q + 0.01) / (0.18 + 0.01)) * 261.5) / 1023; } else { - lut[i] = (p * (171.2102946929 - 95) / 0.01125000 + 95) / 1023; + lut[i] = (q * (171.2102946929 - 95) / 0.01125000 + 95) / 1023; } } } else { for (int i = 0; i < bit_length; ++i) { auto const p = static_cast(i) / (bit_length - 1); - if (p >= (171.2102946929 / 1023)) { + auto const q = (p * (to - from)) + from; + if (q >= (171.2102946929 / 1023)) { lut[i] = pow(10, ((p * 1023 - 420) / 261.5)) * (0.18 + 0.01) - 0.01; } else { - lut[i] = (p * 1023 - 95) * 0.01125000 / (171.2102946929 - 95); + lut[i] = (q * 1023 - 95) * 0.01125000 / (171.2102946929 - 95); } } } -- cgit v1.2.3