Add the rest of the files for the premultiplied alpha commit.
[movit] / lift_gamma_gain_effect_test.cpp
1 // Unit tests for LiftGammaGainEffect.
2
3 #include "test_util.h"
4 #include "gtest/gtest.h"
5 #include "lift_gamma_gain_effect.h"
6
7 TEST(LiftGammaGainEffectTest, DefaultIsNoop) {
8         float data[] = {
9                 0.0f, 0.0f, 0.0f, 1.0f,
10                 0.5f, 0.5f, 0.5f, 0.3f,
11                 1.0f, 0.0f, 0.0f, 1.0f,
12                 0.0f, 1.0f, 0.0f, 0.7f,
13                 0.0f, 0.0f, 1.0f, 1.0f,
14         };
15
16         float out_data[5 * 4];
17         EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
18         tester.get_chain()->add_effect(new LiftGammaGainEffect());
19         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
20
21         expect_equal(data, out_data, 4, 5);
22 }
23
24 TEST(LiftGammaGainEffectTest, Gain) {
25         float data[] = {
26                 0.0f, 0.0f, 0.0f, 1.0f,
27                 0.5f, 0.5f, 0.5f, 0.3f,
28                 1.0f, 0.0f, 0.0f, 1.0f,
29                 0.0f, 1.0f, 0.0f, 0.7f,
30                 0.0f, 0.0f, 1.0f, 1.0f,
31         };
32         float gain[3] = { 0.8f, 1.0f, 1.2f };
33         float expected_data[] = {
34                 0.0f, 0.0f, 0.0f, 1.0f,
35                 0.4f, 0.5f, 0.6f, 0.3f,
36                 0.8f, 0.0f, 0.0f, 1.0f,
37                 0.0f, 1.0f, 0.0f, 0.7f,
38                 0.0f, 0.0f, 1.2f, 1.0f,
39         };
40
41         float out_data[5 * 4];
42         EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
43         Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
44         ASSERT_TRUE(lgg_effect->set_vec3("gain", gain));
45         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
46
47         expect_equal(expected_data, out_data, 4, 5);
48 }
49
50 TEST(LiftGammaGainEffectTest, LiftIsDoneInApproximatelysRGB) {
51         float data[] = {
52                 0.0f, 0.0f, 0.0f, 1.0f,
53                 0.5f, 0.5f, 0.5f, 0.3f,
54                 1.0f, 0.0f, 0.0f, 1.0f,
55                 0.0f, 1.0f, 0.0f, 0.7f,
56                 0.0f, 0.0f, 1.0f, 1.0f,
57         };
58         float lift[3] = { 0.0f, 0.1f, 0.2f };
59         float expected_data[] = {
60                 0.0f, 0.1f , 0.2f, 1.0f,
61                 0.5f, 0.55f, 0.6f, 0.3f,
62                 1.0f, 0.1f,  0.2f, 1.0f,
63                 0.0f, 1.0f,  0.2f, 0.7f,
64                 0.0f, 0.1f,  1.0f, 1.0f,
65         };
66
67         float out_data[5 * 4];
68         EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
69         Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
70         ASSERT_TRUE(lgg_effect->set_vec3("lift", lift));
71         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
72
73         // sRGB is only approximately gamma-2.2, so loosen up the limits a bit.
74         expect_equal(expected_data, out_data, 4, 5, 0.03, 0.003);
75 }
76
77 TEST(LiftGammaGainEffectTest, Gamma22IsApproximatelysRGB) {
78         float data[] = {
79                 0.0f, 0.0f, 0.0f, 1.0f,
80                 0.5f, 0.5f, 0.5f, 0.3f,
81                 1.0f, 0.0f, 0.0f, 1.0f,
82                 0.0f, 1.0f, 0.0f, 0.7f,
83                 0.0f, 0.0f, 1.0f, 1.0f,
84         };
85         float gamma[3] = { 2.2f, 2.2f, 2.2f };
86
87         float out_data[5 * 4];
88         EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
89         Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
90         ASSERT_TRUE(lgg_effect->set_vec3("gamma", gamma));
91         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
92
93         expect_equal(data, out_data, 4, 5);
94 }