1 // Unit tests for VignetteEffect.
5 #include "effect_chain.h"
6 #include "vignette_effect.h"
7 #include "gtest/gtest.h"
8 #include "image_format.h"
11 TEST(VignetteEffectTest, HugeInnerRadiusDoesNothing) {
14 float data[size * size] = {
20 float out_data[size * size];
22 EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
23 Effect *vignette_effect = tester.get_chain()->add_effect(new VignetteEffect());
24 ASSERT_TRUE(vignette_effect->set_float("inner_radius", 10.0f));
25 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
27 expect_equal(data, out_data, size, size);
30 TEST(VignetteEffectTest, HardCircle) {
33 float data[size * size], out_data[size * size], expected_data[size * size];
34 for (int y = 0; y < size; ++y) {
35 for (int x = 0; x < size; ++x) {
36 data[y * size + x] = 1.0f;
39 for (int y = 0; y < size; ++y) {
40 const float yf = (y + 0.5f) / size;
41 for (int x = 0; x < size; ++x) {
42 const float xf = (x + 0.5f) / size;
43 if (hypot(xf - 0.5, yf - 0.5) < 0.3) {
44 expected_data[y * size + x] = 1.0f;
46 expected_data[y * size + x] = 0.0f;
51 EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
52 Effect *vignette_effect = tester.get_chain()->add_effect(new VignetteEffect());
53 ASSERT_TRUE(vignette_effect->set_float("radius", 0.0f));
54 ASSERT_TRUE(vignette_effect->set_float("inner_radius", 0.3f));
55 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
57 expect_equal(expected_data, out_data, size, size);
60 TEST(VignetteEffectTest, BurstFromUpperLeftCorner) {
61 const int width = 16, height = 24;
64 float data[width * height], out_data[width * height], expected_data[width * height];
65 for (int y = 0; y < height; ++y) {
66 for (int x = 0; x < width; ++x) {
67 data[y * width + x] = 1.0f;
70 for (int y = 0; y < height; ++y) {
71 const float yf = (y + 0.5f) / width; // Note: Division by width.
72 for (int x = 0; x < width; ++x) {
73 const float xf = (x + 0.5f) / width;
74 const float d = hypot(xf, yf) / radius;
76 expected_data[y * width + x] = 0.0f;
78 expected_data[y * width + x] = cos(d * 0.5 * M_PI) * cos(d * 0.5 * M_PI);
83 EffectChainTester tester(data, width, height, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
84 Effect *vignette_effect = tester.get_chain()->add_effect(new VignetteEffect());
85 float center[] = { 0.0f, 0.0f };
86 ASSERT_TRUE(vignette_effect->set_vec2("center", center));
87 ASSERT_TRUE(vignette_effect->set_float("radius", radius));
88 ASSERT_TRUE(vignette_effect->set_float("inner_radius", 0.0f));
89 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
91 expect_equal(expected_data, out_data, width, height);