]> git.sesse.net Git - movit/blob - saturation_effect_test.cpp
Release Movit 1.6.1.
[movit] / saturation_effect_test.cpp
1 // Unit tests for SaturationEffect.
2
3 #include <epoxy/gl.h>
4
5 #include "effect_chain.h"
6 #include "gtest/gtest.h"
7 #include "image_format.h"
8 #include "saturation_effect.h"
9 #include "test_util.h"
10
11 namespace movit {
12
13 TEST(SaturationEffectTest, SaturationOneIsPassThrough) {
14         float data[] = {
15                 1.0f, 0.5f, 0.75f, 0.6f,
16         };
17         float out_data[4];
18         EffectChainTester tester(data, 1, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
19         Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
20         ASSERT_TRUE(saturation_effect->set_float("saturation", 1.0f));
21         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
22
23         expect_equal(data, out_data, 1, 1);
24 }
25
26 TEST(SaturationEffectTest, SaturationZeroRemovesColorButPreservesAlpha) {
27         float data[] = {
28                 0.0f, 0.0f, 0.0f, 1.0f,
29                 0.5f, 0.5f, 0.5f, 0.3f,
30                 1.0f, 0.0f, 0.0f, 1.0f,
31                 0.0f, 1.0f, 0.0f, 0.7f,
32                 0.0f, 0.0f, 1.0f, 1.0f,
33         };
34         float expected_data[] = {
35                 0.0f, 0.0f, 0.0f, 1.0f,
36                 0.5f, 0.5f, 0.5f, 0.3f,
37                 0.2126f, 0.2126f, 0.2126f, 1.0f,
38                 0.7152f, 0.7152f, 0.7152f, 0.7f,
39                 0.0722f, 0.0722f, 0.0722f, 1.0f,
40         };
41
42         float out_data[5 * 4];
43         EffectChainTester tester(data, 5, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
44         Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
45         ASSERT_TRUE(saturation_effect->set_float("saturation", 0.0f));
46         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
47
48         expect_equal(expected_data, out_data, 4, 5);
49 }
50
51 TEST(SaturationEffectTest, DoubleSaturation) {
52         float data[] = {
53                 0.0f, 0.0f, 0.0f, 1.0f,
54                 0.5f, 0.5f, 0.5f, 0.3f,
55                 0.3f, 0.1f, 0.1f, 1.0f,
56         };
57         float expected_data[] = {
58                 0.0f, 0.0f, 0.0f, 1.0f,
59                 0.5f, 0.5f, 0.5f, 0.3f,
60                 0.4570f, 0.0575f, 0.0575f, 1.0f,
61         };
62
63         float out_data[3 * 4];
64         EffectChainTester tester(data, 3, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
65         Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
66         ASSERT_TRUE(saturation_effect->set_float("saturation", 2.0f));
67         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
68
69         expect_equal(expected_data, out_data, 4, 3);
70 }
71
72 }  // namespace movit