]> git.sesse.net Git - movit/commitdiff
Support negative values for lift in LiftGammaGainEffect.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 13 Sep 2017 18:28:26 +0000 (20:28 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 13 Sep 2017 18:28:26 +0000 (20:28 +0200)
Patch by Jean-Baptiste Mardelle <jb@kdenlive.org> (except the test,
which is by myself). Based on work from Dušan Hanuš <hanus@pixelhouse.cz>.

lift_gamma_gain_effect.frag
lift_gamma_gain_effect_test.cpp
version.h

index 7342d7505eb53da6e66167b4921138ef2f5a68dc..ceb2081c752591e71277b10af64e8e499f2f2cb1 100644 (file)
@@ -14,6 +14,10 @@ vec4 FUNCNAME(vec2 tc) {
 
        x.rgb = pow(x.rgb, vec3(1.0/2.2));
        x.rgb += PREFIX(lift) * (vec3(1) - x.rgb);
 
        x.rgb = pow(x.rgb, vec3(1.0/2.2));
        x.rgb += PREFIX(lift) * (vec3(1) - x.rgb);
+
+       // Clip out-of-gamut values again.
+       x.rgb = max(x.rgb, 0.0);
+
        x.rgb = pow(x.rgb, PREFIX(inv_gamma_22));
        x.rgb *= PREFIX(gain_pow_inv_gamma);
        x.rgb *= x.aaa;
        x.rgb = pow(x.rgb, PREFIX(inv_gamma_22));
        x.rgb *= PREFIX(gain_pow_inv_gamma);
        x.rgb *= x.aaa;
index 1be2847a91ee3d0c5260333461462a5452f3494a..f9163a8b32ea53188c831386512d78172828c58d 100644 (file)
@@ -119,4 +119,31 @@ TEST(LiftGammaGainEffectTest, OutOfGamutColorsAreClipped) {
        expect_equal(expected_data, out_data, 4, 3);
 }
 
        expect_equal(expected_data, out_data, 4, 3);
 }
 
+TEST(LiftGammaGainEffectTest, NegativeLiftIsClamped) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               1.0f, 0.0f, 0.0f, 1.0f,
+               0.0f, 1.0f, 0.0f, 0.7f,
+               0.0f, 0.0f, 1.0f, 1.0f,
+       };
+       float lift[3] = { 0.0f, -0.1f, -0.2f };
+       float expected_data[] = {
+               0.0f, 0.0f , 0.0f, 1.0f,  // Note: Clamped below zero.
+               0.5f, 0.45f, 0.4f, 0.3f,
+               1.0f, 0.0f,  0.0f, 1.0f,  // Unaffected.
+               0.0f, 1.0f,  0.0f, 0.7f,
+               0.0f, 0.0f,  1.0f, 1.0f,
+       };
+
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
+       Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
+       ASSERT_TRUE(lgg_effect->set_vec3("lift", lift));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
+
+       // sRGB is only approximately gamma-2.2, so loosen up the limits a bit.
+       expect_equal(expected_data, out_data, 4, 5, 0.03, 0.003);
+}
+
 }  // namespace movit
 }  // namespace movit
index 12f73f03037731455f5b4422e4567c12a07dd307..57e46451a1e904a5762ce6dd55c6d299af8f86b6 100644 (file)
--- a/version.h
+++ b/version.h
@@ -5,6 +5,6 @@
 // changes, even within git versions. There is no specific version
 // documentation outside the regular changelogs, though.
 
 // changes, even within git versions. There is no specific version
 // documentation outside the regular changelogs, though.
 
-#define MOVIT_VERSION 30
+#define MOVIT_VERSION 31
 
 #endif // !defined(_MOVIT_VERSION_H)
 
 #endif // !defined(_MOVIT_VERSION_H)