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