From 665acd29039b278b6de87121b458675ab025ee33 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 9 Jun 2020 15:14:10 +0200 Subject: Fix T69497: Color Correction node ignores mask in certain cases Happens when some of the color correction terms are mathematically undefined: foe example, when pow() is to be calculated and the X argument is negative. There is no ground-truth result in such cases, so ignore such terms entirely. This is a generalization of D6696 from Jacques. Differential Revision: https://developer.blender.org/D7966 --- .../operations/COM_ColorCorrectionOperation.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source/blender/compositor') diff --git a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp index 39ffb690328..893c052831c 100644 --- a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp @@ -38,6 +38,15 @@ void ColorCorrectionOperation::initExecution() this->m_inputMask = this->getInputSocketReader(1); } +/* Calculate x^y if the function is defined. Otherwise return the given fallback value. */ +BLI_INLINE float color_correct_powf_safe(const float x, const float y, const float fallback_value) +{ + if (x < 0) { + return fallback_value; + } + return powf(x, y); +} + void ColorCorrectionOperation::executePixelSampled(float output[4], float x, float y, @@ -116,9 +125,9 @@ void ColorCorrectionOperation::executePixelSampled(float output[4], b = 0.5f + ((b - 0.5f) * contrast); /* Check for negative values to avoid nan. */ - r = (r > 0.0f) ? powf(r * gain + lift, invgamma) : r; - g = (g > 0.0f) ? powf(g * gain + lift, invgamma) : g; - b = (b > 0.0f) ? powf(b * gain + lift, invgamma) : b; + r = color_correct_powf_safe(r * gain + lift, invgamma, r); + g = color_correct_powf_safe(g * gain + lift, invgamma, g); + b = color_correct_powf_safe(b * gain + lift, invgamma, b); // mix with mask r = mvalue * inputImageColor[0] + value * r; -- cgit v1.2.3