Blender V5.0
effects.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 * SPDX-FileCopyrightText: 2003-2024 Blender Authors
3 * SPDX-FileCopyrightText: 2005-2006 Peter Schlaile <peter [at] schlaile [dot] de>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later */
6
10
11#include "DNA_scene_types.h"
12#include "DNA_sequence_types.h"
13
15#include "IMB_imbuf.hh"
16#include "IMB_metadata.hh"
17
18#include "RE_pipeline.h"
19
20#include "SEQ_render.hh"
21#include "SEQ_time.hh"
22
23#include "effects.hh"
24#include "render.hh"
25
26namespace blender::seq {
27
29 ImBuf *ibuf1,
30 ImBuf *ibuf2,
31 bool uninitialized_pixels)
32{
33 ImBuf *out;
34 Scene *scene = context->scene;
35 int x = context->rectx;
36 int y = context->recty;
37 int base_flags = uninitialized_pixels ? IB_uninitialized_pixels : 0;
38
39 if (!ibuf1 && !ibuf2) {
40 /* Hmm, global float option? */
41 out = IMB_allocImBuf(x, y, 32, IB_byte_data | base_flags);
42 }
43 else if ((ibuf1 && ibuf1->float_buffer.data) || (ibuf2 && ibuf2->float_buffer.data)) {
44 /* if any inputs are float, output is float too */
45 out = IMB_allocImBuf(x, y, 32, IB_float_data | base_flags);
46 }
47 else {
48 out = IMB_allocImBuf(x, y, 32, IB_byte_data | base_flags);
49 }
50
51 if (out->float_buffer.data) {
52 if (ibuf1 && !ibuf1->float_buffer.data) {
53 seq_imbuf_to_sequencer_space(scene, ibuf1, true);
54 }
55
56 if (ibuf2 && !ibuf2->float_buffer.data) {
57 seq_imbuf_to_sequencer_space(scene, ibuf2, true);
58 }
59
61 }
62 else {
63 if (ibuf1 && !ibuf1->byte_buffer.data) {
65 }
66
67 if (ibuf2 && !ibuf2->byte_buffer.data) {
69 }
70 }
71
72 /* If effect only affecting a single channel, forward input's metadata to the output. */
73 if (ibuf1 != nullptr && ibuf1 == ibuf2) {
74 IMB_metadata_copy(out, ibuf1);
75 }
76
77 return out;
78}
79
81{
82 int n = 2 * size + 1;
83 Array<float> gaussian(n);
84
85 float sum = 0.0f;
86 float fac = (rad > 0.0f ? 1.0f / rad : 0.0f);
87 for (int i = -size; i <= size; i++) {
88 float val = RE_filter_value(R_FILTER_GAUSS, float(i) * fac);
89 sum += val;
90 gaussian[i + size] = val;
91 }
92
93 float inv_sum = 1.0f / sum;
94 for (int i = 0; i < n; i++) {
95 gaussian[i] *= inv_sum;
96 }
97
98 return gaussian;
99}
100
101static void init_noop(Strip * /*strip*/) {}
102
103static void load_noop(Strip * /*strip*/) {}
104
105static void free_noop(Strip * /*strip*/, const bool /*do_id_user*/) {}
106
108{
109 return 2;
110}
111
112static StripEarlyOut early_out_noop(const Strip * /*strip*/, float /*fac*/)
113{
115}
116
117StripEarlyOut early_out_fade(const Strip * /*strip*/, float fac)
118{
119 if (fac == 0.0f) {
121 }
122 if (fac == 1.0f) {
124 }
126}
127
128StripEarlyOut early_out_mul_input2(const Strip * /*strip*/, float fac)
129{
130 if (fac == 0.0f) {
132 }
134}
135
136StripEarlyOut early_out_mul_input1(const Strip * /*strip*/, float fac)
137{
138 if (fac == 0.0f) {
140 }
142}
143
144static void get_default_fac_noop(const Scene * /*scene*/,
145 const Strip * /*strip*/,
146 float /*timeline_frame*/,
147 float *fac)
148{
149 *fac = 1.0f;
150}
151
152void get_default_fac_fade(const Scene *scene, const Strip *strip, float timeline_frame, float *fac)
153{
154 *fac = float(timeline_frame - time_left_handle_frame_get(scene, strip));
155 *fac /= time_strip_length_get(scene, strip);
156 *fac = math::clamp(*fac, 0.0f, 1.0f);
157}
158
160{
161 EffectHandle rval;
162
163 rval.init = init_noop;
165 rval.load = load_noop;
166 rval.free = free_noop;
169 rval.execute = nullptr;
170 rval.copy = nullptr;
171
172 switch (strip_type) {
173 case STRIP_TYPE_CROSS:
175 break;
178 break;
179 case STRIP_TYPE_ADD:
181 break;
182 case STRIP_TYPE_SUB:
184 break;
185 case STRIP_TYPE_MUL:
187 break;
190 break;
193 break;
196 break;
197 case STRIP_TYPE_WIPE:
199 break;
200 case STRIP_TYPE_GLOW:
202 break;
203 case STRIP_TYPE_SPEED:
205 break;
206 case STRIP_TYPE_COLOR:
208 break;
211 break;
214 break;
217 break;
218 case STRIP_TYPE_TEXT:
220 break;
221 default:
222 break;
223 }
224
225 return rval;
226}
227
229{
230 EffectHandle rval;
231
232 rval.init = init_noop;
234 rval.load = load_noop;
235 rval.free = free_noop;
238 rval.execute = nullptr;
239 rval.copy = nullptr;
240
241 switch (blend) {
244 break;
245 case STRIP_BLEND_ADD:
247 break;
248 case STRIP_BLEND_SUB:
250 break;
253 break;
256 break;
259 break;
260 case STRIP_BLEND_MUL:
262 break;
275 case STRIP_BLEND_HUE:
282 break;
283 default:
284 break;
285 }
286
287 return rval;
288}
289
291{
292 EffectHandle rval = {};
293
294 if (strip->is_effect()) {
295 rval = effect_handle_get(StripType(strip->type));
296 if ((strip->runtime.flag & STRIP_EFFECT_NOT_LOADED) != 0) {
297 rval.load(strip);
299 }
300 }
301
302 return rval;
303}
304
306{
307 EffectHandle rval = {};
308
309 if (strip->blend_mode != STRIP_BLEND_REPLACE) {
310 if ((strip->runtime.flag & STRIP_EFFECT_NOT_LOADED) != 0) {
311 /* load the effect first */
312 rval = effect_handle_get(StripType(strip->type));
313 rval.load(strip);
314 }
315
317 if ((strip->runtime.flag & STRIP_EFFECT_NOT_LOADED) != 0) {
318 /* now load the blend and unset unloaded flag */
319 rval.load(strip);
321 }
322 }
323
324 return rval;
325}
326
327int effect_get_num_inputs(int strip_type)
328{
329 EffectHandle rval = effect_handle_get(StripType(strip_type));
330 if (rval.execute == nullptr) {
331 return 0;
332 }
333 return rval.num_inputs();
334}
335
336} // namespace blender::seq
@ R_FILTER_GAUSS
@ STRIP_EFFECT_NOT_LOADED
@ STRIP_TYPE_GAUSSIAN_BLUR
@ STRIP_TYPE_GAMCROSS
@ STRIP_TYPE_COLORMIX
@ STRIP_TYPE_WIPE
@ STRIP_TYPE_TEXT
@ STRIP_TYPE_ADD
@ STRIP_TYPE_GLOW
@ STRIP_TYPE_SUB
@ STRIP_TYPE_MUL
@ STRIP_TYPE_SPEED
@ STRIP_TYPE_COLOR
@ STRIP_TYPE_ADJUSTMENT
@ STRIP_TYPE_MULTICAM
@ STRIP_TYPE_ALPHAUNDER
@ STRIP_TYPE_CROSS
@ STRIP_TYPE_ALPHAOVER
@ STRIP_BLEND_LINEAR_BURN
@ STRIP_BLEND_SUB
@ STRIP_BLEND_VIVID_LIGHT
@ STRIP_BLEND_LIGHTEN
@ STRIP_BLEND_OVERLAY
@ STRIP_BLEND_SATURATION
@ STRIP_BLEND_SOFT_LIGHT
@ STRIP_BLEND_EXCLUSION
@ STRIP_BLEND_COLOR_BURN
@ STRIP_BLEND_GAMCROSS
@ STRIP_BLEND_ALPHAUNDER
@ STRIP_BLEND_HUE
@ STRIP_BLEND_DODGE
@ STRIP_BLEND_LIN_LIGHT
@ STRIP_BLEND_CROSS
@ STRIP_BLEND_ALPHAOVER
@ STRIP_BLEND_PIN_LIGHT
@ STRIP_BLEND_REPLACE
@ STRIP_BLEND_ADD
@ STRIP_BLEND_DIFFERENCE
@ STRIP_BLEND_HARD_LIGHT
@ STRIP_BLEND_MUL
@ STRIP_BLEND_BLEND_COLOR
@ STRIP_BLEND_DARKEN
@ STRIP_BLEND_VALUE
@ STRIP_BLEND_SCREEN
void IMB_colormanagement_assign_float_colorspace(ImBuf *ibuf, const char *name)
void IMB_byte_from_float(ImBuf *ibuf)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
@ IB_float_data
@ IB_byte_data
@ IB_uninitialized_pixels
void IMB_metadata_copy(ImBuf *ibuf_dst, const ImBuf *ibuf_src)
Definition metadata.cc:59
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static T sum(const btAlignedObjectArray< T > &items)
nullptr float
#define out
float RE_filter_value(int type, float x)
T clamp(const T &a, const T &min, const T &max)
EffectHandle strip_blend_mode_handle_get(Strip *strip)
Definition effects.cc:305
void mul_effect_get_handle(EffectHandle &rval)
void seq_imbuf_to_sequencer_space(const Scene *scene, ImBuf *ibuf, bool make_float)
Definition render.cc:115
EffectHandle strip_effect_handle_get(Strip *strip)
Definition effects.cc:290
void alpha_under_effect_get_handle(EffectHandle &rval)
void wipe_effect_get_handle(EffectHandle &rval)
void gaussian_blur_effect_get_handle(EffectHandle &rval)
void solid_color_effect_get_handle(EffectHandle &rval)
StripEarlyOut early_out_mul_input2(const Strip *, float fac)
Definition effects.cc:128
void text_effect_get_handle(EffectHandle &rval)
int time_left_handle_frame_get(const Scene *, const Strip *strip)
Array< float > make_gaussian_blur_kernel(float rad, int size)
Definition effects.cc:80
ImBuf * prepare_effect_imbufs(const RenderData *context, ImBuf *ibuf1, ImBuf *ibuf2, bool uninitialized_pixels)
Definition effects.cc:28
void gamma_cross_effect_get_handle(EffectHandle &rval)
void blend_mode_effect_get_handle(EffectHandle &rval)
int time_strip_length_get(const Scene *scene, const Strip *strip)
void get_default_fac_fade(const Scene *scene, const Strip *strip, float timeline_frame, float *fac)
Definition effects.cc:152
void cross_effect_get_handle(EffectHandle &rval)
void multi_camera_effect_get_handle(EffectHandle &rval)
static StripEarlyOut early_out_noop(const Strip *, float)
Definition effects.cc:112
void speed_effect_get_handle(EffectHandle &rval)
void add_effect_get_handle(EffectHandle &rval)
static void load_noop(Strip *)
Definition effects.cc:103
static void get_default_fac_noop(const Scene *, const Strip *, float, float *fac)
Definition effects.cc:144
StripEarlyOut early_out_mul_input1(const Strip *, float fac)
Definition effects.cc:136
static void init_noop(Strip *)
Definition effects.cc:101
EffectHandle effect_handle_get(StripType strip_type)
Definition effects.cc:159
void adjustment_effect_get_handle(EffectHandle &rval)
static void free_noop(Strip *, const bool)
Definition effects.cc:105
void sub_effect_get_handle(EffectHandle &rval)
static EffectHandle effect_handle_for_blend_mode_get(StripBlendMode blend)
Definition effects.cc:228
void glow_effect_get_handle(EffectHandle &rval)
static int num_inputs_default()
Definition effects.cc:107
void color_mix_effect_get_handle(EffectHandle &rval)
void alpha_over_effect_get_handle(EffectHandle &rval)
StripEarlyOut early_out_fade(const Strip *, float fac)
Definition effects.cc:117
int effect_get_num_inputs(int strip_type)
Definition effects.cc:327
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
ColorManagedColorspaceSettings sequencer_colorspace_settings
StripRuntime runtime
void(* copy)(Strip *dst, const Strip *src, int flag)
ImBuf *(* execute)(const RenderData *context, SeqRenderState *state, Strip *strip, float timeline_frame, float fac, ImBuf *ibuf1, ImBuf *ibuf2)
void(* get_default_fac)(const Scene *scene, const Strip *strip, float timeline_frame, float *fac)
void(* free)(Strip *strip, bool do_id_user)
StripEarlyOut(* early_out)(const Strip *strip, float fac)
void(* load)(Strip *seqconst)
void(* init)(Strip *strip)
i
Definition text_draw.cc:230
static int blend(const Tex *tex, const float texvec[3], TexResult *texres)