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_LuminanceMatteOperation.h"
25
LuminanceMatteOperation::LuminanceMatteOperation() : NodeOperation()
27
addInputSocket(COM_DT_COLOR);
28
addOutputSocket(COM_DT_VALUE);
30
this->m_inputImageProgram = NULL;
33
void LuminanceMatteOperation::initExecution()
35
this->m_inputImageProgram = this->getInputSocketReader(0);
38
void LuminanceMatteOperation::deinitExecution()
40
this->m_inputImageProgram = NULL;
43
void LuminanceMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
47
const float high = this->m_settings->t1;
48
const float low = this->m_settings->t2;
52
this->m_inputImageProgram->read(inColor, x, y, sampler);
54
/* one line thread-friend algorithm:
55
* output[0] = max(inputValue[3], min(high, max(low, ((inColor[0]-low)/(high-low))))
59
if (inColor[0] > high) {
62
else if (inColor[0] < low) {
66
alpha = (inColor[0] - low) / (high - low);
70
/* store matte(alpha) value in [0] to go with
71
* COM_SetAlphaOperation and the Value output
74
/* don't make something that was more transparent less transparent */
75
if (alpha < inColor[3]) {
79
/* leave now it was before */
80
output[0] = inColor[3];