1 // Unit tests for DiffusionEffect.
3 #include "diffusion_effect.h"
4 #include "effect_chain.h"
5 #include "gtest/gtest.h"
6 #include "image_format.h"
9 TEST(DiffusionEffectTest, IdentityTransformDoesNothing) {
12 float data[size * size] = {
18 float out_data[size * size];
20 EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
21 Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
22 ASSERT_TRUE(diffusion_effect->set_float("radius", 0.0f));
23 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
25 expect_equal(data, out_data, size, size);
28 TEST(DiffusionEffectTest, FlattensOutWhitePyramid) {
31 float data[size * size] = {
32 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
33 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
34 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
35 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
36 0.0, 0.0, 0.5, 0.7, 1.0, 0.7, 0.5, 0.0, 0.0,
37 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
38 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
39 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
40 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
42 float expected_data[size * size] = {
43 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
44 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
45 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
46 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
47 0.0, 0.0, 0.4, 0.5, 0.6, 0.5, 0.4, 0.0, 0.0,
48 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
49 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
50 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
51 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
53 float out_data[size * size];
55 EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
56 Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
57 ASSERT_TRUE(diffusion_effect->set_float("radius", 2.0f));
58 ASSERT_TRUE(diffusion_effect->set_float("blurred_mix_amount", 0.7f));
59 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
61 expect_equal(expected_data, out_data, size, size, 0.05f, 0.002);