Change output gamma correction to be closer to EasyDCP behaviour.
authorCarl Hetherington <cth@carlh.net>
Mon, 29 Apr 2013 14:22:55 +0000 (15:22 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 29 Apr 2013 14:22:55 +0000 (15:22 +0100)
src/picture_frame.cc
src/util.cc
src/util.h
src/wscript
src/xyz_srgb_lut.cc [deleted file]
src/xyz_srgb_lut.h [deleted file]

index 98802101ef4576bb0594b4d075cb58decbad8c9d..7e6bc1f8f30dfaff8818dfe397b62035243a1f2b 100644 (file)
@@ -26,7 +26,6 @@
 #include "lut.h"
 #include "util.h"
 #include "gamma_lut.h"
-#include "xyz_srgb_lut.h"
 
 #define DCI_GAMMA 2.6
 
@@ -84,7 +83,7 @@ MonoPictureFrame::argb_frame (int reduce, float srgb_gamma) const
 {
        opj_image_t* xyz_frame = decompress_j2k (const_cast<uint8_t*> (_buffer->RoData()), _buffer->Size(), reduce);
        assert (xyz_frame->numcomps == 3);
-       shared_ptr<ARGBFrame> f = xyz_to_rgb (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA), XYZsRGBLUT::cache.get (12, srgb_gamma));
+       shared_ptr<ARGBFrame> f = xyz_to_rgb (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA), GammaLUT::cache.get (12, 1 / srgb_gamma));
        opj_image_destroy (xyz_frame);
        return f;
 }
@@ -139,7 +138,7 @@ StereoPictureFrame::argb_frame (Eye eye, int reduce, float srgb_gamma) const
        }
        
        assert (xyz_frame->numcomps == 3);
-       shared_ptr<ARGBFrame> f = xyz_to_rgb (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA), XYZsRGBLUT::cache.get (12, srgb_gamma));
+       shared_ptr<ARGBFrame> f = xyz_to_rgb (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA), GammaLUT::cache.get (12, 1 / srgb_gamma));
        opj_image_destroy (xyz_frame);
        return f;
 }
index 2fae85611d7204ee7c54290f3b7c8409b10004bd..c66e63f5104bfb14d272dde96e74bf90af34bf0d 100644 (file)
@@ -35,7 +35,6 @@
 #include "types.h"
 #include "argb_frame.h"
 #include "gamma_lut.h"
-#include "xyz_srgb_lut.h"
 
 using std::string;
 using std::stringstream;
@@ -203,11 +202,13 @@ libdcp::decompress_j2k (uint8_t* data, int64_t size, int reduce)
  *  @return RGB image.
  */
 shared_ptr<ARGBFrame>
-libdcp::xyz_to_rgb (opj_image_t* xyz_frame, shared_ptr<const GammaLUT> lut_in, shared_ptr<const XYZsRGBLUT> lut_out)
+libdcp::xyz_to_rgb (opj_image_t* xyz_frame, shared_ptr<const GammaLUT> lut_in, shared_ptr<const GammaLUT> lut_out)
 {
        float const dci_coefficient = 48.0 / 52.37;
 
-        /* sRGB color matrix for XYZ -> RGB */
+        /* sRGB color matrix for XYZ -> RGB.  This is the same as the one used by the Fraunhofer
+          EasyDCP player, I think.
+       */
 
        float const colour_matrix[3][3] = {
                {  3.24096989631653,   -1.5373831987381,  -0.498610764741898 },
@@ -264,9 +265,9 @@ libdcp::xyz_to_rgb (opj_image_t* xyz_frame, shared_ptr<const GammaLUT> lut_in, s
                        d.b = max (d.b, 0.0);
                        
                        /* Out gamma LUT */
-                       *argb_line++ = lut_out->lut()[(int) (d.b * max_colour)];
-                       *argb_line++ = lut_out->lut()[(int) (d.g * max_colour)];
-                       *argb_line++ = lut_out->lut()[(int) (d.r * max_colour)];
+                       *argb_line++ = lut_out->lut()[(int) (d.b * max_colour)] * 0xff;
+                       *argb_line++ = lut_out->lut()[(int) (d.g * max_colour)] * 0xff;
+                       *argb_line++ = lut_out->lut()[(int) (d.r * max_colour)] * 0xff;
                        *argb_line++ = 0xff;
                }
                
index 2036a7ce4a75376936f480eb6924910c357e8a9b..6332ddc08f157a4f3ec50754f94b7a20408dc137 100644 (file)
@@ -60,7 +60,7 @@ extern std::string content_kind_to_string (ContentKind kind);
 extern ContentKind content_kind_from_string (std::string kind);
 extern bool empty_or_white_space (std::string s);
 extern opj_image_t* decompress_j2k (uint8_t* data, int64_t size, int reduce);
-extern boost::shared_ptr<ARGBFrame> xyz_to_rgb (opj_image_t* xyz_frame, boost::shared_ptr<const GammaLUT>, boost::shared_ptr<const XYZsRGBLUT>);
+extern boost::shared_ptr<ARGBFrame> xyz_to_rgb (opj_image_t* xyz_frame, boost::shared_ptr<const GammaLUT>, boost::shared_ptr<const GammaLUT>);
 
 }
 
index efba25025bb2e6021e22a7551752bf614e72a9ce..3960f2b0c54e8ccaba4830294e185d0210337a1f 100644 (file)
@@ -31,7 +31,6 @@ def build(bld):
                  util.cc
                  version.cc
                  xml.cc
-                 xyz_srgb_lut.cc
                  """
 
     headers = """
diff --git a/src/xyz_srgb_lut.cc b/src/xyz_srgb_lut.cc
deleted file mode 100644 (file)
index 3d20719..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <iostream>
-#include <cmath>
-#include "xyz_srgb_lut.h"
-
-using namespace libdcp;
-
-LUTCache<XYZsRGBLUT> XYZsRGBLUT::cache;
-
-XYZsRGBLUT::XYZsRGBLUT(int bits, float gamma)
-       : LUT<int> (bits, gamma)
-{
-       int const bit_length = pow(2, bits);
-
-       for (int i = 0; i < bit_length; ++i) {
-               float v = float(i) / (bit_length - 1);
-               if (v < (0.04045 / 12.92)) {
-                       v *= 12.92;
-               } else {
-                       v = (1.055 * pow (v, (1 / gamma))) - 0.055;
-               }
-
-               _lut[i] = int(v * 255);
-       }
-}
diff --git a/src/xyz_srgb_lut.h b/src/xyz_srgb_lut.h
deleted file mode 100644 (file)
index 63f8917..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "lut.h"
-#include "lut_cache.h"
-
-namespace libdcp {
-
-class XYZsRGBLUT : public LUT<int>
-{
-public:
-       XYZsRGBLUT(int colour_depth, float gamma);
-       static LUTCache<XYZsRGBLUT> cache;
-};
-
-}