[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49618] trunk/blender/source/blender: inpaint node from tomato branch by Peter Schlaile

Campbell Barton ideasman42 at gmail.com
Mon Aug 6 15:45:11 CEST 2012


Revision: 49618
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49618
Author:   campbellbarton
Date:     2012-08-06 13:45:11 +0000 (Mon, 06 Aug 2012)
Log Message:
-----------
inpaint node from tomato branch by Peter Schlaile

http://en.wikipedia.org/wiki/Inpainting

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/compositor/CMakeLists.txt
    trunk/blender/source/blender/compositor/intern/COM_Converter.cpp
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h
    trunk/blender/source/blender/nodes/CMakeLists.txt
    trunk/blender/source/blender/nodes/NOD_composite.h

Added Paths:
-----------
    trunk/blender/source/blender/compositor/nodes/COM_InpaintNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_InpaintNode.h
    trunk/blender/source/blender/compositor/operations/COM_InpaintOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_InpaintOperation.h
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_inpaint.c

Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h	2012-08-06 13:40:29 UTC (rev 49617)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h	2012-08-06 13:45:11 UTC (rev 49618)
@@ -671,6 +671,7 @@
 #define CMP_NODE_KEYINGSCREEN		269
 #define CMP_NODE_KEYING			270
 #define CMP_NODE_TRACKPOS		271
+#define CMP_NODE_INPAINT                272
 
 #define CMP_NODE_GLARE		301
 #define CMP_NODE_TONEMAP	302

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2012-08-06 13:40:29 UTC (rev 49617)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2012-08-06 13:45:11 UTC (rev 49618)
@@ -1990,6 +1990,7 @@
 	register_node_type_cmp_bilateralblur(ttype);
 	register_node_type_cmp_vecblur(ttype);
 	register_node_type_cmp_dilateerode(ttype);
+	register_node_type_cmp_inpaint(ttype);
 	register_node_type_cmp_defocus(ttype);
 	
 	register_node_type_cmp_valtorgb(ttype);

Modified: trunk/blender/source/blender/compositor/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/compositor/CMakeLists.txt	2012-08-06 13:40:29 UTC (rev 49617)
+++ trunk/blender/source/blender/compositor/CMakeLists.txt	2012-08-06 13:45:11 UTC (rev 49618)
@@ -286,6 +286,8 @@
 	nodes/COM_FilterNode.h
 	nodes/COM_DilateErodeNode.cpp
 	nodes/COM_DilateErodeNode.h
+	nodes/COM_InpaintNode.cpp
+	nodes/COM_InpaintNode.h
 	nodes/COM_BlurNode.cpp
 	nodes/COM_BlurNode.h
 	nodes/COM_BokehBlurNode.cpp
@@ -590,6 +592,8 @@
 	operations/COM_ConvolutionEdgeFilterOperation.cpp
 	operations/COM_DilateErodeOperation.cpp
 	operations/COM_DilateErodeOperation.h
+	operations/COM_InpaintOperation.cpp
+	operations/COM_InpaintOperation.h
 	operations/COM_GlareThresholdOperation.cpp
 	operations/COM_GlareThresholdOperation.h
 	operations/COM_GlareBaseOperation.cpp

Modified: trunk/blender/source/blender/compositor/intern/COM_Converter.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_Converter.cpp	2012-08-06 13:40:29 UTC (rev 49617)
+++ trunk/blender/source/blender/compositor/intern/COM_Converter.cpp	2012-08-06 13:45:11 UTC (rev 49618)
@@ -74,6 +74,7 @@
 #include "COM_HueSaturationValueNode.h"
 #include "COM_IDMaskNode.h"
 #include "COM_ImageNode.h"
+#include "COM_InpaintNode.h"
 #include "COM_InvertNode.h"
 #include "COM_KeyingNode.h"
 #include "COM_KeyingScreenNode.h"
@@ -303,6 +304,9 @@
 		case CMP_NODE_DILATEERODE:
 			node = new DilateErodeNode(b_node);
 			break;
+		case CMP_NODE_INPAINT:
+			node = new InpaintNode(b_node);
+			break;
 		case CMP_NODE_LENSDIST:
 			node = new LensDistortionNode(b_node);
 			break;

Added: trunk/blender/source/blender/compositor/nodes/COM_InpaintNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_InpaintNode.cpp	                        (rev 0)
+++ trunk/blender/source/blender/compositor/nodes/COM_InpaintNode.cpp	2012-08-06 13:45:11 UTC (rev 49618)
@@ -0,0 +1,48 @@
+/*
+ * 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: Peter Schlaile
+ *		Jeroen Bakker 
+ *		Monique Dewanchand
+ */
+
+#include "COM_InpaintNode.h"
+#include "DNA_scene_types.h"
+#include "COM_ExecutionSystem.h"
+#include "COM_InpaintOperation.h"
+#include "BLI_math.h"
+
+InpaintNode::InpaintNode(bNode *editorNode) : Node(editorNode)
+{
+	/* pass */
+}
+
+void InpaintNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
+{
+	
+	bNode *editorNode = this->getbNode();
+
+	/* if (editorNode->custom1 == CMP_NODE_INPAINT_SIMPLE) { */
+	if (true) {
+		InpaintSimpleOperation *operation = new InpaintSimpleOperation();
+		operation->setbNode(editorNode);
+		operation->setIterations(editorNode->custom2);
+		this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
+		this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0));
+		graph->addOperation(operation);
+	}
+}

Added: trunk/blender/source/blender/compositor/nodes/COM_InpaintNode.h
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_InpaintNode.h	                        (rev 0)
+++ trunk/blender/source/blender/compositor/nodes/COM_InpaintNode.h	2012-08-06 13:45:11 UTC (rev 49618)
@@ -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: Peter Schlaile
+ *		Jeroen Bakker 
+ *		Monique Dewanchand
+ */
+
+#ifndef _COM_InpaintNode_h_
+#define _COM_InpaintNode_h_
+
+#include "COM_Node.h"
+
+/**
+ * @brief InpaintNode
+ * @ingroup Node
+ */
+class InpaintNode : public Node {
+public:
+	InpaintNode(bNode *editorNode);
+	void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
+};
+
+#endif

Added: trunk/blender/source/blender/compositor/operations/COM_InpaintOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_InpaintOperation.cpp	                        (rev 0)
+++ trunk/blender/source/blender/compositor/operations/COM_InpaintOperation.cpp	2012-08-06 13:45:11 UTC (rev 49618)
@@ -0,0 +1,305 @@
+/*
+ * 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: Peter Schlaile
+ *		Jeroen Bakker 
+ *		Monique Dewanchand
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "COM_InpaintOperation.h"
+#include "COM_OpenCLDevice.h"
+
+#include "BLI_math.h"
+
+#define ASSERT_XY_RANGE(x, y)  \
+	BLI_assert(x >= 0 && x < this->getWidth() && \
+	           y >= 0 && y < this->getHeight())
+
+
+// Inpaint (simple convolve using average of known pixels)
+InpaintSimpleOperation::InpaintSimpleOperation() : NodeOperation()
+{
+	this->addInputSocket(COM_DT_COLOR);
+	this->addOutputSocket(COM_DT_COLOR);
+	this->setComplex(true);
+	this->m_inputImageProgram = NULL;
+	this->m_pixelorder = NULL;
+	this->m_manhatten_distance = NULL;
+	this->m_cached_buffer = NULL;
+	this->m_cached_buffer_ready = false;
+}
+void InpaintSimpleOperation::initExecution()
+{
+	this->m_inputImageProgram = this->getInputSocketReader(0);
+
+	this->m_cached_buffer = NULL;
+	this->m_pixelorder = NULL;
+	this->m_manhatten_distance = NULL;
+	this->m_cached_buffer = NULL;
+	this->m_cached_buffer_ready = false;
+
+	this->initMutex();
+}
+
+void InpaintSimpleOperation::clamp_xy(int & x, int & y) 
+{
+	int width = this->getWidth();
+	int height = this->getHeight();
+
+	if (x < 0) {
+		x = 0;
+	}
+	else if (x >= width) {
+		x = width - 1;
+	}
+
+	if (y < 0) {
+		y = 0;
+	}
+	else if (y >= height) {
+		y = height - 1;
+	}
+}
+
+float InpaintSimpleOperation::get(int x, int y, int component) 
+{
+	int width = this->getWidth();
+
+	ASSERT_XY_RANGE(x, y);
+
+	return this->m_cached_buffer[
+	           y * width * COM_NUMBER_OF_CHANNELS
+	           + x * COM_NUMBER_OF_CHANNELS + component];
+}
+
+void InpaintSimpleOperation::set(int x, int y, int component, float v) 
+{
+	int width = this->getWidth();
+
+	ASSERT_XY_RANGE(x, y);
+
+	this->m_cached_buffer[
+	    y * width * COM_NUMBER_OF_CHANNELS
+	    + x * COM_NUMBER_OF_CHANNELS + component] = v;
+}
+
+int InpaintSimpleOperation::mdist(int x, int y) 
+{
+	int width = this->getWidth();
+
+	ASSERT_XY_RANGE(x, y);
+
+	return this->m_manhatten_distance[y * width + x];
+}
+
+bool InpaintSimpleOperation::next_pixel(int & x, int & y, int & curr, int iters)
+{
+	int width = this->getWidth();
+
+	if (curr >= this->m_area_size) {
+		return false;
+	}
+	
+	int r = this->m_pixelorder[curr++];
+
+	x = r % width;
+	y = r / width;
+
+	if (mdist(x, y) > iters) {
+		return false;
+	}
+	
+	return true;
+}
+
+void InpaintSimpleOperation::calc_manhatten_distance() 
+{
+	int width = this->getWidth();
+	int height = this->getHeight();
+	short *m = this->m_manhatten_distance = new short[width * height];
+	int *offsets;
+
+	offsets = (int *)MEM_callocN(sizeof(int) * (width + height + 1), "InpaintSimpleOperation offsets");
+
+	for (int j = 0; j < height; j++) {
+		for (int i = 0; i < width; i++) {
+			int r = 0;
+			/* no need to clamp here */
+			if (get(i, j, 3) < 1.0f) {
+				r = width + height;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list