Add the rest of the files for the premultiplied alpha commit.
[movit] / gamma_expansion_effect_test.cpp
1 // Unit tests for GammaExpansionEffect.
2
3 #include "test_util.h"
4 #include "gtest/gtest.h"
5 #include "gamma_expansion_effect.h"
6
7 TEST(GammaExpansionEffectTest, sRGB_KeyValues) {
8         float data[] = {
9                 0.0f, 1.0f,
10                 0.040f, 0.041f,  // On either side of the discontinuity.
11         };
12         float expected_data[] = {
13                 0.0f, 1.0f,
14                 0.00309f, 0.00317f, 
15         };
16         float out_data[4];
17         EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB);
18         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
19
20         expect_equal(expected_data, out_data, 2, 2);
21 }
22
23 TEST(GammaExpansionEffectTest, sRGB_RampAlwaysIncreases) {
24         float data[256], out_data[256];
25         for (unsigned i = 0; i < 256; ++i) {
26                 data[i] = i / 255.0f;
27         }
28         EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB);
29         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
30
31         for (unsigned i = 1; i < 256; ++i) {
32                 EXPECT_GT(out_data[i], out_data[i - 1])
33                    << "No increase between " << i-1 << " and " << i;
34         }
35 }
36
37 TEST(GammaExpansionEffectTest, sRGB_AlphaIsUnchanged) {
38         float data[] = {
39                 0.0f, 0.0f, 0.0f, 0.0f,
40                 0.0f, 0.0f, 0.0f, 0.25f,
41                 0.0f, 0.0f, 0.0f, 0.5f,
42                 0.0f, 0.0f, 0.0f, 0.75f,
43                 0.0f, 0.0f, 0.0f, 1.0f,
44         };
45         float out_data[5 * 4];
46         EffectChainTester tester(data, 5, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
47         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
48
49         expect_equal(data, out_data, 5, 1);
50 }
51
52 TEST(GammaExpansionEffectTest, Rec709_KeyValues) {
53         float data[] = {
54                 0.0f, 1.0f,
55                 0.080f, 0.082f,  // On either side of the discontinuity.
56         };
57         float expected_data[] = {
58                 0.0f, 1.0f,
59                 0.017778f, 0.018167f,
60         };
61         float out_data[4];
62         EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_709);
63         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
64
65         expect_equal(expected_data, out_data, 2, 2);
66 }
67
68 TEST(GammaExpansionEffectTest, Rec709_RampAlwaysIncreases) {
69         float data[256], out_data[256];
70         for (unsigned i = 0; i < 256; ++i) {
71                 data[i] = i / 255.0f;
72         }
73         EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_709);
74         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
75
76         for (unsigned i = 1; i < 256; ++i) {
77                 EXPECT_GT(out_data[i], out_data[i - 1])
78                    << "No increase between " << i-1 << " and " << i;
79         }
80 }
81
82 TEST(GammaExpansionEffectTest, Rec709_AlphaIsUnchanged) {
83         float data[] = {
84                 0.0f, 0.0f, 0.0f, 0.0f,
85                 0.0f, 0.0f, 0.0f, 0.25f,
86                 0.0f, 0.0f, 0.0f, 0.5f,
87                 0.0f, 0.0f, 0.0f, 0.75f,
88                 0.0f, 0.0f, 0.0f, 1.0f,
89         };
90         float out_data[5 * 4];
91         EffectChainTester tester(data, 5, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_REC_709);
92         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
93
94         expect_equal(data, out_data, 5, 1);
95 }