]> git.sesse.net Git - movit/blob - overlay_effect_test.cpp
Fix multiply-defined symbols with multiple YCbCrInputs in the same chain.
[movit] / overlay_effect_test.cpp
1 // Unit tests for OverlayEffect.
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 "overlay_effect.h"
10 #include "test_util.h"
11 #include "util.h"
12
13 namespace movit {
14
15 TEST(OverlayEffectTest, TopDominatesBottomWhenNoAlpha) {
16         for (int swap_inputs = 0; swap_inputs < 2; ++swap_inputs) {  // false, true.
17                 float data_a[] = {
18                         0.0f, 0.25f,
19                         0.75f, 1.0f,
20                 };
21                 float data_b[] = {
22                         1.0f, 0.5f,
23                         0.75f, 0.6f,
24                 };
25                 float out_data[4];
26                 EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
27                 Effect *input1 = tester.get_chain()->last_added_effect();
28                 Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
29
30                 OverlayEffect *effect = new OverlayEffect();
31                 CHECK(effect->set_int("swap_inputs", swap_inputs));
32                 tester.get_chain()->add_effect(effect, input1, input2);
33                 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
34
35                 if (swap_inputs) {
36                         expect_equal(data_a, out_data, 2, 2);
37                 } else {
38                         expect_equal(data_b, out_data, 2, 2);
39                 }
40         }
41 }
42
43 TEST(OverlayEffectTest, BottomDominatesTopWhenTopIsTransparent) {
44         float data_a[] = {
45                 1.0f, 0.0f, 0.0f, 0.5f,
46         };
47         float data_b[] = {
48                 0.5f, 0.5f, 0.5f, 0.0f,
49         };
50         float out_data[4];
51         EffectChainTester tester(data_a, 1, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
52         Effect *input1 = tester.get_chain()->last_added_effect();
53         Effect *input2 = tester.add_input(data_b, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
54
55         tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
56         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
57
58         expect_equal(data_a, out_data, 4, 1);
59 }
60
61 TEST(OverlayEffectTest, ZeroAlphaRemainsZeroAlpha) {
62         float data_a[] = {
63                 0.0f, 0.25f, 0.5f, 0.0f
64         };
65         float data_b[] = {
66                 1.0f, 1.0f, 1.0f, 0.0f
67         };
68         float expected_data[] = {
69                 0.0f, 0.0f, 0.0f, 0.0f
70         };
71         float out_data[4];
72         EffectChainTester tester(data_a, 1, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
73         Effect *input1 = tester.get_chain()->last_added_effect();
74         Effect *input2 = tester.add_input(data_b, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
75
76         tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
77         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
78
79         EXPECT_FLOAT_EQ(0.0f, expected_data[3]);
80 }
81
82 // This is tested against what Photoshop does: (255,0,128, 0.25) over (128,255,0, 0.5)
83 // becomes (179,153,51, 0.63). (Actually we fudge 0.63 to 0.625, because that's
84 // what it should be.)
85 TEST(OverlayEffectTest, PhotoshopReferenceTest) {
86         float data_a[] = {
87                 128.0f/255.0f, 1.0f, 0.0f, 0.5f
88         };
89         float data_b[] = {
90                 1.0f, 0.0f, 128.0f/255.0f, 0.25f
91         };
92         float expected_data[] = {
93                 179.0f/255.0f, 153.0f/255.0f, 51.0f/255.0f, 0.625f
94         };
95         float out_data[4];
96         EffectChainTester tester(data_a, 1, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
97         Effect *input1 = tester.get_chain()->last_added_effect();
98         Effect *input2 = tester.add_input(data_b, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
99
100         tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
101         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
102
103         expect_equal(expected_data, out_data, 4, 1);
104 }
105
106 }  // namespace movit