1 // Unit tests for VignetteEffect.
6 #include "effect_chain.h"
7 #include "gtest/gtest.h"
8 #include "image_format.h"
10 #include "vignette_effect.h"
14 TEST(VignetteEffectTest, HugeInnerRadiusDoesNothing) {
17 float data[size * size] = {
23 float out_data[size * size];
25 EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
26 Effect *vignette_effect = tester.get_chain()->add_effect(new VignetteEffect());
27 ASSERT_TRUE(vignette_effect->set_float("inner_radius", 10.0f));
28 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
30 expect_equal(data, out_data, size, size);
33 TEST(VignetteEffectTest, HardCircle) {
36 float data[size * size], out_data[size * size], expected_data[size * size];
37 for (int y = 0; y < size; ++y) {
38 for (int x = 0; x < size; ++x) {
39 data[y * size + x] = 1.0f;
42 for (int y = 0; y < size; ++y) {
43 const float yf = (y + 0.5f) / size;
44 for (int x = 0; x < size; ++x) {
45 const float xf = (x + 0.5f) / size;
46 if (hypot(xf - 0.5, yf - 0.5) < 0.3) {
47 expected_data[y * size + x] = 1.0f;
49 expected_data[y * size + x] = 0.0f;
54 EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
55 Effect *vignette_effect = tester.get_chain()->add_effect(new VignetteEffect());
56 ASSERT_TRUE(vignette_effect->set_float("radius", 0.0f));
57 ASSERT_TRUE(vignette_effect->set_float("inner_radius", 0.3f));
58 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
60 expect_equal(expected_data, out_data, size, size);
63 TEST(VignetteEffectTest, BurstFromUpperLeftCorner) {
64 const int width = 16, height = 24;
67 float data[width * height], out_data[width * height], expected_data[width * height];
68 for (int y = 0; y < height; ++y) {
69 for (int x = 0; x < width; ++x) {
70 data[y * width + x] = 1.0f;
73 for (int y = 0; y < height; ++y) {
74 const float yf = (y + 0.5f) / width; // Note: Division by width.
75 for (int x = 0; x < width; ++x) {
76 const float xf = (x + 0.5f) / width;
77 const float d = hypot(xf, yf) / radius;
79 expected_data[y * width + x] = 0.0f;
81 expected_data[y * width + x] = cos(d * 0.5 * M_PI) * cos(d * 0.5 * M_PI);
86 EffectChainTester tester(data, width, height, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
87 Effect *vignette_effect = tester.get_chain()->add_effect(new VignetteEffect());
88 float center[] = { 0.0f, 0.0f };
89 ASSERT_TRUE(vignette_effect->set_vec2("center", center));
90 ASSERT_TRUE(vignette_effect->set_float("radius", radius));
91 ASSERT_TRUE(vignette_effect->set_float("inner_radius", 0.0f));
92 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
94 expect_equal(expected_data, out_data, width, height);