1 // Unit tests for LumaMixEffect.
5 #include "effect_chain.h"
6 #include "gtest/gtest.h"
7 #include "image_format.h"
9 #include "luma_mix_effect.h"
10 #include "test_util.h"
14 TEST(LumaMixEffectTest, HardWipe) {
28 EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
29 Effect *input1 = tester.get_chain()->last_added_effect();
30 Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
31 Effect *input3 = tester.add_input(data_luma, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
33 Effect *luma_mix_effect = tester.get_chain()->add_effect(new LumaMixEffect(), input1, input2, input3);
34 ASSERT_TRUE(luma_mix_effect->set_float("transition_width", 100000.0f));
37 ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.0f));
38 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
39 expect_equal(data_a, out_data, 2, 2);
41 // Lower right from B, the rest from A.
42 float expected_data_049[] = {
46 ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.49f));
47 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
48 expect_equal(expected_data_049, out_data, 2, 2);
50 // Lower two from B, the rest from A.
51 float expected_data_051[] = {
55 ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.51f));
56 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
57 expect_equal(expected_data_051, out_data, 2, 2);
59 ASSERT_TRUE(luma_mix_effect->set_float("progress", 1.0f));
60 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
61 expect_equal(data_b, out_data, 2, 2);
64 TEST(LumaMixEffectTest, SoftWipeHalfWayThrough) {
77 // At this point, the luma range and the mix range should exactly line up,
78 // so we get a straight-up fade by luma.
79 float expected_data[] = {
80 data_a[0] + (data_b[0] - data_a[0]) * data_luma[0],
81 data_a[1] + (data_b[1] - data_a[1]) * data_luma[1],
82 data_a[2] + (data_b[2] - data_a[2]) * data_luma[2],
83 data_a[3] + (data_b[3] - data_a[3]) * data_luma[3],
87 EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
88 Effect *input1 = tester.get_chain()->last_added_effect();
89 Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
90 Effect *input3 = tester.add_input(data_luma, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
92 Effect *luma_mix_effect = tester.get_chain()->add_effect(new LumaMixEffect(), input1, input2, input3);
93 ASSERT_TRUE(luma_mix_effect->set_float("transition_width", 1.0f));
94 ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.5f));
95 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
96 expect_equal(expected_data, out_data, 2, 2);
99 TEST(LumaMixEffectTest, Inverse) {
108 float data_luma[] = {
113 EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
114 Effect *input1 = tester.get_chain()->last_added_effect();
115 Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
116 Effect *input3 = tester.add_input(data_luma, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
118 Effect *luma_mix_effect = tester.get_chain()->add_effect(new LumaMixEffect(), input1, input2, input3);
119 ASSERT_TRUE(luma_mix_effect->set_float("transition_width", 100000.0f));
120 ASSERT_TRUE(luma_mix_effect->set_int("inverse", 1));
122 // Inverse is not the same as reverse, so progress=0 should behave identically
123 // as HardWipe, ie. everything should be from A.
125 ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.0f));
126 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
127 expect_equal(data_a, out_data, 2, 2);
129 // Lower two from A, the rest from B.
130 float expected_data_049[] = {
134 ASSERT_TRUE(luma_mix_effect->set_float("progress", 0.49f));
135 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
136 expect_equal(expected_data_049, out_data, 2, 2);