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-08-19 07:05:38 +0400
committerDalai Felinto <dfelinto@gmail.com>2012-08-19 07:05:38 +0400
commit48eb27791bcd0b28b3fad384552009fa4b712d00 (patch)
treecf5cd3bd86ec2c28a20c357ebb3176ad273a6675 /source/blender/compositor
parente4a6602a9ac9c7d43a882770f19323b6d5616a4b (diff)
The Distance Node in 2.49/2.5/2.6 pre-tiles has a different calculation for RGB and YCC. While RGB
calculate the distance in 3d between R,G and B, the YCC only takes Cb and Cr into consideration. This commit makes COM_DistanceMatteOperation inheritable and expose the calculate distance function to be re-implemented for the YCC node operation. Thanks Troy Sobotka for the report over email. Patch incorporates review suggestions by Jeroen Bakker.
Diffstat (limited to 'source/blender/compositor')
-rw-r--r--source/blender/compositor/CMakeLists.txt6
-rw-r--r--source/blender/compositor/nodes/COM_DistanceMatteNode.cpp33
-rw-r--r--source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp (renamed from source/blender/compositor/operations/COM_DistanceMatteOperation.cpp)28
-rw-r--r--source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h (renamed from source/blender/compositor/operations/COM_DistanceMatteOperation.h)13
-rw-r--r--source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cpp35
-rw-r--r--source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h43
6 files changed, 134 insertions, 24 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index 65d46bf515a..c110d4f077e 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -473,8 +473,10 @@ set(SRC
operations/COM_DifferenceMatteOperation.h
operations/COM_LuminanceMatteOperation.cpp
operations/COM_LuminanceMatteOperation.h
- operations/COM_DistanceMatteOperation.cpp
- operations/COM_DistanceMatteOperation.h
+ operations/COM_DistanceRGBMatteOperation.cpp
+ operations/COM_DistanceRGBMatteOperation.h
+ operations/COM_DistanceYCCMatteOperation.cpp
+ operations/COM_DistanceYCCMatteOperation.h
operations/COM_ChromaMatteOperation.cpp
operations/COM_ChromaMatteOperation.h
operations/COM_ColorMatteOperation.cpp
diff --git a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp
index d6730ef6a00..87e7b9d0788 100644
--- a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp
+++ b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp
@@ -21,8 +21,10 @@
#include "COM_DistanceMatteNode.h"
#include "BKE_node.h"
-#include "COM_DistanceMatteOperation.h"
+#include "COM_DistanceRGBMatteOperation.h"
+#include "COM_DistanceYCCMatteOperation.h"
#include "COM_SetAlphaOperation.h"
+#include "COM_ConvertRGBToYCCOperation.h"
DistanceMatteNode::DistanceMatteNode(bNode *editorNode) : Node(editorNode)
{
@@ -36,12 +38,33 @@ void DistanceMatteNode::convertToOperations(ExecutionSystem *graph, CompositorCo
OutputSocket *outputSocketImage = this->getOutputSocket(0);
OutputSocket *outputSocketMatte = this->getOutputSocket(1);
- DistanceMatteOperation *operation = new DistanceMatteOperation();
+ NodeOperation *operation;
bNode *editorsnode = getbNode();
- operation->setSettings((NodeChroma *)editorsnode->storage);
+ NodeChroma *storage = (NodeChroma *)editorsnode->storage;
- inputSocketImage->relinkConnections(operation->getInputSocket(0), 0, graph);
- inputSocketKey->relinkConnections(operation->getInputSocket(1), 1, graph);
+ /* work in RGB color space */
+ if (storage->channel == 1) {
+ operation = new DistanceRGBMatteOperation();
+ ((DistanceRGBMatteOperation *) operation)->setSettings(storage);
+
+ inputSocketImage->relinkConnections(operation->getInputSocket(0), 0, graph);
+ inputSocketKey->relinkConnections(operation->getInputSocket(1), 1, graph);
+ }
+ /* work in YCbCr color space */
+ else {
+ operation = new DistanceYCCMatteOperation();
+ ((DistanceYCCMatteOperation *) operation)->setSettings(storage);
+
+ ConvertRGBToYCCOperation *operationYCCImage = new ConvertRGBToYCCOperation();
+ inputSocketImage->relinkConnections(operationYCCImage->getInputSocket(0), 0, graph);
+ addLink(graph, operationYCCImage->getOutputSocket(), operation->getInputSocket(0));
+ graph->addOperation(operationYCCImage);
+
+ ConvertRGBToYCCOperation *operationYCCMatte = new ConvertRGBToYCCOperation();
+ inputSocketKey->relinkConnections(operationYCCMatte->getInputSocket(0), 1, graph);
+ addLink(graph, operationYCCMatte->getOutputSocket(), operation->getInputSocket(1));
+ graph->addOperation(operationYCCMatte);
+ }
if (outputSocketMatte->isConnected()) {
outputSocketMatte->relinkConnections(operation->getOutputSocket());
diff --git a/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp
index b65b5e0f224..df3809ba129 100644
--- a/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp
+++ b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp
@@ -19,32 +19,39 @@
* Dalai Felinto
*/
-#include "COM_DistanceMatteOperation.h"
+#include "COM_DistanceRGBMatteOperation.h"
#include "BLI_math.h"
-DistanceMatteOperation::DistanceMatteOperation() : NodeOperation()
+DistanceRGBMatteOperation::DistanceRGBMatteOperation() : NodeOperation()
{
- addInputSocket(COM_DT_COLOR);
- addInputSocket(COM_DT_COLOR);
- addOutputSocket(COM_DT_VALUE);
+ this->addInputSocket(COM_DT_COLOR);
+ this->addInputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VALUE);
this->m_inputImageProgram = NULL;
this->m_inputKeyProgram = NULL;
}
-void DistanceMatteOperation::initExecution()
+void DistanceRGBMatteOperation::initExecution()
{
this->m_inputImageProgram = this->getInputSocketReader(0);
this->m_inputKeyProgram = this->getInputSocketReader(1);
}
-void DistanceMatteOperation::deinitExecution()
+void DistanceRGBMatteOperation::deinitExecution()
{
this->m_inputImageProgram = NULL;
this->m_inputKeyProgram = NULL;
}
-void DistanceMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
+float DistanceRGBMatteOperation::calculateDistance(float key[4], float image[4])
+{
+ return sqrt(pow((key[0] - image[0]), 2) +
+ pow((key[1] - image[1]), 2) +
+ pow((key[2] - image[2]), 2));
+}
+
+void DistanceRGBMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
{
float inKey[4];
float inImage[4];
@@ -58,9 +65,7 @@ void DistanceMatteOperation::executePixel(float output[4], float x, float y, Pix
this->m_inputKeyProgram->read(inKey, x, y, sampler);
this->m_inputImageProgram->read(inImage, x, y, sampler);
- distance = sqrt(pow((inKey[0] - inImage[0]), 2) +
- pow((inKey[1] - inImage[1]), 2) +
- pow((inKey[2] - inImage[2]), 2));
+ distance = this->calculateDistance(inKey, inImage);
/* store matte(alpha) value in [0] to go with
* COM_SetAlphaOperation and the Value output
@@ -87,4 +92,3 @@ void DistanceMatteOperation::executePixel(float output[4], float x, float y, Pix
output[0] = inImage[3];
}
}
-
diff --git a/source/blender/compositor/operations/COM_DistanceMatteOperation.h b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h
index a176e5da888..5a34135b1a4 100644
--- a/source/blender/compositor/operations/COM_DistanceMatteOperation.h
+++ b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h
@@ -19,8 +19,8 @@
* Dalai Felinto
*/
-#ifndef _COM_DistanceMatteOperation_h
-#define _COM_DistanceMatteOperation_h
+#ifndef _COM_DistanceRGBMatteOperation_h
+#define _COM_DistanceRGBMatteOperation_h
#include "COM_MixBaseOperation.h"
@@ -28,16 +28,19 @@
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class DistanceMatteOperation : public NodeOperation {
-private:
+class DistanceRGBMatteOperation : public NodeOperation {
+protected:
NodeChroma *m_settings;
SocketReader *m_inputImageProgram;
SocketReader *m_inputKeyProgram;
+
+ virtual float calculateDistance(float key[4], float image[4]);
+
public:
/**
* Default constructor
*/
- DistanceMatteOperation();
+ DistanceRGBMatteOperation();
/**
* the inner loop of this program
diff --git a/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cpp b/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cpp
new file mode 100644
index 00000000000..32ed7486f5b
--- /dev/null
+++ b/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cpp
@@ -0,0 +1,35 @@
+/*
+ * 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:
+ * Dalai Felinto
+ */
+
+#include "COM_DistanceYCCMatteOperation.h"
+#include "BLI_math.h"
+
+DistanceYCCMatteOperation::DistanceYCCMatteOperation() : DistanceRGBMatteOperation()
+{
+ /* pass */
+}
+
+float DistanceYCCMatteOperation::calculateDistance(float key[4], float image[4])
+{
+ return sqrt(pow((key[1] - image[1]), 2) +
+ pow((key[2] - image[2]), 2));
+}
+
diff --git a/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h b/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h
new file mode 100644
index 00000000000..f4866a327f1
--- /dev/null
+++ b/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h
@@ -0,0 +1,43 @@
+/*
+ * 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:
+ * Dalai Felinto
+ */
+
+#ifndef _COM_DistanceYCCMatteOperation_h
+#define _COM_DistanceYCCMatteOperation_h
+#include "COM_MixBaseOperation.h"
+#include "COM_DistanceRGBMatteOperation.h"
+
+
+/**
+ * this program converts an input color to an output value.
+ * it assumes we are in sRGB color space.
+ */
+class DistanceYCCMatteOperation : public DistanceRGBMatteOperation {
+protected:
+ virtual float calculateDistance(float key[4], float image[4]);
+
+public:
+ /**
+ * Default constructor
+ */
+ DistanceYCCMatteOperation();
+
+};
+#endif