2012-06-14 12:19:13 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2012-06-15 09:58:52 +00:00
|
|
|
KeyingBlurOperation::KeyingBlurOperation() : NodeOperation()
|
2012-06-14 12:19:13 +00:00
|
|
|
{
|
|
|
|
this->addInputSocket(COM_DT_VALUE);
|
|
|
|
this->addOutputSocket(COM_DT_VALUE);
|
|
|
|
|
2012-06-25 08:21:55 +00:00
|
|
|
this->size = 0;
|
2012-06-25 17:27:54 +00:00
|
|
|
this->axis = BLUR_AXIS_X;
|
2012-06-14 12:19:13 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-06-15 09:58:52 +00:00
|
|
|
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
|
2012-06-14 12:19:13 +00:00
|
|
|
float *buffer = inputBuffer->getBuffer();
|
|
|
|
|
|
|
|
int bufferWidth = inputBuffer->getWidth();
|
|
|
|
int bufferHeight = inputBuffer->getHeight();
|
|
|
|
|
2012-06-25 08:21:55 +00:00
|
|
|
int i, count = 0;
|
2012-06-14 12:19:13 +00:00
|
|
|
|
|
|
|
float average = 0.0f;
|
|
|
|
|
2012-06-25 08:21:55 +00:00
|
|
|
if (this->axis == 0) {
|
|
|
|
for (i = -this->size + 1; i < this->size; i++) {
|
|
|
|
int cx = x + i;
|
2012-06-14 12:19:13 +00:00
|
|
|
|
2012-06-25 08:21:55 +00:00
|
|
|
if (cx >= 0 && cx < bufferWidth) {
|
|
|
|
int bufferIndex = (y * bufferWidth + cx) * 4;
|
|
|
|
|
|
|
|
average += buffer[bufferIndex];
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = -this->size + 1; i < this->size; i++) {
|
|
|
|
int cy = y + i;
|
|
|
|
|
|
|
|
if (cy >= 0 && cy < bufferHeight) {
|
|
|
|
int bufferIndex = (cy * bufferWidth + x) * 4;
|
2012-06-14 12:19:13 +00:00
|
|
|
|
|
|
|
average += buffer[bufferIndex];
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
average /= (float) count;
|
|
|
|
|
|
|
|
color[0] = average;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyingBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
|
|
|
{
|
|
|
|
rcti newInput;
|
|
|
|
|
2012-06-25 17:27:54 +00:00
|
|
|
if (this->axis == BLUR_AXIS_X) {
|
2012-06-25 08:21:55 +00:00
|
|
|
newInput.xmin = input->xmin - this->size;
|
|
|
|
newInput.ymin = input->ymin;
|
|
|
|
newInput.xmax = input->xmax + this->size;
|
|
|
|
newInput.ymax = input->ymax;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newInput.xmin = input->xmin;
|
|
|
|
newInput.ymin = input->ymin - this->size;
|
|
|
|
newInput.xmax = input->xmax;
|
|
|
|
newInput.ymax = input->ymax + this->size;
|
|
|
|
}
|
2012-06-14 12:19:13 +00:00
|
|
|
|
|
|
|
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
|
|
|
|
}
|