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_BlurBaseOperation.h"
25
#include "MEM_guardedalloc.h"
28
#include "RE_pipeline.h"
31
BlurBaseOperation::BlurBaseOperation(DataType data_type) : NodeOperation()
33
/* data_type is almost always COM_DT_COLOR except for alpha-blur */
34
this->addInputSocket(data_type);
35
this->addInputSocket(COM_DT_VALUE);
36
this->addOutputSocket(data_type);
37
this->setComplex(true);
38
this->m_inputProgram = NULL;
41
this->m_deleteData = false;
42
this->m_sizeavailable = false;
44
void BlurBaseOperation::initExecution()
46
this->m_inputProgram = this->getInputSocketReader(0);
47
this->m_inputSize = this->getInputSocketReader(1);
48
this->m_data->image_in_width = this->getWidth();
49
this->m_data->image_in_height = this->getHeight();
50
if (this->m_data->relative) {
51
switch (this->m_data->aspect) {
52
case CMP_NODE_BLUR_ASPECT_NONE:
53
this->m_data->sizex = (int)(this->m_data->percentx * 0.01f * this->m_data->image_in_width);
54
this->m_data->sizey = (int)(this->m_data->percenty * 0.01f * this->m_data->image_in_height);
56
case CMP_NODE_BLUR_ASPECT_Y:
57
this->m_data->sizex = (int)(this->m_data->percentx * 0.01f * this->m_data->image_in_width);
58
this->m_data->sizey = (int)(this->m_data->percenty * 0.01f * this->m_data->image_in_width);
60
case CMP_NODE_BLUR_ASPECT_X:
61
this->m_data->sizex = (int)(this->m_data->percentx * 0.01f * this->m_data->image_in_height);
62
this->m_data->sizey = (int)(this->m_data->percenty * 0.01f * this->m_data->image_in_height);
67
QualityStepHelper::initExecution(COM_QH_MULTIPLY);
71
float *BlurBaseOperation::make_gausstab(int rad)
73
float *gausstab, sum, val;
78
gausstab = (float *)MEM_mallocN(sizeof(float) * n, __func__);
81
for (i = -rad; i <= rad; i++) {
82
val = RE_filter_value(this->m_data->filtertype, (float)i / (float)rad);
84
gausstab[i + rad] = val;
88
for (i = 0; i < n; i++)
94
/* normalized distance from the current (inverted so 1.0 is close and 0.0 is far)
95
* 'ease' is applied after, looks nicer */
96
float *BlurBaseOperation::make_dist_fac_inverse(int rad, int falloff)
98
float *dist_fac_invert, val;
103
dist_fac_invert = (float *)MEM_mallocN(sizeof(float) * n, __func__);
105
for (i = -rad; i <= rad; i++) {
106
val = 1.0f - fabsf(((float)i / (float)rad));
108
/* keep in sync with proportional_falloff_curve_only_items */
111
/* ease - gives less hard lines for dilate/erode feather */
112
val = (3.0f * val * val - 2.0f * val * val * val);
115
val = sqrtf(2.0f * val - val * val);
133
dist_fac_invert[i + rad] = val;
136
return dist_fac_invert;
139
void BlurBaseOperation::deinitExecution()
141
this->m_inputProgram = NULL;
142
this->m_inputSize = NULL;
143
if (this->m_deleteData) {
149
void BlurBaseOperation::updateSize()
151
if (!this->m_sizeavailable) {
153
this->getInputSocketReader(1)->read(result, 0, 0, COM_PS_NEAREST);
154
this->m_size = result[0];
155
this->m_sizeavailable = true;