Blender V5.3
effects.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include "BLI_array.hh"
12#include "BLI_math_color_c.hh"
14#include "BLI_task.hh"
15
16#include "IMB_imbuf_types.hh"
17#include "SEQ_effects.hh"
18
19#include "render.hh"
20
21namespace blender {
22
23struct ImBuf;
24struct Scene;
25struct Strip;
26
27namespace seq {
28
29struct SeqRenderState;
30struct RenderData;
31
32enum class StripEarlyOut {
33 NoInput = -1, /* No input needed. */
34 DoEffect = 0, /* No early out (do the effect). */
35 UseInput1 = 1, /* Output = input1. */
36 UseInput2 = 2, /* Output = input2. */
37};
38
40 /* #init is only called on first creation, or when changing effect type. */
41 void (*init)(Strip *strip);
42
43 /* duplicate */
44 void (*copy)(Strip *dst, const Strip *src, int flag);
45
46 /* destruct */
47 void (*free)(Strip *strip, bool do_id_user);
48
49 StripEarlyOut (*early_out)(const Strip *strip, float fac);
50
51 /* execute the effect */
52 SeqResult (*execute)(const RenderData *context,
54 Strip *strip,
55 float timeline_frame,
56 float fac,
57 const SeqResult &input1,
58 const SeqResult &input2);
59};
60
66
72void strip_effect_speed_rebuild_map(Scene *scene, Strip *strip);
77 Strip *strip_speed,
78 float timeline_frame,
79 int input);
80
82 const SeqResult &ibuf1,
83 const SeqResult &ibuf2,
84 bool uninitialized_pixels = true);
85
86Array<float> make_gaussian_blur_kernel(float rad, int size);
87
88inline float4 load_premul_pixel(const uchar *ptr)
89{
90 float4 res;
92 return res;
93}
94
95inline float4 load_premul_pixel(const float *ptr)
96{
97 return float4(ptr);
98}
99
100inline void store_premul_pixel(const float4 &pix, uchar *dst)
101{
103}
104
105inline void store_premul_pixel(const float4 &pix, float *dst)
106{
107 *reinterpret_cast<float4 *>(dst) = pix;
108}
109
110StripEarlyOut early_out_mul_input1(const Strip * /*strip*/, float fac);
111StripEarlyOut early_out_mul_input2(const Strip * /*strip*/, float fac);
112StripEarlyOut early_out_fade(const Strip * /*strip*/, float fac);
113
114EffectHandle effect_handle_get(StripType strip_type);
115
116float effect_fader_calc(Scene *scene, Strip *strip, float timeline_frame, bool is_current_frame);
117
118void add_effect_get_handle(EffectHandle &rval);
119void adjustment_effect_get_handle(EffectHandle &rval);
120void alpha_over_effect_get_handle(EffectHandle &rval);
121void alpha_under_effect_get_handle(EffectHandle &rval);
122void blend_mode_effect_get_handle(EffectHandle &rval);
123void color_mix_effect_get_handle(EffectHandle &rval);
124void compositor_effect_get_handle(EffectHandle &rval);
125void cross_effect_get_handle(EffectHandle &rval);
126void gamma_cross_effect_get_handle(EffectHandle &rval);
127void gaussian_blur_effect_get_handle(EffectHandle &rval);
128void glow_effect_get_handle(EffectHandle &rval);
129void mul_effect_get_handle(EffectHandle &rval);
130void multi_camera_effect_get_handle(EffectHandle &rval);
131void solid_color_effect_get_handle(EffectHandle &rval);
132void speed_effect_get_handle(EffectHandle &rval);
133void sub_effect_get_handle(EffectHandle &rval);
134void text_effect_get_handle(EffectHandle &rval);
137
138/* Given `OpT` that implements an `apply` function:
139 *
140 * template <typename T>
141 * void apply(const T *src1, const T *src2, T *dst, int64_t size) const;
142 *
143 * this function calls the apply() function in parallel
144 * chunks of the image to process, and with uchar or float types
145 * All images are expected to have 4 (RGBA) color channels. */
146template<typename OpT>
147static void apply_effect_op(const OpT &op, const ImBuf *src1, const ImBuf *src2, ImBuf *dst)
148{
149 BLI_assert_msg(src1->channels == 0 || src1->channels == 4,
150 "Sequencer only supports 4 channel images");
151 BLI_assert_msg(src2->channels == 0 || src2->channels == 4,
152 "Sequencer only supports 4 channel images");
153 BLI_assert_msg(dst->channels == 0 || dst->channels == 4,
154 "Sequencer only supports 4 channel images");
155 float *dst_float_data = dst->float_data_for_write();
156 uchar *dst_byte_data = dst->byte_data_for_write();
157 threading::parallel_for(IndexRange(size_t(dst->x) * dst->y), 32 * 1024, [&](IndexRange range) {
158 int64_t offset = range.first() * 4;
159 if (dst_float_data) {
160 const float *src1_ptr = src1->float_data() + offset;
161 const float *src2_ptr = src2->float_data() + offset;
162 float *dst_ptr = dst_float_data + offset;
163 op.apply(src1_ptr, src2_ptr, dst_ptr, range.size());
164 }
165 else {
166 const uchar *src1_ptr = src1->byte_data() + offset;
167 const uchar *src2_ptr = src2->byte_data() + offset;
168 uchar *dst_ptr = dst_byte_data + offset;
169 op.apply(src1_ptr, src2_ptr, dst_ptr, range.size());
170 }
171 });
172}
173
174} // namespace seq
175} // namespace blender
#define BLI_assert_msg(a, msg)
constexpr IndexRange()=default
const int state
EffectHandle strip_blend_mode_handle_get(Strip *strip)
Definition effects.cc:293
void mul_effect_get_handle(EffectHandle &rval)
EffectHandle strip_effect_handle_get(Strip *strip)
Definition effects.cc:284
void alpha_under_effect_get_handle(EffectHandle &rval)
void wipe_effect_get_handle(EffectHandle &rval)
float4 load_premul_pixel(const uchar *ptr)
Definition effects.hh:88
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:121
void text_effect_get_handle(EffectHandle &rval)
Array< float > make_gaussian_blur_kernel(float rad, int size)
Definition effects.cc:77
void gamma_cross_effect_get_handle(EffectHandle &rval)
void blend_mode_effect_get_handle(EffectHandle &rval)
SeqResult prepare_effect_imbufs(const RenderData *context, const SeqResult &ibuf1, const SeqResult &ibuf2, bool uninitialized_pixels)
Definition effects.cc:34
void compositor_effect_get_handle(EffectHandle &rval)
void cross_effect_get_handle(EffectHandle &rval)
void multi_camera_effect_get_handle(EffectHandle &rval)
float strip_speed_effect_target_frame_get(Scene *scene, Strip *strip_speed, float timeline_frame, int input)
void speed_effect_get_handle(EffectHandle &rval)
void add_effect_get_handle(EffectHandle &rval)
void strip_effect_speed_rebuild_map(Scene *scene, Strip *strip)
StripEarlyOut early_out_mul_input1(const Strip *, float fac)
Definition effects.cc:129
EffectHandle effect_handle_get(StripType strip_type)
Definition effects.cc:156
void transform_effect_get_handle(EffectHandle &rval)
void adjustment_effect_get_handle(EffectHandle &rval)
void sub_effect_get_handle(EffectHandle &rval)
void glow_effect_get_handle(EffectHandle &rval)
static void apply_effect_op(const OpT &op, const ImBuf *src1, const ImBuf *src2, ImBuf *dst)
Definition effects.hh:147
void store_premul_pixel(const float4 &pix, uchar *dst)
Definition effects.hh:100
void color_mix_effect_get_handle(EffectHandle &rval)
float effect_fader_calc(Scene *scene, Strip *strip, float timeline_frame, const bool is_current_frame)
Definition effects.cc:318
void alpha_over_effect_get_handle(EffectHandle &rval)
StripEarlyOut early_out_fade(const Strip *, float fac)
Definition effects.cc:110
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
VecBase< float, 4 > float4
unsigned char uchar
Definition BKE_text.h:58
MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4])
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
uint8_t * byte_data_for_write()
Definition allocimbuf.cc:60
float * float_data_for_write()
Definition allocimbuf.cc:79
void(*) copy(Strip *dst, const Strip *src, int flag)
Definition effects.hh:44
void(*) free(Strip *strip, bool do_id_user)
Definition effects.hh:47
void(*) init(Strip *strip)
Definition effects.hh:41
StripEarlyOut(*) early_out(const Strip *strip, float fac)
Definition effects.hh:49
SeqResult(*) execute(const RenderData *context, SeqRenderState *state, Strip *strip, float timeline_frame, float fac, const SeqResult &input1, const SeqResult &input2)
Definition effects.hh:52