From: Steinar H. Gunderson Date: Fri, 12 Oct 2012 21:43:28 +0000 (+0200) Subject: Support non-grayscale formats in the test pipeline, since we will want color quite... X-Git-Tag: 1.0~291 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=2fdbe6e32ef5de09db9c890b6cd4355bf65dd1e5 Support non-grayscale formats in the test pipeline, since we will want color quite soon. --- diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index e5ca1cc..0161a92 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -15,8 +15,8 @@ TEST(EffectChainTest, EmptyChain) { 0.75f, 1.0f, 1.0f, }; float out_data[6]; - EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(data, out_data, 3, 2); } @@ -35,9 +35,9 @@ TEST(EffectChainTest, Identity) { 0.75f, 1.0f, 1.0f, }; float out_data[6]; - EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); tester.get_chain()->add_effect(new IdentityEffect()); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(data, out_data, 3, 2); } @@ -57,9 +57,9 @@ TEST(EffectChainTest, TextureBouncePreservesIdentity) { 0.75f, 1.0f, 1.0f, }; float out_data[6]; - EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); tester.get_chain()->add_effect(new BouncingIdentityEffect()); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(data, out_data, 3, 2); } @@ -74,9 +74,9 @@ TEST(MirrorTest, BasicTest) { 1.0f, 1.0f, 0.75f, }; float out_data[6]; - EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); tester.get_chain()->add_effect(new MirrorEffect()); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(expected_data, out_data, 3, 2); } diff --git a/gamma_compression_effect_test.cpp b/gamma_compression_effect_test.cpp index 4662a01..6211acc 100644 --- a/gamma_compression_effect_test.cpp +++ b/gamma_compression_effect_test.cpp @@ -17,8 +17,8 @@ TEST(GammaCompressionEffectTest, sRGB_KeyValues) { 0.040f, 0.041f, }; float out_data[4]; - EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_sRGB); + EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB); expect_equal(expected_data, out_data, 2, 2); } @@ -28,8 +28,8 @@ TEST(GammaCompressionEffectTest, sRGB_RampAlwaysIncreases) { for (unsigned i = 0; i < 256; ++i) { data[i] = i / 255.0f; } - EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_LINEAR); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_sRGB); + EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB); for (unsigned i = 1; i < 256; ++i) { EXPECT_GT(out_data[i], out_data[i - 1]) @@ -47,8 +47,8 @@ TEST(GammaCompressionEffectTest, Rec709_KeyValues) { 0.080f, 0.082f, }; float out_data[4]; - EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_REC_709); + EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709); expect_equal(expected_data, out_data, 2, 2); } @@ -58,8 +58,8 @@ TEST(GammaCompressionEffectTest, Rec709_RampAlwaysIncreases) { for (unsigned i = 0; i < 256; ++i) { data[i] = i / 255.0f; } - EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_LINEAR); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_REC_709); + EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709); for (unsigned i = 1; i < 256; ++i) { EXPECT_GT(out_data[i], out_data[i - 1]) diff --git a/gamma_expansion_effect_test.cpp b/gamma_expansion_effect_test.cpp index b315d8f..ed124c4 100644 --- a/gamma_expansion_effect_test.cpp +++ b/gamma_expansion_effect_test.cpp @@ -14,8 +14,8 @@ TEST(GammaExpansionEffectTest, sRGB_KeyValues) { 0.00309f, 0.00317f, }; float out_data[4]; - EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_sRGB); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(expected_data, out_data, 2, 2); } @@ -25,8 +25,8 @@ TEST(GammaExpansionEffectTest, sRGB_RampAlwaysIncreases) { for (unsigned i = 0; i < 256; ++i) { data[i] = i / 255.0f; } - EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_sRGB); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); for (unsigned i = 1; i < 256; ++i) { EXPECT_GT(out_data[i], out_data[i - 1]) @@ -44,8 +44,8 @@ TEST(GammaExpansionEffectTest, Rec709_KeyValues) { 0.017778f, 0.018167f, }; float out_data[4]; - EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_REC_709); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_709); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(expected_data, out_data, 2, 2); } @@ -55,8 +55,8 @@ TEST(GammaExpansionEffectTest, Rec709_RampAlwaysIncreases) { for (unsigned i = 0; i < 256; ++i) { data[i] = i / 255.0f; } - EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_REC_709); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_709); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); for (unsigned i = 1; i < 256; ++i) { EXPECT_GT(out_data[i], out_data[i - 1]) diff --git a/mix_effect_test.cpp b/mix_effect_test.cpp index cae4b28..910182d 100644 --- a/mix_effect_test.cpp +++ b/mix_effect_test.cpp @@ -18,14 +18,14 @@ TEST(MixEffectTest, FiftyFiftyMix) { 0.75f, 0.8f, }; float out_data[4]; - EffectChainTester tester(data_a, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); Effect *input1 = tester.get_chain()->last_added_effect(); - Effect *input2 = tester.add_input(data_b, COLORSPACE_sRGB, GAMMA_LINEAR); + Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); Effect *mix_effect = tester.get_chain()->add_effect(new MixEffect(), input1, input2); ASSERT_TRUE(mix_effect->set_float("strength_first", 0.5f)); ASSERT_TRUE(mix_effect->set_float("strength_second", 0.5f)); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(expected_data, out_data, 2, 2); } @@ -40,14 +40,14 @@ TEST(MixEffectTest, OnlyA) { 0.75f, 0.6f, }; float out_data[4]; - EffectChainTester tester(data_a, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); Effect *input1 = tester.get_chain()->last_added_effect(); - Effect *input2 = tester.add_input(data_b, COLORSPACE_sRGB, GAMMA_LINEAR); + Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); Effect *mix_effect = tester.get_chain()->add_effect(new MixEffect(), input1, input2); ASSERT_TRUE(mix_effect->set_float("strength_first", 1.0f)); ASSERT_TRUE(mix_effect->set_float("strength_second", 0.0f)); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(data_a, out_data, 2, 2); } @@ -66,14 +66,14 @@ TEST(MixEffectTest, DoesNotSumToOne) { 0.6f, 0.4f, }; float out_data[4]; - EffectChainTester tester(data_a, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); Effect *input1 = tester.get_chain()->last_added_effect(); - Effect *input2 = tester.add_input(data_b, COLORSPACE_sRGB, GAMMA_LINEAR); + Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); Effect *mix_effect = tester.get_chain()->add_effect(new MixEffect(), input1, input2); ASSERT_TRUE(mix_effect->set_float("strength_first", 1.0f)); ASSERT_TRUE(mix_effect->set_float("strength_second", -1.0f)); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(expected_data, out_data, 2, 2); } @@ -92,14 +92,14 @@ TEST(MixEffectTest, MixesLinearlyDespitesRGBInputsAndOutputs) { 0.54807f, 0.73536f, }; float out_data[4]; - EffectChainTester tester(data_a, 2, 2, COLORSPACE_sRGB, GAMMA_sRGB); + EffectChainTester tester(data_a, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB); Effect *input1 = tester.get_chain()->last_added_effect(); - Effect *input2 = tester.add_input(data_b, COLORSPACE_sRGB, GAMMA_sRGB); + Effect *input2 = tester.add_input(data_b, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB); Effect *mix_effect = tester.get_chain()->add_effect(new MixEffect(), input1, input2); ASSERT_TRUE(mix_effect->set_float("strength_first", 0.5f)); ASSERT_TRUE(mix_effect->set_float("strength_second", 0.5f)); - tester.run(out_data, COLORSPACE_sRGB, GAMMA_sRGB); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB); expect_equal(expected_data, out_data, 2, 2); } diff --git a/test_util.cpp b/test_util.cpp index c8337d2..bcfc97a 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -7,10 +7,10 @@ #include -EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned height, ColorSpace color_space, GammaCurve gamma_curve) +EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned height, MovitPixelFormat pixel_format, ColorSpace color_space, GammaCurve gamma_curve) : chain(width, height), width(width), height(height) { - add_input(data, color_space, gamma_curve); + add_input(data, pixel_format, color_space, gamma_curve); glGenTextures(1, &texnum); check_error(); @@ -34,30 +34,30 @@ EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned check_error(); } -Input *EffectChainTester::add_input(const float *data, ColorSpace color_space, GammaCurve gamma_curve) +Input *EffectChainTester::add_input(const float *data, MovitPixelFormat pixel_format, ColorSpace color_space, GammaCurve gamma_curve) { ImageFormat format; format.color_space = color_space; format.gamma_curve = gamma_curve; - FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height); + FlatInput *input = new FlatInput(format, pixel_format, GL_FLOAT, width, height); input->set_pixel_data(data); chain.add_input(input); return input; } -void EffectChainTester::run(float *out_data, ColorSpace color_space, GammaCurve gamma_curve) +void EffectChainTester::run(float *out_data, GLenum format, ColorSpace color_space, GammaCurve gamma_curve) { - ImageFormat format; - format.color_space = color_space; - format.gamma_curve = gamma_curve; - chain.add_output(format); + ImageFormat image_format; + image_format.color_space = color_space; + image_format.gamma_curve = gamma_curve; + chain.add_output(image_format); chain.finalize(); chain.render_to_fbo(fbo, width, height); glBindFramebuffer(GL_FRAMEBUFFER, fbo); - glReadPixels(0, 0, width, height, GL_RED, GL_FLOAT, out_data); + glReadPixels(0, 0, width, height, format, GL_FLOAT, out_data); // Flip upside-down to compensate for different origin. for (unsigned y = 0; y < height / 2; ++y) { diff --git a/test_util.h b/test_util.h index ab52c63..6a3e16b 100644 --- a/test_util.h +++ b/test_util.h @@ -5,10 +5,10 @@ class EffectChainTester { public: - EffectChainTester(const float *data, unsigned width, unsigned height, ColorSpace color_space, GammaCurve gamma_curve); + EffectChainTester(const float *data, unsigned width, unsigned height, MovitPixelFormat pixel_format, ColorSpace color_space, GammaCurve gamma_curve); EffectChain *get_chain() { return &chain; } - Input *add_input(const float *data, ColorSpace color_space, GammaCurve gamma_curve); - void run(float *out_data, ColorSpace color_space, GammaCurve gamma_curve); + Input *add_input(const float *data, MovitPixelFormat pixel_format, ColorSpace color_space, GammaCurve gamma_curve); + void run(float *out_data, GLenum format, ColorSpace color_space, GammaCurve gamma_curve); private: EffectChain chain;