1 // Unit tests for OverlayEffect.
5 #include "effect_chain.h"
6 #include "gtest/gtest.h"
7 #include "image_format.h"
9 #include "overlay_effect.h"
10 #include "test_util.h"
15 TEST(OverlayEffectTest, TopDominatesBottomWhenNoAlpha) {
16 for (int swap_inputs = 0; swap_inputs < 2; ++swap_inputs) { // false, true.
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);
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);
36 expect_equal(data_a, out_data, 2, 2);
38 expect_equal(data_b, out_data, 2, 2);
43 TEST(OverlayEffectTest, BottomDominatesTopWhenTopIsTransparent) {
45 1.0f, 0.0f, 0.0f, 0.5f,
48 0.5f, 0.5f, 0.5f, 0.0f,
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);
55 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
56 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
58 expect_equal(data_a, out_data, 4, 1);
61 TEST(OverlayEffectTest, ZeroAlphaRemainsZeroAlpha) {
63 0.0f, 0.25f, 0.5f, 0.0f
66 1.0f, 1.0f, 1.0f, 0.0f
68 float expected_data[] = {
69 0.0f, 0.0f, 0.0f, 0.0f
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);
76 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
77 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
79 EXPECT_FLOAT_EQ(0.0f, expected_data[3]);
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) {
87 128.0f/255.0f, 1.0f, 0.0f, 0.5f
90 1.0f, 0.0f, 128.0f/255.0f, 0.25f
92 float expected_data[] = {
93 179.0f/255.0f, 153.0f/255.0f, 51.0f/255.0f, 0.625f
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);
100 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
101 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
103 expect_equal(expected_data, out_data, 4, 1);