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.
This commit is contained in:
Dalai Felinto
2012-08-19 03:05:38 +00:00
parent e4a6602a9a
commit 48eb27791b
6 changed files with 134 additions and 24 deletions

View File

@@ -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

View File

@@ -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());

View File

@@ -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];
}
}

View File

@@ -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

View File

@@ -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));
}

View File

@@ -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