]> git.sesse.net Git - movit/blob - luma_mix_effect_test.cpp
Release Movit 1.7.1.
[movit] / luma_mix_effect_test.cpp
1 // Unit tests for LumaMixEffect.
2
3 #include <epoxy/gl.h>
4
5 #include "effect_chain.h"
6 #include "gtest/gtest.h"
7 #include "image_format.h"
8 #include "input.h"
9 #include "luma_mix_effect.h"
10 #include "test_util.h"
11
12 namespace movit {
13
14 TEST(LumaMixEffectTest, HardWipe) {
15         float data_a[] = {
16                 0.0f, 0.25f,
17                 0.75f, 1.0f,
18         };
19         float data_b[] = {
20                 1.0f, 0.5f,
21                 0.65f, 0.6f,
22         };
23         float data_luma[] = {
24                 0.0f, 0.25f,
25                 0.5f, 0.75f,
26         };
27
28         EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
29         Effect *input1 = tester.get_chain()->last_added_effect();
30         Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
31         Effect *input3 = tester.add_input(data_luma, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
32
33         Effect *luma_mix_effect = tester.get_chain()->add_effect(new LumaMixEffect(), input1, input2, input3);
34         ASSERT_TRUE(luma_mix_effect->set_float("transition_width", 100000.0f));
35
36         float out_data[4];
37         ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.0f));
38         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
39         expect_equal(data_a, out_data, 2, 2);
40
41         // Lower right from B, the rest from A.
42         float expected_data_049[] = {
43                 0.0f, 0.25f,
44                 0.75f, 0.6f,
45         };
46         ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.49f));
47         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
48         expect_equal(expected_data_049, out_data, 2, 2);
49
50         // Lower two from B, the rest from A.
51         float expected_data_051[] = {
52                 0.0f, 0.25f,
53                 0.65f, 0.6f,
54         };
55         ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.51f));
56         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
57         expect_equal(expected_data_051, out_data, 2, 2);
58
59         ASSERT_TRUE(luma_mix_effect->set_float("progress", 1.0f));
60         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
61         expect_equal(data_b, out_data, 2, 2);
62 }
63
64 TEST(LumaMixEffectTest, SoftWipeHalfWayThrough) {
65         float data_a[] = {
66                 0.0f, 0.25f,
67                 0.75f, 1.0f,
68         };
69         float data_b[] = {
70                 1.0f, 0.5f,
71                 0.65f, 0.6f,
72         };
73         float data_luma[] = {
74                 0.0f, 0.25f,
75                 0.5f, 0.75f,
76         };
77         // At this point, the luma range and the mix range should exactly line up,
78         // so we get a straight-up fade by luma.
79         float expected_data[] = {
80                 data_a[0] + (data_b[0] - data_a[0]) * data_luma[0],
81                 data_a[1] + (data_b[1] - data_a[1]) * data_luma[1],
82                 data_a[2] + (data_b[2] - data_a[2]) * data_luma[2],
83                 data_a[3] + (data_b[3] - data_a[3]) * data_luma[3],
84         };
85         float out_data[4];
86
87         EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
88         Effect *input1 = tester.get_chain()->last_added_effect();
89         Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
90         Effect *input3 = tester.add_input(data_luma, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
91
92         Effect *luma_mix_effect = tester.get_chain()->add_effect(new LumaMixEffect(), input1, input2, input3);
93         ASSERT_TRUE(luma_mix_effect->set_float("transition_width", 1.0f));
94         ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.5f));
95         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
96         expect_equal(expected_data, out_data, 2, 2);
97 }
98
99 TEST(LumaMixEffectTest, Inverse) {
100         float data_a[] = {
101                 0.0f, 0.25f,
102                 0.75f, 1.0f,
103         };
104         float data_b[] = {
105                 1.0f, 0.5f,
106                 0.65f, 0.6f,
107         };
108         float data_luma[] = {
109                 0.0f, 0.25f,
110                 0.5f, 0.75f,
111         };
112
113         EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
114         Effect *input1 = tester.get_chain()->last_added_effect();
115         Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
116         Effect *input3 = tester.add_input(data_luma, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
117
118         Effect *luma_mix_effect = tester.get_chain()->add_effect(new LumaMixEffect(), input1, input2, input3);
119         ASSERT_TRUE(luma_mix_effect->set_float("transition_width", 100000.0f));
120         ASSERT_TRUE(luma_mix_effect->set_int("inverse", 1));
121
122         // Inverse is not the same as reverse, so progress=0 should behave identically
123         // as HardWipe, ie. everything should be from A.
124         float out_data[4];
125         ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.0f));
126         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
127         expect_equal(data_a, out_data, 2, 2);
128
129         // Lower two from A, the rest from B.
130         float expected_data_049[] = {
131                 1.0f, 0.5f,
132                 0.75f, 1.0f,
133         };
134         ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.49f));
135         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
136         expect_equal(expected_data_049, out_data, 2, 2);
137 }
138
139 }  // namespace movit