1 // Unit tests for DiffusionEffect.
5 #include "diffusion_effect.h"
6 #include "effect_chain.h"
7 #include "gtest/gtest.h"
8 #include "image_format.h"
13 TEST(DiffusionEffectTest, IdentityTransformDoesNothing) {
16 float data[size * size] = {
22 float out_data[size * size];
24 EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
25 Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
26 ASSERT_TRUE(diffusion_effect->set_float("radius", 0.0f));
27 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
29 expect_equal(data, out_data, size, size);
32 TEST(DiffusionEffectTest, FlattensOutWhitePyramid) {
35 float data[size * size] = {
36 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
37 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
40 0.0, 0.0, 0.5, 0.7, 1.0, 0.7, 0.5, 0.0, 0.0,
41 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
42 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
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,
46 float expected_data[size * size] = {
47 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
48 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
51 0.0, 0.0, 0.4, 0.5, 0.6, 0.5, 0.4, 0.0, 0.0,
52 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
53 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
54 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
55 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
57 float out_data[size * size];
59 EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
60 Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
61 ASSERT_TRUE(diffusion_effect->set_float("radius", 2.0f));
62 ASSERT_TRUE(diffusion_effect->set_float("blurred_mix_amount", 0.7f));
63 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
65 expect_equal(expected_data, out_data, size, size, 0.05f, 0.002);