[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43306] branches/tile/source/blender/ compositor: Tile - Chroma Matte Node

Dalai Felinto dfelinto at gmail.com
Wed Jan 11 19:24:23 CET 2012


Revision: 43306
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43306
Author:   dfelinto
Date:     2012-01-11 18:24:22 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
Tile - Chroma Matte Node
note - shadow adjust (c->t3) and lift (c->fsize) are no longer used in the algorith (since somewhere in 2.5 dev).
The properties are still in ChromaNode and have a RNA property.

This should be address in trunk, not in Tile I think.
If those are parameters needed for a more robust algorith we bring it to Tile later.

Modified Paths:
--------------
    branches/tile/source/blender/compositor/CMakeLists.txt
    branches/tile/source/blender/compositor/intern/COM_Converter.cpp

Added Paths:
-----------
    branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp
    branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.h
    branches/tile/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp
    branches/tile/source/blender/compositor/operations/COM_ChromaMatteOperation.h

Modified: branches/tile/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-11 17:25:44 UTC (rev 43305)
+++ branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-11 18:24:22 UTC (rev 43306)
@@ -159,6 +159,8 @@
 		nodes/COM_LuminanceMatteNode.h
 		nodes/COM_DistanceMatteNode.cpp
 		nodes/COM_DistanceMatteNode.h
+		nodes/COM_ChromaMatteNode.cpp
+		nodes/COM_ChromaMatteNode.h
 		nodes/COM_LensDistortionNode.cpp
 		nodes/COM_LensDistortionNode.h
 
@@ -385,6 +387,8 @@
 	operations/COM_LuminanceMatteOperation.h
 	operations/COM_DistanceMatteOperation.cpp
 	operations/COM_DistanceMatteOperation.h
+	operations/COM_ChromaMatteOperation.cpp
+	operations/COM_ChromaMatteOperation.h
 
 	operations/COM_ReadBufferOperation.cpp
 	operations/COM_ReadBufferOperation.h

Modified: branches/tile/source/blender/compositor/intern/COM_Converter.cpp
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-11 17:25:44 UTC (rev 43305)
+++ branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-11 18:24:22 UTC (rev 43306)
@@ -76,6 +76,7 @@
 #include "COM_DifferenceMatteNode.h"
 #include "COM_LuminanceMatteNode.h"
 #include "COM_DistanceMatteNode.h"
+#include "COM_ChromaMatteNode.h"
 #include "COM_BlurNode.h"
 #include "COM_BokehBlurNode.h"
 #include "COM_DilateErodeNode.h"
@@ -238,6 +239,9 @@
 	case CMP_NODE_DIST_MATTE:
 		node = new DistanceMatteNode(bNode);
 		break;
+	case CMP_NODE_CHROMA_MATTE:
+		node = new ChromaMatteNode(bNode);
+		break;
 	case CMP_NODE_BLUR:
 		node = new BlurNode(bNode);
 		break;

Added: branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp	2012-01-11 18:24:22 UTC (rev 43306)
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor:
+ *		Dalai Felinto
+ */
+
+#include "COM_ChromaMatteNode.h"
+#include "BKE_node.h"
+#include "COM_ChromaMatteOperation.h"
+#include "COM_ConvertRGBToYCCOperation.h"
+#include "COM_SetAlphaOperation.h"
+
+ChromaMatteNode::ChromaMatteNode(bNode *editorNode): Node(editorNode)
+{}
+
+void ChromaMatteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) {
+	InputSocket *inputSocketImage = this->getInputSocket(0);
+	InputSocket *inputSocketKey = this->getInputSocket(1);
+	OutputSocket *outputSocketImage = this->getOutputSocket(0);
+	OutputSocket *outputSocketMatte = this->getOutputSocket(1);
+
+	ConvertRGBToYCCOperation *operationRGBToYCC_Image = new ConvertRGBToYCCOperation();
+	ConvertRGBToYCCOperation *operationRGBToYCC_Key = new ConvertRGBToYCCOperation();
+	operationRGBToYCC_Image->setMode(0); /* BLI_YCC_ITU_BT601 */
+	operationRGBToYCC_Key->setMode(0); /* BLI_YCC_ITU_BT601 */
+
+	ChromaMatteOperation *operation = new ChromaMatteOperation();
+	bNode* editorsnode = getbNode();
+	operation->setSettings((NodeChroma*)editorsnode->storage);
+
+	inputSocketImage->relinkConnections(operationRGBToYCC_Image->getInputSocket(0), true, 0, graph);
+	inputSocketKey->relinkConnections(operationRGBToYCC_Key->getInputSocket(0), true, 0, graph);
+
+	addLink(graph, operationRGBToYCC_Image->getOutputSocket(), operation->getInputSocket(0));
+	addLink(graph, operationRGBToYCC_Key->getOutputSocket(), operation->getInputSocket(1));
+
+	graph->addOperation(operationRGBToYCC_Image);
+	graph->addOperation(operationRGBToYCC_Key);
+	graph->addOperation(operation);
+
+	if (outputSocketMatte->isConnected()) {
+		outputSocketMatte->relinkConnections(operation->getOutputSocket());
+	}
+
+	SetAlphaOperation *operationAlpha = new SetAlphaOperation();
+	addLink(graph, operationRGBToYCC_Image->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0));
+	addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1));
+
+	graph->addOperation(operationAlpha);
+	addPreviewOperation(graph, operationAlpha->getOutputSocket(), 9);
+
+	if (outputSocketImage->isConnected()) {
+		outputSocketImage->relinkConnections(operationAlpha->getOutputSocket());
+	}
+}


Property changes on: branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp
___________________________________________________________________
Added: svn:eol
   + native

Added: branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.h
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.h	2012-01-11 18:24:22 UTC (rev 43306)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor:
+ *		Dalai Felinto
+ */
+
+#ifndef COM_ChromaMatteNODE_H
+#define COM_ChromaMatteNODE_H
+
+#include "COM_Node.h"
+
+/**
+  * @brief ChromaMatteNode
+  * @ingroup Node
+  */
+class ChromaMatteNode : public Node
+{
+public:
+	ChromaMatteNode(bNode *editorNode);
+	void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
+};
+
+#endif // COM_ChromaMatteNODE_H


Property changes on: branches/tile/source/blender/compositor/nodes/COM_ChromaMatteNode.h
___________________________________________________________________
Added: svn:eol
   + native

Added: branches/tile/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp	2012-01-11 18:24:22 UTC (rev 43306)
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor:
+ *		Dalai Felinto
+ */
+
+#include "COM_ChromaMatteOperation.h"
+#include "COM_InputSocket.h"
+#include "COM_OutputSocket.h"
+#include "BLI_math.h"
+
+ChromaMatteOperation::ChromaMatteOperation(): NodeOperation() {
+	addInputSocket(COM_DT_COLOR);
+	addInputSocket(COM_DT_COLOR);
+	addOutputSocket(COM_DT_VALUE);
+
+	inputImageProgram = NULL;
+	inputKeyProgram = NULL;
+}
+
+void ChromaMatteOperation::initExecution() {
+	this->inputImageProgram = this->getInputSocketReader(0);
+	this->inputKeyProgram = this->getInputSocketReader(1);
+}
+
+void ChromaMatteOperation::deinitExecution() {
+	this->inputImageProgram= NULL;
+	this->inputKeyProgram= NULL;
+}
+
+void ChromaMatteOperation::executePixel(float* outputValue, float x, float y, MemoryBuffer *inputBuffers[]) {
+	float inKey[4];
+	float inImage[4];
+
+	const float acceptance = this->settings->t1; /* in radians */
+	const float cutoff = this->settings->t2; /* in radians */
+	const float gain = this->settings->fstrength;
+
+	float x_angle, z_angle, alpha;
+	float theta, beta;
+	float kfg;
+
+	this->inputKeyProgram->read(inKey, x, y, inputBuffers);
+	this->inputImageProgram->read(inImage, x, y, inputBuffers);
+
+	/* store matte(alpha) value in [0] to go with
+	 * COM_SetAlphaOperation and the Value output
+	 */
+
+	/* Algorithm from book "Video Demistified," does not include the spill reduction part */
+	/* find theta, the angle that the color space should be rotated based on key*/
+	theta=atan2(inKey[2], inKey[1]);
+
+	/*rotate the cb and cr into x/z space */
+	x_angle=inImage[1]*cosf(theta)+inImage[2]*sinf(theta);
+	z_angle=inImage[2]*cosf(theta)-inImage[1]*sinf(theta);
+
+	/*if within the acceptance angle */
+	/* if kfg is <0 then the pixel is outside of the key color */
+	kfg= x_angle-(fabsf(z_angle)/tanf(acceptance/2.f));
+
+	if(kfg>0.f) {  /* found a pixel that is within key color */
+		alpha=(1.f-kfg)*(gain);
+
+		beta=atan2(z_angle,x_angle);
+
+		/* if beta is within the cutoff angle */
+		if(fabsf(beta) < (cutoff/2.f)) {
+			alpha=0.f;
+		}
+
+		/* don't make something that was more transparent less transparent */
+		if (alpha<inImage[3]) {
+			outputValue[0]=alpha;
+		}
+		else {
+			outputValue[0]=inImage[3];
+		}
+	}

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list