In ResampleEffect, precompute the Lanczos function into a table.
[movit] / complex_modulate_effect_test.cpp
1 // Unit tests for ComplexModulateEffect.
2
3 #include <epoxy/gl.h>
4
5 #include "effect_chain.h"
6 #include "gtest/gtest.h"
7 #include "complex_modulate_effect.h"
8 #include "image_format.h"
9 #include "input.h"
10 #include "test_util.h"
11
12 namespace movit {
13
14 TEST(ComplexModulateEffectTest, Identity) {
15         const int size = 3;
16         float data_a[size * 4] = {
17                 0.0f, 0.1f, 0.2f, 0.1f,
18                 0.4f, 0.3f, 0.8f, 2.0f,
19                 0.5f, 0.2f, 0.1f, 0.0f,
20         };
21         float data_b[size * 2] = {
22                 1.0f, 0.0f,
23                 1.0f, 0.0f,
24                 1.0f, 0.0f,
25         };
26         float out_data[size * 4];
27
28         EffectChainTester tester(data_a, 1, size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
29         Effect *input1 = tester.get_chain()->last_added_effect();
30         Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR);
31
32         tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
33         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
34
35         expect_equal(data_a, out_data, 4, size);
36 }
37
38 TEST(ComplexModulateEffectTest, ComplexMultiplication) {
39         const int size = 2;
40         float data_a[size * 4] = {
41                 0.0f, 0.1f, 0.2f, 0.1f,
42                 0.4f, 0.3f, 0.8f, 2.0f,
43         };
44         float data_b[size * 2] = {
45                 0.0f,  1.0f,
46                 0.5f, -0.8f,
47         };
48         float expected_data[size * 4] = {
49                 -0.1f,   0.0f,  -0.1f, 0.2f,
50                  0.44f, -0.17f,  2.0f, 0.36f,
51         };
52         float out_data[size * 4];
53
54         EffectChainTester tester(data_a, 1, size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
55         Effect *input1 = tester.get_chain()->last_added_effect();
56         Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR);
57
58         tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
59         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
60
61         expect_equal(expected_data, out_data, 4, size);
62 }
63
64 TEST(ComplexModulateEffectTest, Repeat) {
65         const int size = 2, repeats = 3;
66         float data_a[size * repeats * 4] = {
67                 0.0f, 0.1f, 0.2f, 0.3f,
68                 1.0f, 1.1f, 1.2f, 1.3f,
69                 2.0f, 2.1f, 2.2f, 2.3f,
70                 3.0f, 3.1f, 3.2f, 3.3f,
71                 4.0f, 4.1f, 4.2f, 4.3f,
72                 5.0f, 5.1f, 5.2f, 5.3f,
73         };
74         float data_b[size * 2] = {
75                 1.0f,  0.0f,
76                 0.0f, -1.0f,
77         };
78         float expected_data[size * repeats * 4] = {
79                 0.0f,  0.1f, 0.2f,  0.3f,
80                 1.1f, -1.0f, 1.3f, -1.2f,
81                 2.0f,  2.1f, 2.2f,  2.3f,
82                 3.1f, -3.0f, 3.3f, -3.2f,
83                 4.0f,  4.1f, 4.2f,  4.3f,
84                 5.1f, -5.0f, 5.3f, -5.2f,
85         };
86         float out_data[size * repeats * 4];
87
88         EffectChainTester tester(data_a, 1, repeats * size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
89         Effect *input1 = tester.get_chain()->last_added_effect();
90         Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR, 1, size);
91
92         Effect *effect = tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
93         ASSERT_TRUE(effect->set_int("num_repeats_y", repeats));
94         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
95
96         expect_equal(expected_data, out_data, 4, size * repeats);
97 }
98
99 }  // namespace movit