Re-add linearised gamma LUT.
authorCarl Hetherington <cth@carlh.net>
Tue, 11 Feb 2014 14:30:38 +0000 (14:30 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 11 Feb 2014 14:30:38 +0000 (14:30 +0000)
src/gamma_lut.cc
src/gamma_lut.h
src/lut_cache.h
src/mono_picture_frame.cc
src/stereo_picture_frame.cc
src/wscript

index 4d61e60c926d4debb7f46c71f1fde735f46eb827..abe35b7cf24e13dc051d28a456c12db08adde13a 100644 (file)
@@ -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);
+               }
        }
 }
index 3fefdfd2b4a87d761c4933b3fae5ed56e5af24b0..76a63ccfe8444665a644df6ec18a7bc23d79e548 100644 (file)
@@ -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;
 };
 
 }
index e228777530c5c48a8eb287e56d46c72ce19cd548..5c75fe6aacb31fddcf8715fcebcd4ebefc318dfb 100644 (file)
@@ -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;
        }
index 6c2609eef81df4f56997284eb33968a8b8a65331..c2f8abb712f6950703c8c417f40397cc20d68ff1 100644 (file)
@@ -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)
                );
 }
index 780ac3622e37bde8370693de9c2002ab3181b73e..0b56b21632c5b444131042aa80d26f7ef68bac98 100644 (file)
@@ -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 *
index 122c0abe11d648ed6f0873230a5833a13a8e75b8..fd9f945b424f6f9611ed014bc9d4ad59fc157bfd 100644 (file)
@@ -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