Support conversion to and from the XYZ color space.
[movit] / gamma_compression_effect_test.cpp
1 // Unit tests for GammaCompressionEffect.
2 //
3 // Pretty much the inverse of the GammaExpansionEffect tests;
4 // EffectChainTest tests that they are actually inverses.
5
6 #include "test_util.h"
7 #include "gtest/gtest.h"
8 #include "gamma_expansion_effect.h"
9
10 TEST(GammaCompressionEffectTest, sRGB_KeyValues) {
11         float data[] = {
12                 0.0f, 1.0f,
13                 0.00309f, 0.00317f,   // On either side of the discontinuity.
14         };
15         float expected_data[] = {
16                 0.0f, 1.0f,
17                 0.040f, 0.041f,
18         };
19         float out_data[4];
20         EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
21         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
22
23         expect_equal(expected_data, out_data, 2, 2);
24 }
25
26 TEST(GammaCompressionEffectTest, sRGB_RampAlwaysIncreases) {
27         float data[256], out_data[256];
28         for (unsigned i = 0; i < 256; ++i) {
29                 data[i] = i / 255.0f;
30         }
31         EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
32         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
33
34         for (unsigned i = 1; i < 256; ++i) {
35                 EXPECT_GT(out_data[i], out_data[i - 1])
36                    << "No increase between " << i-1 << " and " << i;
37         }
38 }
39
40 TEST(GammaCompressionEffectTest, Rec709_KeyValues) {
41         float data[] = {
42                 0.0f, 1.0f,
43                 0.017778f, 0.018167f,  // On either side of the discontinuity.
44         };
45         float expected_data[] = {
46                 0.0f, 1.0f,
47                 0.080f, 0.082f,
48         };
49         float out_data[4];
50         EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
51         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
52
53         expect_equal(expected_data, out_data, 2, 2);
54 }
55
56 TEST(GammaCompressionEffectTest, Rec709_RampAlwaysIncreases) {
57         float data[256], out_data[256];
58         for (unsigned i = 0; i < 256; ++i) {
59                 data[i] = i / 255.0f;
60         }
61         EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
62         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
63
64         for (unsigned i = 1; i < 256; ++i) {
65                 EXPECT_GT(out_data[i], out_data[i - 1])
66                    << "No increase between " << i-1 << " and " << i;
67         }
68 }