[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48256] trunk/blender/source/blender/ compositor: Optimization of Keying Blur operation

Sergey Sharybin sergey.vfx at gmail.com
Mon Jun 25 10:22:12 CEST 2012


Revision: 48256
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48256
Author:   nazgul
Date:     2012-06-25 08:21:55 +0000 (Mon, 25 Jun 2012)
Log Message:
-----------
Optimization of Keying Blur operation

Separate X and Y passes of blurring like it's done for flat
gaussian blur. This reduces computing difficulty from size^2
to 2*size without any visual changes in matte.

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/nodes/COM_KeyingNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_KeyingNode.h
    trunk/blender/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_KeyingBlurOperation.h

Modified: trunk/blender/source/blender/compositor/nodes/COM_KeyingNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_KeyingNode.cpp	2012-06-25 07:41:01 UTC (rev 48255)
+++ trunk/blender/source/blender/compositor/nodes/COM_KeyingNode.cpp	2012-06-25 08:21:55 UTC (rev 48256)
@@ -66,13 +66,21 @@
 			addLink(graph, separateOperation->getOutputSocket(0), combineOperation->getInputSocket(channel));
 		}
 		else {
-			KeyingBlurOperation *blurOperation = new KeyingBlurOperation();
+			KeyingBlurOperation *blurXOperation = new KeyingBlurOperation();
+			KeyingBlurOperation *blurYOperation = new KeyingBlurOperation();
 
-			blurOperation->setSize(size);
+			blurXOperation->setSize(size);
+			blurXOperation->setAxis(KeyingBlurOperation::BLUR_AXIS_X);
 
-			addLink(graph, separateOperation->getOutputSocket(0), blurOperation->getInputSocket(0));
-			addLink(graph, blurOperation->getOutputSocket(0), combineOperation->getInputSocket(channel));
-			graph->addOperation(blurOperation);
+			blurYOperation->setSize(size);
+			blurYOperation->setAxis(KeyingBlurOperation::BLUR_AXIS_Y);
+
+			addLink(graph, separateOperation->getOutputSocket(), blurXOperation->getInputSocket(0));
+			addLink(graph, blurXOperation->getOutputSocket(), blurYOperation->getInputSocket(0));
+			addLink(graph, blurYOperation->getOutputSocket(0), combineOperation->getInputSocket(channel));
+
+			graph->addOperation(blurXOperation);
+			graph->addOperation(blurYOperation);
 		}
 	}
 
@@ -86,17 +94,24 @@
 	return convertYCCToRGBOperation->getOutputSocket(0);
 }
 
-OutputSocket *KeyingNode::setupPostBlur(ExecutionSystem *graph, OutputSocket *postBLurInput, int size)
+OutputSocket *KeyingNode::setupPostBlur(ExecutionSystem *graph, OutputSocket *postBlurInput, int size)
 {
-	KeyingBlurOperation *blurOperation = new KeyingBlurOperation();
+	KeyingBlurOperation *blurXOperation = new KeyingBlurOperation();
+	KeyingBlurOperation *blurYOperation = new KeyingBlurOperation();
 
-	blurOperation->setSize(size);
+	blurXOperation->setSize(size);
+	blurXOperation->setAxis(KeyingBlurOperation::BLUR_AXIS_X);
 
-	addLink(graph, postBLurInput, blurOperation->getInputSocket(0));
+	blurYOperation->setSize(size);
+	blurYOperation->setAxis(KeyingBlurOperation::BLUR_AXIS_Y);
 
-	graph->addOperation(blurOperation);
+	addLink(graph, postBlurInput, blurXOperation->getInputSocket(0));
+	addLink(graph, blurXOperation->getOutputSocket(), blurYOperation->getInputSocket(0));
 
-	return blurOperation->getOutputSocket();
+	graph->addOperation(blurXOperation);
+	graph->addOperation(blurYOperation);
+
+	return blurYOperation->getOutputSocket();
 }
 
 OutputSocket *KeyingNode::setupDilateErode(ExecutionSystem *graph, OutputSocket *dilateErodeInput, int distance)

Modified: trunk/blender/source/blender/compositor/nodes/COM_KeyingNode.h
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_KeyingNode.h	2012-06-25 07:41:01 UTC (rev 48255)
+++ trunk/blender/source/blender/compositor/nodes/COM_KeyingNode.h	2012-06-25 08:21:55 UTC (rev 48256)
@@ -30,7 +30,7 @@
 class KeyingNode : public Node {
 protected:
 	OutputSocket *setupPreBlur(ExecutionSystem *graph, InputSocket *inputImage, int size, OutputSocket **originalImage);
-	OutputSocket *setupPostBlur(ExecutionSystem *graph, OutputSocket *postBLurInput, int size);
+	OutputSocket *setupPostBlur(ExecutionSystem *graph, OutputSocket *postBlurInput, int size);
 	OutputSocket *setupDilateErode(ExecutionSystem *graph, OutputSocket *dilateErodeInput, int distance);
 	OutputSocket *setupDespill(ExecutionSystem *graph, OutputSocket *despillInput, OutputSocket *inputSrceen, float factor);
 	OutputSocket *setupClip(ExecutionSystem *graph, OutputSocket *clipInput, int kernelRadius, float kernelTolerance,

Modified: trunk/blender/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp	2012-06-25 07:41:01 UTC (rev 48255)
+++ trunk/blender/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp	2012-06-25 08:21:55 UTC (rev 48256)
@@ -33,7 +33,8 @@
 	this->addInputSocket(COM_DT_VALUE);
 	this->addOutputSocket(COM_DT_VALUE);
 
-	this->size = 0.0f;
+	this->size = 0;
+	this->axis = 0;
 
 	this->setComplex(true);
 }
@@ -53,23 +54,35 @@
 	int bufferWidth = inputBuffer->getWidth();
 	int bufferHeight = inputBuffer->getHeight();
 
-	int i, j, count = 0;
+	int i, count = 0;
 
 	float average = 0.0f;
 
-	for (i = -this->size + 1; i < this->size; i++) {
-		for (j = -this->size + 1; j < this->size; j++) {
-			int cx = x + j, cy = y + i;
+	if (this->axis == 0) {
+		for (i = -this->size + 1; i < this->size; i++) {
+			int cx = x + i;
 
-			if (cx >= 0 && cx < bufferWidth && cy >= 0 && cy < bufferHeight) {
-				int bufferIndex = (cy * bufferWidth + cx) * 4;
+			if (cx >= 0 && cx < bufferWidth) {
+				int bufferIndex = (y * bufferWidth + cx) * 4;
 
 				average += buffer[bufferIndex];
 				count++;
 			}
 		}
 	}
+	else {
+		for (i = -this->size + 1; i < this->size; i++) {
+			int cy = y + i;
 
+			if (cy >= 0 && cy < bufferHeight) {
+				int bufferIndex = (cy * bufferWidth + x) * 4;
+
+				average += buffer[bufferIndex];
+				count++;
+			}
+		}
+	}
+
 	average /= (float) count;
 
 	color[0] = average;
@@ -79,10 +92,18 @@
 {
 	rcti newInput;
 
-	newInput.xmin = input->xmin - this->size;
-	newInput.ymin = input->ymin - this->size;
-	newInput.xmax = input->xmax + this->size;
-	newInput.ymax = input->ymax + this->size;
+	if (this->axis == 0) {
+		newInput.xmin = input->xmin - this->size;
+		newInput.ymin = input->ymin;
+		newInput.xmax = input->xmax + this->size;
+		newInput.ymax = input->ymax;
+	}
+	else {
+		newInput.xmin = input->xmin;
+		newInput.ymin = input->ymin - this->size;
+		newInput.xmax = input->xmax;
+		newInput.ymax = input->ymax + this->size;
+	}
 
 	return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
 }

Modified: trunk/blender/source/blender/compositor/operations/COM_KeyingBlurOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_KeyingBlurOperation.h	2012-06-25 07:41:01 UTC (rev 48255)
+++ trunk/blender/source/blender/compositor/operations/COM_KeyingBlurOperation.h	2012-06-25 08:21:55 UTC (rev 48256)
@@ -32,11 +32,18 @@
 class KeyingBlurOperation : public NodeOperation {
 protected:
 	int size;
+	int axis;
 
 public:
+	enum BlurAxis {
+		BLUR_AXIS_X = 0,
+		BLUR_AXIS_Y = 1
+	};
+
 	KeyingBlurOperation();
 
-	void setSize(float value) {this->size = value;}
+	void setSize(int value) {this->size = value;}
+	void setAxis(int value) {this->axis = value;}
 
 	void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
 




More information about the Bf-blender-cvs mailing list