[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46972] branches/soc-2011-tomato/source/ blender: Port mask node to new compositor system

Sergey Sharybin sergey.vfx at gmail.com
Thu May 24 16:01:01 CEST 2012


Revision: 46972
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46972
Author:   nazgul
Date:     2012-05-24 14:01:00 +0000 (Thu, 24 May 2012)
Log Message:
-----------
Port mask node to new compositor system

Works in the same way as double edge node -- not actually multithreaded
but currently it's fast enough to be used in such way. In the future it
might be changed in some way.

Move actual mask rasterization code to BKE so it's resued by old compositor
system and new compositor. Also in the future it might be used to display
mask preview in mask editor.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
    branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp
    branches/soc-2011-tomato/source/blender/nodes/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_mask.c

Added Paths:
-----------
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_MaskNode.cpp
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_MaskNode.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_MaskOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_MaskOperation.h

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-05-24 13:57:02 UTC (rev 46971)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-05-24 14:01:00 UTC (rev 46972)
@@ -110,6 +110,9 @@
 void BKE_mask_object_shape_unlink(struct MaskObject *maskobj, struct MaskObjectShape *maskobj_shape);
 void BKE_mask_object_shape_sort(struct MaskObject *maskobj);
 
+/* rasterization */
+void BKE_mask_rasterize(struct Mask *mask, int width, int height, float *buffer);
+
 #define MASKPOINT_ISSEL(p)  ( ((p)->bezt.f1 | (p)->bezt.f2 | (p)->bezt.f2) & SELECT)
 #define MASKPOINT_SEL(p)    { (p)->bezt.f1 |=  SELECT; (p)->bezt.f2 |=  SELECT; (p)->bezt.f3 |=  SELECT; } (void)0
 #define MASKPOINT_DESEL(p)  { (p)->bezt.f1 &= ~SELECT; (p)->bezt.f2 &= ~SELECT; (p)->bezt.f3 &= ~SELECT; } (void)0

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-05-24 13:57:02 UTC (rev 46971)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-05-24 14:01:00 UTC (rev 46972)
@@ -55,6 +55,8 @@
 #include "BKE_movieclip.h"
 #include "BKE_utildefines.h"
 
+#include "raskter.h"
+
 /* mask objects */
 
 MaskObject *BKE_mask_object_new(Mask *mask, const char *name)
@@ -1271,3 +1273,46 @@
 {
 	BLI_sortlist(&maskobj->splines_shapes, mask_object_shape_sort_cb);
 }
+
+/* rasterization */
+void BKE_mask_rasterize(Mask *mask, int width, int height, float *buffer)
+{
+	MaskObject *maskobj;
+
+	for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) {
+		MaskSpline *spline;
+
+		for (spline = maskobj->splines.first; spline; spline = spline->next) {
+			float *diff_points;
+			int tot_diff_point;
+
+			diff_points = BKE_mask_spline_differentiate(spline, &tot_diff_point);
+
+			/* TODO, make this optional! */
+			if (width != height) {
+				float *fp;
+				int i;
+				float asp;
+
+				if (width < height) {
+					fp = &diff_points[0];
+					asp = (float)width / (float)height;
+				}
+				else {
+					fp = &diff_points[1];
+					asp = (float)height / (float)width;
+				}
+
+				for (i = 0; i < tot_diff_point; i++, fp += 2) {
+					(*fp) = (((*fp) - 0.5f) / asp) + 0.5f;
+				}
+			}
+
+			if (tot_diff_point) {
+				PLX_raskterize(diff_points, tot_diff_point, buffer, width, height);
+
+				MEM_freeN(diff_points);
+			}
+		}
+	}
+}

Modified: branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt	2012-05-24 13:57:02 UTC (rev 46971)
+++ branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt	2012-05-24 14:01:00 UTC (rev 46972)
@@ -134,6 +134,8 @@
 	nodes/COM_MovieClipNode.h
 	nodes/COM_OutputFileNode.cpp
 	nodes/COM_OutputFileNode.h
+	nodes/COM_MaskNode.cpp
+	nodes/COM_MaskNode.h
 
 # output nodes
 	nodes/COM_CompositorNode.cpp
@@ -603,6 +605,9 @@
 
 	operations/COM_AntiAliasOperation.cpp
 	operations/COM_AntiAliasOperation.h
+
+	operations/COM_MaskOperation.cpp
+	operations/COM_MaskOperation.h
 )
 
 blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}")

Modified: branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp	2012-05-24 13:57:02 UTC (rev 46971)
+++ branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp	2012-05-24 14:01:00 UTC (rev 46972)
@@ -111,6 +111,7 @@
 #include "COM_DefocusNode.h"
 #include "COM_DoubleEdgeMaskNode.h"
 #include "COM_CropNode.h"
+#include "COM_MaskNode.h"
 
 Node *Converter::convert(bNode *bNode)
 {
@@ -347,6 +348,9 @@
 	case CMP_NODE_CROP:
 		node = new CropNode(bNode);
 		break;
+	case CMP_NODE_MASK:
+		node = new MaskNode(bNode);
+		break;
 	/* not inplemented yet */
 	default:
 		node = new MuteNode(bNode);

Added: branches/soc-2011-tomato/source/blender/compositor/nodes/COM_MaskNode.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/nodes/COM_MaskNode.cpp	                        (rev 0)
+++ branches/soc-2011-tomato/source/blender/compositor/nodes/COM_MaskNode.cpp	2012-05-24 14:01:00 UTC (rev 46972)
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2012, 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:
+ *		Jeroen Bakker
+ *		Monique Dewanchand
+ *		Sergey Sharybin
+ */
+
+#include "COM_MaskNode.h"
+#include "COM_ExecutionSystem.h"
+#include "COM_MaskOperation.h"
+
+extern "C" {
+	#include "DNA_mask_types.h"
+}
+
+MaskNode::MaskNode(bNode *editorNode): Node(editorNode)
+{
+}
+
+void MaskNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context)
+{
+	const RenderData *data = &context->getScene()->r;
+
+	InputSocket *inputImage = this->getInputSocket(0);
+	OutputSocket *outputMask = this->getOutputSocket(0);
+
+	bNode *editorNode = this->getbNode();
+	Mask *mask = (Mask *)editorNode->id;
+
+	// always connect the output image
+	MaskOperation *operation = new MaskOperation();
+
+	if (inputImage->isConnected()) {
+		inputImage->relinkConnections(operation->getInputSocket(0), 0, graph);
+	}
+	else {
+		operation->setMaskWidth(data->xsch * data->size / 100.0f);
+		operation->setMaskHeight(data->ysch * data->size / 100.0f);
+	}
+
+	if (outputMask->isConnected()) {
+		outputMask->relinkConnections(operation->getOutputSocket());
+	}
+
+	operation->setMask(mask);
+	operation->setFramenumber(context->getFramenumber());
+
+	graph->addOperation(operation);
+}

Added: branches/soc-2011-tomato/source/blender/compositor/nodes/COM_MaskNode.h
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/nodes/COM_MaskNode.h	                        (rev 0)
+++ branches/soc-2011-tomato/source/blender/compositor/nodes/COM_MaskNode.h	2012-05-24 14:01:00 UTC (rev 46972)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2012, 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:
+ *		Jeroen Bakker
+ *		Monique Dewanchand
+ *		Sergey Sharybin
+ */
+
+#include "COM_Node.h"
+#include "DNA_node_types.h"
+
+/**
+  * @brief MaskNode
+  * @ingroup Node
+  */
+class MaskNode : public Node {
+
+
+public:
+	MaskNode(bNode *editorNode);
+	void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
+
+};

Added: branches/soc-2011-tomato/source/blender/compositor/operations/COM_MaskOperation.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_MaskOperation.cpp	                        (rev 0)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_MaskOperation.cpp	2012-05-24 14:01:00 UTC (rev 46972)
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2012, 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:
+ *		Jeroen Bakker
+ *		Monique Dewanchand
+ *		Sergey Sharybin
+ */
+
+#include "COM_MaskOperation.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
+#include "DNA_scene_types.h"
+
+extern "C" {
+	#include "BKE_mask.h"
+}
+
+MaskOperation::MaskOperation(): NodeOperation()
+{
+	this->addInputSocket(COM_DT_COLOR);
+	this->addOutputSocket(COM_DT_COLOR);
+	this->mask = NULL;
+	this->maskWidth = 0;
+	this->maskHeight = 0;
+	this->framenumber = 0;
+	this->rasterizedMask = NULL;
+	setComplex(true);
+}
+
+void MaskOperation::initExecution()
+{
+	initMutex();
+	this->rasterizedMask = NULL;
+}
+
+void MaskOperation::deinitExecution()
+{
+	if (this->rasterizedMask) {
+		MEM_freeN(rasterizedMask);
+		this->rasterizedMask = NULL;
+	}
+}
+
+void *MaskOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
+{
+	if (this->rasterizedMask)
+		return this->rasterizedMask;
+
+	BLI_mutex_lock(getMutex());
+	if (this->rasterizedMask == NULL) {
+		int width = this->getWidth();
+		int height = this->getHeight();
+
+		this->rasterizedMask = (float *)MEM_callocN(sizeof(float) * width * height, "rasterized mask");
+		BKE_mask_rasterize(mask, width, height, this->rasterizedMask);
+	}

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list