1 // Unit tests for FlatInput.
5 #include "effect_chain.h"
6 #include "flat_input.h"
7 #include "gtest/gtest.h"
10 TEST(FlatInput, SimpleGrayscale) {
19 float expected_data[4 * size] = {
25 float out_data[4 * size];
27 EffectChainTester tester(data, 1, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
28 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
30 expect_equal(expected_data, out_data, 4, size);
33 TEST(FlatInput, RGB) {
36 float data[3 * size] = {
43 float expected_data[4 * size] = {
50 float out_data[4 * size];
52 EffectChainTester tester(data, 1, size, FORMAT_RGB, COLORSPACE_sRGB, GAMMA_LINEAR);
53 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
55 expect_equal(expected_data, out_data, 4, size);
58 TEST(FlatInput, RGBA) {
61 float data[4 * size] = {
68 float expected_data[4 * size] = {
75 float out_data[4 * size];
77 EffectChainTester tester(data, 1, size, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
78 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
80 expect_equal(expected_data, out_data, 4, size);
83 // Note: The sRGB conversion itself is tested in EffectChainTester,
84 // since it also wants to test the chain building itself.
85 // Here, we merely test that alpha is left alone; the test will usually
86 // run using the sRGB OpenGL extension, but might be run with a
87 // GammaExpansionEffect if the card/driver happens not to support that.
88 TEST(FlatInput, AlphaIsNotModifiedBySRGBConversion) {
91 unsigned char data[4 * size] = {
98 float expected_data[4 * size] = {
100 0, 0, 0, 63.0 / 255.0,
101 0, 0, 0, 127.0 / 255.0,
102 0, 0, 0, 191.0 / 255.0,
103 0, 0, 0, 255.0 / 255.0,
105 float out_data[4 * size];
107 EffectChainTester tester(NULL, 1, size);
108 tester.add_input(data, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
109 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
111 expect_equal(expected_data, out_data, 4, size);
114 TEST(FlatInput, BGR) {
117 float data[3 * size] = {
124 float expected_data[4 * size] = {
131 float out_data[4 * size];
133 EffectChainTester tester(data, 1, size, FORMAT_BGR, COLORSPACE_sRGB, GAMMA_LINEAR);
134 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
136 expect_equal(expected_data, out_data, 4, size);
139 TEST(FlatInput, BGRA) {
142 float data[4 * size] = {
149 float expected_data[4 * size] = {
156 float out_data[4 * size];
158 EffectChainTester tester(data, 1, size, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
159 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
161 expect_equal(expected_data, out_data, 4, size);
164 TEST(FlatInput, Pitch) {
167 const int height = 4;
169 float data[pitch * height] = {
175 float expected_data[4 * width * height] = {
176 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
177 0.5, 0.5, 0.5, 1.0, 0.5, 0.5, 0.5, 1.0,
178 0.7, 0.7, 0.7, 1.0, 0.2, 0.2, 0.2, 1.0,
179 1.0, 1.0, 1.0, 1.0, 0.6, 0.6, 0.6, 1.0,
181 float out_data[4 * width * height];
183 EffectChainTester tester(NULL, width, height);
186 format.color_space = COLORSPACE_sRGB;
187 format.gamma_curve = GAMMA_LINEAR;
189 FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
190 input->set_pitch(pitch);
191 input->set_pixel_data(data);
192 tester.get_chain()->add_input(input);
194 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
195 expect_equal(expected_data, out_data, 4 * width, height);
198 TEST(FlatInput, UpdatedData) {
200 const int height = 4;
202 float data[width * height] = {
208 float out_data[width * height];
210 EffectChainTester tester(NULL, width, height);
213 format.color_space = COLORSPACE_sRGB;
214 format.gamma_curve = GAMMA_LINEAR;
216 FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
217 input->set_pixel_data(data);
218 tester.get_chain()->add_input(input);
220 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
221 expect_equal(data, out_data, width, height);
224 input->invalidate_pixel_data();
226 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
227 expect_equal(data, out_data, width, height);