2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include "COM_DistanceRGBMatteOperation.h"
25
DistanceRGBMatteOperation::DistanceRGBMatteOperation() : NodeOperation()
27
this->addInputSocket(COM_DT_COLOR);
28
this->addInputSocket(COM_DT_COLOR);
29
this->addOutputSocket(COM_DT_VALUE);
31
this->m_inputImageProgram = NULL;
32
this->m_inputKeyProgram = NULL;
35
void DistanceRGBMatteOperation::initExecution()
37
this->m_inputImageProgram = this->getInputSocketReader(0);
38
this->m_inputKeyProgram = this->getInputSocketReader(1);
41
void DistanceRGBMatteOperation::deinitExecution()
43
this->m_inputImageProgram = NULL;
44
this->m_inputKeyProgram = NULL;
47
float DistanceRGBMatteOperation::calculateDistance(float key[4], float image[4])
49
return len_v3v3(key, image);
52
void DistanceRGBMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
57
const float tolerance = this->m_settings->t1;
58
const float falloff = this->m_settings->t2;
63
this->m_inputKeyProgram->read(inKey, x, y, sampler);
64
this->m_inputImageProgram->read(inImage, x, y, sampler);
66
distance = this->calculateDistance(inKey, inImage);
68
/* store matte(alpha) value in [0] to go with
69
* COM_SetAlphaOperation and the Value output
72
/*make 100% transparent */
73
if (distance < tolerance) {
76
/*in the falloff region, make partially transparent */
77
else if (distance < falloff + tolerance) {
78
distance = distance - tolerance;
79
alpha = distance / falloff;
80
/*only change if more transparent than before */
81
if (alpha < inImage[3]) {
84
else { /* leave as before */
85
output[0] = inImage[3];
90
output[0] = inImage[3];