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"
14 TEST(OverlayEffectTest, TopDominatesBottomWhenNoAlpha) {
24 EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
25 Effect *input1 = tester.get_chain()->last_added_effect();
26 Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
28 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
29 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
31 expect_equal(data_b, out_data, 2, 2);
34 TEST(OverlayEffectTest, BottomDominatesTopWhenTopIsTransparent) {
36 1.0f, 0.0f, 0.0f, 0.5f,
39 0.5f, 0.5f, 0.5f, 0.0f,
42 EffectChainTester tester(data_a, 1, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
43 Effect *input1 = tester.get_chain()->last_added_effect();
44 Effect *input2 = tester.add_input(data_b, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
46 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
47 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
49 expect_equal(data_a, out_data, 4, 1);
52 TEST(OverlayEffectTest, ZeroAlphaRemainsZeroAlpha) {
54 0.0f, 0.25f, 0.5f, 0.0f
57 1.0f, 1.0f, 1.0f, 0.0f
59 float expected_data[] = {
60 0.0f, 0.0f, 0.0f, 0.0f
63 EffectChainTester tester(data_a, 1, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
64 Effect *input1 = tester.get_chain()->last_added_effect();
65 Effect *input2 = tester.add_input(data_b, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
67 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
68 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
70 EXPECT_FLOAT_EQ(0.0f, expected_data[3]);
73 // This is tested against what Photoshop does: (255,0,128, 0.25) over (128,255,0, 0.5)
74 // becomes (179,153,51, 0.63). (Actually we fudge 0.63 to 0.625, because that's
75 // what it should be.)
76 TEST(OverlayEffectTest, PhotoshopReferenceTest) {
78 128.0f/255.0f, 1.0f, 0.0f, 0.5f
81 1.0f, 0.0f, 128.0f/255.0f, 0.25f
83 float expected_data[] = {
84 179.0f/255.0f, 153.0f/255.0f, 51.0f/255.0f, 0.625f
87 EffectChainTester tester(data_a, 1, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
88 Effect *input1 = tester.get_chain()->last_added_effect();
89 Effect *input2 = tester.add_input(data_b, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
91 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
92 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
94 expect_equal(expected_data, out_data, 4, 1);