summaryrefslogtreecommitdiff
path: root/src/gamma_lut.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-02-11 14:30:38 +0000
committerCarl Hetherington <cth@carlh.net>2014-02-11 14:30:38 +0000
commit7dd07caa5fbfabde5563de4ade76b7c11d68c59c (patch)
treef09accda608f459e7f7b0f09a0b69b9fa97cbc37 /src/gamma_lut.cc
parentabdc11acdaa8f059ad3c664b6d39a2757efaddc5 (diff)
Re-add linearised gamma LUT.
Diffstat (limited to 'src/gamma_lut.cc')
-rw-r--r--src/gamma_lut.cc19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/gamma_lut.cc b/src/gamma_lut.cc
index 4d61e60c..abe35b7c 100644
--- a/src/gamma_lut.cc
+++ b/src/gamma_lut.cc
@@ -25,13 +25,26 @@ using namespace dcp;
LUTCache<GammaLUT> GammaLUT::cache;
-GammaLUT::GammaLUT (int bit_depth, float gamma)
+GammaLUT::GammaLUT (int bit_depth, float gamma, bool linearised)
: _bit_depth (bit_depth)
, _gamma (gamma)
+ , _linearised (linearised)
{
_lut = new float[int(std::pow(2.0f, _bit_depth))];
int const bit_length = pow (2, _bit_depth);
- for (int i = 0; i < bit_length; ++i) {
- _lut[i] = pow(float(i) / (bit_length - 1), gamma);
+
+ if (_linearised) {
+ for (int i = 0; i < bit_length; ++i) {
+ float const p = static_cast<float> (i) / (bit_length - 1);
+ if (p > 0.04045) {
+ _lut[i] = pow ((p + 0.055) / 1.055, gamma);
+ } else {
+ _lut[i] = p / 12.92;
+ }
+ }
+ } else {
+ for (int i = 0; i < bit_length; ++i) {
+ _lut[i] = pow(float(i) / (bit_length - 1), gamma);
+ }
}
}