Fixed area of interest for black/white clipping, so now there should be no
artifacts in the boundaries of tiles. Also added test blur operation which could potentially give better results than gaussian blur for keying. Not user yet, to enable uncomment like with USE_GAUSSIAN_BLUR in file COM_KeyingNode.cpp.
This commit is contained in:
@@ -328,6 +328,8 @@ set(SRC
|
||||
nodes/COM_KeyingScreenNode.h
|
||||
operations/COM_KeyingOperation.cpp
|
||||
operations/COM_KeyingOperation.h
|
||||
operations/COM_KeyingBlurOperation.cpp
|
||||
operations/COM_KeyingBlurOperation.h
|
||||
operations/COM_KeyingScreenOperation.cpp
|
||||
operations/COM_KeyingScreenOperation.h
|
||||
operations/COM_KeyingDespillOperation.cpp
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "COM_ExecutionSystem.h"
|
||||
|
||||
#include "COM_KeyingOperation.h"
|
||||
#include "COM_KeyingBlurOperation.h"
|
||||
#include "COM_KeyingDespillOperation.h"
|
||||
#include "COM_KeyingClipOperation.h"
|
||||
|
||||
@@ -40,6 +41,8 @@
|
||||
|
||||
#include "COM_SetAlphaOperation.h"
|
||||
|
||||
// #define USE_GAUSSIAN_BLUR
|
||||
|
||||
KeyingNode::KeyingNode(bNode *editorNode): Node(editorNode)
|
||||
{
|
||||
}
|
||||
@@ -69,6 +72,7 @@ OutputSocket *KeyingNode::setupPreBlur(ExecutionSystem *graph, InputSocket *inpu
|
||||
addLink(graph, separateOperation->getOutputSocket(0), combineOperation->getInputSocket(channel));
|
||||
}
|
||||
else {
|
||||
#ifdef USE_GAUSSIAN_BLUR
|
||||
SetValueOperation *setValueOperation = new SetValueOperation();
|
||||
setValueOperation->setValue(1.0f);
|
||||
graph->addOperation(setValueOperation);
|
||||
@@ -81,6 +85,15 @@ OutputSocket *KeyingNode::setupPreBlur(ExecutionSystem *graph, InputSocket *inpu
|
||||
addLink(graph, setValueOperation->getOutputSocket(0), blurOperation->getInputSocket(1));
|
||||
addLink(graph, blurOperation->getOutputSocket(0), combineOperation->getInputSocket(channel));
|
||||
graph->addOperation(blurOperation);
|
||||
#else
|
||||
KeyingBlurOperation *blurOperation = new KeyingBlurOperation();
|
||||
|
||||
blurOperation->setSize(size);
|
||||
|
||||
addLink(graph, separateOperation->getOutputSocket(0), blurOperation->getInputSocket(0));
|
||||
addLink(graph, blurOperation->getOutputSocket(0), combineOperation->getInputSocket(channel));
|
||||
graph->addOperation(blurOperation);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +109,7 @@ OutputSocket *KeyingNode::setupPreBlur(ExecutionSystem *graph, InputSocket *inpu
|
||||
|
||||
OutputSocket *KeyingNode::setupPostBlur(ExecutionSystem *graph, OutputSocket *postBLurInput, int size)
|
||||
{
|
||||
#ifdef USE_GAUSSIAN_BLUR
|
||||
memset(&postBlurData, 0, sizeof(postBlurData));
|
||||
|
||||
postBlurData.sizex = size;
|
||||
@@ -116,6 +130,17 @@ OutputSocket *KeyingNode::setupPostBlur(ExecutionSystem *graph, OutputSocket *po
|
||||
graph->addOperation(blurOperation);
|
||||
|
||||
return blurOperation->getOutputSocket();
|
||||
#else
|
||||
KeyingBlurOperation *blurOperation = new KeyingBlurOperation();
|
||||
|
||||
blurOperation->setSize(size);
|
||||
|
||||
addLink(graph, postBLurInput, blurOperation->getInputSocket(0));
|
||||
|
||||
graph->addOperation(blurOperation);
|
||||
|
||||
return blurOperation->getOutputSocket();
|
||||
#endif
|
||||
}
|
||||
|
||||
OutputSocket *KeyingNode::setupDilateErode(ExecutionSystem *graph, OutputSocket *dilateErodeInput, int distance)
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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:
|
||||
* Jeroen Bakker
|
||||
* Monique Dewanchand
|
||||
* Sergey Sharybin
|
||||
*/
|
||||
|
||||
#include "COM_KeyingBlurOperation.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math.h"
|
||||
|
||||
KeyingBlurOperation::KeyingBlurOperation(): NodeOperation()
|
||||
{
|
||||
this->addInputSocket(COM_DT_VALUE);
|
||||
this->addOutputSocket(COM_DT_VALUE);
|
||||
|
||||
this->size = 0.0f;
|
||||
|
||||
this->setComplex(true);
|
||||
}
|
||||
|
||||
void *KeyingBlurOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
|
||||
{
|
||||
void *buffer = getInputOperation(0)->initializeTileData(rect, memoryBuffers);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void KeyingBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
|
||||
{
|
||||
MemoryBuffer *inputBuffer = (MemoryBuffer*)data;
|
||||
float *buffer = inputBuffer->getBuffer();
|
||||
|
||||
int bufferWidth = inputBuffer->getWidth();
|
||||
int bufferHeight = inputBuffer->getHeight();
|
||||
|
||||
int i, j, 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 (cx >= 0 && cx < bufferWidth && cy >= 0 && cy < bufferHeight) {
|
||||
int bufferIndex = (cy * bufferWidth + cx) * 4;
|
||||
|
||||
average += buffer[bufferIndex];
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
average /= (float) count;
|
||||
|
||||
color[0] = average;
|
||||
}
|
||||
|
||||
bool KeyingBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
||||
{
|
||||
rcti newInput;
|
||||
|
||||
newInput.xmin = 0;
|
||||
newInput.ymin = 0;
|
||||
newInput.xmax = this->getWidth();
|
||||
newInput.ymax = this->getHeight();
|
||||
|
||||
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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:
|
||||
* Jeroen Bakker
|
||||
* Monique Dewanchand
|
||||
* Sergey Sharybin
|
||||
*/
|
||||
|
||||
#ifndef _COM_KeyingBlurOperation_h
|
||||
#define _COM_KeyingBlurOperation_h
|
||||
|
||||
#include "COM_NodeOperation.h"
|
||||
|
||||
/**
|
||||
* Class with implementation of bluring for keying node
|
||||
*/
|
||||
class KeyingBlurOperation : public NodeOperation {
|
||||
protected:
|
||||
int size;
|
||||
|
||||
public:
|
||||
KeyingBlurOperation();
|
||||
|
||||
void setSize(float value) {this->size = value;}
|
||||
|
||||
void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
|
||||
|
||||
void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data);
|
||||
|
||||
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -90,3 +90,15 @@ void KeyingClipOperation::executePixel(float *color, int x, int y, MemoryBuffer
|
||||
color[0] = (color[0] - this->clipBlack) / (this->clipWhite - this->clipBlack);
|
||||
}
|
||||
}
|
||||
|
||||
bool KeyingClipOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
||||
{
|
||||
rcti newInput;
|
||||
|
||||
newInput.xmin = 0;
|
||||
newInput.ymin = 0;
|
||||
newInput.xmax = this->getWidth();
|
||||
newInput.ymax = this->getHeight();
|
||||
|
||||
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
|
||||
|
||||
void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data);
|
||||
|
||||
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -101,3 +101,15 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler
|
||||
color[0] = distance;
|
||||
}
|
||||
}
|
||||
|
||||
bool KeyingOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
||||
{
|
||||
rcti newInput;
|
||||
|
||||
newInput.xmin = 0;
|
||||
newInput.ymin = 0;
|
||||
newInput.xmax = this->getWidth();
|
||||
newInput.ymax = this->getHeight();
|
||||
|
||||
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
void setScreenBalance(float value) {this->screenBalance = value;}
|
||||
|
||||
void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]);
|
||||
|
||||
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user