1 // Unit tests for OverlayEffect.
4 #include "gtest/gtest.h"
5 #include "overlay_effect.h"
7 TEST(OverlayEffectTest, TopDominatesBottomWhenNoAlpha) {
17 EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
18 Effect *input1 = tester.get_chain()->last_added_effect();
19 Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
21 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
22 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
24 expect_equal(data_b, out_data, 2, 2);
27 TEST(OverlayEffectTest, BottomDominatesTopWhenTopIsTransparent) {
29 1.0f, 0.0f, 0.0f, 0.5f,
32 0.5f, 0.5f, 0.5f, 0.0f,
35 EffectChainTester tester(data_a, 1, 1, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
36 Effect *input1 = tester.get_chain()->last_added_effect();
37 Effect *input2 = tester.add_input(data_b, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
39 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
40 tester.run(out_data, GL_BGRA, COLORSPACE_sRGB, GAMMA_LINEAR);
42 expect_equal(data_a, out_data, 4, 1);
45 TEST(OverlayEffectTest, ZeroAlphaRemainsZeroAlpha) {
47 0.0f, 0.25f, 0.5f, 0.0f
50 1.0f, 1.0f, 1.0f, 0.0f
52 float expected_data[] = {
53 0.0f, 0.0f, 0.0f, 0.0f
56 EffectChainTester tester(data_a, 1, 1, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
57 Effect *input1 = tester.get_chain()->last_added_effect();
58 Effect *input2 = tester.add_input(data_b, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
60 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
61 tester.run(out_data, GL_BGRA, COLORSPACE_sRGB, GAMMA_LINEAR);
63 EXPECT_FLOAT_EQ(0.0f, expected_data[3]);
66 // This is tested against what Photoshop does: (255,0,128, 0.25) over (128,255,0, 0.5)
67 // becomes (179,153,51, 0.63). (Actually we fudge 0.63 to 0.625, because that's
68 // what it should be.)
69 TEST(OverlayEffectTest, PhotoshopReferenceTest) {
71 128.0f/255.0f, 1.0f, 0.0f, 0.5f
74 1.0f, 0.0f, 128.0f/255.0f, 0.25f
76 float expected_data[] = {
77 179.0f/255.0f, 153.0f/255.0f, 51.0f/255.0f, 0.625f
80 EffectChainTester tester(data_a, 1, 1, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
81 Effect *input1 = tester.get_chain()->last_added_effect();
82 Effect *input2 = tester.add_input(data_b, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
84 tester.get_chain()->add_effect(new OverlayEffect(), input1, input2);
85 tester.run(out_data, GL_BGRA, COLORSPACE_sRGB, GAMMA_LINEAR);
87 expect_equal(expected_data, out_data, 4, 1);