]> git.sesse.net Git - movit/blobdiff - gamma_compression_effect_test.cpp
Fix some outdated comments in GammaExpansionEffect.
[movit] / gamma_compression_effect_test.cpp
index 4662a01aa31af7dc6caea5e1828c353ce6ba1e63..e65acee34e4974b6c8a2a500a15556b5255c982e 100644 (file)
@@ -3,9 +3,10 @@
 // Pretty much the inverse of the GammaExpansionEffect tests;
 // EffectChainTest tests that they are actually inverses.
 
-#include "test_util.h"
+#include <GL/glew.h>
 #include "gtest/gtest.h"
-#include "gamma_expansion_effect.h"
+#include "image_format.h"
+#include "test_util.h"
 
 TEST(GammaCompressionEffectTest, sRGB_KeyValues) {
        float data[] = {
@@ -17,8 +18,8 @@ TEST(GammaCompressionEffectTest, sRGB_KeyValues) {
                0.040f, 0.041f,
        };
        float out_data[4];
-       EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_sRGB);
+       EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
 
        expect_equal(expected_data, out_data, 2, 2);
 }
@@ -28,8 +29,8 @@ TEST(GammaCompressionEffectTest, sRGB_RampAlwaysIncreases) {
        for (unsigned i = 0; i < 256; ++i) {
                data[i] = i / 255.0f;
        }
-       EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_LINEAR);
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_sRGB);
+       EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
 
        for (unsigned i = 1; i < 256; ++i) {
                EXPECT_GT(out_data[i], out_data[i - 1])
@@ -47,8 +48,8 @@ TEST(GammaCompressionEffectTest, Rec709_KeyValues) {
                0.080f, 0.082f,
        };
        float out_data[4];
-       EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_REC_709);
+       EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
 
        expect_equal(expected_data, out_data, 2, 2);
 }
@@ -58,11 +59,32 @@ TEST(GammaCompressionEffectTest, Rec709_RampAlwaysIncreases) {
        for (unsigned i = 0; i < 256; ++i) {
                data[i] = i / 255.0f;
        }
-       EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_LINEAR);
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_REC_709);
+       EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
 
        for (unsigned i = 1; i < 256; ++i) {
                EXPECT_GT(out_data[i], out_data[i - 1])
                   << "No increase between " << i-1 << " and " << i;
        }
 }
+
+TEST(GammaCompressionEffectTest, Rec2020_12BitIsVeryCloseToRec709) {
+       float data[256];
+       for (unsigned i = 0; i < 256; ++i) {
+               data[i] = i / 255.0f;
+       }
+       float out_data_709[256];
+       float out_data_2020[256];
+
+       EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data_709, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
+       EffectChainTester tester2(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester2.run(out_data_2020, GL_RED, COLORSPACE_sRGB, GAMMA_REC_2020_12_BIT);
+
+       double sqdiff = 0.0;
+       for (unsigned i = 0; i < 256; ++i) {
+               EXPECT_NEAR(out_data_709[i], out_data_2020[i], 1e-3);
+               sqdiff += (out_data_709[i] - out_data_2020[i]) * (out_data_709[i] - out_data_2020[i]);
+       }
+       EXPECT_GT(sqdiff, 1e-6);
+}