]> git.sesse.net Git - movit/blobdiff - effect_chain_test.cpp
Make the sRGB intermediate test slightly more stringent (so that e.g. 0.0 will not...
[movit] / effect_chain_test.cpp
index 596570c67dd3dc6858ea0815c7202d1e50936c67..adf832ac61e4ad445f115a72b83f324352f78812 100644 (file)
@@ -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