[Bf-blender-cvs] [3699ab1] master: Fix T45711: Color spill average algorithm broken

Campbell Barton noreply at git.blender.org
Wed Aug 26 10:44:43 CEST 2015


Commit: 3699ab1843c399b784cb6327a6c888db81e9e6e0
Author: Campbell Barton
Date:   Wed Aug 26 18:37:42 2015 +1000
Branches: master
https://developer.blender.org/rB3699ab1843c399b784cb6327a6c888db81e9e6e0

Fix T45711: Color spill average algorithm broken

Thanks to @kevindietrich for finding the cause!

===================================================================

M	source/blender/compositor/nodes/COM_ColorSpillNode.cpp
M	source/blender/compositor/operations/COM_ColorSpillOperation.cpp
M	source/blender/compositor/operations/COM_ColorSpillOperation.h

===================================================================

diff --git a/source/blender/compositor/nodes/COM_ColorSpillNode.cpp b/source/blender/compositor/nodes/COM_ColorSpillNode.cpp
index c3a911e..f33f285 100644
--- a/source/blender/compositor/nodes/COM_ColorSpillNode.cpp
+++ b/source/blender/compositor/nodes/COM_ColorSpillNode.cpp
@@ -38,16 +38,10 @@ void ColorSpillNode::convertToOperations(NodeConverter &converter, const Composi
 	NodeOutput *outputSocketImage = this->getOutputSocket(0);
 	
 	ColorSpillOperation *operation;
-	if (editorsnode->custom2 == 0) {
-		// Simple color spill
-		operation = new ColorSpillOperation();
-	}
-	else {
-		// Average color spill
-		operation = new ColorSpillAverageOperation();
-	}
+	operation = new ColorSpillOperation();
 	operation->setSettings((NodeColorspill *)editorsnode->storage);
 	operation->setSpillChannel(editorsnode->custom1 - 1); // Channel for spilling
+	operation->setSpillMethod(editorsnode->custom2); // Channel method
 	converter.addOperation(operation);
 	
 	converter.mapInputSocket(inputSocketImage, operation->getInputSocket(0));
diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.cpp b/source/blender/compositor/operations/COM_ColorSpillOperation.cpp
index 873ec72..0769e5d 100644
--- a/source/blender/compositor/operations/COM_ColorSpillOperation.cpp
+++ b/source/blender/compositor/operations/COM_ColorSpillOperation.cpp
@@ -33,6 +33,7 @@ ColorSpillOperation::ColorSpillOperation() : NodeOperation()
 	this->m_inputImageReader = NULL;
 	this->m_inputFacReader = NULL;
 	this->m_spillChannel = 1; // GREEN
+	this->m_spillMethod = 0;
 }
 
 void ColorSpillOperation::initExecution()
@@ -91,7 +92,17 @@ void ColorSpillOperation::executePixelSampled(float output[4], float x, float y,
 	this->m_inputFacReader->readSampled(fac, x, y, sampler);
 	this->m_inputImageReader->readSampled(input, x, y, sampler);
 	float rfac = min(1.0f, fac[0]);
-	float map = calculateMapValue(rfac, input);
+	float map;
+
+	switch (this->m_spillMethod) {
+		case 0:  /* simple */
+			map = rfac * (input[this->m_spillChannel] - (this->m_settings->limscale * input[this->m_settings->limchan]));
+			break;
+		default:  /* average */
+			map = rfac * (input[this->m_spillChannel] - (this->m_settings->limscale * AVG(input[this->m_channel2], input[this->m_channel3])));
+			break;
+	}
+
 	if (map > 0.0f) {
 		output[0] = input[0] + this->m_rmut * (this->m_settings->uspillr * map);
 		output[1] = input[1] + this->m_gmut * (this->m_settings->uspillg * map);
@@ -102,13 +113,3 @@ void ColorSpillOperation::executePixelSampled(float output[4], float x, float y,
 		copy_v4_v4(output, input);
 	}
 }
-float ColorSpillOperation::calculateMapValue(float fac, float *input)
-{
-	return fac * (input[this->m_spillChannel] - (this->m_settings->limscale * input[this->m_settings->limchan]));
-}
-
-
-float ColorSpillAverageOperation::calculateMapValue(float fac, float *input)
-{
-	return fac * (input[this->m_spillChannel] - (this->m_settings->limscale * AVG(input[this->m_channel2], input[this->m_channel3])));
-}
diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.h b/source/blender/compositor/operations/COM_ColorSpillOperation.h
index f9dc9ef..3b94c29 100644
--- a/source/blender/compositor/operations/COM_ColorSpillOperation.h
+++ b/source/blender/compositor/operations/COM_ColorSpillOperation.h
@@ -34,6 +34,7 @@ protected:
 	SocketReader *m_inputImageReader;
 	SocketReader *m_inputFacReader;
 	int m_spillChannel;
+	int m_spillMethod;
 	int m_channel2;
 	int m_channel3;
 	float m_rmut, m_gmut, m_bmut;
@@ -53,12 +54,9 @@ public:
 
 	void setSettings(NodeColorspill *nodeColorSpill) { this->m_settings = nodeColorSpill; }
 	void setSpillChannel(int channel) { this->m_spillChannel = channel; }
+	void setSpillMethod(int method) { this->m_spillMethod = method; }
 	
 	float calculateMapValue(float fac, float *input);
 };
 
-class ColorSpillAverageOperation : public ColorSpillOperation {
-public:
-	float calculateMapValue(float fac, float *input);
-};
 #endif




More information about the Bf-blender-cvs mailing list