Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2012-11-14 23:53:46 +0400
committerDalai Felinto <dfelinto@gmail.com>2012-11-14 23:53:46 +0400
commit7cfb79256e5cd21405528887b8d3b6b405ebba62 (patch)
treed9673a353431d25a27251233c32cd406f4ce81a5 /source/blender/compositor
parent71389d4d74fd1e632ff0e23416d33ca5e63c609d (diff)
Map Range Node (tiles)
this node allows for more control for normalization of the mapped input range. Made during BlenderPRO 2012 - Brasilia, Brazil :) Idea and testing: Daniel Salazar Implementation: yours truly Reviewed by Lukas Toenne and Sergey Sharybin
Diffstat (limited to 'source/blender/compositor')
-rw-r--r--source/blender/compositor/CMakeLists.txt4
-rw-r--r--source/blender/compositor/intern/COM_Converter.cpp4
-rw-r--r--source/blender/compositor/nodes/COM_MapRangeNode.cpp54
-rw-r--r--source/blender/compositor/nodes/COM_MapRangeNode.h38
-rw-r--r--source/blender/compositor/operations/COM_MapRangeOperation.cpp81
-rw-r--r--source/blender/compositor/operations/COM_MapRangeOperation.h71
6 files changed, 252 insertions, 0 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index b3e76a287ea..8259cb6f297 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -267,6 +267,8 @@ set(SRC
nodes/COM_MathNode.h
nodes/COM_MapValueNode.cpp
nodes/COM_MapValueNode.h
+ nodes/COM_MapRangeNode.cpp
+ nodes/COM_MapRangeNode.h
operations/COM_NormalizeOperation.cpp
operations/COM_NormalizeOperation.h
@@ -572,6 +574,8 @@ set(SRC
operations/COM_SetAlphaOperation.h
operations/COM_MapValueOperation.cpp
operations/COM_MapValueOperation.h
+ operations/COM_MapRangeOperation.cpp
+ operations/COM_MapRangeOperation.h
# Distort operation
operations/COM_TranslateOperation.h
diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp
index 2b09c9d5b8c..9c4a32f20c9 100644
--- a/source/blender/compositor/intern/COM_Converter.cpp
+++ b/source/blender/compositor/intern/COM_Converter.cpp
@@ -83,6 +83,7 @@
#include "COM_LuminanceMatteNode.h"
#include "COM_MapUVNode.h"
#include "COM_MapValueNode.h"
+#include "COM_MapRangeNode.h"
#include "COM_MaskNode.h"
#include "COM_MathNode.h"
#include "COM_MixNode.h"
@@ -351,6 +352,9 @@ Node *Converter::convert(bNode *b_node, bool fast)
case CMP_NODE_MAP_VALUE:
node = new MapValueNode(b_node);
break;
+ case CMP_NODE_MAP_RANGE:
+ node = new MapRangeNode(b_node);
+ break;
case CMP_NODE_TRANSFORM:
node = new TransformNode(b_node);
break;
diff --git a/source/blender/compositor/nodes/COM_MapRangeNode.cpp b/source/blender/compositor/nodes/COM_MapRangeNode.cpp
new file mode 100644
index 00000000000..232be3d41b0
--- /dev/null
+++ b/source/blender/compositor/nodes/COM_MapRangeNode.cpp
@@ -0,0 +1,54 @@
+/*
+ * 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
+ * Daniel Salazar
+ */
+
+#include "COM_MapRangeNode.h"
+
+#include "COM_MapRangeOperation.h"
+#include "COM_ExecutionSystem.h"
+
+MapRangeNode::MapRangeNode(bNode *editorNode) : Node(editorNode)
+{
+ /* pass */
+}
+
+void MapRangeNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
+{
+ InputSocket *valueSocket = this->getInputSocket(0);
+ InputSocket *sourceMinSocket = this->getInputSocket(1);
+ InputSocket *sourceMaxSocket = this->getInputSocket(2);
+ InputSocket *destMinSocket = this->getInputSocket(3);
+ InputSocket *destMaxSocket = this->getInputSocket(4);
+ OutputSocket *outputSocket = this->getOutputSocket(0);
+
+ MapRangeOperation *operation = new MapRangeOperation();
+
+ valueSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
+ sourceMinSocket->relinkConnections(operation->getInputSocket(1), 1, graph);
+ sourceMaxSocket->relinkConnections(operation->getInputSocket(2), 2, graph);
+ destMinSocket->relinkConnections(operation->getInputSocket(3), 3, graph);
+ destMaxSocket->relinkConnections(operation->getInputSocket(4), 4, graph);
+ outputSocket->relinkConnections(operation->getOutputSocket(0));
+
+ operation->setUseClamp(this->getbNode()->custom1);
+
+ graph->addOperation(operation);
+}
diff --git a/source/blender/compositor/nodes/COM_MapRangeNode.h b/source/blender/compositor/nodes/COM_MapRangeNode.h
new file mode 100644
index 00000000000..6667720be3d
--- /dev/null
+++ b/source/blender/compositor/nodes/COM_MapRangeNode.h
@@ -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:
+ * Dalai Felinto
+ * Daniel Salazar
+ */
+
+#ifndef __COM_MAPRANGENODE_H__
+#define __COM_MAPRANGENODE_H__
+
+#include "COM_Node.h"
+#include "DNA_node_types.h"
+/**
+ * @brief MapRangeNode
+ * @ingroup Node
+ */
+class MapRangeNode : public Node {
+public:
+ MapRangeNode(bNode *editorNode);
+ void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
+};
+
+#endif /* __COM_MAPRANGENODE_H__ */
diff --git a/source/blender/compositor/operations/COM_MapRangeOperation.cpp b/source/blender/compositor/operations/COM_MapRangeOperation.cpp
new file mode 100644
index 00000000000..3facaaebc9c
--- /dev/null
+++ b/source/blender/compositor/operations/COM_MapRangeOperation.cpp
@@ -0,0 +1,81 @@
+/*
+ * 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
+ * Daniel Salazar
+ */
+
+#include "COM_MapRangeOperation.h"
+
+MapRangeOperation::MapRangeOperation() : NodeOperation()
+{
+ this->addInputSocket(COM_DT_VALUE);
+ this->addInputSocket(COM_DT_VALUE);
+ this->addInputSocket(COM_DT_VALUE);
+ this->addInputSocket(COM_DT_VALUE);
+ this->addInputSocket(COM_DT_VALUE);
+ this->addOutputSocket(COM_DT_VALUE);
+ this->m_inputOperation = NULL;
+ this->m_useClamp = FALSE;
+}
+
+void MapRangeOperation::initExecution()
+{
+ this->m_inputOperation = this->getInputSocketReader(0);
+ this->m_sourceMinOperation = this->getInputSocketReader(1);
+ this->m_sourceMaxOperation = this->getInputSocketReader(2);
+ this->m_destMinOperation = this->getInputSocketReader(3);
+ this->m_destMaxOperation = this->getInputSocketReader(4);
+}
+
+void MapRangeOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
+{
+ float inputs[8]; /* includes the 5 inputs + 3 pads */
+ float value;
+ float source_min, source_max;
+ float dest_min, dest_max;
+
+ this->m_inputOperation->read(inputs, x, y, sampler);
+ this->m_sourceMinOperation->read(inputs+1, x, y, sampler);
+ this->m_sourceMaxOperation->read(inputs+2, x, y, sampler);
+ this->m_destMinOperation->read(inputs+3, x, y, sampler);
+ this->m_destMaxOperation->read(inputs+4, x, y, sampler);
+
+ value = inputs[0];
+ source_min = inputs[1];
+ source_max = inputs[2];
+ dest_min = inputs[3];
+ dest_max = inputs[4];
+
+ value = (value - source_min) / (source_max - source_min);
+ value = dest_min + value * (dest_max - dest_min);
+
+ if (this->m_useClamp)
+ CLAMP(value, dest_min, dest_max);
+
+ output[0] = value;
+}
+
+void MapRangeOperation::deinitExecution()
+{
+ this->m_inputOperation = NULL;
+ this->m_sourceMinOperation = NULL;
+ this->m_sourceMaxOperation = NULL;
+ this->m_destMinOperation = NULL;
+ this->m_destMaxOperation = NULL;
+}
diff --git a/source/blender/compositor/operations/COM_MapRangeOperation.h b/source/blender/compositor/operations/COM_MapRangeOperation.h
new file mode 100644
index 00000000000..00dfc68168c
--- /dev/null
+++ b/source/blender/compositor/operations/COM_MapRangeOperation.h
@@ -0,0 +1,71 @@
+/*
+ * 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
+ * Daniel Salazar
+ */
+
+#ifndef _COM_MapRangeOperation_h
+#define _COM_MapRangeOperation_h
+#include "COM_NodeOperation.h"
+#include "DNA_texture_types.h"
+
+/**
+ * this program converts an input color to an output value.
+ * it assumes we are in sRGB color space.
+ */
+class MapRangeOperation : public NodeOperation {
+private:
+ /**
+ * Cached reference to the inputProgram
+ */
+ SocketReader *m_inputOperation;
+ SocketReader *m_sourceMinOperation;
+ SocketReader *m_sourceMaxOperation;
+ SocketReader *m_destMinOperation;
+ SocketReader *m_destMaxOperation;
+
+ bool m_useClamp;
+public:
+ /**
+ * Default constructor
+ */
+ MapRangeOperation();
+
+ /**
+ * the inner loop of this program
+ */
+ void executePixel(float output[4], float x, float y, PixelSampler sampler);
+
+ /**
+ * Initialize the execution
+ */
+ void initExecution();
+
+ /**
+ * Deinitialize the execution
+ */
+ void deinitExecution();
+
+ /**
+ * Clamp the output
+ */
+ void setUseClamp(bool value) { this->m_useClamp = value; }
+
+};
+#endif