Blender V4.3
rna_movieclip.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <climits>
10#include <cstdlib>
11
12#include "MEM_guardedalloc.h"
13
14#include "DNA_movieclip_types.h"
15#include "DNA_scene_types.h"
16
17#include "RNA_access.hh"
18#include "RNA_define.hh"
19
20#include "rna_internal.hh"
21
22#include "BKE_movieclip.h"
23#include "BKE_tracking.h"
24
25#include "WM_types.hh"
26
27#include "IMB_imbuf.hh"
28#include "IMB_imbuf_types.hh"
29#include "IMB_metadata.hh"
30
31#ifdef RNA_RUNTIME
32
33# include "DEG_depsgraph.hh"
34
35# include "ED_clip.hh"
36
37# include "DNA_screen_types.h"
38# include "DNA_space_types.h"
39
40# include "SEQ_relations.hh"
41
42static void rna_MovieClip_reload_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
43{
44 MovieClip *clip = (MovieClip *)ptr->owner_id;
45
47}
48
49static void rna_MovieClip_size_get(PointerRNA *ptr, int *values)
50{
51 MovieClip *clip = (MovieClip *)ptr->owner_id;
52
53 values[0] = clip->lastsize[0];
54 values[1] = clip->lastsize[1];
55}
56
57static float rna_MovieClip_fps_get(PointerRNA *ptr)
58{
59 MovieClip *clip = (MovieClip *)ptr->owner_id;
60 return BKE_movieclip_get_fps(clip);
61}
62
63static void rna_MovieClip_use_proxy_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
64{
65 MovieClip *clip = (MovieClip *)ptr->owner_id;
68}
69
70static void rna_MovieClipUser_proxy_render_settings_update(Main *bmain,
71 Scene * /*scene*/,
73{
74 ID *id = ptr->owner_id;
76
77 /* when changing render settings of space clip user
78 * clear cache for clip, so all the memory is available
79 * for new render settings
80 */
81 if (GS(id->name) == ID_SCR) {
82 bScreen *screen = (bScreen *)id;
83 ScrArea *area;
84 SpaceLink *sl;
85
86 for (area = static_cast<ScrArea *>(screen->areabase.first); area; area = area->next) {
87 for (sl = static_cast<SpaceLink *>(area->spacedata.first); sl; sl = sl->next) {
88 if (sl->spacetype == SPACE_CLIP) {
89 SpaceClip *sc = (SpaceClip *)sl;
90
91 if (&sc->user == user) {
93
94 if (clip && (clip->flag & MCLIP_USE_PROXY)) {
97 }
98
99 break;
100 }
101 }
102 }
103 }
104 }
105}
106
107static PointerRNA rna_MovieClip_metadata_get(MovieClip *clip)
108{
109 if (clip == nullptr || clip->anim == nullptr) {
110 return PointerRNA_NULL;
111 }
112
113 IDProperty *metadata = IMB_anim_load_metadata(clip->anim);
114 if (metadata == nullptr) {
115 return PointerRNA_NULL;
116 }
117
118 PointerRNA ptr = RNA_pointer_create(nullptr, &RNA_IDPropertyWrapPtr, metadata);
119 return ptr;
120}
121
122static std::optional<std::string> rna_MovieClipUser_path(const PointerRNA *ptr)
123{
124 if (ptr->owner_id) {
125 // MovieClipUser *mc_user = ptr->data;
126
127 switch (GS(ptr->owner_id->name)) {
128 case ID_CA:
130 default:
131 break;
132 }
133 }
134
135 return "";
136}
137
138#else
139
141{
142 StructRNA *srna;
143 PropertyRNA *prop;
144
145 static const EnumPropertyItem clip_tc_items[] = {
147 "NONE",
148 0,
149 "None",
150 "Ignore generated timecodes, seek in movie stream based on calculated timestamp"},
152 "RECORD_RUN",
153 0,
154 "Record Run",
155 "Seek based on timestamps read from movie stream, giving the best match between scene and "
156 "movie times"},
158 "FREE_RUN_NO_GAPS",
159 0,
160 "Record Run No Gaps",
161 "Effectively convert movie to an image sequence, ignoring incomplete or dropped frames, "
162 "and changes in frame rate"},
163 {0, nullptr, 0, nullptr, nullptr},
164 };
165
166 srna = RNA_def_struct(brna, "MovieClipProxy", nullptr);
167 RNA_def_struct_ui_text(srna, "Movie Clip Proxy", "Proxy parameters for a movie clip");
168 RNA_def_struct_sdna(srna, "MovieClipProxy");
169
170 /* build proxy sized */
171 prop = RNA_def_property(srna, "build_25", PROP_BOOLEAN, PROP_NONE);
172 RNA_def_property_boolean_sdna(prop, nullptr, "build_size_flag", MCLIP_PROXY_SIZE_25);
175 prop, "25%", "Build proxy resolution 25% of the original footage dimension");
176
177 prop = RNA_def_property(srna, "build_50", PROP_BOOLEAN, PROP_NONE);
178 RNA_def_property_boolean_sdna(prop, nullptr, "build_size_flag", MCLIP_PROXY_SIZE_50);
181 prop, "50%", "Build proxy resolution 50% of the original footage dimension");
182
183 prop = RNA_def_property(srna, "build_75", PROP_BOOLEAN, PROP_NONE);
184 RNA_def_property_boolean_sdna(prop, nullptr, "build_size_flag", MCLIP_PROXY_SIZE_75);
187 prop, "75%", "Build proxy resolution 75% of the original footage dimension");
188
189 prop = RNA_def_property(srna, "build_100", PROP_BOOLEAN, PROP_NONE);
190 RNA_def_property_boolean_sdna(prop, nullptr, "build_size_flag", MCLIP_PROXY_SIZE_100);
193 prop, "100%", "Build proxy resolution 100% of the original footage dimension");
194
195 prop = RNA_def_property(srna, "build_undistorted_25", PROP_BOOLEAN, PROP_NONE);
196 RNA_def_property_boolean_sdna(prop, nullptr, "build_size_flag", MCLIP_PROXY_UNDISTORTED_SIZE_25);
199 prop, "25%", "Build proxy resolution 25% of the original undistorted footage dimension");
200
201 prop = RNA_def_property(srna, "build_undistorted_50", PROP_BOOLEAN, PROP_NONE);
202 RNA_def_property_boolean_sdna(prop, nullptr, "build_size_flag", MCLIP_PROXY_UNDISTORTED_SIZE_50);
205 prop, "50%", "Build proxy resolution 50% of the original undistorted footage dimension");
206
207 prop = RNA_def_property(srna, "build_undistorted_75", PROP_BOOLEAN, PROP_NONE);
208 RNA_def_property_boolean_sdna(prop, nullptr, "build_size_flag", MCLIP_PROXY_UNDISTORTED_SIZE_75);
211 prop, "75%", "Build proxy resolution 75% of the original undistorted footage dimension");
212
213 prop = RNA_def_property(srna, "build_undistorted_100", PROP_BOOLEAN, PROP_NONE);
215 prop, nullptr, "build_size_flag", MCLIP_PROXY_UNDISTORTED_SIZE_100);
218 prop, "100%", "Build proxy resolution 100% of the original undistorted footage dimension");
219
220 /* Build time-codes. */
221 prop = RNA_def_property(srna, "build_record_run", PROP_BOOLEAN, PROP_NONE);
222 RNA_def_property_boolean_sdna(prop, nullptr, "build_tc_flag", IMB_TC_RECORD_RUN);
224 RNA_def_property_ui_text(prop, "Rec Run", "Build record run time code index");
225
226 /* quality of proxied image */
227 prop = RNA_def_property(srna, "quality", PROP_INT, PROP_UNSIGNED);
228 RNA_def_property_int_sdna(prop, nullptr, "quality");
230 RNA_def_property_ui_text(prop, "Quality", "JPEG quality of proxy images");
231 RNA_def_property_ui_range(prop, 1, 100, 1, -1);
232
233 prop = RNA_def_property(srna, "timecode", PROP_ENUM, PROP_NONE);
234 RNA_def_property_enum_sdna(prop, nullptr, "tc");
236 RNA_def_property_enum_items(prop, clip_tc_items);
237 RNA_def_property_ui_text(prop, "Timecode", "");
238 RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClip_reload_update");
239
240 /* directory */
241 prop = RNA_def_property(srna, "directory", PROP_STRING, PROP_DIRPATH);
242 RNA_def_property_string_sdna(prop, nullptr, "dir");
244 RNA_def_property_ui_text(prop, "Directory", "Location to store the proxy files");
245 RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClip_reload_update");
246}
247
249{
250 StructRNA *srna;
251 PropertyRNA *prop;
252
253 static const EnumPropertyItem clip_render_size_items[] = {
254 {MCLIP_PROXY_RENDER_SIZE_25, "PROXY_25", 0, "25%", ""},
255 {MCLIP_PROXY_RENDER_SIZE_50, "PROXY_50", 0, "50%", ""},
256 {MCLIP_PROXY_RENDER_SIZE_75, "PROXY_75", 0, "75%", ""},
257 {MCLIP_PROXY_RENDER_SIZE_100, "PROXY_100", 0, "100%", ""},
258 {MCLIP_PROXY_RENDER_SIZE_FULL, "FULL", 0, "None, full render", ""},
259 {0, nullptr, 0, nullptr, nullptr},
260 };
261
262 srna = RNA_def_struct(brna, "MovieClipUser", nullptr);
264 srna,
265 "Movie Clip User",
266 "Parameters defining how a MovieClip data-block is used by another data-block");
267 RNA_def_struct_path_func(srna, "rna_MovieClipUser_path");
268
270
271 prop = RNA_def_property(srna, "frame_current", PROP_INT, PROP_TIME);
272 RNA_def_property_int_sdna(prop, nullptr, "framenr");
275 prop, "Current Frame", "Current frame number in movie or image sequence");
276
277 /* render size */
278 prop = RNA_def_property(srna, "proxy_render_size", PROP_ENUM, PROP_NONE);
279 RNA_def_property_enum_sdna(prop, nullptr, "render_size");
280 RNA_def_property_enum_items(prop, clip_render_size_items);
282 "Proxy Render Size",
283 "Display preview using full resolution or different proxy resolutions");
285 prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClipUser_proxy_render_settings_update");
286
287 /* render undistorted */
288 prop = RNA_def_property(srna, "use_render_undistorted", PROP_BOOLEAN, PROP_NONE);
289 RNA_def_property_boolean_sdna(prop, nullptr, "render_flag", MCLIP_PROXY_RENDER_UNDISTORT);
290 RNA_def_property_ui_text(prop, "Render Undistorted", "Render preview using undistorted proxy");
292 prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClipUser_proxy_render_settings_update");
293
295}
296
298{
299 StructRNA *srna;
300
301 srna = RNA_def_struct(brna, "MovieClipScopes", nullptr);
302 RNA_def_struct_ui_text(srna, "MovieClipScopes", "Scopes for statistical view of a movie clip");
303}
304
306{
307 StructRNA *srna;
308 PropertyRNA *prop;
309 FunctionRNA *func;
310 PropertyRNA *parm;
311
312 static const EnumPropertyItem clip_source_items[] = {
313 {MCLIP_SRC_SEQUENCE, "SEQUENCE", 0, "Image Sequence", "Multiple image files, as a sequence"},
314 {MCLIP_SRC_MOVIE, "MOVIE", 0, "Movie File", "Movie file"},
315 {0, nullptr, 0, nullptr, nullptr},
316 };
317
318 srna = RNA_def_struct(brna, "MovieClip", "ID");
320 srna, "MovieClip", "MovieClip data-block referencing an external movie file");
321 RNA_def_struct_ui_icon(srna, ICON_SEQUENCE);
322
323 prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
324 RNA_def_property_string_sdna(prop, nullptr, "filepath");
325 RNA_def_property_ui_text(prop, "File Path", "Filename of the movie or sequence file");
326 RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClip_reload_update");
327
328 prop = RNA_def_property(srna, "tracking", PROP_POINTER, PROP_NONE);
329 RNA_def_property_struct_type(prop, "MovieTracking");
330
331 prop = RNA_def_property(srna, "proxy", PROP_POINTER, PROP_NONE);
332 RNA_def_property_struct_type(prop, "MovieClipProxy");
333
334 /* use proxy */
335 prop = RNA_def_property(srna, "use_proxy", PROP_BOOLEAN, PROP_NONE);
336 RNA_def_property_boolean_sdna(prop, nullptr, "flag", MCLIP_USE_PROXY);
339 prop, "Use Proxy / Timecode", "Use a preview proxy and/or timecode index for this clip");
340 RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClip_use_proxy_update");
341
342 prop = RNA_def_int_vector(srna,
343 "size",
344 2,
345 nullptr,
346 0,
347 0,
348 "Size",
349 "Width and height in pixels, zero when image data can't be loaded",
350 0,
351 0);
352 RNA_def_property_int_funcs(prop, "rna_MovieClip_size_get", nullptr, nullptr);
354
355 prop = RNA_def_property(srna, "display_aspect", PROP_FLOAT, PROP_XYZ);
356 RNA_def_property_float_sdna(prop, nullptr, "aspx");
357 RNA_def_property_array(prop, 2);
358 RNA_def_property_range(prop, 0.1f, FLT_MAX);
359 RNA_def_property_ui_range(prop, 0.1f, 5000.0f, 1, 2);
361 prop, "Display Aspect", "Display Aspect for this clip, does not affect rendering");
363
364 /* source */
365 prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
366 RNA_def_property_enum_items(prop, clip_source_items);
367 RNA_def_property_ui_text(prop, "Source", "Where the clip comes from");
369
370 /* custom proxy directory */
371 prop = RNA_def_property(srna, "use_proxy_custom_directory", PROP_BOOLEAN, PROP_NONE);
375 prop,
376 "Proxy Custom Directory",
377 "Create proxy images in a custom directory (default is movie location)");
378 RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClip_reload_update");
379
380 /* grease pencil */
381 prop = RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE);
382 RNA_def_property_pointer_sdna(prop, nullptr, "gpd");
383 RNA_def_property_struct_type(prop, "GreasePencil");
385 prop, nullptr, nullptr, nullptr, "rna_GPencil_datablocks_annotations_poll");
387 RNA_def_property_ui_text(prop, "Grease Pencil", "Grease pencil data for this movie clip");
389
390 /* start_frame */
391 prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_NONE);
392 RNA_def_property_int_sdna(prop, nullptr, "start_frame");
394 "Start Frame",
395 "Global scene frame number at which this movie starts playing "
396 "(affects all data associated with a clip)");
398
399 /* frame_offset */
400 prop = RNA_def_property(srna, "frame_offset", PROP_INT, PROP_NONE);
401 RNA_def_property_int_sdna(prop, nullptr, "frame_offset");
403 prop,
404 "Frame Offset",
405 "Offset of footage first frame relative to its file name "
406 "(affects only how footage is loading, does not change data associated with a clip)");
408
409 /* length */
410 prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_NONE);
412 RNA_def_property_int_sdna(prop, nullptr, "len");
413 RNA_def_property_ui_text(prop, "Duration", "Detected duration of movie clip in frames");
414
415 /* FPS */
416 prop = RNA_def_property(srna, "fps", PROP_FLOAT, PROP_NONE);
418 RNA_def_property_float_funcs(prop, "rna_MovieClip_fps_get", nullptr, nullptr);
420 prop, "Frame Rate", "Detected frame rate of the movie clip in frames per second");
421
422 /* color management */
423 prop = RNA_def_property(srna, "colorspace_settings", PROP_POINTER, PROP_NONE);
424 RNA_def_property_pointer_sdna(prop, nullptr, "colorspace_settings");
425 RNA_def_property_struct_type(prop, "ColorManagedInputColorspaceSettings");
426 RNA_def_property_ui_text(prop, "Color Space Settings", "Input color space settings");
427
428 /* metadata */
429 func = RNA_def_function(srna, "metadata", "rna_MovieClip_metadata_get");
430 RNA_def_function_ui_description(func, "Retrieve metadata of the movie file");
431 /* return type */
432 parm = RNA_def_pointer(
433 func, "metadata", "IDPropertyWrapPtr", "", "Dict-like object containing the metadata");
435 RNA_def_function_return(func, parm);
436
438}
439
447
448#endif
void BKE_movieclip_clear_cache(struct MovieClip *clip)
float BKE_movieclip_get_fps(struct MovieClip *clip)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_SOURCE
Definition DNA_ID.h:1110
@ ID_CA
@ ID_SCR
@ MCLIP_PROXY_RENDER_SIZE_75
@ MCLIP_PROXY_RENDER_SIZE_100
@ MCLIP_PROXY_RENDER_SIZE_50
@ MCLIP_PROXY_RENDER_SIZE_FULL
@ MCLIP_PROXY_RENDER_SIZE_25
@ MCLIP_SRC_SEQUENCE
@ MCLIP_SRC_MOVIE
@ MCLIP_PROXY_SIZE_75
@ MCLIP_PROXY_UNDISTORTED_SIZE_100
@ MCLIP_PROXY_UNDISTORTED_SIZE_75
@ MCLIP_PROXY_SIZE_25
@ MCLIP_PROXY_SIZE_100
@ MCLIP_PROXY_UNDISTORTED_SIZE_50
@ MCLIP_PROXY_SIZE_50
@ MCLIP_PROXY_UNDISTORTED_SIZE_25
@ MCLIP_PROXY_RENDER_UNDISTORT
@ MCLIP_USE_PROXY_CUSTOM_DIR
@ MCLIP_USE_PROXY
#define MINAFRAME
#define MAXFRAME
@ SPACE_CLIP
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
@ IMB_TC_RECORD_RUN_NO_GAPS
@ IMB_TC_NONE
@ IMB_TC_RECORD_RUN
Contains defines and structs used throughout the imbuf module.
IDProperty * IMB_anim_load_metadata(ImBufAnim *anim)
Definition anim_movie.cc:94
Read Guarded memory(de)allocation.
@ PARM_RNAPTR
Definition RNA_types.hh:399
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_INT
Definition RNA_types.hh:66
@ PROP_STRING
Definition RNA_types.hh:68
@ PROP_POINTER
Definition RNA_types.hh:70
PropertyFlag
Definition RNA_types.hh:201
@ PROP_ANIMATABLE
Definition RNA_types.hh:220
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_ID_REFCOUNT
Definition RNA_types.hh:253
@ PROP_TIME
Definition RNA_types.hh:156
@ PROP_XYZ
Definition RNA_types.hh:172
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_DIRPATH
Definition RNA_types.hh:140
@ PROP_UNSIGNED
Definition RNA_types.hh:152
@ PROP_FILEPATH
Definition RNA_types.hh:139
constexpr PointerRNA PointerRNA_NULL
Definition RNA_types.hh:45
#define ND_DISPLAY
Definition WM_types.hh:458
#define NC_MOVIECLIP
Definition WM_types.hh:364
#define GS(x)
Definition iris.cc:202
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
void rna_def_animdata_common(StructRNA *srna)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_define_lib_overridable(const bool make_overridable)
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
std::optional< std::string > rna_CameraBackgroundImage_image_or_movieclip_user_path(const PointerRNA *ptr)
static void rna_def_movieclip(BlenderRNA *brna)
static void rna_def_movieclip_proxy(BlenderRNA *brna)
void RNA_def_movieclip(BlenderRNA *brna)
static void rna_def_movieclipUser(BlenderRNA *brna)
static void rna_def_movieClipScopes(BlenderRNA *brna)
#define FLT_MAX
Definition stdcycles.h:14
void SEQ_relations_invalidate_movieclip_strips(Main *bmain, MovieClip *clip_target)
Definition DNA_ID.h:413
char name[66]
Definition DNA_ID.h:425
ID * owner_id
Definition RNA_types.hh:40
void * data
Definition RNA_types.hh:42
struct ScrArea * next
struct MovieClipUser user
PointerRNA * ptr
Definition wm_files.cc:4126