Blender V5.3
movieclip.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdio>
10#include <cstring>
11#include <fcntl.h>
12#include <optional>
13
14#ifndef WIN32
15# include <unistd.h>
16#else
17# include <io.h>
18#endif
19
20#include <ctime>
21
22#include "MEM_guardedalloc.h"
23
24/* Allow using deprecated functionality for .blend file I/O. */
25#define DNA_DEPRECATED_ALLOW
26
28
29#include "DNA_movieclip_types.h"
30#include "DNA_node_types.h"
31#include "DNA_scene_types.h"
32#include "DNA_space_types.h"
33
34#include "BLI_fileops.hh"
35#include "BLI_listbase.hh"
36#include "BLI_math_vector_c.hh"
37#include "BLI_path_utils.hh"
38#include "BLI_string.hh"
39#include "BLI_threads.hh"
40#include "BLI_utildefines.hh"
41
42#include "BLT_translation.hh"
43
44#include "BKE_bpath.hh"
45#include "BKE_colortools.hh"
46#include "BKE_idtype.hh"
47#include "BKE_image.hh" /* openanim */
48#include "BKE_lib_id.hh"
49#include "BKE_lib_query.hh"
50#include "BKE_main.hh"
51#include "BKE_movieclip.hh"
53#include "BKE_tracking.hh"
54
55#include "IMB_cache.hh"
57#include "IMB_imbuf.hh"
58#include "IMB_imbuf_types.hh"
59
60#include "MOV_read.hh"
61
62#include "DEG_depsgraph.hh"
64
65#include "GPU_texture.hh"
66
67#include "BLO_read_write.hh"
68
69#include "CLG_log.h"
70
71namespace blender {
72
73static CLG_LogRef LOG = {"gpu.texture"};
74
75static void free_buffers(MovieClip *clip);
76
79{
80 /* TODO: we could store those in undo cache storage as well, and preserve them instead of
81 * re-creating them... */
82 clip->runtime.gputextures.clear_no_delete();
83
84 clip->runtime.last_update = 0;
85}
86
87static void movie_clip_init_data(ID *id)
88{
89 MovieClip *movie_clip = id_cast<MovieClip *>(id);
90 INIT_DEFAULT_STRUCT_AFTER(movie_clip, id);
91
94}
95
96static void movie_clip_copy_data(Main * /*bmain*/,
97 std::optional<Library *> /*owner_library*/,
98 ID *id_dst,
99 const ID *id_src,
100 const int flag)
101{
102 MovieClip *movie_clip_dst = id_cast<MovieClip *>(id_dst);
103 const MovieClip *movie_clip_src = id_cast<const MovieClip *>(id_src);
104
105 /* We never handle user-count here for owned data. */
106 const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
107
108 movie_clip_dst->anim = nullptr;
109 movie_clip_dst->cache = nullptr;
110
111 BKE_tracking_copy(&movie_clip_dst->tracking, &movie_clip_src->tracking, flag_subdata);
112 movie_clip_dst->tracking_context = nullptr;
113
115 &movie_clip_src->colorspace_settings);
116}
117
118static void movie_clip_free_data(ID *id)
119{
120 MovieClip *movie_clip = id_cast<MovieClip *>(id);
121
122 /* Also frees animation-data. */
123 free_buffers(movie_clip);
124
125 BKE_tracking_free(&movie_clip->tracking);
126}
127
129{
130 MovieClip *movie_clip = id_cast<MovieClip *>(id);
131 MovieTracking *tracking = &movie_clip->tracking;
132
134
135 for (MovieTrackingObject &object : tracking->objects) {
136 for (MovieTrackingTrack &track : object.tracks) {
138 }
139 for (MovieTrackingPlaneTrack &plane_track : object.plane_tracks) {
141 }
142 }
143}
144
146 IDTypeForeachCacheFunctionCallback function_callback,
147 void *user_data)
148{
149 MovieClip *movie_clip = id_cast<MovieClip *>(id);
150 IDCacheKey key{};
151 key.id_session_uid = id->session_uid;
152 key.identifier = offsetof(MovieClip, cache);
153 function_callback(id, &key, reinterpret_cast<void **>(&movie_clip->cache), 0, user_data);
154
155 key.identifier = offsetof(MovieClip, tracking.camera.intrinsics);
156 function_callback(id, &key, (&movie_clip->tracking.camera.intrinsics), 0, user_data);
157}
158
160{
161 MovieClip *movie_clip = id_cast<MovieClip *>(id);
163 bpath_data, movie_clip->filepath, sizeof(movie_clip->filepath));
164}
165
166static void write_movieTracks(BlendWriter *writer, ListBaseT<MovieTrackingTrack> *tracks)
167{
168 MovieTrackingTrack *track;
169
170 track = tracks->first();
171 while (track) {
172 writer->write_struct(track);
173
174 if (track->markers) {
175 writer->write_struct_array(track->markersnr, track->markers);
176 }
177
178 track = track->next;
179 }
180}
181
183 ListBaseT<MovieTrackingPlaneTrack> *plane_tracks_base)
184{
185 for (MovieTrackingPlaneTrack &plane_track : *plane_tracks_base) {
186 writer->write_struct(&plane_track);
187
188 writer->write_pointer_array(plane_track.point_tracksnr, plane_track.point_tracks);
189 writer->write_struct_array(plane_track.markersnr, plane_track.markers);
190 }
191}
192
194 MovieTrackingReconstruction *reconstruction)
195{
196 if (reconstruction->camnr) {
197 writer->write_struct_array(reconstruction->camnr, reconstruction->cameras);
198 }
199}
200
201static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address)
202{
203 MovieClip *clip = id_cast<MovieClip *>(id);
204
205 /* Clean up, important in undo case to reduce false detection of changed datablocks. */
206 clip->anim = nullptr;
207 clip->tracking_context = nullptr;
208 clip->tracking.stats = nullptr;
209
210 MovieTracking *tracking = &clip->tracking;
211
212 writer->write_id_struct(id_address, clip, [](BlendStructWriter<MovieClip> &struct_writer) {
213 struct_writer.shallow_data.runtime = {};
214 });
215 BKE_id_blend_write(writer, &clip->id);
216
217 for (MovieTrackingObject &object : tracking->objects) {
218 writer->write_struct(&object);
219 write_movieTracks(writer, &object.tracks);
220 write_moviePlaneTracks(writer, &object.plane_tracks);
221 write_movieReconstruction(writer, &object.reconstruction);
222 }
223}
224
226 MovieTrackingReconstruction *reconstruction)
227{
228 BLO_read_array_and_validate_size(reader, &reconstruction->cameras, &reconstruction->camnr);
229}
230
232 ListBaseT<MovieTrackingTrack> *tracksbase)
233{
234 BLO_read_struct_list(reader, MovieTrackingTrack, tracksbase);
235
236 for (MovieTrackingTrack &track : *tracksbase) {
237 BLO_read_array_and_validate_size(reader, &track.markers, &track.markersnr);
238 }
239}
240
242 ListBaseT<MovieTrackingPlaneTrack> *plane_tracks_base)
243{
244 BLO_read_struct_list(reader, MovieTrackingPlaneTrack, plane_tracks_base);
245
246 for (MovieTrackingPlaneTrack &plane_track : *plane_tracks_base) {
248 reader, &plane_track.point_tracks, &plane_track.point_tracksnr);
249 for (int i = 0; i < plane_track.point_tracksnr; i++) {
250 BLO_read_struct(reader, MovieTrackingTrack, &plane_track.point_tracks[i]);
251 }
252
253 BLO_read_array_and_validate_size(reader, &plane_track.markers, &plane_track.markersnr);
254 }
255}
256
258{
259 MovieClip *clip = id_cast<MovieClip *>(id);
260 MovieTracking *tracking = &clip->tracking;
261
262 direct_link_movieTracks(reader, &tracking->tracks_legacy);
265
268
269 clip->anim = nullptr;
270 clip->tracking_context = nullptr;
271 clip->tracking.stats = nullptr;
272
273 /* Needed for proper versioning, will be nullptr for all newer files anyway. */
275
276 clip->tracking.dopesheet.ok = 0;
277 clip->tracking.dopesheet.channels.clear_no_delete();
278 clip->tracking.dopesheet.coverage_segments.clear_no_delete();
279
281
282 for (MovieTrackingObject &object : tracking->objects) {
283 direct_link_movieTracks(reader, &object.tracks);
284 direct_link_moviePlaneTracks(reader, &object.plane_tracks);
285 direct_link_movieReconstruction(reader, &object.reconstruction);
286
287 BLO_read_struct(reader, MovieTrackingTrack, &object.active_track);
288 BLO_read_struct(reader, MovieTrackingPlaneTrack, &object.active_plane_track);
289 }
290
292}
293
295 .id_code = MovieClip::id_type,
296 .id_filter = FILTER_ID_MC,
297 .dependencies_id_types = FILTER_ID_GD_LEGACY | FILTER_ID_IM,
298 .main_listbase_index = INDEX_ID_MC,
299 .struct_size = sizeof(MovieClip),
300 .name = "MovieClip",
301 .name_plural = N_("movieclips"),
302 .translation_context = BLT_I18NCONTEXT_ID_MOVIECLIP,
304 .asset_type_info = nullptr,
305
306 .init_data = movie_clip_init_data,
307 .copy_data = movie_clip_copy_data,
308 .free_data = movie_clip_free_data,
309 .make_local = nullptr,
310 .foreach_id = movie_clip_foreach_id,
311 .foreach_cache = movie_clip_foreach_cache,
312 .foreach_path = movie_clip_foreach_path,
313 .foreach_working_space_color = nullptr,
314 .foreach_asset_weak_reference = nullptr,
315 .owner_pointer_get = nullptr,
316
317 .blend_write = movieclip_blend_write,
318 .blend_read_data = movieclip_blend_read_data,
319 .blend_read_after_liblink = nullptr,
320
321 .blend_read_undo_preserve = nullptr,
322
323 .lib_override_apply_post = nullptr,
324};
325
326/*********************** movieclip buffer loaders *************************/
327
328static int sequence_guess_offset(const char *full_name, int head_len, ushort numlen)
329{
330 char num[FILE_MAX] = {0};
331
332 BLI_strncpy(num, full_name + head_len, numlen + 1);
333
334 return atoi(num);
335}
336
337static int rendersize_to_proxy(const MovieClipUser *user, int flag)
338{
339 if ((flag & MCLIP_USE_PROXY) == 0) {
340 return IMB_PROXY_NONE;
341 }
342
343 switch (user->render_size) {
345 return IMB_PROXY_25;
346
348 return IMB_PROXY_50;
349
351 return IMB_PROXY_75;
352
354 return IMB_PROXY_100;
355
357 return IMB_PROXY_NONE;
358 }
359
360 return IMB_PROXY_NONE;
361}
362
363static int rendersize_to_number(int render_size)
364{
365 switch (render_size) {
367 return 25;
368
370 return 50;
371
373 return 75;
374
376 return 100;
377
379 return 100;
380 }
381
382 return 100;
383}
384
385static void get_sequence_filepath(const MovieClip *clip,
386 const int framenr,
387 char filepath[FILE_MAX])
388{
389 ushort numlen;
390 char head[FILE_MAX], tail[FILE_MAX];
391 int offset;
392
393 BLI_strncpy(filepath, clip->filepath, sizeof(clip->filepath));
394 BLI_path_sequence_decode(filepath, head, sizeof(head), tail, sizeof(tail), &numlen);
395
396 /* Movie-clips always points to first image from sequence, auto-guess offset for now.
397 * Could be something smarter in the future. */
398 offset = sequence_guess_offset(clip->filepath, strlen(head), numlen);
399
400 if (numlen) {
402 FILE_MAX,
403 head,
404 tail,
405 numlen,
406 offset + framenr - clip->start_frame + clip->frame_offset);
407 }
408 else {
409 BLI_strncpy(filepath, clip->filepath, sizeof(clip->filepath));
410 }
411
412 BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&clip->id));
413}
414
415/* supposed to work with sequences only */
416static void get_proxy_filepath(const MovieClip *clip,
417 int proxy_render_size,
418 bool undistorted,
419 int framenr,
420 char filepath[FILE_MAX])
421{
422 int size = rendersize_to_number(proxy_render_size);
423 char dir[FILE_MAX], clipdir[FILE_MAX], clipfile[FILE_MAX];
424 int proxynr = framenr - clip->start_frame + 1 + clip->frame_offset;
425
426 BLI_path_split_dir_file(clip->filepath, clipdir, FILE_MAX, clipfile, FILE_MAX);
427
428 if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
429 STRNCPY(dir, clip->proxy.dir);
430 }
431 else {
432 SNPRINTF(dir, "%s" SEP_STR "BL_proxy", clipdir);
433 }
434
435 if (undistorted) {
436 BLI_snprintf(filepath,
437 FILE_MAX,
438 "%s" SEP_STR "%s" SEP_STR "proxy_%d_undistorted" SEP_STR "%08d",
439 dir,
440 clipfile,
441 size,
442 proxynr);
443 }
444 else {
445 BLI_snprintf(filepath,
446 FILE_MAX,
447 "%s" SEP_STR "%s" SEP_STR "proxy_%d" SEP_STR "%08d",
448 dir,
449 clipfile,
450 size,
451 proxynr);
452 }
453
455 BLI_path_frame(filepath, FILE_MAX, 1, 0);
456 BLI_strncat(filepath, ".jpg", FILE_MAX);
457}
458
460 const MovieClipUser *user,
461 int framenr,
462 int flag)
463{
464 ImBuf *ibuf;
465 char filepath[FILE_MAX];
466 bool use_proxy = false;
467 ColorManagedColorspaceSettings *colorspace_settings;
468
469 use_proxy = (flag & MCLIP_USE_PROXY) && user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL;
470 if (use_proxy) {
471 int undistort = user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
472 get_proxy_filepath(clip, user->render_size, undistort, framenr, filepath);
473
474 /* Well, this is a bit weird, but proxies for movie sources
475 * are built in the same exact color space as the input,
476 *
477 * But image sequences are built in the display space.
478 */
479 if (clip->source == MCLIP_SRC_MOVIE) {
480 colorspace_settings = &clip->colorspace_settings;
481 }
482 else {
483 colorspace_settings = nullptr;
484 }
485 }
486 else {
487 get_sequence_filepath(clip, framenr, filepath);
488 colorspace_settings = &clip->colorspace_settings;
489 }
490
492
493 /* read ibuf */
494 ibuf = IMB_load_image_from_filepath(filepath, loadflag, colorspace_settings);
495
496 return ibuf;
497}
498
500{
501 char filepath_abs[FILE_MAX];
502
503 if (!clip->anim) {
504 STRNCPY(filepath_abs, clip->filepath);
505 BLI_path_abs(filepath_abs, ID_BLEND_PATH_FROM_GLOBAL(&clip->id));
506
507 /* FIXME: make several stream accessible in image editor, too */
508 clip->anim = openanim(filepath_abs, ImBufFlags::Zero, 0, false, &clip->colorspace_settings);
509
510 if (clip->anim) {
511 if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
512 char dir[FILE_MAX];
513 STRNCPY(dir, clip->proxy.dir);
515 MOV_set_custom_proxy_dir(clip->anim, dir);
516 }
517 }
518 }
519}
520
522 const MovieClipUser *user,
523 int framenr,
524 int flag)
525{
526 ImBuf *ibuf = nullptr;
527 int proxy = rendersize_to_proxy(user, flag);
528
530
531 if (clip->anim) {
532 int fra = framenr - clip->start_frame + clip->frame_offset;
533
534 ibuf = MOV_decode_frame(clip->anim, fra, IMB_Proxy_Size(proxy));
535 }
536
537 return ibuf;
538}
539
541{
542 if (clip->source == MCLIP_SRC_MOVIE) {
544
545 if (clip->anim) {
546 clip->len = MOV_get_duration_frames(clip->anim);
547 }
548 }
549 else if (clip->source == MCLIP_SRC_SEQUENCE) {
550 ushort numlen;
551 char filepath[FILE_MAX], head[FILE_MAX], tail[FILE_MAX];
552
553 BLI_path_sequence_decode(clip->filepath, head, sizeof(head), tail, sizeof(tail), &numlen);
554
555 if (numlen == 0) {
556 /* there's no number group in file name, assume it's single framed sequence */
557 clip->len = 1;
558 }
559 else {
560 clip->len = 0;
561 for (;;) {
562 get_sequence_filepath(clip, clip->len + clip->start_frame, filepath);
563
564 if (BLI_exists(filepath)) {
565 clip->len++;
566 }
567 else {
568 break;
569 }
570 }
571 }
572 }
573}
574
575/*********************** image buffer cache *************************/
576
578 /* regular imbuf cache */
580
581 /* cached postprocessed shot */
582 struct {
583 ImBuf *ibuf;
584 int framenr;
586
587 /* cache for undistorted shot */
588 float focal_length;
589 float principal_point[2];
590 float polynomial_k[3];
591 float division_k[2];
592 float nuke_k[2];
593 float nuke_p[2];
594 float brown_k[4];
595 float brown_p[2];
596 short distortion_model;
598
599 int proxy;
600 short render_flag;
602
603 /* cache for stable shot */
604 struct {
606
607 ImBuf *ibuf;
608 int framenr;
610
611 float loc[2], scale, angle, aspect;
612 int proxy, filter;
613 short render_flag;
615
617
619};
620
626
630
631static int user_frame_to_cache_frame(MovieClip *clip, int framenr)
632{
633 int index;
634
635 index = framenr - clip->start_frame + clip->frame_offset;
636
637 if (clip->source == MCLIP_SRC_SEQUENCE) {
638 if (clip->cache->sequence_offset == -1) {
639 ushort numlen;
640 char head[FILE_MAX], tail[FILE_MAX];
641
642 BLI_path_sequence_decode(clip->filepath, head, sizeof(head), tail, sizeof(tail), &numlen);
643
644 /* see comment in get_sequence_filepath */
645 clip->cache->sequence_offset = sequence_guess_offset(clip->filepath, strlen(head), numlen);
646 }
647
648 index += clip->cache->sequence_offset;
649 }
650
651 if (index < 0) {
652 return framenr - index;
653 }
654
655 return framenr;
656}
657
658static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags)
659{
660 const MovieClipImBufCacheKey *key = static_cast<const MovieClipImBufCacheKey *>(userkey);
661
662 *framenr = key->framenr;
663 *proxy = key->proxy;
664 *render_flags = key->render_flag;
665}
666
667static uint movieclip_hashhash(const void *keyv)
668{
669 const MovieClipImBufCacheKey *key = static_cast<const MovieClipImBufCacheKey *>(keyv);
670 int rval = key->framenr;
671
672 return rval;
673}
674
675static bool imbufcache_hashcmp(const void *av, const void *bv)
676{
677 const MovieClipImBufCacheKey *a = static_cast<const MovieClipImBufCacheKey *>(av);
678 const MovieClipImBufCacheKey *b = static_cast<const MovieClipImBufCacheKey *>(bv);
679
680 return ((a->framenr != b->framenr) || (a->proxy != b->proxy) ||
681 (a->render_flag != b->render_flag));
682}
683
684static void *moviecache_getprioritydata(void *key_v)
685{
686 MovieClipImBufCacheKey *key = static_cast<MovieClipImBufCacheKey *>(key_v);
687 MovieClipCachePriorityData *priority_data;
688
689 priority_data = MEM_new_zeroed<MovieClipCachePriorityData>("movie cache clip priority data");
690 priority_data->framenr = key->framenr;
691
692 return priority_data;
693}
694
695static int moviecache_getitempriority(void *last_userkey_v, void *priority_data_v)
696{
697 MovieClipImBufCacheKey *last_userkey = static_cast<MovieClipImBufCacheKey *>(last_userkey_v);
698 MovieClipCachePriorityData *priority_data = static_cast<MovieClipCachePriorityData *>(
699 priority_data_v);
700
701 return -abs(last_userkey->framenr - priority_data->framenr);
702}
703
704static void moviecache_prioritydeleter(void *priority_data_v)
705{
706 MovieClipCachePriorityData *priority_data = static_cast<MovieClipCachePriorityData *>(
707 priority_data_v);
708
709 MEM_delete(priority_data);
710}
711
712static ImBuf *get_imbuf_cache(MovieClip *clip, const MovieClipUser *user, int flag)
713{
714 if (clip->cache) {
716
717 if (!clip->cache->is_still_sequence) {
718 key.framenr = user_frame_to_cache_frame(clip, user->framenr);
719 }
720 else {
721 key.framenr = 1;
722 }
723
724 if (flag & MCLIP_USE_PROXY) {
725 key.proxy = rendersize_to_proxy(user, flag);
726 key.render_flag = user->render_flag;
727 }
728 else {
729 key.proxy = IMB_PROXY_NONE;
730 key.render_flag = 0;
731 }
732
733 return IMB_cache_get(clip->cache->imbufcache, &key, nullptr);
734 }
735
736 return nullptr;
737}
738
739static bool has_imbuf_cache(MovieClip *clip, const MovieClipUser *user, int flag)
740{
741 if (clip->cache) {
743
744 key.framenr = user_frame_to_cache_frame(clip, user->framenr);
745
746 if (flag & MCLIP_USE_PROXY) {
747 key.proxy = rendersize_to_proxy(user, flag);
748 key.render_flag = user->render_flag;
749 }
750 else {
751 key.proxy = IMB_PROXY_NONE;
752 key.render_flag = 0;
753 }
754
755 return IMB_cache_has_frame(clip->cache->imbufcache, &key);
756 }
757
758 return false;
759}
760
761static bool put_imbuf_cache(
762 MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, int flag, bool destructive)
763{
765
766 if (clip->cache == nullptr) {
767 ImBufCache *imbufcache;
768
769 // char cache_name[64];
770 // SNPRINTF(cache_name, "movie %s", clip->id.name);
771
772 clip->cache = MEM_new_zeroed<MovieClipCache>("movieClipCache");
773
774 imbufcache = IMB_cache_create(
776
782
783 clip->cache->imbufcache = imbufcache;
784 clip->cache->sequence_offset = -1;
785 if (clip->source == MCLIP_SRC_SEQUENCE) {
786 ushort numlen;
787 BLI_path_sequence_decode(clip->filepath, nullptr, 0, nullptr, 0, &numlen);
788 clip->cache->is_still_sequence = (numlen == 0);
789 }
790 }
791
792 if (!clip->cache->is_still_sequence) {
793 key.framenr = user_frame_to_cache_frame(clip, user->framenr);
794 }
795 else {
796 key.framenr = 1;
797 }
798
799 if (flag & MCLIP_USE_PROXY) {
800 key.proxy = rendersize_to_proxy(user, flag);
801 key.render_flag = user->render_flag;
802 }
803 else {
804 key.proxy = IMB_PROXY_NONE;
805 key.render_flag = 0;
806 }
807
808 if (destructive) {
809 IMB_cache_put(clip->cache->imbufcache, &key, ibuf);
810 return true;
811 }
812
813 return IMB_cache_put_if_possible(clip->cache->imbufcache, &key, ibuf);
814}
815
816static bool moviecache_check_free_proxy(ImBuf * /*ibuf*/, void *userkey, void * /*userdata*/)
817{
818 MovieClipImBufCacheKey *key = static_cast<MovieClipImBufCacheKey *>(userkey);
819
820 return !(key->proxy == IMB_PROXY_NONE && key->render_flag == 0);
821}
822
823/*********************** common functions *************************/
824
825/* only image block itself */
826static MovieClip *movieclip_alloc(Main *bmain, const char *name)
827{
828 MovieClip *clip;
829
830 clip = BKE_id_new<MovieClip>(bmain, name);
831
832 return clip;
833}
834
836{
837 int width, height;
838 MovieClipUser user = {};
839
841 BKE_movieclip_get_size(clip, &user, &width, &height);
842
843 if (!width || !height) {
844 clip->lastsize[0] = clip->lastsize[1] = IMG_SIZE_FALLBACK;
845 }
846}
847
848static void detect_clip_source(Main *bmain, MovieClip *clip)
849{
850 ImBuf *ibuf;
851 char filepath[FILE_MAX];
852
853 STRNCPY(filepath, clip->filepath);
854 BLI_path_abs(filepath, ID_BLEND_PATH(bmain, &clip->id));
855
857 if (ibuf) {
859 IMB_freeImBuf(ibuf);
860 }
861 else {
862 clip->source = MCLIP_SRC_MOVIE;
863 }
864}
865
866MovieClip *BKE_movieclip_file_add(Main *bmain, const char *filepath)
867{
868 MovieClip *clip;
869 int file;
870 char filepath_abs[FILE_MAX];
871
872 STRNCPY(filepath_abs, filepath);
873 BLI_path_abs(filepath_abs, BKE_main_blendfile_path(bmain));
874
875 /* exists? */
876 file = BLI_open(filepath_abs, O_BINARY | O_RDONLY, 0);
877 if (file == -1) {
878 return nullptr;
879 }
880 close(file);
881
882 /* ** add new movieclip ** */
883
884 /* create a short library name */
885 clip = movieclip_alloc(bmain, BLI_path_basename(filepath));
886 STRNCPY(clip->filepath, filepath);
887
888 detect_clip_source(bmain, clip);
889
891 if (clip->lastsize[0]) {
892 int width = clip->lastsize[0];
893
894 clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width;
895 }
896
898
899 return clip;
900}
901
902MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, bool *r_exists)
903{
904 MovieClip *clip;
905 char filepath_abs[FILE_MAX], filepath_test[FILE_MAX];
906
907 STRNCPY(filepath_abs, filepath);
908 BLI_path_abs(filepath_abs, BKE_main_blendfile_path(bmain));
909
910 /* first search an identical filepath */
911 for (clip = bmain->movieclips.first(); clip; clip = static_cast<MovieClip *>(clip->id.next)) {
912 STRNCPY(filepath_test, clip->filepath);
913 BLI_path_abs(filepath_test, ID_BLEND_PATH(bmain, &clip->id));
914
915 if (BLI_path_cmp(filepath_test, filepath_abs) == 0) {
916 id_us_plus(&clip->id); /* officially should not, it doesn't link here! */
917 if (r_exists) {
918 *r_exists = true;
919 }
920 return clip;
921 }
922 }
923
924 if (r_exists) {
925 *r_exists = false;
926 }
927 return BKE_movieclip_file_add(bmain, filepath);
928}
929
930MovieClip *BKE_movieclip_file_add_exists(Main *bmain, const char *filepath)
931{
932 return BKE_movieclip_file_add_exists_ex(bmain, filepath, nullptr);
933}
934
935static void real_ibuf_size(
936 const MovieClip *clip, const MovieClipUser *user, const ImBuf *ibuf, int *width, int *height)
937{
938 *width = ibuf->x;
939 *height = ibuf->y;
940
941 if (clip->flag & MCLIP_USE_PROXY) {
942 switch (user->render_size) {
944 (*width) *= 4;
945 (*height) *= 4;
946 break;
947
949 (*width) *= 2.0f;
950 (*height) *= 2.0f;
951 break;
952
954 *width = float(*width) * 4.0f / 3.0f;
955 *height = float(*height) * 4.0f / 3.0f;
956 break;
957
960 break;
961 }
962 }
963}
964
965static ImBuf *get_undistorted_ibuf(MovieClip *clip, MovieDistortion *distortion, ImBuf *ibuf)
966{
967 ImBuf *undistibuf;
968
969 if (distortion) {
970 undistibuf = BKE_tracking_distortion_exec(
971 distortion, &clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f, true);
972 }
973 else {
974 undistibuf = BKE_tracking_undistort_frame(&clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f);
975 }
976
977 IMB_scale(undistibuf, ibuf->x, ibuf->y, IMBScaleFilter::Box, false);
978
979 return undistibuf;
980}
981
982static bool need_undistortion_postprocess(const MovieClipUser *user, int clip_flag)
983{
984 bool result = false;
985 const bool uses_full_frame = ((clip_flag & MCLIP_USE_PROXY) == 0) ||
987 /* Only full undistorted render can be used as on-fly undistorting image. */
988 result |= uses_full_frame && (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) != 0;
989 return result;
990}
991
993 int clip_flag,
994 MovieClipPostprocFlag postprocess_flag)
995{
996 bool result = (postprocess_flag != MovieClipPostprocFlag::None);
997 result |= need_undistortion_postprocess(user, clip_flag);
998 return result;
999}
1000
1002{
1003 const MovieClipCache *cache = clip->cache;
1004 const MovieTrackingCamera *camera = &clip->tracking.camera;
1005
1006 if (camera->focal != cache->postprocessed.focal_length) {
1007 return false;
1008 }
1009
1010 /* check for distortion model changes */
1011 if (!equals_v2v2(camera->principal_point, cache->postprocessed.principal_point)) {
1012 return false;
1013 }
1014
1015 if (camera->distortion_model != cache->postprocessed.distortion_model) {
1016 return false;
1017 }
1018
1019 if (!equals_v3v3(&camera->k1, cache->postprocessed.polynomial_k)) {
1020 return false;
1021 }
1022
1023 if (!equals_v2v2(&camera->division_k1, cache->postprocessed.division_k)) {
1024 return false;
1025 }
1026
1027 if (!equals_v2v2(&camera->nuke_k1, cache->postprocessed.nuke_k)) {
1028 return false;
1029 }
1030 if (!equals_v2v2(&camera->nuke_p1, cache->postprocessed.nuke_p)) {
1031 return false;
1032 }
1033
1034 if (!equals_v4v4(&camera->brown_k1, cache->postprocessed.brown_k)) {
1035 return false;
1036 }
1037 if (!equals_v2v2(&camera->brown_p1, cache->postprocessed.brown_p)) {
1038 return false;
1039 }
1040
1041 return true;
1042}
1043
1045 const MovieClipUser *user,
1046 int flag,
1047 MovieClipPostprocFlag postprocess_flag)
1048{
1049 const MovieClipCache *cache = clip->cache;
1050 int framenr = user->framenr;
1051 short proxy = IMB_PROXY_NONE;
1052 int render_flag = 0;
1053
1054 if (flag & MCLIP_USE_PROXY) {
1055 proxy = rendersize_to_proxy(user, flag);
1056 render_flag = user->render_flag;
1057 }
1058
1059 /* no cache or no cached postprocessed image */
1060 if (!clip->cache || !clip->cache->postprocessed.ibuf) {
1061 return nullptr;
1062 }
1063
1064 /* Postprocessing happened for other frame. */
1065 if (cache->postprocessed.framenr != framenr) {
1066 return nullptr;
1067 }
1068
1069 /* cached ibuf used different proxy settings */
1070 if (cache->postprocessed.render_flag != render_flag || cache->postprocessed.proxy != proxy) {
1071 return nullptr;
1072 }
1073
1074 if (cache->postprocessed.flag != postprocess_flag) {
1075 return nullptr;
1076 }
1077
1078 if (need_undistortion_postprocess(user, flag)) {
1079 if (!check_undistortion_cache_flags(clip)) {
1080 return nullptr;
1081 }
1082 }
1083 else if (cache->postprocessed.undistortion_used) {
1084 return nullptr;
1085 }
1086
1087 IMB_refImBuf(cache->postprocessed.ibuf);
1088
1089 return cache->postprocessed.ibuf;
1090}
1091
1093 const MovieClipUser *user,
1094 ImBuf *ibuf,
1095 int flag,
1096 MovieClipPostprocFlag postprocess_flag)
1097{
1098 ImBuf *postproc_ibuf = nullptr;
1099
1100 if (need_undistortion_postprocess(user, flag)) {
1101 postproc_ibuf = get_undistorted_ibuf(clip, nullptr, ibuf);
1102 }
1103 else {
1104 postproc_ibuf = IMB_dupImBuf(ibuf);
1105 }
1106
1107 if (postprocess_flag != MovieClipPostprocFlag::None) {
1108 bool disable_red = flag_is_set(postprocess_flag, MovieClipPostprocFlag::DisableRed);
1109 bool disable_green = flag_is_set(postprocess_flag, MovieClipPostprocFlag::DisableGreen);
1110 bool disable_blue = flag_is_set(postprocess_flag, MovieClipPostprocFlag::DisableBlue);
1111 bool grayscale = flag_is_set(postprocess_flag, MovieClipPostprocFlag::PreviewGray);
1112
1113 if (disable_red || disable_green || disable_blue || grayscale) {
1114 BKE_tracking_disable_channels(postproc_ibuf, disable_red, disable_green, disable_blue, true);
1115 }
1116 }
1117
1118 return postproc_ibuf;
1119}
1120
1122 const MovieClipUser *user,
1123 ImBuf *ibuf,
1124 int flag,
1125 MovieClipPostprocFlag postprocess_flag)
1126{
1127 MovieClipCache *cache = clip->cache;
1129
1130 cache->postprocessed.framenr = user->framenr;
1131 cache->postprocessed.flag = postprocess_flag;
1132
1133 if (flag & MCLIP_USE_PROXY) {
1134 cache->postprocessed.proxy = rendersize_to_proxy(user, flag);
1135 cache->postprocessed.render_flag = user->render_flag;
1136 }
1137 else {
1138 cache->postprocessed.proxy = IMB_PROXY_NONE;
1139 cache->postprocessed.render_flag = 0;
1140 }
1141
1142 if (need_undistortion_postprocess(user, flag)) {
1143 cache->postprocessed.distortion_model = camera->distortion_model;
1144 cache->postprocessed.focal_length = camera->focal;
1145 copy_v2_v2(cache->postprocessed.principal_point, camera->principal_point);
1146 copy_v3_v3(cache->postprocessed.polynomial_k, &camera->k1);
1147 copy_v2_v2(cache->postprocessed.division_k, &camera->division_k1);
1148 copy_v2_v2(cache->postprocessed.nuke_k, &camera->nuke_k1);
1149 copy_v2_v2(cache->postprocessed.nuke_p, &camera->nuke_p1);
1150 copy_v4_v4(cache->postprocessed.brown_k, &camera->brown_k1);
1151 copy_v2_v2(cache->postprocessed.brown_p, &camera->brown_p1);
1152 cache->postprocessed.undistortion_used = true;
1153 }
1154 else {
1155 cache->postprocessed.undistortion_used = false;
1156 }
1157
1158 IMB_refImBuf(ibuf);
1159
1160 if (cache->postprocessed.ibuf) {
1161 IMB_freeImBuf(cache->postprocessed.ibuf);
1162 }
1163
1164 cache->postprocessed.ibuf = ibuf;
1165}
1166
1168 const MovieClipUser *user,
1169 int flag,
1170 MovieClipPostprocFlag postprocess_flag,
1171 MovieClipCacheFlag cache_flag)
1172{
1173 ImBuf *ibuf = nullptr;
1174 int framenr = user->framenr;
1175 bool need_postprocess = false;
1176
1177 /* cache isn't threadsafe itself and also loading of movies
1178 * can't happen from concurrent threads that's why we use lock here */
1180
1181 /* try to obtain cached postprocessed frame first */
1182 if (need_postprocessed_frame(user, flag, postprocess_flag)) {
1183 ibuf = get_postprocessed_cached_frame(clip, user, flag, postprocess_flag);
1184
1185 if (!ibuf) {
1186 need_postprocess = true;
1187 }
1188 }
1189
1190 if (!ibuf) {
1191 ibuf = get_imbuf_cache(clip, user, flag);
1192 }
1193
1194 if (!ibuf) {
1195 bool use_sequence = false;
1196
1197 /* undistorted proxies for movies should be read as image sequence */
1198 use_sequence = (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) &&
1200
1201 if (clip->source == MCLIP_SRC_SEQUENCE || use_sequence) {
1202 ibuf = movieclip_load_sequence_file(clip, user, framenr, flag);
1203 }
1204 else {
1205 ibuf = movieclip_load_movie_file(clip, user, framenr, flag);
1206 }
1207
1208 if (ibuf && !flag_is_set(cache_flag, MovieClipCacheFlag::SkipCache)) {
1209 put_imbuf_cache(clip, user, ibuf, flag, true);
1210 }
1211 }
1212
1213 if (ibuf) {
1214 real_ibuf_size(clip, user, ibuf, &clip->lastsize[0], &clip->lastsize[1]);
1215
1216 /* Post-process frame and put to cache if needed. */
1217 if (need_postprocess) {
1218 ImBuf *tmpibuf = ibuf;
1219 ibuf = postprocess_frame(clip, user, tmpibuf, flag, postprocess_flag);
1220 IMB_freeImBuf(tmpibuf);
1221 if (ibuf && !flag_is_set(cache_flag, MovieClipCacheFlag::SkipCache)) {
1222 put_postprocessed_frame_to_cache(clip, user, ibuf, flag, postprocess_flag);
1223 }
1224 }
1225 }
1226
1228
1229 /* Fallback render in case proxies are not enabled or built */
1232 {
1233 MovieClipUser user_fallback = *user;
1235
1237 clip, &user_fallback, flag, postprocess_flag, cache_flag);
1238 }
1239
1240 return ibuf;
1241}
1242
1248
1250 const MovieClipUser *user,
1251 const MovieClipFlag flag,
1252 const MovieClipCacheFlag cache_flag)
1253{
1255 clip, user, flag, MovieClipPostprocFlag::None, cache_flag);
1256}
1257
1259 const MovieClipUser *user,
1260 const MovieClipPostprocFlag postprocess_flag)
1261{
1263 clip, user, clip->flag, postprocess_flag, MovieClipCacheFlag::None);
1264}
1265
1267 const MovieClipUser *user,
1268 ImBuf *reference_ibuf,
1269 const int framenr,
1270 const MovieClipPostprocFlag postprocess_flag)
1271{
1272 MovieClipCache *cache = clip->cache;
1273 MovieTracking *tracking = &clip->tracking;
1274 ImBuf *stableibuf;
1275 float tloc[2], tscale, tangle;
1276 short proxy = IMB_PROXY_NONE;
1277 int render_flag = 0;
1278 int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr);
1279
1280 if (clip->flag & MCLIP_USE_PROXY) {
1281 proxy = rendersize_to_proxy(user, clip->flag);
1282 render_flag = user->render_flag;
1283 }
1284
1285 /* there's no cached frame or it was calculated for another frame */
1286 if (!cache->stabilized.ibuf || cache->stabilized.framenr != framenr) {
1287 return nullptr;
1288 }
1289
1290 if (cache->stabilized.reference_ibuf != reference_ibuf) {
1291 return nullptr;
1292 }
1293
1294 /* cached ibuf used different proxy settings */
1295 if (cache->stabilized.render_flag != render_flag || cache->stabilized.proxy != proxy) {
1296 return nullptr;
1297 }
1298
1299 if (cache->stabilized.postprocess_flag != postprocess_flag) {
1300 return nullptr;
1301 }
1302
1303 /* stabilization also depends on pixel aspect ratio */
1304 if (cache->stabilized.aspect != tracking->camera.pixel_aspect) {
1305 return nullptr;
1306 }
1307
1308 if (cache->stabilized.filter != tracking->stabilization.filter) {
1309 return nullptr;
1310 }
1311
1312 stableibuf = cache->stabilized.ibuf;
1313
1315 clip, clip_framenr, stableibuf->x, stableibuf->y, tloc, &tscale, &tangle);
1316
1317 /* check for stabilization parameters */
1318 if (tscale != cache->stabilized.scale || tangle != cache->stabilized.angle ||
1319 !equals_v2v2(tloc, cache->stabilized.loc))
1320 {
1321 return nullptr;
1322 }
1323
1324 IMB_refImBuf(stableibuf);
1325
1326 return stableibuf;
1327}
1328
1330 const MovieClipUser *user,
1331 ImBuf *ibuf,
1332 const int framenr,
1333 const MovieClipPostprocFlag postprocess_flag)
1334{
1335 MovieClipCache *cache = clip->cache;
1336 MovieTracking *tracking = &clip->tracking;
1337 ImBuf *stableibuf;
1338 float tloc[2], tscale, tangle;
1339 int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr);
1340
1341 stableibuf = BKE_tracking_stabilize_frame(clip, clip_framenr, ibuf, tloc, &tscale, &tangle);
1342
1343 copy_v2_v2(cache->stabilized.loc, tloc);
1344
1345 cache->stabilized.reference_ibuf = ibuf;
1346 cache->stabilized.scale = tscale;
1347 cache->stabilized.angle = tangle;
1348 cache->stabilized.framenr = framenr;
1349 cache->stabilized.aspect = tracking->camera.pixel_aspect;
1350 cache->stabilized.filter = tracking->stabilization.filter;
1351
1352 if (clip->flag & MCLIP_USE_PROXY) {
1353 cache->stabilized.proxy = rendersize_to_proxy(user, clip->flag);
1354 cache->stabilized.render_flag = user->render_flag;
1355 }
1356 else {
1357 cache->stabilized.proxy = IMB_PROXY_NONE;
1358 cache->stabilized.render_flag = 0;
1359 }
1360
1361 cache->stabilized.postprocess_flag = postprocess_flag;
1362
1363 if (cache->stabilized.ibuf) {
1364 IMB_freeImBuf(cache->stabilized.ibuf);
1365 }
1366
1367 cache->stabilized.ibuf = stableibuf;
1368
1369 IMB_refImBuf(stableibuf);
1370
1371 return stableibuf;
1372}
1373
1375 const MovieClipUser *user,
1376 const MovieClipPostprocFlag postprocess_flag,
1377 float r_loc[2],
1378 float *r_scale,
1379 float *r_angle)
1380{
1381 ImBuf *ibuf, *stableibuf = nullptr;
1382 int framenr = user->framenr;
1383
1384 ibuf = BKE_movieclip_get_postprocessed_ibuf(clip, user, postprocess_flag);
1385
1386 if (!ibuf) {
1387 return nullptr;
1388 }
1389
1391 MovieClipCache *cache = clip->cache;
1392
1393 stableibuf = get_stable_cached_frame(clip, user, ibuf, framenr, postprocess_flag);
1394
1395 if (!stableibuf) {
1396 stableibuf = put_stabilized_frame_to_cache(clip, user, ibuf, framenr, postprocess_flag);
1397 }
1398
1399 if (r_loc) {
1400 copy_v2_v2(r_loc, cache->stabilized.loc);
1401 }
1402
1403 if (r_scale) {
1404 *r_scale = cache->stabilized.scale;
1405 }
1406
1407 if (r_angle) {
1408 *r_angle = cache->stabilized.angle;
1409 }
1410 }
1411 else {
1412 if (r_loc) {
1413 zero_v2(r_loc);
1414 }
1415
1416 if (r_scale) {
1417 *r_scale = 1.0f;
1418 }
1419
1420 if (r_angle) {
1421 *r_angle = 0.0f;
1422 }
1423
1424 stableibuf = ibuf;
1425 }
1426
1427 if (stableibuf != ibuf) {
1428 IMB_freeImBuf(ibuf);
1429 ibuf = stableibuf;
1430 }
1431
1432 return ibuf;
1433}
1434
1436{
1437 ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
1438
1439 if (ibuf) {
1440 IMB_freeImBuf(ibuf);
1441 return true;
1442 }
1443
1444 return false;
1445}
1446
1448 const MovieClipUser *user,
1449 int *r_width,
1450 int *r_height)
1451{
1452 /* TODO(sergey): Support reading sequences of different resolution. */
1453 if (clip->lastsize[0] != 0 && clip->lastsize[1] != 0) {
1454 *r_width = clip->lastsize[0];
1455 *r_height = clip->lastsize[1];
1456 }
1457 else {
1458 ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
1459
1460 if (ibuf && ibuf->x && ibuf->y) {
1461 real_ibuf_size(clip, user, ibuf, r_width, r_height);
1462 }
1463 else {
1464 *r_width = clip->lastsize[0];
1465 *r_height = clip->lastsize[1];
1466 }
1467
1468 if (ibuf) {
1469 IMB_freeImBuf(ibuf);
1470 }
1471 }
1472}
1473void BKE_movieclip_get_size_fl(MovieClip *clip, const MovieClipUser *user, float r_size[2])
1474{
1475 int width, height;
1476 BKE_movieclip_get_size(clip, user, &width, &height);
1477
1478 r_size[0] = float(width);
1479 r_size[1] = float(height);
1480}
1481
1483{
1484 if (!clip->len) {
1486 }
1487
1488 return clip->len;
1489}
1490
1492{
1493 if (clip->source != MCLIP_SRC_MOVIE) {
1494 return 0.0f;
1495 }
1497 if (clip->anim == nullptr) {
1498 return 0.0f;
1499 }
1500 return MOV_get_fps(clip->anim);
1501}
1502
1503void BKE_movieclip_get_aspect(MovieClip *clip, float *aspx, float *aspy)
1504{
1505 *aspx = 1.0;
1506
1507 /* x is always 1 */
1508 *aspy = clip->aspy / clip->aspx / clip->tracking.camera.pixel_aspect;
1509}
1510
1512 const MovieClipUser *user,
1513 int *r_totseg,
1514 int **r_points)
1515{
1516 *r_totseg = 0;
1517 *r_points = nullptr;
1518
1519 if (clip->cache) {
1520 int proxy = rendersize_to_proxy(user, clip->flag);
1521
1524 clip->cache->imbufcache, proxy, user->render_flag, r_totseg, r_points);
1526 }
1527}
1528
1530{
1531 /* TODO: clamp framenr here? */
1532
1533 user->framenr = framenr;
1534}
1535
1536static void free_buffers(MovieClip *clip)
1537{
1538 if (clip->cache) {
1540
1541 if (clip->cache->postprocessed.ibuf) {
1542 IMB_freeImBuf(clip->cache->postprocessed.ibuf);
1543 }
1544
1545 if (clip->cache->stabilized.ibuf) {
1546 IMB_freeImBuf(clip->cache->stabilized.ibuf);
1547 }
1548
1549 MEM_delete(clip->cache);
1550 clip->cache = nullptr;
1551 }
1552
1553 if (clip->anim) {
1554 MOV_close(clip->anim);
1555 clip->anim = nullptr;
1556 }
1557
1559 for (tex = clip->runtime.gputextures.first(); tex;
1560 tex = static_cast<MovieClip_RuntimeGPUTexture *>(tex->next))
1561 {
1562 if (tex->gputexture != nullptr) {
1564 tex->gputexture = nullptr;
1565 }
1566 }
1567 clip->runtime.gputextures.free_no_destruct();
1568}
1569
1571{
1572 free_buffers(clip);
1573}
1574
1576{
1577 if (clip->cache && clip->cache->imbufcache) {
1579 }
1580}
1581
1583{
1584 /* clear cache */
1585 free_buffers(clip);
1586
1587 /* update clip source */
1588 detect_clip_source(bmain, clip);
1589
1590 /* Tag for re-calculation of the actual size. */
1591 clip->lastsize[0] = clip->lastsize[1] = 0;
1592
1595
1596 BKE_ntree_update_tag_id_changed(bmain, &clip->id);
1597}
1598
1600 const MovieClipUser *user,
1601 MovieClipScopes *scopes)
1602{
1603 if (scopes->ok) {
1604 return;
1605 }
1606
1607 if (scopes->track_preview) {
1609 scopes->track_preview = nullptr;
1610 }
1611
1612 if (scopes->track_search) {
1613 IMB_freeImBuf(scopes->track_search);
1614 scopes->track_search = nullptr;
1615 }
1616
1617 scopes->marker = nullptr;
1618 scopes->track = nullptr;
1619 scopes->track_locked = true;
1620
1621 scopes->scene_framenr = user->framenr;
1622 scopes->ok = true;
1623
1624 if (clip == nullptr) {
1625 return;
1626 }
1627
1628 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
1629 MovieTrackingTrack *track = tracking_object->active_track;
1630 if (track == nullptr) {
1631 return;
1632 }
1633
1634 const int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr);
1635 MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
1636
1637 scopes->marker = marker;
1638 scopes->track = track;
1639
1640 if (marker->flag & MARKER_DISABLED) {
1641 scopes->track_disabled = true;
1642 }
1643 else {
1644 ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
1645
1646 scopes->track_disabled = false;
1647
1648 if (ibuf && (ibuf->byte_data() || ibuf->float_data())) {
1649 MovieTrackingMarker undist_marker = *marker;
1650
1652 int width, height;
1653 float aspy = 1.0f / clip->tracking.camera.pixel_aspect;
1654
1655 BKE_movieclip_get_size(clip, user, &width, &height);
1656
1657 undist_marker.pos[0] *= width;
1658 undist_marker.pos[1] *= height * aspy;
1659
1661 &clip->tracking, width, height, undist_marker.pos, undist_marker.pos);
1662
1663 undist_marker.pos[0] /= width;
1664 undist_marker.pos[1] /= height * aspy;
1665 }
1666
1668 ibuf, track, &undist_marker, true, true);
1669
1670 scopes->undist_marker = undist_marker;
1671
1672 scopes->frame_width = ibuf->x;
1673 scopes->frame_height = ibuf->y;
1674
1675 scopes->use_track_mask = (track->flag & TRACK_PREVIEW_ALPHA) != 0;
1676 }
1677
1678 IMB_freeImBuf(ibuf);
1679 }
1680
1681 if ((track->flag & TRACK_LOCKED) == 0) {
1682 float pat_min[2], pat_max[2];
1683
1684 scopes->track_locked = false;
1685
1686 /* XXX: would work fine with non-transformed patterns, but would likely fail
1687 * with transformed patterns, but that would be easier to debug when
1688 * we'll have real pattern sampling (at least to test) */
1689 BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
1690
1691 scopes->slide_scale[0] = pat_max[0] - pat_min[0];
1692 scopes->slide_scale[1] = pat_max[1] - pat_min[1];
1693 }
1694}
1695
1697 const ImBuf *ibuf,
1698 int cfra,
1699 int proxy_render_size,
1700 bool undistorted,
1701 bool threaded)
1702{
1703 char filepath[FILE_MAX];
1704 int quality, rectx, recty;
1705 int size = rendersize_to_number(proxy_render_size);
1706
1707 get_proxy_filepath(clip, proxy_render_size, undistorted, cfra, filepath);
1708
1709 rectx = ibuf->x * size / 100.0f;
1710 recty = ibuf->y * size / 100.0f;
1711
1712 ImBuf *scaleibuf = IMB_scale_into_new(ibuf, rectx, recty, IMBScaleFilter::Bilinear, threaded);
1713
1714 quality = clip->proxy.quality;
1715 scaleibuf->ftype = IMB_FTYPE_JPG;
1716 scaleibuf->foptions.quality = quality;
1717 if (scaleibuf->can_contain_alpha()) {
1718 scaleibuf->color_mode = ImColorMode::RGB;
1719 }
1720
1721 /* TODO: currently the most weak part of multi-threaded proxies,
1722 * could be solved in a way that thread only prepares memory
1723 * buffer and write to disk happens separately
1724 */
1726
1728 if (IMB_save_image(scaleibuf, filepath, ImBufFlags::ByteData) == 0) {
1729 perror(filepath);
1730 }
1731
1733
1734 IMB_freeImBuf(scaleibuf);
1735}
1736
1738 MovieClipFlag clip_flag,
1739 MovieDistortion *distortion,
1740 int cfra,
1741 const int *build_sizes,
1742 int build_count,
1743 bool undistorted)
1744{
1745 ImBuf *ibuf;
1746 MovieClipUser user;
1747
1748 if (!build_count) {
1749 return;
1750 }
1751
1752 user.framenr = cfra;
1753 user.render_flag = {};
1755
1756 ibuf = BKE_movieclip_get_ibuf_flag(clip, &user, clip_flag, MovieClipCacheFlag::SkipCache);
1757
1758 if (ibuf) {
1759 ImBuf *tmpibuf = ibuf;
1760 int i;
1761
1762 if (undistorted) {
1763 tmpibuf = get_undistorted_ibuf(clip, distortion, ibuf);
1764 }
1765
1766 for (i = 0; i < build_count; i++) {
1767 movieclip_build_proxy_ibuf(clip, tmpibuf, cfra, build_sizes[i], undistorted, true);
1768 }
1769
1770 IMB_freeImBuf(ibuf);
1771
1772 if (tmpibuf != ibuf) {
1773 IMB_freeImBuf(tmpibuf);
1774 }
1775 }
1776}
1777
1779 ImBuf *ibuf,
1780 MovieDistortion *distortion,
1781 int cfra,
1782 const int *build_sizes,
1783 int build_count,
1784 bool undistorted)
1785{
1786 if (!build_count) {
1787 return;
1788 }
1789
1790 if (ibuf) {
1791 ImBuf *tmpibuf = ibuf;
1792 int i;
1793
1794 if (undistorted) {
1795 tmpibuf = get_undistorted_ibuf(clip, distortion, ibuf);
1796 }
1797
1798 for (i = 0; i < build_count; i++) {
1799 movieclip_build_proxy_ibuf(clip, tmpibuf, cfra, build_sizes[i], undistorted, false);
1800 }
1801
1802 if (tmpibuf != ibuf) {
1803 IMB_freeImBuf(tmpibuf);
1804 }
1805 }
1806}
1807
1809{
1810 return clip->flag & MCLIP_USE_PROXY;
1811}
1812
1813float BKE_movieclip_remap_scene_to_clip_frame(const MovieClip *clip, const float framenr)
1814{
1815 return framenr - float(clip->start_frame) + 1.0f;
1816}
1817
1818float BKE_movieclip_remap_clip_to_scene_frame(const MovieClip *clip, const float framenr)
1819{
1820 return framenr + float(clip->start_frame) - 1.0f;
1821}
1822
1823void BKE_movieclip_filepath_for_frame(MovieClip *clip, const MovieClipUser *user, char *filepath)
1824{
1825 if (clip->source == MCLIP_SRC_SEQUENCE) {
1826 int use_proxy;
1827
1828 use_proxy = (clip->flag & MCLIP_USE_PROXY) &&
1830
1831 if (use_proxy) {
1832 int undistort = user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
1833 get_proxy_filepath(clip, user->render_size, undistort, user->framenr, filepath);
1834 }
1835 else {
1836 get_sequence_filepath(clip, user->framenr, filepath);
1837 }
1838 }
1839 else {
1840 BLI_strncpy(filepath, clip->filepath, FILE_MAX);
1841 BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&clip->id));
1842 }
1843}
1844
1846{
1847 ImBuf *ibuf = nullptr;
1848
1849 if (clip->source == MCLIP_SRC_MOVIE) {
1850 ibuf = movieclip_load_movie_file(clip, user, user->framenr, clip->flag);
1851 }
1852
1853 return ibuf;
1854}
1855
1857{
1858 bool has_frame = false;
1859
1861 has_frame = has_imbuf_cache(clip, user, clip->flag);
1863
1864 return has_frame;
1865}
1866
1868{
1869 bool result;
1870
1872 result = put_imbuf_cache(clip, user, ibuf, clip->flag, false);
1874
1875 return result;
1876}
1877
1878static void movieclip_eval_update_reload(Depsgraph *depsgraph, Main *bmain, MovieClip *clip)
1879{
1880 BKE_movieclip_reload(bmain, clip);
1881 if (DEG_is_active(depsgraph)) {
1882 MovieClip *clip_orig = DEG_get_original(clip);
1883 BKE_movieclip_reload(bmain, clip_orig);
1884 }
1885}
1886
1887static void movieclip_eval_update_generic(Depsgraph *depsgraph, MovieClip *clip)
1888{
1890 if (DEG_is_active(depsgraph)) {
1891 MovieClip *clip_orig = DEG_get_original(clip);
1893 }
1894}
1895
1896void BKE_movieclip_eval_update(Depsgraph *depsgraph, Main *bmain, MovieClip *clip)
1897{
1898 DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip);
1899 if (clip->id.recalc & ID_RECALC_SOURCE) {
1900 movieclip_eval_update_reload(depsgraph, bmain, clip);
1901 }
1902 else {
1903 movieclip_eval_update_generic(depsgraph, clip);
1904 }
1905 clip->runtime.last_update = DEG_get_update_count(depsgraph);
1906}
1907
1908/* -------------------------------------------------------------------- */
1911
1913{
1914 /* Check if we have an existing entry for that clip user. */
1916 for (tex = clip->runtime.gputextures.first(); tex;
1917 tex = static_cast<MovieClip_RuntimeGPUTexture *>(tex->next))
1918 {
1919 if (memcmp(&tex->user, cuser, sizeof(MovieClipUser)) == 0) {
1920 break;
1921 }
1922 }
1923
1924 /* If not, allocate a new one. */
1925 if (tex == nullptr) {
1926 tex = MEM_new<MovieClip_RuntimeGPUTexture>(__func__);
1927 memcpy(&tex->user, cuser, sizeof(MovieClipUser));
1928 BLI_addtail(&clip->runtime.gputextures, tex);
1929 }
1930
1931 return &tex->gputexture;
1932}
1933
1935{
1936 if (clip == nullptr) {
1937 return nullptr;
1938 }
1939
1940 gpu::Texture **tex = movieclip_get_gputexture_ptr(clip, cuser);
1941 if (*tex) {
1942 return *tex;
1943 }
1944
1945 /* check if we have a valid image buffer */
1946 ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, cuser);
1947 if (ibuf == nullptr) {
1948 CLOG_ERROR(&LOG, "Failed to create GPU texture from Blender movie clip");
1949 *tex = GPU_texture_create_error(2, false);
1950 return *tex;
1951 }
1952
1953 /* This only means RGBA16F instead of RGBA32F. */
1956 if (!ibuf->float_data()) {
1958 }
1959 *tex = IMB_create_gpu_texture(clip->id.name + 2, ibuf, flags);
1960
1961 /* Do not generate mips for movieclips... too slow. */
1962 GPU_texture_mipmap_mode(*tex, false, true);
1963
1964 IMB_freeImBuf(ibuf);
1965
1966 return *tex;
1967}
1968
1970{
1971 /* Number of gpu textures to keep around as cache.
1972 * We don't want to keep too many GPU textures for
1973 * movie clips around, as they can be large. */
1974 const int MOVIECLIP_NUM_GPUTEXTURES = 1;
1975
1976 while (clip->runtime.gputextures.count() > MOVIECLIP_NUM_GPUTEXTURES) {
1979 /* Free GLSL image binding. */
1980 if (tex->gputexture) {
1982 }
1983 MEM_delete(tex);
1984 }
1985}
1986
1988
1989} // namespace blender
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
File and directory operations.
#define O_BINARY
#define FILE_MAX
#define BLI_path_cmp
#define SNPRINTF(dst, format,...)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define BLT_I18NCONTEXT_ID_MOVIECLIP
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define FILTER_ID_GD_LEGACY
Definition DNA_ID.h:1204
#define FILTER_ID_MC
Definition DNA_ID.h:1212
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
Definition DNA_ID.h:691
#define ID_BLEND_PATH(_bmain, _id)
Definition DNA_ID.h:688
#define FILTER_ID_IM
Definition DNA_ID.h:1206
#define IMG_SIZE_FALLBACK
Read Blender memory allocation and freeing.
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define offsetof(t, d)
#define abs
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
BMesh Iterators.
void BKE_movieclip_reload(Main *bmain, MovieClip *clip)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
static bool need_postprocessed_frame(const MovieClipUser *user, int clip_flag, MovieClipPostprocFlag postprocess_flag)
Definition movieclip.cc:992
static void movieclip_eval_update_generic(Depsgraph *depsgraph, MovieClip *clip)
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_tracking_copy(MovieTracking *tracking_dst, const MovieTracking *tracking_src, int flag)
Definition tracking.cc:311
static void movie_clip_foreach_id(ID *id, LibraryForeachIDData *data)
Definition movieclip.cc:128
void BKE_movieclip_get_size(MovieClip *clip, const MovieClipUser *user, int *r_width, int *r_height)
GPUTextureCreateFlags
Definition IMB_imbuf.hh:611
static void get_proxy_filepath(const MovieClip *clip, int proxy_render_size, bool undistorted, int framenr, char filepath[FILE_MAX])
Definition movieclip.cc:416
bool BKE_movieclip_has_frame(MovieClip *clip, const MovieClipUser *user)
static void put_postprocessed_frame_to_cache(MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, int flag, MovieClipPostprocFlag postprocess_flag)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void BKE_ntree_update_tag_id_changed(Main *bmain, ID *id)
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:324
static void movie_clip_foreach_path(ID *id, BPathForeachPathData *bpath_data)
Definition movieclip.cc:159
void BLO_read_pointer_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size)
void IMB_cache_get_cache_segments(ImBufCache *cache, int proxy, int render_flags, int *r_totseg, int **r_points)
Definition cache.cc:491
void id_us_plus(ID *id)
Definition lib_id.cc:433
uint64_t DEG_get_update_count(const Depsgraph *depsgraph)
Definition depsgraph.cc:356
void MOV_close(MovieReader *anim)
Definition movie_read.cc:70
MINLINE void copy_v2_v2(float r[2], const float a[2])
MovieTrackingObject * BKE_tracking_object_get_active(const MovieTracking *tracking)
Definition tracking.cc:1982
void BKE_tracking_stabilization_data_get(MovieClip *clip, int framenr, int width, int height, float translation[2], float *scale, float *angle)
void IMB_cache_free(ImBufCache *cache)
Definition cache.cc:446
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
void BKE_movieclip_clear_cache(MovieClip *clip)
static void movieclip_blend_read_data(BlendDataReader *reader, ID *id)
Definition movieclip.cc:257
static void movie_clip_foreach_cache(ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data)
Definition movieclip.cc:145
bool BKE_movieclip_proxy_enabled(MovieClip *clip)
ImBuf * BKE_tracking_undistort_frame(MovieTracking *tracking, ImBuf *ibuf, int calibration_width, int calibration_height, float overscan)
Definition tracking.cc:2471
void(*)(ID *id, const IDCacheKey *cache_key, void **cache_p, uint flags, void *user_data) IDTypeForeachCacheFunctionCallback
ImBuf * BKE_tracking_get_search_imbuf(const ImBuf *ibuf, const MovieTrackingTrack *track, const MovieTrackingMarker *marker, bool anchored, bool disable_channels)
Definition tracking.cc:2665
unsigned short ushort
Definition BKE_text.h:56
void DEG_debug_print_eval(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
void BKE_color_managed_colorspace_settings_copy(ColorManagedColorspaceSettings *colorspace_settings, const ColorManagedColorspaceSettings *settings)
static void write_movieReconstruction(BlendWriter *writer, MovieTrackingReconstruction *reconstruction)
Definition movieclip.cc:193
ImBuf * MOV_decode_frame(MovieReader *anim, int frame_index, IMB_Proxy_Size preview_size)
static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags)
Definition movieclip.cc:658
ImBuf * BKE_movieclip_get_postprocessed_ibuf(MovieClip *clip, const MovieClipUser *user, MovieClipPostprocFlag postprocess_flag)
bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(1)
static bool need_undistortion_postprocess(const MovieClipUser *user, int clip_flag)
Definition movieclip.cc:982
static void movieclip_eval_update_reload(Depsgraph *depsgraph, Main *bmain, MovieClip *clip)
IDTypeInfo IDType_ID_MC
Definition movieclip.cc:294
void IMB_refImBuf(ImBuf *ibuf)
ImBufCache * IMB_cache_create(const char *name, int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp)
Definition cache.cc:270
@ LOCK_MOVIECLIP
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:1063
void IMB_cache_put(ImBufCache *cache, void *userkey, ImBuf *ibuf)
Definition cache.cc:369
@ MCLIP_PROXY_RENDER_UNDISTORT
@ MCLIP_PROXY_RENDER_USE_FALLBACK_RENDER
static bool has_imbuf_cache(MovieClip *clip, const MovieClipUser *user, int flag)
Definition movieclip.cc:739
static void write_movieTracks(BlendWriter *writer, ListBaseT< MovieTrackingTrack > *tracks)
Definition movieclip.cc:166
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
@ MCLIP_PROXY_RENDER_SIZE_FULL
@ MCLIP_PROXY_RENDER_SIZE_100
float BKE_movieclip_get_fps(MovieClip *clip)
void BKE_id_blend_write(BlendWriter *writer, ID *id)
Definition lib_id.cc:2890
static void direct_link_movieTracks(BlendDataReader *reader, ListBaseT< MovieTrackingTrack > *tracksbase)
Definition movieclip.cc:231
static void movieclip_open_anim_file(MovieClip *clip)
Definition movieclip.cc:499
@ LIB_ID_CREATE_NO_USER_REFCOUNT
void BKE_movieclip_get_size_fl(MovieClip *clip, const MovieClipUser *user, float r_size[2])
ImBuf * IMB_dupImBuf(const ImBuf *ibuf1)
ImBuf * IMB_cache_get(ImBufCache *cache, void *userkey, bool *r_is_cached_empty)
Definition cache.cc:403
void BKE_tracking_dopesheet_tag_update(MovieTracking *tracking)
Definition tracking.cc:3355
static ImBuf * put_stabilized_frame_to_cache(MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, const int framenr, const MovieClipPostprocFlag postprocess_flag)
static ImBuf * postprocess_frame(MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, int flag, MovieClipPostprocFlag postprocess_flag)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:259
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
static void detect_clip_source(Main *bmain, MovieClip *clip)
Definition movieclip.cc:848
ImBuf * BKE_movieclip_anim_ibuf_for_frame_no_lock(MovieClip *clip, const MovieClipUser *user)
void IMB_cache_cleanup(ImBufCache *cache, bool(cleanup_check_cb)(ImBuf *ibuf, void *userkey, void *userdata), void *userdata)
Definition cache.cc:467
static ImBuf * movieclip_get_postprocessed_ibuf(MovieClip *clip, const MovieClipUser *user, int flag, MovieClipPostprocFlag postprocess_flag, MovieClipCacheFlag cache_flag)
void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter)
void BKE_movieclip_get_cache_segments(MovieClip *clip, const MovieClipUser *user, int *r_totseg, int **r_points)
static void movie_clip_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int flag)
Definition movieclip.cc:96
bool IMB_save_image(ImBuf *ibuf, const char *filepath, ImBufFlags flags)
Definition writeimage.cc:40
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
static ImBuf * get_imbuf_cache(MovieClip *clip, const MovieClipUser *user, int flag)
Definition movieclip.cc:712
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
ImBuf * IMB_load_image_from_filepath(const char *filepath, ImBufFlags flags, ColorManagedColorspaceSettings *colorspace_settings=nullptr)
Definition readimage.cc:201
void BKE_tracking_marker_pattern_minmax(const MovieTrackingMarker *marker, float min[2], float max[2])
Definition tracking.cc:1500
MINLINE bool equals_v4v4(const float v1[4], const float v2[4]) ATTR_WARN_UNUSED_RESULT
void BKE_movieclip_get_aspect(MovieClip *clip, float *aspx, float *aspy)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static void write_moviePlaneTracks(BlendWriter *writer, ListBaseT< MovieTrackingPlaneTrack > *plane_tracks_base)
Definition movieclip.cc:182
static void moviecache_prioritydeleter(void *priority_data_v)
Definition movieclip.cc:704
void IMB_freeImBuf(ImBuf *ibuf)
void BKE_tracking_disable_channels(ImBuf *ibuf, bool disable_red, bool disable_green, bool disable_blue, bool grayscale)
Definition tracking.cc:2820
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_tracking_undistort_v2(MovieTracking *tracking, int image_width, int image_height, const float co[2], float r_co[2])
Definition tracking.cc:2448
static ImBuf * get_stable_cached_frame(MovieClip *clip, const MovieClipUser *user, ImBuf *reference_ibuf, const int framenr, const MovieClipPostprocFlag postprocess_flag)
static bool moviecache_check_free_proxy(ImBuf *, void *userkey, void *)
Definition movieclip.cc:816
BMesh const char void * data
static int rendersize_to_proxy(const MovieClipUser *user, int flag)
Definition movieclip.cc:337
static void * moviecache_getprioritydata(void *key_v)
Definition movieclip.cc:684
static void movie_clip_free_data(ID *id)
Definition movieclip.cc:118
static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBaseT< MovieTrackingPlaneTrack > *plane_tracks_base)
Definition movieclip.cc:241
bool BKE_movieclip_put_frame_if_possible(MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf)
ImBuf * BKE_movieclip_get_stable_ibuf(MovieClip *clip, const MovieClipUser *user, MovieClipPostprocFlag postprocess_flag, float r_loc[2], float *r_scale, float *r_angle)
static void direct_link_movieReconstruction(BlendDataReader *reader, MovieTrackingReconstruction *reconstruction)
Definition movieclip.cc:225
void BKE_movieclip_build_proxy_frame_for_ibuf(MovieClip *clip, ImBuf *ibuf, MovieDistortion *distortion, int cfra, const int *build_sizes, int build_count, bool undistorted)
void BKE_tracking_settings_init(MovieTracking *tracking)
Definition tracking.cc:331
ImBuf * BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan, bool undistort)
Definition tracking.cc:2324
static void movieclip_build_proxy_ibuf(const MovieClip *clip, const ImBuf *ibuf, int cfra, int proxy_render_size, bool undistorted, bool threaded)
void BKE_movieclip_update_scopes(MovieClip *clip, const MovieClipUser *user, MovieClipScopes *scopes)
static bool check_undistortion_cache_flags(const MovieClip *clip)
ImBuf * BKE_movieclip_get_ibuf(MovieClip *clip, const MovieClipUser *user)
MovieReader * openanim(const char *filepath, ImBufFlags ibuf_flags, int streamindex, bool keep_original_colorspace, ColorManagedColorspaceSettings *colorspace_settings)
static ImBuf * movieclip_load_movie_file(MovieClip *clip, const MovieClipUser *user, int framenr, int flag)
Definition movieclip.cc:521
static gpu::Texture ** movieclip_get_gputexture_ptr(MovieClip *clip, MovieClipUser *cuser)
void BKE_movieclip_clear_proxy_cache(MovieClip *clip)
ATTR_WARN_UNUSED_RESULT const size_t num
static void movieclip_calc_length(MovieClip *clip)
Definition movieclip.cc:540
static uint movieclip_hashhash(const void *keyv)
Definition movieclip.cc:667
void BKE_color_managed_colorspace_settings_init(ColorManagedColorspaceSettings *colorspace_settings)
MovieClip * BKE_movieclip_file_add_exists(Main *bmain, const char *filepath)
Definition movieclip.cc:930
MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
static ImBuf * get_undistorted_ibuf(MovieClip *clip, MovieDistortion *distortion, ImBuf *ibuf)
Definition movieclip.cc:965
void BKE_movieclip_user_set_frame(MovieClipUser *user, int framenr)
void IMB_cache_set_priority_callback(ImBufCache *cache, ImBufCacheGetPriorityDataFP getprioritydatafp, ImBufCacheGetItemPriorityFP getitempriorityfp, ImBufCachePriorityDeleterFP prioritydeleterfp)
Definition cache.cc:299
void BLO_read_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size, const int elems=1)
float BKE_movieclip_remap_scene_to_clip_frame(const MovieClip *clip, float framenr)
static int user_frame_to_cache_frame(MovieClip *clip, int framenr)
Definition movieclip.cc:631
bool IMB_cache_has_frame(ImBufCache *cache, void *userkey)
Definition cache.cc:434
static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition movieclip.cc:201
void IMB_cache_set_getdata_callback(ImBufCache *cache, ImBufCacheGetKeyDataFP getdatafp)
Definition cache.cc:294
void BKE_tracking_free(MovieTracking *tracking)
Definition tracking.cc:159
int BKE_movieclip_get_duration(MovieClip *clip)
T * DEG_get_original(T *id)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
bool BKE_bpath_foreach_path_fixed_process(BPathForeachPathData *bpath_data, char *path, size_t path_maxncpy)
Definition bpath.cc:130
static void movie_clip_init_data(ID *id)
Definition movieclip.cc:87
@ INDEX_ID_MC
Definition DNA_ID.h:1310
gpu::Texture * IMB_create_gpu_texture(const char *name, ImBuf *ibuf, GPUTextureCreateFlags flags)
Definition util_gpu.cc:452
ImBuf * BKE_movieclip_get_ibuf_flag(MovieClip *clip, const MovieClipUser *user, MovieClipFlag flag, MovieClipCacheFlag cache_flag)
static void movie_clip_runtime_reset(MovieClip *clip)
Definition movieclip.cc:78
bool IMB_cache_put_if_possible(ImBufCache *cache, void *userkey, ImBuf *ibuf)
Definition cache.cc:374
void GPU_texture_free(gpu::Texture *texture)
void BKE_movieclip_build_proxy_frame(MovieClip *clip, MovieClipFlag clip_flag, MovieDistortion *distortion, int cfra, const int *build_sizes, int build_count, bool undistorted)
static ImBuf * movieclip_load_sequence_file(MovieClip *clip, const MovieClipUser *user, int framenr, int flag)
Definition movieclip.cc:459
@ ID_RECALC_SOURCE
Definition DNA_ID.h:1143
float MOV_get_fps(const MovieReader *anim)
static bool put_imbuf_cache(MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, int flag, bool destructive)
Definition movieclip.cc:761
static int moviecache_getitempriority(void *last_userkey_v, void *priority_data_v)
Definition movieclip.cc:695
static bool imbufcache_hashcmp(const void *av, const void *bv)
Definition movieclip.cc:675
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
Definition path_utils.cc:61
void BLI_path_split_dir_file(const char *filepath, char *dir, size_t dir_maxncpy, char *file, size_t file_maxncpy) ATTR_NONNULL(1
static void free_buffers(MovieClip *clip)
ImBuf * BKE_tracking_stabilize_frame(MovieClip *clip, int framenr, ImBuf *ibuf, float translation[2], float *scale, float *angle)
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
static CLG_LogRef LOG
Definition logging.cpp:12
bool BKE_movieclip_has_cached_frame(MovieClip *clip, const MovieClipUser *user)
gpu::Texture * GPU_texture_create_error(int dimension, bool array)
float BKE_movieclip_remap_clip_to_scene_frame(const MovieClip *clip, float framenr)
void MOV_set_custom_proxy_dir(MovieReader *anim, const char *dir)
MINLINE void copy_v4_v4(float r[4], const float a[4])
static void real_ibuf_size(const MovieClip *clip, const MovieClipUser *user, const ImBuf *ibuf, int *width, int *height)
Definition movieclip.cc:935
void BKE_movieclip_eval_update(Depsgraph *depsgraph, Main *bmain, MovieClip *clip)
static int sequence_guess_offset(const char *full_name, int head_len, ushort numlen)
Definition movieclip.cc:328
void BKE_movieclip_free_gputexture(MovieClip *clip)
static MovieClip * movieclip_alloc(Main *bmain, const char *name)
Definition movieclip.cc:826
ImBuf * IMB_scale_into_new(const ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
Definition scaling.cc:531
bool IMB_scale(ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
Definition scaling.cc:467
static ImBuf * get_postprocessed_cached_frame(const MovieClip *clip, const MovieClipUser *user, int flag, MovieClipPostprocFlag postprocess_flag)
int MOV_get_duration_frames(const MovieReader *anim)
void BLI_thread_unlock(int type)
Definition threads.cc:336
static int rendersize_to_number(int render_size)
Definition movieclip.cc:363
static void movieclip_load_get_size(MovieClip *clip)
Definition movieclip.cc:835
gpu::Texture * BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser)
MINLINE void zero_v2(float r[2])
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612
bool BLI_file_ensure_parent_dir_exists(const char *filepath) ATTR_NONNULL(1)
Definition fileops_c.cc:454
MovieClip * BKE_movieclip_file_add(Main *bmain, const char *filepath)
Definition movieclip.cc:866
MovieClip * BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, bool *r_exists)
Definition movieclip.cc:902
char char size_t char * BLI_strncat(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void BLI_thread_lock(int type)
Definition threads.cc:331
void BKE_movieclip_filepath_for_frame(MovieClip *clip, const MovieClipUser *user, char *filepath)
static void get_sequence_filepath(const MovieClip *clip, const int framenr, char filepath[FILE_MAX])
Definition movieclip.cc:385
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition BKE_idtype.hh:50
MovieTrackingMarker * BKE_tracking_marker_get(MovieTrackingTrack *track, int framenr)
Definition tracking.cc:1363
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void write_pointer_array(int64_t num, const void *data)
void write_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_array(const int64_t array_size, const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
unsigned int id_session_uid
Definition BKE_idtype.hh:78
char name[258]
Definition DNA_ID.h:433
void * next
Definition DNA_ID.h:418
unsigned int recalc
Definition DNA_ID.h:446
ImbFormatOptions foptions
const uint8_t * byte_data() const
const float * float_data() const
ImColorMode color_mode
eImbFileType ftype
bool can_contain_alpha() const
ListBaseT< MovieClip > movieclips
Definition BKE_main.hh:419
struct blender::MovieClipCache::@040202166235346345247040047204042373030372021373 postprocessed
struct blender::MovieClipCache::@172310131335001324254172243023316024314303310246 stabilized
ImBufCache * imbufcache
Definition movieclip.cc:579
struct MovieTrackingTrack * track
struct MovieTrackingMarker * marker
struct MovieTrackingMarker undist_marker
eMovieClipProxy_RenderFlag render_flag
eMovieClipProxy_RenderSize render_size
ListBaseT< MovieClip_RuntimeGPUTexture > gputextures
struct MovieReader * anim
struct MovieClipCache * cache
ColorManagedColorspaceSettings colorspace_settings
struct MovieTracking tracking
MovieClip_Runtime runtime
ListBaseT< MovieTrackingDopesheetCoverageSegment > coverage_segments
ListBaseT< MovieTrackingDopesheetChannel > channels
MovieTrackingTrack * active_track
struct MovieReconstructedCamera * cameras
TrackingStabilizationFilter filter
struct MovieTrackingTrack * next
MovieTrackingMarker * markers
MovieTrackingStats * stats
MovieTrackingPlaneTrack * act_plane_track_legacy
ListBaseT< MovieTrackingPlaneTrack > plane_tracks_legacy
MovieTrackingCamera camera
MovieTrackingStabilization stabilization
ListBaseT< MovieTrackingTrack > tracks_legacy
MovieTrackingReconstruction reconstruction_legacy
MovieTrackingTrack * act_track_legacy
ListBaseT< MovieTrackingObject > objects
MovieTrackingDopesheet dopesheet
#define SEP_STR
Definition unit.cc:41
#define N_(msgid)