summaryrefslogtreecommitdiff
path: root/src/modified_gamma_transfer_function.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-05-05 20:56:14 +0200
committerCarl Hetherington <cth@carlh.net>2022-05-05 21:09:40 +0200
commitcbbb9e63b7ec7a5c34f186ceafe5da6be8faa739 (patch)
tree79ccaa11973954138df02c2022b2ea25c0717b9d /src/modified_gamma_transfer_function.cc
parentad7244de981a7dd0b9b4f8f3d62d4704f1968012 (diff)
Allow LUTs to be created with a particular range.
Diffstat (limited to 'src/modified_gamma_transfer_function.cc')
-rw-r--r--src/modified_gamma_transfer_function.cc16
1 files changed, 9 insertions, 7 deletions
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<double>
-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<double>(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<double>(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<double>(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;
}
}
}