File: complex_modulate_effect_test.cpp

package info (click to toggle)
movit 1.7.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,248 kB
  • sloc: cpp: 16,677; sh: 3,940; makefile: 167
file content (99 lines) | stat: -rw-r--r-- 3,030 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Unit tests for ComplexModulateEffect.

#include <epoxy/gl.h>

#include "effect_chain.h"
#include "gtest/gtest.h"
#include "complex_modulate_effect.h"
#include "image_format.h"
#include "input.h"
#include "test_util.h"

namespace movit {

TEST(ComplexModulateEffectTest, Identity) {
	const int size = 3;
	float data_a[size * 4] = {
		0.0f, 0.1f, 0.2f, 0.1f,
		0.4f, 0.3f, 0.8f, 2.0f,
		0.5f, 0.2f, 0.1f, 0.0f,
	};
	float data_b[size * 2] = {
		1.0f, 0.0f,
		1.0f, 0.0f,
		1.0f, 0.0f,
	};
	float out_data[size * 4];

	EffectChainTester tester(data_a, 1, size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
	Effect *input1 = tester.get_chain()->last_added_effect();
	Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR);

	tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
	tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);

	expect_equal(data_a, out_data, 4, size);
}

TEST(ComplexModulateEffectTest, ComplexMultiplication) {
	const int size = 2;
	float data_a[size * 4] = {
		0.0f, 0.1f, 0.2f, 0.1f,
		0.4f, 0.3f, 0.8f, 2.0f,
	};
	float data_b[size * 2] = {
		0.0f,  1.0f,
		0.5f, -0.8f,
	};
	float expected_data[size * 4] = {
		-0.1f,   0.0f,  -0.1f, 0.2f,
		 0.44f, -0.17f,  2.0f, 0.36f,
	};
	float out_data[size * 4];

	EffectChainTester tester(data_a, 1, size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
	Effect *input1 = tester.get_chain()->last_added_effect();
	Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR);

	tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
	tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);

	expect_equal(expected_data, out_data, 4, size);
}

TEST(ComplexModulateEffectTest, Repeat) {
	const int size = 2, repeats = 3;
	float data_a[size * repeats * 4] = {
		0.0f, 0.1f, 0.2f, 0.3f,
		1.0f, 1.1f, 1.2f, 1.3f,
		2.0f, 2.1f, 2.2f, 2.3f,
		3.0f, 3.1f, 3.2f, 3.3f,
		4.0f, 4.1f, 4.2f, 4.3f,
		5.0f, 5.1f, 5.2f, 5.3f,
	};
	float data_b[size * 2] = {
		1.0f,  0.0f,
		0.0f, -1.0f,
	};
	float expected_data[size * repeats * 4] = {
		0.0f,  0.1f, 0.2f,  0.3f,
		1.1f, -1.0f, 1.3f, -1.2f,
		2.0f,  2.1f, 2.2f,  2.3f,
		3.1f, -3.0f, 3.3f, -3.2f,
		4.0f,  4.1f, 4.2f,  4.3f,
		5.1f, -5.0f, 5.3f, -5.2f,
	};
	float out_data[size * repeats * 4];

	EffectChainTester tester(data_a, 1, repeats * size, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
	Effect *input1 = tester.get_chain()->last_added_effect();
	Effect *input2 = tester.add_input(data_b, FORMAT_RG, COLORSPACE_sRGB, GAMMA_LINEAR, 1, size);

	Effect *effect = tester.get_chain()->add_effect(new ComplexModulateEffect(), input1, input2);
	ASSERT_TRUE(effect->set_int("num_repeats_y", repeats));
	tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);

	expect_equal(expected_data, out_data, 4, size * repeats);
}

}  // namespace movit