]> git.sesse.net Git - movit/blob - flat_input_test.cpp
Add resample_effect_test to .gitignore.
[movit] / flat_input_test.cpp
1 // Unit tests for FlatInput.
2
3 #include "test_util.h"
4 #include "gtest/gtest.h"
5 #include "flat_input.h"
6
7 TEST(FlatInput, SimpleGrayscale) {
8         const int size = 4;
9
10         float data[size] = {
11                 0.0,
12                 0.5,
13                 0.7,
14                 1.0,
15         };
16         float expected_data[4 * size] = {
17                 0.0, 0.0, 0.0, 1.0,
18                 0.5, 0.5, 0.5, 1.0,
19                 0.7, 0.7, 0.7, 1.0,
20                 1.0, 1.0, 1.0, 1.0,
21         };
22         float out_data[4 * size];
23
24         EffectChainTester tester(data, 1, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
25         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
26
27         expect_equal(expected_data, out_data, 4, size);
28 }
29
30 TEST(FlatInput, RGB) {
31         const int size = 5;
32
33         float data[3 * size] = {
34                 0.0, 0.0, 0.0,
35                 0.5, 0.0, 0.0,
36                 0.0, 0.5, 0.0,
37                 0.0, 0.0, 0.7,
38                 0.0, 0.3, 0.7,
39         };
40         float expected_data[4 * size] = {
41                 0.0, 0.0, 0.0, 1.0,
42                 0.5, 0.0, 0.0, 1.0,
43                 0.0, 0.5, 0.0, 1.0,
44                 0.0, 0.0, 0.7, 1.0,
45                 0.0, 0.3, 0.7, 1.0,
46         };
47         float out_data[4 * size];
48
49         EffectChainTester tester(data, 1, size, FORMAT_RGB, COLORSPACE_sRGB, GAMMA_LINEAR);
50         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
51
52         expect_equal(expected_data, out_data, 4, size);
53 }
54
55 TEST(FlatInput, RGBA) {
56         const int size = 5;
57
58         float data[4 * size] = {
59                 0.0, 0.0, 0.0, 1.0,
60                 0.5, 0.0, 0.0, 0.3,
61                 0.0, 0.5, 0.0, 0.7,
62                 0.0, 0.0, 0.7, 1.0,
63                 0.0, 0.3, 0.7, 0.2,
64         };
65         float expected_data[4 * size] = {
66                 0.0, 0.0, 0.0, 1.0,
67                 0.5, 0.0, 0.0, 0.3,
68                 0.0, 0.5, 0.0, 0.7,
69                 0.0, 0.0, 0.7, 1.0,
70                 0.0, 0.3, 0.7, 0.2,
71         };
72         float out_data[4 * size];
73
74         EffectChainTester tester(data, 1, size, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
75         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
76
77         expect_equal(expected_data, out_data, 4, size);
78 }
79
80 TEST(FlatInput, BGR) {
81         const int size = 5;
82
83         float data[3 * size] = {
84                 0.0, 0.0, 0.0,
85                 0.5, 0.0, 0.0,
86                 0.0, 0.5, 0.0,
87                 0.0, 0.0, 0.7,
88                 0.0, 0.3, 0.7,
89         };
90         float expected_data[4 * size] = {
91                 0.0, 0.0, 0.0, 1.0,
92                 0.0, 0.0, 0.5, 1.0,
93                 0.0, 0.5, 0.0, 1.0,
94                 0.7, 0.0, 0.0, 1.0,
95                 0.7, 0.3, 0.0, 1.0,
96         };
97         float out_data[4 * size];
98
99         EffectChainTester tester(data, 1, size, FORMAT_BGR, COLORSPACE_sRGB, GAMMA_LINEAR);
100         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
101
102         expect_equal(expected_data, out_data, 4, size);
103 }
104
105 TEST(FlatInput, BGRA) {
106         const int size = 5;
107
108         float data[4 * size] = {
109                 0.0, 0.0, 0.0, 1.0,
110                 0.5, 0.0, 0.0, 0.3,
111                 0.0, 0.5, 0.0, 0.7,
112                 0.0, 0.0, 0.7, 1.0,
113                 0.0, 0.3, 0.7, 0.2,
114         };
115         float expected_data[4 * size] = {
116                 0.0, 0.0, 0.0, 1.0,
117                 0.0, 0.0, 0.5, 0.3,
118                 0.0, 0.5, 0.0, 0.7,
119                 0.7, 0.0, 0.0, 1.0,
120                 0.7, 0.3, 0.0, 0.2,
121         };
122         float out_data[4 * size];
123
124         EffectChainTester tester(data, 1, size, FORMAT_BGRA, COLORSPACE_sRGB, GAMMA_LINEAR);
125         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
126
127         expect_equal(expected_data, out_data, 4, size);
128 }
129
130 TEST(FlatInput, Pitch) {
131         const int pitch = 3;
132         const int width = 2;
133         const int height = 4;
134
135         float data[pitch * height] = {
136                 0.0, 1.0, 999.0f,
137                 0.5, 0.5, 999.0f,
138                 0.7, 0.2, 999.0f,
139                 1.0, 0.6, 999.0f,
140         };
141         float expected_data[4 * width * height] = {
142                 0.0, 0.0, 0.0, 1.0,  1.0, 1.0, 1.0, 1.0,
143                 0.5, 0.5, 0.5, 1.0,  0.5, 0.5, 0.5, 1.0,
144                 0.7, 0.7, 0.7, 1.0,  0.2, 0.2, 0.2, 1.0,
145                 1.0, 1.0, 1.0, 1.0,  0.6, 0.6, 0.6, 1.0,
146         };
147         float out_data[4 * width * height];
148
149         EffectChainTester tester(NULL, width, height);
150
151         ImageFormat format;
152         format.color_space = COLORSPACE_sRGB;
153         format.gamma_curve = GAMMA_LINEAR;
154
155         FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
156         input->set_pitch(pitch);
157         input->set_pixel_data(data);
158         tester.get_chain()->add_input(input);
159
160         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
161         expect_equal(expected_data, out_data, 4 * width, height);
162 }
163
164 TEST(FlatInput, UpdatedData) {
165         const int width = 2;
166         const int height = 4;
167
168         float data[width * height] = {
169                 0.0, 1.0,
170                 0.5, 0.5,
171                 0.7, 0.2,
172                 1.0, 0.6,
173         };
174         float out_data[width * height];
175
176         EffectChainTester tester(NULL, width, height);
177
178         ImageFormat format;
179         format.color_space = COLORSPACE_sRGB;
180         format.gamma_curve = GAMMA_LINEAR;
181
182         FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
183         input->set_pixel_data(data);
184         tester.get_chain()->add_input(input);
185
186         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
187         expect_equal(data, out_data, width, height);
188
189         data[6] = 0.3;
190         input->invalidate_pixel_data();
191
192         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
193         expect_equal(data, out_data, width, height);
194 }