1 // Unit tests for ComplexModulateEffect.
5 #include "effect_chain.h"
6 #include "gtest/gtest.h"
7 #include "complex_modulate_effect.h"
8 #include "image_format.h"
10 #include "test_util.h"
14 TEST(ComplexModulateEffectTest, Identity) {
16 float data_a[size * 4] = {
17 0.0f, 0.1f, 0.2f, 0.1f,
18 0.4f, 0.3f, 0.8f, 2.0f,
19 0.5f, 0.2f, 0.1f, 0.0f,
21 float data_b[size * 2] = {
26 float out_data[size * 4];
28 EffectChainTester tester(data_a, 1, size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
29 Effect *input1 = tester.get_chain()->last_added_effect();
30 Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR);
32 tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
33 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
35 expect_equal(data_a, out_data, 4, size);
38 TEST(ComplexModulateEffectTest, ComplexMultiplication) {
40 float data_a[size * 4] = {
41 0.0f, 0.1f, 0.2f, 0.1f,
42 0.4f, 0.3f, 0.8f, 2.0f,
44 float data_b[size * 2] = {
48 float expected_data[size * 4] = {
49 -0.1f, 0.0f, -0.1f, 0.2f,
50 0.44f, -0.17f, 2.0f, 0.36f,
52 float out_data[size * 4];
54 EffectChainTester tester(data_a, 1, size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
55 Effect *input1 = tester.get_chain()->last_added_effect();
56 Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR);
58 tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
59 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
61 expect_equal(expected_data, out_data, 4, size);
64 TEST(ComplexModulateEffectTest, Repeat) {
65 const int size = 2, repeats = 3;
66 float data_a[size * repeats * 4] = {
67 0.0f, 0.1f, 0.2f, 0.3f,
68 1.0f, 1.1f, 1.2f, 1.3f,
69 2.0f, 2.1f, 2.2f, 2.3f,
70 3.0f, 3.1f, 3.2f, 3.3f,
71 4.0f, 4.1f, 4.2f, 4.3f,
72 5.0f, 5.1f, 5.2f, 5.3f,
74 float data_b[size * 2] = {
78 float expected_data[size * repeats * 4] = {
79 0.0f, 0.1f, 0.2f, 0.3f,
80 1.1f, -1.0f, 1.3f, -1.2f,
81 2.0f, 2.1f, 2.2f, 2.3f,
82 3.1f, -3.0f, 3.3f, -3.2f,
83 4.0f, 4.1f, 4.2f, 4.3f,
84 5.1f, -5.0f, 5.3f, -5.2f,
86 float out_data[size * repeats * 4];
88 EffectChainTester tester(data_a, 1, repeats * size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
89 Effect *input1 = tester.get_chain()->last_added_effect();
90 Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR, 1, size);
92 Effect *effect = tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
93 ASSERT_TRUE(effect->set_int("num_repeats_y", repeats));
94 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
96 expect_equal(expected_data, out_data, 4, size * repeats);