]> git.sesse.net Git - movit/blob - overlay_effect_test.cpp
d0867a13136e504a82bfa1a5dd3a0df9524186f1
[movit] / overlay_effect_test.cpp
1 // Unit tests for OverlayEffect.
2
3 #include "test_util.h"
4 #include "gtest/gtest.h"
5 #include "overlay_effect.h"
6
7 TEST(OverlayEffectTest, TopDominatesBottomWhenNoAlpha) {
8         float data_a[] = {
9                 0.0f, 0.25f,
10                 0.75f, 1.0f,
11         };
12         float data_b[] = {
13                 1.0f, 0.5f,
14                 0.75f, 0.6f,
15         };
16         float out_data[4];
17         EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
18         Effect *input1 = tester.get_chain()->last_added_effect();
19         Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
20
21         tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
22         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
23
24         expect_equal(data_b, out_data, 2, 2);
25 }
26
27 TEST(OverlayEffectTest, BottomDominatesTopWhenTopIsTransparent) {
28         float data_a[] = {
29                 1.0f, 0.0f, 0.0f, 0.5f,
30         };
31         float data_b[] = {
32                 0.5f, 0.5f, 0.5f, 0.0f,
33         };
34         float out_data[4];
35         EffectChainTester tester(data_a, 1, 1, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
36         Effect *input1 = tester.get_chain()->last_added_effect();
37         Effect *input2 = tester.add_input(data_b, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
38
39         tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
40         tester.run(out_data, GL_BGRA, COLORSPACE_sRGB, GAMMA_LINEAR);
41
42         expect_equal(data_a, out_data, 4, 1);
43 }
44
45 TEST(OverlayEffectTest, ZeroAlphaRemainsZeroAlpha) {
46         float data_a[] = {
47                 0.0f, 0.25f, 0.5f, 0.0f
48         };
49         float data_b[] = {
50                 1.0f, 1.0f, 1.0f, 0.0f
51         };
52         float expected_data[] = {
53                 0.0f, 0.0f, 0.0f, 0.0f
54         };
55         float out_data[4];
56         EffectChainTester tester(data_a, 1, 1, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
57         Effect *input1 = tester.get_chain()->last_added_effect();
58         Effect *input2 = tester.add_input(data_b, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
59
60         tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
61         tester.run(out_data, GL_BGRA, COLORSPACE_sRGB, GAMMA_LINEAR);
62
63         EXPECT_FLOAT_EQ(0.0f, expected_data[3]);
64 }
65
66 // This is tested against what Photoshop does: (255,0,128, 0.25) over (128,255,0, 0.5)
67 // becomes (179,153,51, 0.63). (Actually we fudge 0.63 to 0.625, because that's
68 // what it should be.)
69 TEST(OverlayEffectTest, PhotoshopReferenceTest) {
70         float data_a[] = {
71                 128.0f/255.0f, 1.0f, 0.0f, 0.5f
72         };
73         float data_b[] = {
74                 1.0f, 0.0f, 128.0f/255.0f, 0.25f
75         };
76         float expected_data[] = {
77                 179.0f/255.0f, 153.0f/255.0f, 51.0f/255.0f, 0.625f
78         };
79         float out_data[4];
80         EffectChainTester tester(data_a, 1, 1, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
81         Effect *input1 = tester.get_chain()->last_added_effect();
82         Effect *input2 = tester.add_input(data_b, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
83
84         tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
85         tester.run(out_data, GL_BGRA, COLORSPACE_sRGB, GAMMA_LINEAR);
86
87         expect_equal(expected_data, out_data, 4, 1);
88 }