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_GlareGhostOperation.h"
25
#include "COM_FastGaussianBlurOperation.h"
27
static float smoothMask(float x, float y)
32
if ((t = 1.0f - sqrtf(x * x + y * y)) > 0.0f) {
40
void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings)
42
const int qt = 1 << settings->quality;
43
const float s1 = 4.f / (float)qt, s2 = 2.f * s1;
46
float sc, isc, u, v, sm, s, t, ofs, scalef[64];
47
const float cmo = 1.f - settings->colmod;
49
MemoryBuffer *gbuf = inputTile->duplicate();
50
MemoryBuffer *tbuf1 = inputTile->duplicate();
54
FastGaussianBlurOperation::IIR_gauss(tbuf1, s1, 0, 3);
55
if (!breaked) FastGaussianBlurOperation::IIR_gauss(tbuf1, s1, 1, 3);
56
if (isBreaked()) breaked = true;
57
if (!breaked) FastGaussianBlurOperation::IIR_gauss(tbuf1, s1, 2, 3);
59
MemoryBuffer *tbuf2 = tbuf1->duplicate();
61
if (isBreaked()) breaked = true;
62
if (!breaked) FastGaussianBlurOperation::IIR_gauss(tbuf2, s2, 0, 3);
63
if (isBreaked()) breaked = true;
64
if (!breaked) FastGaussianBlurOperation::IIR_gauss(tbuf2, s2, 1, 3);
65
if (isBreaked()) breaked = true;
66
if (!breaked) FastGaussianBlurOperation::IIR_gauss(tbuf2, s2, 2, 3);
68
if (settings->iter & 1) ofs = 0.5f; else ofs = 0.f;
69
for (x = 0; x < (settings->iter * 4); x++) {
71
cm[x][0] = cm[x][1] = cm[x][2] = 1;
72
if (y == 1) fRGB_rgbmult(cm[x], 1.f, cmo, cmo);
73
if (y == 2) fRGB_rgbmult(cm[x], cmo, cmo, 1.f);
74
if (y == 3) fRGB_rgbmult(cm[x], cmo, 1.f, cmo);
75
scalef[x] = 2.1f * (1.f - (x + ofs) / (float)(settings->iter * 4));
76
if (x & 1) scalef[x] = -0.99f / scalef[x];
81
for (y = 0; y < gbuf->getHeight() && (!breaked); y++) {
82
v = ((float)y + 0.5f) / (float)gbuf->getHeight();
83
for (x = 0; x < gbuf->getWidth(); x++) {
84
u = ((float)x + 0.5f) / (float)gbuf->getWidth();
85
s = (u - 0.5f) * sc + 0.5f, t = (v - 0.5f) * sc + 0.5f;
86
tbuf1->readCubic(c, s * gbuf->getWidth(), t * gbuf->getHeight());
87
sm = smoothMask(s, t);
89
s = (u - 0.5f) * isc + 0.5f, t = (v - 0.5f) * isc + 0.5f;
90
tbuf2->readCubic(tc, s * gbuf->getWidth() - 0.5f, t * gbuf->getHeight() - 0.5f);
91
sm = smoothMask(s, t);
92
madd_v3_v3fl(c, tc, sm);
94
gbuf->writePixel(x, y, c);
96
if (isBreaked()) breaked = true;
100
memset(tbuf1->getBuffer(), 0, tbuf1->getWidth() * tbuf1->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
101
for (n = 1; n < settings->iter && (!breaked); n++) {
102
for (y = 0; y < gbuf->getHeight() && (!breaked); y++) {
103
v = ((float)y + 0.5f) / (float)gbuf->getHeight();
104
for (x = 0; x < gbuf->getWidth(); x++) {
105
u = ((float)x + 0.5f) / (float)gbuf->getWidth();
106
tc[0] = tc[1] = tc[2] = 0.f;
107
for (p = 0; p < 4; p++) {
109
s = (u - 0.5f) * scalef[np] + 0.5f;
110
t = (v - 0.5f) * scalef[np] + 0.5f;
111
gbuf->readCubic(c, s * gbuf->getWidth() - 0.5f, t * gbuf->getHeight() - 0.5f);
112
mul_v3_v3(c, cm[np]);
113
sm = smoothMask(s, t) * 0.25f;
114
madd_v3_v3fl(tc, c, sm);
116
tbuf1->addPixel(x, y, tc);
118
if (isBreaked()) breaked = true;
120
memcpy(gbuf->getBuffer(), tbuf1->getBuffer(), tbuf1->getWidth() * tbuf1->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
122
memcpy(data, gbuf->getBuffer(), gbuf->getWidth() * gbuf->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));