[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47643] branches/soc-2011-tomato/source/ blender: Changes to keying nodes:

Sergey Sharybin sergey.vfx at gmail.com
Sat Jun 9 19:15:45 CEST 2012


Revision: 47643
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47643
Author:   nazgul
Date:     2012-06-09 17:15:38 +0000 (Sat, 09 Jun 2012)
Log Message:
-----------
Changes to keying nodes:

- Replace FastGaussian blur with GaussianBokeh blur which should give better results.
- Changes a bit formula of saturation which in some cases gives better result.
  Also included (commented out) original formula which was also checked by Brecht
  and which gave better result in some other cases.
- Made clipping white/black temporal dependent, so hopefully it wouldn't destroy
  gradients on edges.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.cpp
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingOperation.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree.c

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

Modified: branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt	2012-06-09 16:45:42 UTC (rev 47642)
+++ branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt	2012-06-09 17:15:38 UTC (rev 47643)
@@ -333,6 +333,8 @@
 	operations/COM_KeyingScreenOperation.h
 	operations/COM_KeyingDespillOperation.cpp
 	operations/COM_KeyingDespillOperation.h
+	operations/COM_KeyingClipOperation.cpp
+	operations/COM_KeyingClipOperation.h
 
 operations/COM_ColorSpillOperation.cpp
 operations/COM_ColorSpillOperation.h

Modified: branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.cpp	2012-06-09 16:45:42 UTC (rev 47642)
+++ branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.cpp	2012-06-09 17:15:38 UTC (rev 47643)
@@ -27,12 +27,13 @@
 
 #include "COM_KeyingOperation.h"
 #include "COM_KeyingDespillOperation.h"
+#include "COM_KeyingClipOperation.h"
 
 #include "COM_SeparateChannelOperation.h"
 #include "COM_CombineChannelsOperation.h"
 #include "COM_ConvertRGBToYCCOperation.h"
 #include "COM_ConvertYCCToRGBOperation.h"
-#include "COM_FastGaussianBlurOperation.h"
+#include "COM_GaussianBokehBlurOperation.h"
 #include "COM_SetValueOperation.h"
 
 #include "COM_DilateErodeOperation.h"
@@ -72,8 +73,9 @@
 			setValueOperation->setValue(1.0f);
 			graph->addOperation(setValueOperation);
 
-			FastGaussianBlurOperation *blurOperation = new FastGaussianBlurOperation();
+			GaussianBokehBlurOperation *blurOperation = new GaussianBokehBlurOperation();
 			blurOperation->setData(&preBlurData);
+			blurOperation->setQuality(COM_QUALITY_HIGH);
 
 			addLink(graph, separateOperation->getOutputSocket(0), blurOperation->getInputSocket(0));
 			addLink(graph, setValueOperation->getOutputSocket(0), blurOperation->getInputSocket(1));
@@ -104,8 +106,9 @@
 	setValueOperation->setValue(1.0f);
 	graph->addOperation(setValueOperation);
 
-	FastGaussianBlurOperation *blurOperation = new FastGaussianBlurOperation();
+	GaussianBokehBlurOperation *blurOperation = new GaussianBokehBlurOperation();
 	blurOperation->setData(&postBlurData);
+	blurOperation->setQuality(COM_QUALITY_HIGH);
 
 	addLink(graph, postBLurInput, blurOperation->getInputSocket(0));
 	addLink(graph, setValueOperation->getOutputSocket(0), blurOperation->getInputSocket(1));
@@ -149,6 +152,20 @@
 	return despillOperation->getOutputSocket(0);
 }
 
+OutputSocket *KeyingNode::setupClip(ExecutionSystem *graph, OutputSocket *clipInput, float clipBlack, float clipWhite)
+{
+	KeyingClipOperation *clipOperation = new KeyingClipOperation();
+
+	clipOperation->setClipBlack(clipBlack);
+	clipOperation->setClipWhite(clipWhite);
+
+	addLink(graph, clipInput, clipOperation->getInputSocket(0));
+
+	graph->addOperation(clipOperation);
+
+	return clipOperation->getOutputSocket(0);
+}
+
 void KeyingNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
 {
 	InputSocket *inputImage = this->getInputSocket(0);
@@ -163,9 +180,6 @@
 	/* keying operation */
 	KeyingOperation *keyingOperation = new KeyingOperation();
 
-	keyingOperation->setClipBlack(keying_data->clip_black);
-	keyingOperation->setClipWhite(keying_data->clip_white);
-
 	inputScreen->relinkConnections(keyingOperation->getInputSocket(1), 1, graph);
 
 	if (keying_data->blur_pre) {
@@ -180,11 +194,14 @@
 
 	graph->addOperation(keyingOperation);
 
+	postprocessedMatte = keyingOperation->getOutputSocket();
+
+	if (keying_data->clip_black > 0.0f || keying_data->clip_white< 1.0f)
+		postprocessedMatte = setupClip(graph, postprocessedMatte, keying_data->clip_black, keying_data->clip_white);
+
 	/* apply blur on matte if needed */
 	if (keying_data->blur_post)
-		postprocessedMatte = setupPostBlur(graph, keyingOperation->getOutputSocket(), keying_data->blur_post);
-	else
-		postprocessedMatte = keyingOperation->getOutputSocket();
+		postprocessedMatte = setupPostBlur(graph, postprocessedMatte, keying_data->blur_post);
 
 	/* matte dilate/erode */
 	if (keying_data->dilate_distance != 0) {

Modified: branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.h
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.h	2012-06-09 16:45:42 UTC (rev 47642)
+++ branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.h	2012-06-09 17:15:38 UTC (rev 47643)
@@ -37,6 +37,7 @@
 	OutputSocket *setupPostBlur(ExecutionSystem *graph, OutputSocket *postBLurInput, int size);
 	OutputSocket *setupDilateErode(ExecutionSystem *graph, OutputSocket *dilateErodeInput, int distance);
 	OutputSocket *setupDespill(ExecutionSystem *graph, OutputSocket *despillInput, InputSocket *inputSrceen, float factor);
+	OutputSocket *setupClip(ExecutionSystem *graph, OutputSocket *clipInput, float clipBlack, float clipWhite);
 public:
 	KeyingNode(bNode *editorNode);
 	void convertToOperations(ExecutionSystem *graph, CompositorContext *context);

Added: branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingClipOperation.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingClipOperation.cpp	                        (rev 0)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingClipOperation.cpp	2012-06-09 17:15:38 UTC (rev 47643)
@@ -0,0 +1,95 @@
+/*
+ * 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_KeyingClipOperation.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
+KeyingClipOperation::KeyingClipOperation(): NodeOperation()
+{
+	this->addInputSocket(COM_DT_VALUE);
+	this->addOutputSocket(COM_DT_VALUE);
+
+	this->clipBlack = 0.0f;
+	this->clipWhite = 1.0f;
+
+	this->pixelReader = NULL;
+}
+
+void KeyingClipOperation::initExecution()
+{
+	this->pixelReader = this->getInputSocketReader(0);
+}
+
+void KeyingClipOperation::deinitExecution()
+{
+	this->pixelReader = NULL;
+}
+
+void KeyingClipOperation::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
+{
+	const int delta = 3;
+
+	float pixelColor[4];
+	int width = this->getWidth(), height = this->getHeight();
+	int count_black = 0, count_white = 0;
+	int i, j;
+
+	this->pixelReader->read(pixelColor, x, y, sampler, inputBuffers);
+
+	for (i = -delta + 1; i < delta; i++) {
+		for (j = -delta + 1; j < delta; j++) {
+			int cx = x + j, cy = y + i;
+
+			if (i == 0 && j == 0)
+				continue;
+
+			if (cx >= 0 && cx < width && cy >= 0 && cy < height) {
+				float value[4];
+
+				this->pixelReader->read(value, cx, cy, sampler, inputBuffers);
+
+				if (value[0] < 0.4f)
+					count_black++;
+				else if (value[0] > 0.6f)
+					count_white++;
+			}
+		}
+	}
+
+	color[0] = pixelColor[0];
+
+	if (count_black >= 22 || count_white >= 22) {
+		if (count_black >= 4 || count_white >= 4) {
+			if (color[0] < this->clipBlack)
+				color[0] = 0.0f;
+			else if (color[0] >= this->clipWhite)
+				color[0] = 1.0f;
+			else
+				color[0] = (color[0] - this->clipBlack) / (this->clipWhite - this->clipBlack);
+		}
+	}
+}

Copied: branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingClipOperation.h (from rev 47639, branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingOperation.h)
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingClipOperation.h	                        (rev 0)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingClipOperation.h	2012-06-09 17:15:38 UTC (rev 47643)
@@ -0,0 +1,50 @@
+/*
+ * 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
+ */
+
+#ifndef _COM_KeyingClipOperation_h
+#define _COM_KeyingClipOperation_h
+
+#include "COM_NodeOperation.h"
+
+/**
+  * Class with implementation of black/white clipping for keying node
+  */
+class KeyingClipOperation : public NodeOperation {
+protected:
+	SocketReader *pixelReader;
+	float clipBlack;
+	float clipWhite;
+
+public:
+	KeyingClipOperation();
+
+	void initExecution();
+	void deinitExecution();
+
+	void setClipBlack(float value) {this->clipBlack = value;}
+	void setClipWhite(float value) {this->clipWhite = value;}
+
+	void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]);
+};
+
+#endif

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingOperation.cpp
===================================================================

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list