[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43330] branches/tile/source/blender/ compositor: Color Matte Node - tiles

Dalai Felinto dfelinto at gmail.com
Thu Jan 12 19:54:26 CET 2012


Revision: 43330
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43330
Author:   dfelinto
Date:     2012-01-12 18:54:19 +0000 (Thu, 12 Jan 2012)
Log Message:
-----------
Color Matte Node - tiles
thanks Jeroen Bakker for review + small corrections

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_ColorMatteNode.cpp
    branches/tile/source/blender/compositor/nodes/COM_ColorMatteNode.h
    branches/tile/source/blender/compositor/operations/COM_ColorMatteOperation.cpp
    branches/tile/source/blender/compositor/operations/COM_ColorMatteOperation.h

Modified: branches/tile/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-12 18:08:07 UTC (rev 43329)
+++ branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-12 18:54:19 UTC (rev 43330)
@@ -161,6 +161,8 @@
 		nodes/COM_DistanceMatteNode.h
 		nodes/COM_ChromaMatteNode.cpp
 		nodes/COM_ChromaMatteNode.h
+		nodes/COM_ColorMatteNode.cpp
+		nodes/COM_ColorMatteNode.h
 		nodes/COM_LensDistortionNode.cpp
 		nodes/COM_LensDistortionNode.h
 
@@ -389,6 +391,8 @@
 	operations/COM_DistanceMatteOperation.h
 	operations/COM_ChromaMatteOperation.cpp
 	operations/COM_ChromaMatteOperation.h
+	operations/COM_ColorMatteOperation.cpp
+	operations/COM_ColorMatteOperation.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-12 18:08:07 UTC (rev 43329)
+++ branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-12 18:54:19 UTC (rev 43330)
@@ -77,6 +77,7 @@
 #include "COM_LuminanceMatteNode.h"
 #include "COM_DistanceMatteNode.h"
 #include "COM_ChromaMatteNode.h"
+#include "COM_ColorMatteNode.h"
 #include "COM_BlurNode.h"
 #include "COM_BokehBlurNode.h"
 #include "COM_DilateErodeNode.h"
@@ -242,6 +243,9 @@
 	case CMP_NODE_CHROMA_MATTE:
 		node = new ChromaMatteNode(bNode);
 		break;
+	case CMP_NODE_COLOR_MATTE:
+		node = new ColorMatteNode(bNode);
+		break;
 	case CMP_NODE_BLUR:
 		node = new BlurNode(bNode);
 		break;

Added: branches/tile/source/blender/compositor/nodes/COM_ColorMatteNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_ColorMatteNode.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_ColorMatteNode.cpp	2012-01-12 18:54:19 UTC (rev 43330)
@@ -0,0 +1,67 @@
+/*
+ * 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_ColorMatteNode.h"
+#include "BKE_node.h"
+#include "COM_ColorMatteOperation.h"
+#include "COM_ConvertRGBToHSVOperation.h"
+#include "COM_SetAlphaOperation.h"
+
+ColorMatteNode::ColorMatteNode(bNode *editorNode): Node(editorNode)
+{}
+
+void ColorMatteNode::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);
+
+	ConvertRGBToHSVOperation *operationRGBToHSV_Image = new ConvertRGBToHSVOperation();
+	ConvertRGBToHSVOperation *operationRGBToHSV_Key = new ConvertRGBToHSVOperation();
+
+	ColorMatteOperation *operation = new ColorMatteOperation();
+	bNode* editorsnode = getbNode();
+	operation->setSettings((NodeChroma*)editorsnode->storage);
+
+	inputSocketImage->relinkConnections(operationRGBToHSV_Image->getInputSocket(0), true, 0, graph);
+	inputSocketKey->relinkConnections(operationRGBToHSV_Key->getInputSocket(0), true, 1, graph);
+
+	addLink(graph, operationRGBToHSV_Image->getOutputSocket(), operation->getInputSocket(0));
+	addLink(graph, operationRGBToHSV_Key->getOutputSocket(), operation->getInputSocket(1));
+
+	if (outputSocketMatte->isConnected()) {
+		outputSocketMatte->relinkConnections(operation->getOutputSocket(0));
+	}
+
+	graph->addOperation(operationRGBToHSV_Image);
+	graph->addOperation(operationRGBToHSV_Key);
+	graph->addOperation(operation);
+
+	SetAlphaOperation *operationAlpha = new SetAlphaOperation();
+	addLink(graph, operationRGBToHSV_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_ColorMatteNode.cpp
___________________________________________________________________
Added: svn:eol
   + native

Added: branches/tile/source/blender/compositor/nodes/COM_ColorMatteNode.h
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_ColorMatteNode.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_ColorMatteNode.h	2012-01-12 18:54:19 UTC (rev 43330)
@@ -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_ColorMatteNODE_H
+#define COM_ColorMatteNODE_H
+
+#include "COM_Node.h"
+
+/**
+  * @brief ColorMatteNode
+  * @ingroup Node
+  */
+class ColorMatteNode : public Node
+{
+public:
+	ColorMatteNode(bNode *editorNode);
+	void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
+};
+
+#endif // COM_ColorMatteNODE_H


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

Added: branches/tile/source/blender/compositor/operations/COM_ColorMatteOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_ColorMatteOperation.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_ColorMatteOperation.cpp	2012-01-12 18:54:19 UTC (rev 43330)
@@ -0,0 +1,80 @@
+/*
+ * 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_ColorMatteOperation.h"
+#include "BLI_math.h"
+
+ColorMatteOperation::ColorMatteOperation(): NodeOperation() {
+	addInputSocket(COM_DT_COLOR);
+	addInputSocket(COM_DT_COLOR);
+	addOutputSocket(COM_DT_VALUE);
+
+	inputImageProgram = NULL;
+	inputKeyProgram = NULL;
+}
+
+void ColorMatteOperation::initExecution() {
+	this->inputImageProgram = this->getInputSocketReader(0);
+	this->inputKeyProgram = this->getInputSocketReader(1);
+}
+
+void ColorMatteOperation::deinitExecution() {
+	this->inputImageProgram= NULL;
+	this->inputKeyProgram= NULL;
+}
+
+void ColorMatteOperation::executePixel(float* outputValue, float x, float y, MemoryBuffer *inputBuffers[]) {
+	float inColor[4];
+	float inKey[4];
+
+	const float hue=this->settings->t1;
+	const float sat=this->settings->t2;
+	const float val=this->settings->t3;
+
+	float h_wrap;
+
+	this->inputImageProgram->read(inColor, x, y, inputBuffers);
+	this->inputKeyProgram->read(inKey, x, y, inputBuffers);
+
+
+	/* store matte(alpha) value in [0] to go with
+	 * COM_SetAlphaOperation and the Value output
+	 */
+
+	if(
+	/* do hue last because it needs to wrap, and does some more checks  */
+
+	/* sat */	(fabsf(inColor[1]-inKey[1]) < sat) &&
+	/* val */	(fabsf(inColor[2]-inKey[2]) < val) &&
+
+	/* multiply by 2 because it wraps on both sides of the hue,
+	 * otherwise 0.5 would key all hue's */
+
+	/* hue */	((h_wrap= 2.f * fabsf(inColor[0]-inKey[0])) < hue || (2.f - h_wrap) < hue)
+	) {
+		outputValue[0]=0.f; /*make transparent*/
+	}
+
+	else { /*pixel is outside key color */
+		outputValue[0]=inColor[3]; /* make pixel just as transparent as it was before */
+	}
+}
+


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

Added: branches/tile/source/blender/compositor/operations/COM_ColorMatteOperation.h
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_ColorMatteOperation.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_ColorMatteOperation.h	2012-01-12 18:54:19 UTC (rev 43330)
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list