1 // Unit tests for FlatInput.
4 #include "gtest/gtest.h"
5 #include "flat_input.h"
7 TEST(FlatInput, SimpleGrayscale) {
16 float expected_data[4 * size] = {
22 float out_data[4 * size];
24 EffectChainTester tester(data, 1, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
25 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
27 expect_equal(expected_data, out_data, 4, size);
30 TEST(FlatInput, RGB) {
33 float data[3 * size] = {
40 float expected_data[4 * size] = {
47 float out_data[4 * size];
49 EffectChainTester tester(data, 1, size, FORMAT_RGB, COLORSPACE_sRGB, GAMMA_LINEAR);
50 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
52 expect_equal(expected_data, out_data, 4, size);
55 TEST(FlatInput, RGBA) {
58 float data[4 * size] = {
65 float expected_data[4 * size] = {
72 float out_data[4 * size];
74 EffectChainTester tester(data, 1, size, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
75 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
77 expect_equal(expected_data, out_data, 4, size);
80 // Note: The sRGB conversion itself is tested in EffectChainTester,
81 // since it also wants to test the chain building itself.
82 // Here, we merely test that alpha is left alone; the test will usually
83 // run using the sRGB OpenGL extension, but might be run with a
84 // GammaExpansionEffect if the card/driver happens not to support that.
85 TEST(FlatInput, AlphaIsNotModifiedBySRGBConversion) {
88 unsigned char data[4 * size] = {
95 float expected_data[4 * size] = {
97 0, 0, 0, 63.0 / 255.0,
98 0, 0, 0, 127.0 / 255.0,
99 0, 0, 0, 191.0 / 255.0,
100 0, 0, 0, 255.0 / 255.0,
102 float out_data[4 * size];
104 EffectChainTester tester(NULL, 1, size);
105 tester.add_input(data, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
106 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
108 expect_equal(expected_data, out_data, 4, size);
111 TEST(FlatInput, BGR) {
114 float data[3 * size] = {
121 float expected_data[4 * size] = {
128 float out_data[4 * size];
130 EffectChainTester tester(data, 1, size, FORMAT_BGR, COLORSPACE_sRGB, GAMMA_LINEAR);
131 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
133 expect_equal(expected_data, out_data, 4, size);
136 TEST(FlatInput, BGRA) {
139 float data[4 * size] = {
146 float expected_data[4 * size] = {
153 float out_data[4 * size];
155 EffectChainTester tester(data, 1, size, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
156 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
158 expect_equal(expected_data, out_data, 4, size);
161 TEST(FlatInput, Pitch) {
164 const int height = 4;
166 float data[pitch * height] = {
172 float expected_data[4 * width * height] = {
173 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
174 0.5, 0.5, 0.5, 1.0, 0.5, 0.5, 0.5, 1.0,
175 0.7, 0.7, 0.7, 1.0, 0.2, 0.2, 0.2, 1.0,
176 1.0, 1.0, 1.0, 1.0, 0.6, 0.6, 0.6, 1.0,
178 float out_data[4 * width * height];
180 EffectChainTester tester(NULL, width, height);
183 format.color_space = COLORSPACE_sRGB;
184 format.gamma_curve = GAMMA_LINEAR;
186 FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
187 input->set_pitch(pitch);
188 input->set_pixel_data(data);
189 tester.get_chain()->add_input(input);
191 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
192 expect_equal(expected_data, out_data, 4 * width, height);
195 TEST(FlatInput, UpdatedData) {
197 const int height = 4;
199 float data[width * height] = {
205 float out_data[width * height];
207 EffectChainTester tester(NULL, width, height);
210 format.color_space = COLORSPACE_sRGB;
211 format.gamma_curve = GAMMA_LINEAR;
213 FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
214 input->set_pixel_data(data);
215 tester.get_chain()->add_input(input);
217 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
218 expect_equal(data, out_data, width, height);
221 input->invalidate_pixel_data();
223 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
224 expect_equal(data, out_data, width, height);