X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain_test.cpp;h=adf832ac61e4ad445f115a72b83f324352f78812;hp=596570c67dd3dc6858ea0815c7202d1e50936c67;hb=009c7510df1ac1b70662b0085ebaf1a619dd761a;hpb=813bc3bfcacfeed72b9b6cfdae6156b35ad4860b diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index 596570c..adf832a 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -1022,6 +1022,38 @@ TEST(EffectChainTest, AspectRatioConversion) { EXPECT_EQ(7, input_store->input_height); } +// Tests that putting a BlueInput (constant color) into its own pass, +// which creates a phase that doesn't need texture coordinates, +// doesn't mess up a second phase that actually does. +TEST(EffectChainTest, FirstPhaseWithNoTextureCoordinates) { + const int size = 2; + float data[] = { + 1.0f, + 0.0f, + }; + float expected_data[] = { + 1.0f, 1.0f, 2.0f, 2.0f, + 0.0f, 0.0f, 1.0f, 2.0f, + }; + float out_data[size * 4]; + // First say that we have sRGB, linear input. + ImageFormat format; + format.color_space = COLORSPACE_sRGB; + format.gamma_curve = GAMMA_LINEAR; + FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 1, size); + + input->set_pixel_data(data); + EffectChainTester tester(NULL, 1, size); + tester.get_chain()->add_input(new BlueInput()); + Effect *phase1_end = tester.get_chain()->add_effect(new BouncingIdentityEffect()); + tester.get_chain()->add_input(input); + tester.get_chain()->add_effect(new AddEffect(), phase1_end, input); + + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); + + expect_equal(expected_data, out_data, 4, size); +} + // An effect that does nothing except changing its output sizes. class VirtualResizeEffect : public Effect { public: @@ -1248,7 +1280,12 @@ TEST(EffectChainTest, StringStreamLocalesWork) { // the test will always succeed. Note that the OpenGL driver might call // setlocale() behind-the-scenes, and that might corrupt the returned // pointer, so we need to take our own copy of it here. - char *saved_locale = strdup(setlocale(LC_ALL, "nb_NO.UTF_8")); + char *saved_locale = setlocale(LC_ALL, "nb_NO.UTF_8"); + if (saved_locale == NULL) { + // The locale wasn't available. + return; + } + saved_locale = strdup(saved_locale); float data[] = { 0.0f, 0.0f, 0.0f, 0.0f, }; @@ -1266,5 +1303,20 @@ TEST(EffectChainTest, StringStreamLocalesWork) { free(saved_locale); } +TEST(EffectChainTest, sRGBIntermediate) { + float data[] = { + 0.0f, 0.5f, 0.0f, 1.0f, + }; + float out_data[4]; + EffectChainTester tester(data, 1, 1, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR, GL_RGBA16F_ARB, GL_SRGB8); + tester.get_chain()->add_effect(new IdentityEffect()); + tester.get_chain()->add_effect(new BouncingIdentityEffect()); + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR); + + EXPECT_GE(fabs(out_data[1] - data[1]), 1e-3) + << "Expected sRGB not to be able to represent 0.5 exactly (got " << out_data[1] << ")"; + EXPECT_LT(fabs(out_data[1] - data[1]), 0.1f) + << "Expected sRGB to be able to represent 0.5 approximately (got " << out_data[1] << ")"; +} } // namespace movit