vec4 x = INPUT(tc);
x.rgb /= x.aaa;
+
+ // pow() of negative numbers is undefined, so clip out-of-gamut values.
+ x.rgb = max(x.rgb, 0.0);
+
x.rgb = pow(x.rgb, vec3(1.0/2.2));
x.rgb += PREFIX(lift) * (vec3(1) - x.rgb);
x.rgb = pow(x.rgb, PREFIX(inv_gamma_22));
expect_equal(data, out_data, 4, 5);
}
+
+TEST(LiftGammaGainEffectTest, OutOfGamutColorsAreClipped) {
+ float data[] = {
+ -0.5f, 0.3f, 0.0f, 1.0f,
+ 0.5f, 0.0f, 0.0f, 1.0f,
+ 0.0f, 1.5f, 0.5f, 0.3f,
+ };
+ float expected_data[] = {
+ 0.0f, 0.3f, 0.0f, 1.0f, // Clipped to zero.
+ 0.5f, 0.0f, 0.0f, 1.0f,
+ 0.0f, 1.5f, 0.5f, 0.3f,
+ };
+
+ float out_data[3 * 4];
+ EffectChainTester tester(data, 1, 3, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
+ tester.get_chain()->add_effect(new LiftGammaGainEffect());
+ tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+ expect_equal(expected_data, out_data, 4, 3);
+}