Blender V4.3
COM_GlareSimpleStarOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7namespace blender::compositor {
8
10 MemoryBuffer *input_tile,
11 const NodeGlare *settings)
12{
13 int i, x, y, ym, yp, xm, xp;
14 float c[4] = {0, 0, 0, 0}, tc[4] = {0, 0, 0, 0};
15 const float f1 = 1.0f - settings->fade;
16 const float f2 = (1.0f - f1) * 0.5f;
17
18 MemoryBuffer tbuf1(*input_tile);
19 MemoryBuffer tbuf2(*input_tile);
20
21 bool breaked = false;
22 for (i = 0; i < settings->iter && (!breaked); i++) {
23 // // (x || x-1, y-1) to (x || x+1, y+1)
24 // // F
25 for (y = 0; y < this->get_height() && (!breaked); y++) {
26 ym = y - i;
27 yp = y + i;
28 for (x = 0; x < this->get_width(); x++) {
29 xm = x - i;
30 xp = x + i;
31 tbuf1.read(c, x, y);
32 mul_v3_fl(c, f1);
33 tbuf1.read(tc, (settings->star_45 ? xm : x), ym);
34 madd_v3_v3fl(c, tc, f2);
35 tbuf1.read(tc, (settings->star_45 ? xp : x), yp);
36 madd_v3_v3fl(c, tc, f2);
37 c[3] = 1.0f;
38 tbuf1.write_pixel(x, y, c);
39
40 tbuf2.read(c, x, y);
41 mul_v3_fl(c, f1);
42 tbuf2.read(tc, xm, (settings->star_45 ? yp : y));
43 madd_v3_v3fl(c, tc, f2);
44 tbuf2.read(tc, xp, (settings->star_45 ? ym : y));
45 madd_v3_v3fl(c, tc, f2);
46 c[3] = 1.0f;
47 tbuf2.write_pixel(x, y, c);
48 }
49 if (is_braked()) {
50 breaked = true;
51 }
52 }
53 // // B
54 for (y = this->get_height() - 1; y >= 0 && (!breaked); y--) {
55 ym = y - i;
56 yp = y + i;
57 for (x = this->get_width() - 1; x >= 0; x--) {
58 xm = x - i;
59 xp = x + i;
60 tbuf1.read(c, x, y);
61 mul_v3_fl(c, f1);
62 tbuf1.read(tc, (settings->star_45 ? xm : x), ym);
63 madd_v3_v3fl(c, tc, f2);
64 tbuf1.read(tc, (settings->star_45 ? xp : x), yp);
65 madd_v3_v3fl(c, tc, f2);
66 c[3] = 1.0f;
67 tbuf1.write_pixel(x, y, c);
68
69 tbuf2.read(c, x, y);
70 mul_v3_fl(c, f1);
71 tbuf2.read(tc, xm, (settings->star_45 ? yp : y));
72 madd_v3_v3fl(c, tc, f2);
73 tbuf2.read(tc, xp, (settings->star_45 ? ym : y));
74 madd_v3_v3fl(c, tc, f2);
75 c[3] = 1.0f;
76 tbuf2.write_pixel(x, y, c);
77 }
78 if (is_braked()) {
79 breaked = true;
80 }
81 }
82 }
83
84 for (i = 0; i < this->get_width() * this->get_height() * 4; i++) {
85 data[i] = tbuf1.get_buffer()[i] + tbuf2.get_buffer()[i];
86 }
87}
88
89} // namespace blender::compositor
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void mul_v3_fl(float r[3], float f)
void generate_glare(float *data, MemoryBuffer *input_tile, const NodeGlare *settings) override
a MemoryBuffer contains access to the data
void read(float *result, float x, float y, PixelSampler sampler=PixelSampler::Nearest, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip) const
void write_pixel(int x, int y, const float color[4])
float * get_buffer()
get the data of this MemoryBuffer