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.
23
#include "COM_BrightnessOperation.h"
25
BrightnessOperation::BrightnessOperation() : NodeOperation()
27
this->addInputSocket(COM_DT_COLOR);
28
this->addInputSocket(COM_DT_VALUE);
29
this->addInputSocket(COM_DT_VALUE);
30
this->addOutputSocket(COM_DT_COLOR);
31
this->m_inputProgram = NULL;
33
void BrightnessOperation::initExecution()
35
this->m_inputProgram = this->getInputSocketReader(0);
36
this->m_inputBrightnessProgram = this->getInputSocketReader(1);
37
this->m_inputContrastProgram = this->getInputSocketReader(2);
40
void BrightnessOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
44
float inputBrightness[4];
45
float inputContrast[4];
46
this->m_inputProgram->read(inputValue, x, y, sampler);
47
this->m_inputBrightnessProgram->read(inputBrightness, x, y, sampler);
48
this->m_inputContrastProgram->read(inputContrast, x, y, sampler);
49
float brightness = inputBrightness[0];
50
float contrast = inputContrast[0];
52
float delta = contrast / 200.0f;
53
a = 1.0f - delta * 2.0f;
55
* The algorithm is by Werner D. Streidt
56
* (http://visca.com/ffactory/archives/5-99/msg00021.html)
57
* Extracted of OpenCV demhist.c
61
b = a * (brightness - delta);
65
b = a * (brightness + delta);
68
output[0] = a * inputValue[0] + b;
69
output[1] = a * inputValue[1] + b;
70
output[2] = a * inputValue[2] + b;
71
output[3] = inputValue[3];
74
void BrightnessOperation::deinitExecution()
76
this->m_inputProgram = NULL;
77
this->m_inputBrightnessProgram = NULL;
78
this->m_inputContrastProgram = NULL;