Fix T47212: incorrect luma coefficients for Luminance Key node.
Differential Revision: https://developer.blender.org/D2982
This commit is contained in:
		@@ -37,14 +37,11 @@ void LuminanceMatteNode::convertToOperations(NodeConverter &converter, const Com
 | 
			
		||||
	NodeOutput *outputSocketImage = this->getOutputSocket(0);
 | 
			
		||||
	NodeOutput *outputSocketMatte = this->getOutputSocket(1);
 | 
			
		||||
 | 
			
		||||
	ConvertRGBToYUVOperation *rgbToYUV = new ConvertRGBToYUVOperation();
 | 
			
		||||
	LuminanceMatteOperation *operationSet = new LuminanceMatteOperation();
 | 
			
		||||
	operationSet->setSettings((NodeChroma *)editorsnode->storage);
 | 
			
		||||
	converter.addOperation(rgbToYUV);
 | 
			
		||||
	converter.addOperation(operationSet);
 | 
			
		||||
 | 
			
		||||
	converter.mapInputSocket(inputSocket, rgbToYUV->getInputSocket(0));
 | 
			
		||||
	converter.addLink(rgbToYUV->getOutputSocket(), operationSet->getInputSocket(0));
 | 
			
		||||
	converter.mapInputSocket(inputSocket, operationSet->getInputSocket(0));
 | 
			
		||||
	converter.mapOutputSocket(outputSocketMatte, operationSet->getOutputSocket(0));
 | 
			
		||||
 | 
			
		||||
	SetAlphaOperation *operation = new SetAlphaOperation();
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,10 @@
 | 
			
		||||
#include "COM_LuminanceMatteOperation.h"
 | 
			
		||||
#include "BLI_math.h"
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
#include "IMB_colormanagement.h"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
LuminanceMatteOperation::LuminanceMatteOperation() : NodeOperation()
 | 
			
		||||
{
 | 
			
		||||
	addInputSocket(COM_DT_COLOR);
 | 
			
		||||
@@ -43,41 +47,34 @@ void LuminanceMatteOperation::deinitExecution()
 | 
			
		||||
void LuminanceMatteOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
 | 
			
		||||
{
 | 
			
		||||
	float inColor[4];
 | 
			
		||||
	this->m_inputImageProgram->readSampled(inColor, x, y, sampler);
 | 
			
		||||
 | 
			
		||||
	const float high = this->m_settings->t1;
 | 
			
		||||
	const float low = this->m_settings->t2;
 | 
			
		||||
	const float luminance = IMB_colormanagement_get_luminance(inColor);
 | 
			
		||||
 | 
			
		||||
	float alpha;
 | 
			
		||||
 | 
			
		||||
	this->m_inputImageProgram->readSampled(inColor, x, y, sampler);
 | 
			
		||||
	
 | 
			
		||||
	/* one line thread-friend algorithm:
 | 
			
		||||
	 * output[0] = max(inputValue[3], min(high, max(low, ((inColor[0] - low) / (high - low))));
 | 
			
		||||
	 * output[0] = min(inputValue[3], min(1.0f, max(0.0f, ((luminance - low) / (high - low))));
 | 
			
		||||
	 */
 | 
			
		||||
		
 | 
			
		||||
	/* test range */
 | 
			
		||||
	if (inColor[0] > high) {
 | 
			
		||||
	if (luminance > high) {
 | 
			
		||||
		alpha = 1.0f;
 | 
			
		||||
	}
 | 
			
		||||
	else if (inColor[0] < low) {
 | 
			
		||||
	else if (luminance < low) {
 | 
			
		||||
		alpha = 0.0f;
 | 
			
		||||
	}
 | 
			
		||||
	else { /*blend */
 | 
			
		||||
		alpha = (inColor[0] - low) / (high - low);
 | 
			
		||||
		alpha = (luminance - low) / (high - low);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/* store matte(alpha) value in [0] to go with
 | 
			
		||||
	 * COM_SetAlphaOperation and the Value output
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
	/* don't make something that was more transparent less transparent */
 | 
			
		||||
	if (alpha < inColor[3]) {
 | 
			
		||||
		output[0] = alpha;
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		/* leave now it was before */
 | 
			
		||||
		output[0] = inColor[3];
 | 
			
		||||
	}
 | 
			
		||||
	output[0] = min_ff(alpha, inColor[3]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user