1 // Unit tests for SaturationEffect.
5 #include "effect_chain.h"
6 #include "gtest/gtest.h"
7 #include "image_format.h"
8 #include "saturation_effect.h"
11 TEST(SaturationEffectTest, SaturationOneIsPassThrough) {
13 1.0f, 0.5f, 0.75f, 0.6f,
16 EffectChainTester tester(data, 1, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
17 Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
18 ASSERT_TRUE(saturation_effect->set_float("saturation", 1.0f));
19 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
21 expect_equal(data, out_data, 1, 1);
24 TEST(SaturationEffectTest, SaturationZeroRemovesColorButPreservesAlpha) {
26 0.0f, 0.0f, 0.0f, 1.0f,
27 0.5f, 0.5f, 0.5f, 0.3f,
28 1.0f, 0.0f, 0.0f, 1.0f,
29 0.0f, 1.0f, 0.0f, 0.7f,
30 0.0f, 0.0f, 1.0f, 1.0f,
32 float expected_data[] = {
33 0.0f, 0.0f, 0.0f, 1.0f,
34 0.5f, 0.5f, 0.5f, 0.3f,
35 0.2126f, 0.2126f, 0.2126f, 1.0f,
36 0.7152f, 0.7152f, 0.7152f, 0.7f,
37 0.0722f, 0.0722f, 0.0722f, 1.0f,
40 float out_data[5 * 4];
41 EffectChainTester tester(data, 5, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
42 Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
43 ASSERT_TRUE(saturation_effect->set_float("saturation", 0.0f));
44 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
46 expect_equal(expected_data, out_data, 4, 5);
49 TEST(SaturationEffectTest, DoubleSaturation) {
51 0.0f, 0.0f, 0.0f, 1.0f,
52 0.5f, 0.5f, 0.5f, 0.3f,
53 0.3f, 0.1f, 0.1f, 1.0f,
55 float expected_data[] = {
56 0.0f, 0.0f, 0.0f, 1.0f,
57 0.5f, 0.5f, 0.5f, 0.3f,
58 0.4570f, 0.0575f, 0.0575f, 1.0f,
61 float out_data[3 * 4];
62 EffectChainTester tester(data, 3, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
63 Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
64 ASSERT_TRUE(saturation_effect->set_float("saturation", 2.0f));
65 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
67 expect_equal(expected_data, out_data, 4, 3);