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.
24
#include "COM_GaussianAlphaXBlurOperation.h"
26
#include "MEM_guardedalloc.h"
29
#include "RE_pipeline.h"
32
GaussianAlphaXBlurOperation::GaussianAlphaXBlurOperation() : BlurBaseOperation(COM_DT_VALUE)
34
this->m_gausstab = NULL;
36
this->m_falloff = -1; /* intentionally invalid, so we can detect uninitialized values */
39
void *GaussianAlphaXBlurOperation::initializeTileData(rcti *rect)
42
if (!this->m_sizeavailable) {
45
void *buffer = getInputOperation(0)->initializeTileData(NULL);
50
void GaussianAlphaXBlurOperation::initExecution()
52
/* BlurBaseOperation::initExecution(); */ /* until we suppoer size input - comment this */
56
if (this->m_sizeavailable) {
57
float rad = this->m_size * this->m_data->sizex;
62
this->m_gausstab = BlurBaseOperation::make_gausstab(rad);
63
this->m_distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->m_falloff);
67
void GaussianAlphaXBlurOperation::updateGauss()
69
if (this->m_gausstab == NULL) {
71
float rad = this->m_size * this->m_data->sizex;
76
this->m_gausstab = BlurBaseOperation::make_gausstab(rad);
79
if (this->m_distbuf_inv == NULL) {
81
float rad = this->m_size * this->m_data->sizex;
86
this->m_distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->m_falloff);
90
BLI_INLINE float finv_test(const float f, const bool test)
92
return (LIKELY(test == false)) ? f : 1.0f - f;
95
void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, void *data)
97
const bool do_invert = this->m_do_subtract;
98
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
99
float *buffer = inputBuffer->getBuffer();
100
int bufferwidth = inputBuffer->getWidth();
101
int bufferstartx = inputBuffer->getRect()->xmin;
102
int bufferstarty = inputBuffer->getRect()->ymin;
105
// int maxy = y; // UNUSED
106
int minx = x - this->m_rad;
107
int maxx = x + this->m_rad; // UNUSED
108
miny = max(miny, inputBuffer->getRect()->ymin);
109
minx = max(minx, inputBuffer->getRect()->xmin);
110
// maxy = min(maxy, inputBuffer->getRect()->ymax);
111
maxx = min(maxx, inputBuffer->getRect()->xmax);
113
/* *** this is the main part which is different to 'GaussianXBlurOperation' *** */
114
int step = getStep();
115
int offsetadd = getOffsetAdd();
116
int bufferindex = ((minx - bufferstartx) * 4) + ((miny - bufferstarty) * 4 * bufferwidth);
119
float alpha_accum = 0.0f;
120
float multiplier_accum = 0.0f;
123
float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
124
float distfacinv_max = 1.0f; /* 0 to 1 */
126
for (int nx = minx; nx <= maxx; nx += step) {
127
const int index = (nx - x) + this->m_rad;
128
float value = finv_test(buffer[bufferindex], do_invert);
133
multiplier = this->m_gausstab[index];
134
alpha_accum += value * multiplier;
135
multiplier_accum += multiplier;
138
/* dilate - find most extreme color */
139
if (value > value_max) {
140
multiplier = this->m_distbuf_inv[index];
142
if (value > value_max) {
144
distfacinv_max = multiplier;
147
bufferindex += offsetadd;
150
/* blend between the max value and gauss blue - gives nice feather */
151
const float value_blur = alpha_accum / multiplier_accum;
152
const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max));
153
output[0] = finv_test(value_final, do_invert);
156
void GaussianAlphaXBlurOperation::deinitExecution()
158
BlurBaseOperation::deinitExecution();
159
MEM_freeN(this->m_gausstab);
160
this->m_gausstab = NULL;
161
MEM_freeN(this->m_distbuf_inv);
162
this->m_distbuf_inv = NULL;
167
bool GaussianAlphaXBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
170
#if 0 /* until we add size input */
177
NodeOperation *operation = this->getInputOperation(1);
178
if (operation->determineDependingAreaOfInterest(&sizeInput, readOperation, output)) {
184
if (this->m_sizeavailable && this->m_gausstab != NULL) {
185
newInput.xmax = input->xmax + this->m_rad + 1;
186
newInput.xmin = input->xmin - this->m_rad - 1;
187
newInput.ymax = input->ymax;
188
newInput.ymin = input->ymin;
191
newInput.xmax = this->getWidth();
193
newInput.ymax = this->getHeight();
196
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);