summaryrefslogtreecommitdiff
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
parentabdc11acdaa8f059ad3c664b6d39a2757efaddc5 (diff)
Re-add linearised gamma LUT.
-rw-r--r--src/gamma_lut.cc19
-rw-r--r--src/gamma_lut.h7
-rw-r--r--src/lut_cache.h4
-rw-r--r--src/mono_picture_frame.cc2
-rw-r--r--src/stereo_picture_frame.cc2
-rw-r--r--src/wscript1
6 files changed, 27 insertions, 8 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);
+ }
}
}
diff --git a/src/gamma_lut.h b/src/gamma_lut.h
index 3fefdfd2..76a63ccf 100644
--- a/src/gamma_lut.h
+++ b/src/gamma_lut.h
@@ -27,7 +27,7 @@ namespace dcp {
class GammaLUT
{
public:
- GammaLUT (int bit_depth, float gamma);
+ GammaLUT (int bit_depth, float gamma, bool linearised);
~GammaLUT () {
delete[] _lut;
@@ -45,12 +45,17 @@ public:
return _gamma;
}
+ bool linearised () const {
+ return _linearised;
+ }
+
static LUTCache<GammaLUT> cache;
private:
float* _lut;
int _bit_depth;
float _gamma;
+ bool _linearised;
};
}
diff --git a/src/lut_cache.h b/src/lut_cache.h
index e2287775..5c75fe6a 100644
--- a/src/lut_cache.h
+++ b/src/lut_cache.h
@@ -28,7 +28,7 @@ template<class T>
class LUTCache : public boost::noncopyable
{
public:
- boost::shared_ptr<T> get (int bit_depth, float gamma)
+ boost::shared_ptr<T> get (int bit_depth, float gamma, bool linearised)
{
for (typename std::list<boost::shared_ptr<T> >::iterator i = _cache.begin(); i != _cache.end(); ++i) {
if ((*i)->bit_depth() == bit_depth && (*i)->gamma() == gamma) {
@@ -36,7 +36,7 @@ public:
}
}
- boost::shared_ptr<T> lut (new T (bit_depth, gamma));
+ boost::shared_ptr<T> lut (new T (bit_depth, gamma, linearised));
_cache.push_back (lut);
return lut;
}
diff --git a/src/mono_picture_frame.cc b/src/mono_picture_frame.cc
index 6c2609ee..c2f8abb7 100644
--- a/src/mono_picture_frame.cc
+++ b/src/mono_picture_frame.cc
@@ -93,6 +93,6 @@ MonoPictureFrame::argb_frame (int reduce, float srgb_gamma) const
{
return xyz_to_rgb (
decompress_j2k (const_cast<uint8_t*> (_buffer->RoData()), _buffer->Size(), reduce),
- GammaLUT::cache.get (12, DCI_GAMMA), GammaLUT::cache.get (12, 1 / srgb_gamma)
+ GammaLUT::cache.get (12, DCI_GAMMA, false), GammaLUT::cache.get (12, 1 / srgb_gamma, false)
);
}
diff --git a/src/stereo_picture_frame.cc b/src/stereo_picture_frame.cc
index 780ac362..0b56b216 100644
--- a/src/stereo_picture_frame.cc
+++ b/src/stereo_picture_frame.cc
@@ -84,7 +84,7 @@ StereoPictureFrame::argb_frame (Eye eye, int reduce, float srgb_gamma) const
break;
}
- return xyz_to_rgb (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA), GammaLUT::cache.get (12, 1 / srgb_gamma));
+ return xyz_to_rgb (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA, false), GammaLUT::cache.get (12, 1 / srgb_gamma, false));
}
uint8_t const *
diff --git a/src/wscript b/src/wscript
index 122c0abe..fd9f945b 100644
--- a/src/wscript
+++ b/src/wscript
@@ -94,6 +94,7 @@ def build(bld):
stereo_picture_mxf.h
stereo_picture_frame.h
subtitle.h
+ subtitle_string.h
types.h
util.h
version.h