As I understand it all SMPTE subtitles are MXF-wrapped.
[libdcp.git] / test / colour_conversion_test.cc
index 060148a646082c79cf3732adaf5d33ec6c033cc3..7ff93468b5c6b72ee9536250b8165d3fa767cae9 100644 (file)
@@ -28,10 +28,10 @@ using boost::shared_ptr;
 using namespace dcp;
 
 static void
-check_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, float gamma)
+check_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, bool inverse, float gamma)
 {
-       float const * lut = tf->lut (bit_depth);
-       int const count = pow (2, bit_depth);
+       double const * lut = tf->lut (bit_depth, inverse);
+       int const count = rint (pow (2.0, bit_depth));
 
        for (int i = 0; i < count; ++i) {
                BOOST_CHECK_CLOSE (lut[i], pow (float(i) / (count - 1), gamma), 0.001);
@@ -39,13 +39,13 @@ check_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, float gamma)
 }
 
 static void
-check_modified_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, float power, float threshold, float A, float B)
+check_modified_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, bool inverse, double power, double threshold, double A, double B)
 {
-       float const * lut = tf->lut (bit_depth);
-       int const count = pow (2, bit_depth);
+       double const * lut = tf->lut (bit_depth, inverse);
+       int const count = rint (pow (2.0, bit_depth));
 
        for (int i = 0; i < count; ++i) {
-               float const x = float(i) / (count - 1);
+               double const x = double(i) / (count - 1);
                if (x > threshold) {
                        BOOST_CHECK_CLOSE (lut[i], pow ((x + A) / (1 + A), power), 0.001);
                } else {
@@ -54,29 +54,31 @@ check_modified_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, floa
        }
 }
 
+/** Check that the gamma correction LUTs are right for sRGB */
 BOOST_AUTO_TEST_CASE (colour_conversion_test1)
 {
-       ColourConversion cc = ColourConversion::srgb_to_xyz;
+       ColourConversion cc = ColourConversion::srgb_to_xyz ();
 
-       check_modified_gamma (cc.in(), 8, 2.4, 0.04045, 0.055, 12.92);
-       check_modified_gamma (cc.in(), 12, 2.4, 0.04045, 0.055, 12.92);
-       check_modified_gamma (cc.in(), 16, 2.4, 0.04045, 0.055, 12.92);
+       check_modified_gamma (cc.in(), 8, false, 2.4, 0.04045, 0.055, 12.92);
+       check_modified_gamma (cc.in(), 12, false, 2.4, 0.04045, 0.055, 12.92);
+       check_modified_gamma (cc.in(), 16, false, 2.4, 0.04045, 0.055, 12.92);
 
-       check_gamma (cc.out(), 8, 2.6);
-       check_gamma (cc.out(), 12, 2.6);
-       check_gamma (cc.out(), 16, 2.6);
+       check_gamma (cc.out(), 8, true, 1 / 2.6);
+       check_gamma (cc.out(), 12, true, 1 / 2.6);
+       check_gamma (cc.out(), 16, true, 1 / 2.6);
 }
 
+/** Check that the gamma correction LUTs are right for REC709 */
 BOOST_AUTO_TEST_CASE (colour_conversion_test2)
 {
-       ColourConversion cc = ColourConversion::rec709_to_xyz;
+       ColourConversion cc = ColourConversion::rec709_to_xyz ();
 
-       check_modified_gamma (cc.in(), 8, 2.4, 0.081, 0.099, 4.5);
-       check_modified_gamma (cc.in(), 12, 2.4, 0.081, 0.099, 4.5);
-       check_modified_gamma (cc.in(), 16, 2.4, 0.081, 0.099, 4.5);
+       check_modified_gamma (cc.in(), 8, false, 1 / 0.45, 0.081, 0.099, 4.5);
+       check_modified_gamma (cc.in(), 12, false, 1 / 0.45, 0.081, 0.099, 4.5);
+       check_modified_gamma (cc.in(), 16, false, 1 / 0.45, 0.081, 0.099, 4.5);
 
-       check_gamma (cc.out(), 8, 2.6);
-       check_gamma (cc.out(), 12, 2.6);
-       check_gamma (cc.out(), 16, 2.6);
+       check_gamma (cc.out(), 8, true, 1 / 2.6);
+       check_gamma (cc.out(), 12, true, 1 / 2.6);
+       check_gamma (cc.out(), 16, true, 1 / 2.6);
 }