[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43800] branches/tile/source/blender/ compositor: Normalize Node - Tile

Dalai Felinto dfelinto at gmail.com
Tue Jan 31 20:57:06 CET 2012


Revision: 43800
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43800
Author:   dfelinto
Date:     2012-01-31 19:57:01 +0000 (Tue, 31 Jan 2012)
Log Message:
-----------
Normalize Node - Tile
The implementation is simple. Fancy alternatives to gather the minimum and
maximum through recursive loop in the tiles proved inefficient (Jeroen Bakker's
 tests)

I'm also using the generic NodeTwoFloats to store the temporary values calculated in the loop.
And different from Blender trunk I'm not checking to see if the value is between the accepted Z range
(e.g. (*val <= BLENDER_ZMAX)). I can't see why that would be necessary. To avoid overflow? If so this be handled (aka clamped) outside the nodes in a generic way.

Credits to Jeroen Bakker for the solution in using mutex (copy pasted from his ToneMap code) and review

Modified Paths:
--------------
    branches/tile/source/blender/compositor/CMakeLists.txt
    branches/tile/source/blender/compositor/intern/COM_Converter.cpp
    branches/tile/source/blender/compositor/operations/COM_TonemapOperation.cpp

Added Paths:
-----------
    branches/tile/source/blender/compositor/nodes/COM_NormalizeNode.cpp
    branches/tile/source/blender/compositor/nodes/COM_NormalizeNode.h
    branches/tile/source/blender/compositor/operations/COM_NormalizeOperation.cpp
    branches/tile/source/blender/compositor/operations/COM_NormalizeOperation.h

Modified: branches/tile/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-31 19:17:14 UTC (rev 43799)
+++ branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-31 19:57:01 UTC (rev 43800)
@@ -239,11 +239,16 @@
 		nodes/COM_CombineYCCANode.cpp
 		nodes/COM_CombineYCCANode.h
 
-		nodes/COM_NormalNode.cpp
-		nodes/COM_NormalNode.h
+	nodes/COM_NormalNode.cpp
+	nodes/COM_NormalNode.h
+	nodes/COM_NormalizeNode.cpp
+	nodes/COM_NormalizeNode.h
 	nodes/COM_MathNode.cpp
 	nodes/COM_MathNode.h
 
+	operations/COM_NormalizeOperation.cpp
+	operations/COM_NormalizeOperation.h
+
 # Filter nodes
 		nodes/COM_FilterNode.cpp
 		nodes/COM_FilterNode.h

Modified: branches/tile/source/blender/compositor/intern/COM_Converter.cpp
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-31 19:17:14 UTC (rev 43799)
+++ branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-31 19:57:01 UTC (rev 43800)
@@ -58,6 +58,7 @@
 #include "COM_InvertNode.h"
 #include "COM_GroupNode.h"
 #include "COM_NormalNode.h"
+#include "COM_NormalizeNode.h"
 #include "COM_ImageNode.h"
 #include "COM_BokehImageNode.h"
 #include "COM_ColorCurveNode.h"
@@ -190,6 +191,9 @@
 	case CMP_NODE_NORMAL:
 		node = new NormalNode(bNode);
 		break;
+	case CMP_NODE_NORMALIZE:
+		node = new NormalizeNode(bNode);
+		break;
 	case CMP_NODE_IMAGE:
 		node = new ImageNode(bNode);
 		break;
@@ -304,7 +308,6 @@
 	case CMP_NODE_CHANNEL_MATTE:
 //	case CMP_NODE_DOUBLEEDGEMASK: // to be re-enabled with next merge from trunk
 	case CMP_NODE_DEFOCUS:
-	case CMP_NODE_NORMALIZE:
 	case CMP_NODE_CROP:
 	case CMP_NODE_BILATERALBLUR:
 	case CMP_NODE_PREMULKEY:

Added: branches/tile/source/blender/compositor/nodes/COM_NormalizeNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_NormalizeNode.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_NormalizeNode.cpp	2012-01-31 19:57:01 UTC (rev 43800)
@@ -0,0 +1,36 @@
+/*
+ * 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:
+ *		Dalai Felinto
+ */
+
+#include "COM_NormalizeNode.h"
+#include "COM_NormalizeOperation.h"
+#include "COM_ExecutionSystem.h"
+
+NormalizeNode::NormalizeNode(bNode *editorNode): Node(editorNode) {
+}
+
+void NormalizeNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context) {
+	NormalizeOperation *operation = new NormalizeOperation();
+
+	this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), true, 0, graph);
+	this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0));
+
+	graph->addOperation(operation);
+}


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

Added: branches/tile/source/blender/compositor/nodes/COM_NormalizeNode.h
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_NormalizeNode.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_NormalizeNode.h	2012-01-31 19:57:01 UTC (rev 43800)
@@ -0,0 +1,37 @@
+/*
+ * 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:
+ *		Dalai Felinto
+ */
+
+#ifndef _COM_NormalizeNode_h_
+#define _COM_NormalizeNode_h_
+
+#include "COM_Node.h"
+
+/**
+  * @brief NormalizeNode
+  * @ingroup Node
+  */
+class NormalizeNode: public Node {
+public:
+    NormalizeNode(bNode *editorNode);
+    void convertToOperations(ExecutionSystem* graph, CompositorContext * context);
+};
+
+#endif


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

Added: branches/tile/source/blender/compositor/operations/COM_NormalizeOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_NormalizeOperation.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_NormalizeOperation.cpp	2012-01-31 19:57:01 UTC (rev 43800)
@@ -0,0 +1,108 @@
+/*
+ * 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:
+ *		Dalai Felinto
+ */
+
+#include "COM_NormalizeOperation.h"
+
+NormalizeOperation::NormalizeOperation(): NodeOperation() {
+	this->addInputSocket(COM_DT_VALUE);
+	this->addOutputSocket(COM_DT_VALUE);
+	this->imageReader = NULL;
+	this->cachedInstance = NULL;
+	this->setComplex(true);
+}
+void NormalizeOperation::initExecution() {
+	this->imageReader = this->getInputSocketReader(0);
+	NodeOperation::initMutex();
+}
+
+void NormalizeOperation::executePixel(float* color, int x, int y, MemoryBuffer *inputBuffers[], void * data) {
+	/* using generic two floats struct to store x: min  y: mult */
+	NodeTwoFloats *minmult = (NodeTwoFloats *)data;
+
+	float output[4];
+	this->imageReader->read(output, x, y, inputBuffers, NULL);
+
+	color[0] = (output[0] - minmult->x) * minmult->y;
+}
+
+void NormalizeOperation::deinitExecution() {
+	this->imageReader = NULL;
+	if (this->cachedInstance) {
+		delete cachedInstance;
+	}
+	NodeOperation::deinitMutex();
+}
+
+bool NormalizeOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) {
+	rcti imageInput;
+
+	NodeOperation* operation = getInputOperation(0);
+	imageInput.xmax = operation->getWidth();
+	imageInput.xmin = 0;
+	imageInput.ymax = operation->getHeight();
+	imageInput.ymin = 0;
+
+	if (operation->determineDependingAreaOfInterest(&imageInput, readOperation, output) ) {
+		return true;
+	}
+	return false;
+}
+
+/* The code below assumes all data is inside range +- this, and that input buffer is single channel */
+#define BLENDER_ZMAX 10000.0f
+
+void* NormalizeOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) {
+
+	BLI_mutex_lock(getMutex());
+
+	if (this->cachedInstance == NULL) {
+		MemoryBuffer* tile = (MemoryBuffer*)imageReader->initializeTileData(rect, memoryBuffers);
+		/* using generic two floats struct to store x: min  y: mult */
+		NodeTwoFloats *minmult = new NodeTwoFloats();
+
+		float *buffer = tile->getBuffer();
+		int p = tile->getWidth() * tile->getHeight();
+		float *bc = buffer;
+
+		float minv = 1.0f+BLENDER_ZMAX;
+		float maxv = -1.0f-BLENDER_ZMAX;
+
+		float value;
+		while (p--) {
+			value=bc[0];
+			maxv = max(value, maxv);
+			minv = min(value, minv);
+			bc+=4;
+		}
+
+		minmult->x = minv;
+		/* The rare case of flat buffer  would cause a divide by 0 */
+		minmult->y = ((maxv!=minv)? 1.0f/(maxv-minv):0.f);
+
+		this->cachedInstance = minmult;
+	}
+
+	BLI_mutex_unlock(getMutex());
+	return this->cachedInstance;
+}
+
+void NormalizeOperation::deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data) {
+}


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

Added: branches/tile/source/blender/compositor/operations/COM_NormalizeOperation.h
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_NormalizeOperation.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_NormalizeOperation.h	2012-01-31 19:57:01 UTC (rev 43800)
@@ -0,0 +1,69 @@
+/*
+ * 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

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list