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_BoxMaskOperation.h"
25
#include "DNA_node_types.h"
27
BoxMaskOperation::BoxMaskOperation() : NodeOperation()
29
this->addInputSocket(COM_DT_VALUE);
30
this->addInputSocket(COM_DT_VALUE);
31
this->addOutputSocket(COM_DT_VALUE);
32
this->m_inputMask = NULL;
33
this->m_inputValue = NULL;
34
this->m_cosine = 0.0f;
37
void BoxMaskOperation::initExecution()
39
this->m_inputMask = this->getInputSocketReader(0);
40
this->m_inputValue = this->getInputSocketReader(1);
41
const double rad = DEG2RAD((double)this->m_data->rotation);
42
this->m_cosine = cos(rad);
43
this->m_sine = sin(rad);
44
this->m_aspectRatio = ((float)this->getWidth()) / this->getHeight();
47
void BoxMaskOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
52
float rx = x / this->getWidth();
53
float ry = y / this->getHeight();
55
const float dy = (ry - this->m_data->y) / this->m_aspectRatio;
56
const float dx = rx - this->m_data->x;
57
rx = this->m_data->x + (this->m_cosine * dx + this->m_sine * dy);
58
ry = this->m_data->y + (-this->m_sine * dx + this->m_cosine * dy);
60
this->m_inputMask->read(inputMask, x, y, sampler);
61
this->m_inputValue->read(inputValue, x, y, sampler);
63
float halfHeight = this->m_data->height / 2.0f;
64
float halfWidth = this->m_data->width / 2.0f;
65
bool inside = (rx > this->m_data->x - halfWidth &&
66
rx < this->m_data->x + halfWidth &&
67
ry > this->m_data->y - halfHeight &&
68
ry < this->m_data->y + halfHeight);
70
switch (this->m_maskType) {
71
case CMP_NODE_MASKTYPE_ADD:
73
output[0] = max(inputMask[0], inputValue[0]);
76
output[0] = inputMask[0];
79
case CMP_NODE_MASKTYPE_SUBTRACT:
81
output[0] = inputMask[0] - inputValue[0];
82
CLAMP(output[0], 0, 1);
85
output[0] = inputMask[0];
88
case CMP_NODE_MASKTYPE_MULTIPLY:
90
output[0] = inputMask[0] * inputValue[0];
96
case CMP_NODE_MASKTYPE_NOT:
98
if (inputMask[0] > 0.0f) {
102
output[0] = inputValue[0];
106
output[0] = inputMask[0];
114
void BoxMaskOperation::deinitExecution()
116
this->m_inputMask = NULL;
117
this->m_inputValue = NULL;