]> git.sesse.net Git - movit/commitdiff
Fix alpha handling with sRGB textures.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 13 Jan 2013 11:50:55 +0000 (12:50 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 13 Jan 2013 11:50:55 +0000 (12:50 +0100)
OverlayEffect needs working alpha, so this cropped up. We don't
really have full alpha handling everywhere, but this is a good
start; I added some tests here and there to tighten it up a bit.

flat_input.cpp
flat_input_test.cpp
gamma_expansion_effect_test.cpp

index 291bb0dcc3a08ce5c9024cd29153883907a0f0eb..6e118bc3a3c1b5633bc786772ce85d377fffb9ed 100644 (file)
@@ -44,7 +44,7 @@ void FlatInput::finalize()
                internal_format = GL_RGBA16F_ARB;
        } else if (output_linear_gamma) {
                assert(type == GL_UNSIGNED_BYTE);
-               internal_format = GL_SRGB8;
+               internal_format = GL_SRGB8_ALPHA8;
        } else {
                assert(type == GL_UNSIGNED_BYTE);
                internal_format = GL_RGBA8;
index 17ee9ce49f407abefc9206df05e1e69559f73c2f..b717764dda03bb136ff7cb3ece897fa04f3c2f43 100644 (file)
@@ -77,6 +77,37 @@ TEST(FlatInput, RGBA) {
        expect_equal(expected_data, out_data, 4, size);
 }
 
+// Note: The sRGB conversion itself is tested in EffectChainTester,
+// since it also wants to test the chain building itself.
+// Here, we merely test that alpha is left alone; the test will usually
+// run using the sRGB OpenGL extension, but might be run with a
+// GammaExpansionEffect if the card/driver happens not to support that.
+TEST(FlatInput, AlphaIsNotModifiedBySRGBConversion) {
+       const int size = 5;
+
+       unsigned char data[4 * size] = {
+               0, 0, 0, 0,
+               0, 0, 0, 63,
+               0, 0, 0, 127,
+               0, 0, 0, 191,
+               0, 0, 0, 255,
+       };
+       float expected_data[4 * size] = {
+               0, 0, 0, 0.0 / 255.0,
+               0, 0, 0, 63.0 / 255.0,
+               0, 0, 0, 127.0 / 255.0,
+               0, 0, 0, 191.0 / 255.0,
+               0, 0, 0, 255.0 / 255.0,
+       };
+       float out_data[4 * size];
+
+        EffectChainTester tester(NULL, 1, size);
+        tester.add_input(data, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 4, size);
+}
+
 TEST(FlatInput, BGR) {
        const int size = 5;
 
index ed124c4f31c7a9d750c91bcf4269e4398fd7839c..71544b4738c1a92caa827d1d5c7e90d3a7941ca3 100644 (file)
@@ -34,6 +34,21 @@ TEST(GammaExpansionEffectTest, sRGB_RampAlwaysIncreases) {
        }
 }
 
+TEST(GammaExpansionEffectTest, sRGB_AlphaIsUnchanged) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 0.0f,
+               0.0f, 0.0f, 0.0f, 0.25f,
+               0.0f, 0.0f, 0.0f, 0.5f,
+               0.0f, 0.0f, 0.0f, 0.75f,
+               0.0f, 0.0f, 0.0f, 1.0f,
+       };
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 5, 1, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 5, 1);
+}
+
 TEST(GammaExpansionEffectTest, Rec709_KeyValues) {
        float data[] = {
                0.0f, 1.0f,
@@ -63,3 +78,18 @@ TEST(GammaExpansionEffectTest, Rec709_RampAlwaysIncreases) {
                   << "No increase between " << i-1 << " and " << i;
        }
 }
+
+TEST(GammaExpansionEffectTest, Rec709_AlphaIsUnchanged) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 0.0f,
+               0.0f, 0.0f, 0.0f, 0.25f,
+               0.0f, 0.0f, 0.0f, 0.5f,
+               0.0f, 0.0f, 0.0f, 0.75f,
+               0.0f, 0.0f, 0.0f, 1.0f,
+       };
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 5, 1, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_REC_709);
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 5, 1);
+}