Blender V5.3
clip_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cerrno>
10#include <fcntl.h>
11#include <mutex>
12#include <sys/types.h>
13
14#ifndef WIN32
15# include <unistd.h>
16#else
17# include <io.h>
18#endif
19
20#include "MEM_guardedalloc.h"
21
22#include "DNA_scene_types.h" /* min/max frames */
23#include "DNA_userdef_types.h"
24
25#include "BLI_fileops.hh"
26#include "BLI_math_vector_c.hh"
27#include "BLI_path_utils.hh"
28#include "BLI_rect.hh"
29#include "BLI_string.hh"
30#include "BLI_task_c.hh"
31#include "BLI_time.hh"
32#include "BLI_utildefines.hh"
33
34#include "BLT_translation.hh"
35
36#include "BKE_context.hh"
37#include "BKE_global.hh"
38#include "BKE_lib_id.hh"
39#include "BKE_main.hh"
40#include "BKE_movieclip.hh"
41#include "BKE_report.hh"
42#include "BKE_tracking.hh"
43
44#include "WM_api.hh"
45#include "WM_types.hh"
46
47#include "IMB_imbuf.hh"
48#include "IMB_imbuf_types.hh"
49
50#include "MOV_read.hh"
51
52#include "ED_clip.hh"
53#include "ED_screen.hh"
54
55#include "UI_interface.hh"
56
57#include "RNA_access.hh"
58#include "RNA_define.hh"
59#include "RNA_enum_types.hh"
60
61#include "UI_view2d.hh"
62
63#include "DEG_depsgraph.hh"
65
66#include "clip_intern.hh" /* own include */
67
68namespace blender {
69
70/* -------------------------------------------------------------------- */
73
74static void sclip_zoom_set(const bContext *C,
75 float zoom,
76 const float location[2],
77 const bool zoom_to_pos)
78{
80 ARegion *region = CTX_wm_region(C);
81
82 float oldzoom = sc->zoom;
83 int width, height;
84
85 sc->zoom = zoom;
86
87 if (sc->zoom < 0.1f || sc->zoom > 4.0f) {
88 /* check zoom limits */
89 ED_space_clip_get_size(sc, &width, &height);
90
91 width *= sc->zoom;
92 height *= sc->zoom;
93
94 if ((width < 4) && (height < 4) && sc->zoom < oldzoom) {
95 sc->zoom = oldzoom;
96 }
97 else if (BLI_rcti_size_x(&region->winrct) <= sc->zoom) {
98 sc->zoom = oldzoom;
99 }
100 else if (BLI_rcti_size_y(&region->winrct) <= sc->zoom) {
101 sc->zoom = oldzoom;
102 }
103 }
104
105 if (zoom_to_pos && location) {
106 float aspx, aspy, w, h, dx, dy;
107
108 ED_space_clip_get_size(sc, &width, &height);
109 ED_space_clip_get_aspect(sc, &aspx, &aspy);
110
111 w = width * aspx;
112 h = height * aspy;
113
114 dx = ((location[0] - 0.5f) * w - sc->xof) * (sc->zoom - oldzoom) / sc->zoom;
115 dy = ((location[1] - 0.5f) * h - sc->yof) * (sc->zoom - oldzoom) / sc->zoom;
116
118 sc->xlockof += dx;
119 sc->ylockof += dy;
120 }
121 else {
122 sc->xof += dx;
123 sc->yof += dy;
124 }
125 }
126}
127
129 float zoomfac,
130 const float location[2],
131 const bool zoom_to_pos)
132{
134
135 sclip_zoom_set(C, sc->zoom * zoomfac, location, zoom_to_pos);
136}
137
138static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float factor)
139{
140 ARegion *region = CTX_wm_region(C);
141
142 float location[2], *mpos = nullptr;
143
144 if (event) {
146
147 ED_clip_mouse_pos(sc, region, event->mval, location);
148 mpos = location;
149 }
150
151 sclip_zoom_set_factor(C, factor, mpos, mpos ? (U.uiflag & USER_ZOOM_TO_MOUSEPOS) != 0 : false);
152
153 ED_region_tag_redraw(region);
154}
155
157
158/* -------------------------------------------------------------------- */
161
162static void clip_filesel(bContext *C, wmOperator *op, const char *dirpath)
163{
164 RNA_string_set(op->ptr, "directory", dirpath);
165
167}
168
169static void open_init(bContext *C, wmOperator *op)
170{
171 PropertyPointerRNA *pprop;
172
173 op->customdata = pprop = MEM_new<PropertyPointerRNA>("OpenPropertyPointerRNA");
175}
176
177static void open_cancel(bContext * /*C*/, wmOperator *op)
178{
179 if (op->customdata) {
180 PropertyPointerRNA *pprop = static_cast<PropertyPointerRNA *>(op->customdata);
181 op->customdata = nullptr;
182 MEM_delete(pprop);
183 }
184}
185
187{
189 bScreen *screen = CTX_wm_screen(C);
190 Main *bmain = CTX_data_main(C);
191 PropertyPointerRNA *pprop;
192 MovieClip *clip = nullptr;
193 char filepath[FILE_MAX];
194
195 if (!RNA_collection_is_empty(op->ptr, "files")) {
196 PointerRNA fileptr;
197 PropertyRNA *prop;
198 char dir_only[FILE_MAX], file_only[FILE_MAX];
199 bool relative = RNA_boolean_get(op->ptr, "relative_path");
200
201 RNA_string_get(op->ptr, "directory", dir_only);
202 if (relative) {
203 BLI_path_rel(dir_only, bmain->filepath);
204 }
205
206 prop = RNA_struct_find_property(op->ptr, "files");
207 RNA_property_collection_lookup_int(op->ptr, prop, 0, &fileptr);
208 RNA_string_get(&fileptr, "name", file_only);
209
210 BLI_path_join(filepath, sizeof(filepath), dir_only, file_only);
211 }
212 else {
213 BKE_report(op->reports, RPT_ERROR, "No files selected to be opened");
214
215 return OPERATOR_CANCELLED;
216 }
217
218 /* default to frame 1 if there's no scene in context */
219
220 errno = 0;
221
222 clip = BKE_movieclip_file_add_exists(bmain, filepath);
223
224 if (!clip) {
225 if (op->customdata) {
226 pprop = static_cast<PropertyPointerRNA *>(op->customdata);
227 op->customdata = nullptr;
228 MEM_delete(pprop);
229 }
230
232 RPT_ERROR,
233 "Cannot read '%s': %s",
234 filepath,
235 errno ? strerror(errno) : RPT_("unsupported movie clip format"));
236
237 return OPERATOR_CANCELLED;
238 }
239
240 if (!op->customdata) {
241 open_init(C, op);
242 }
243
244 /* hook into UI */
245 pprop = static_cast<PropertyPointerRNA *>(op->customdata);
246
247 if (pprop->prop) {
248 /* when creating new ID blocks, use is already 1, but RNA
249 * pointer use also increases user, so this compensates it */
250 id_us_min(&clip->id);
251
252 PointerRNA idptr = RNA_id_pointer_create(&clip->id);
253 RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr, nullptr);
254 RNA_property_update(C, &pprop->ptr, pprop->prop);
255 }
256 else if (sc) {
257 ED_space_clip_set_clip(C, screen, sc, clip);
258 }
259
261
263 op->customdata = nullptr;
264 MEM_delete(pprop);
265
266 return OPERATOR_FINISHED;
267}
268
269static wmOperatorStatus open_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
270{
272 char dirpath[FILE_MAX];
273 MovieClip *clip = nullptr;
274
275 if (sc) {
276 clip = ED_space_clip_get_clip(sc);
277 }
278
279 if (clip) {
280 STRNCPY(dirpath, clip->filepath);
281
282 BLI_path_abs(dirpath, ID_BLEND_PATH_FROM_GLOBAL(&clip->id));
283 BLI_path_parent_dir(dirpath);
284 }
285 else {
286 STRNCPY(dirpath, U.textudir);
287 }
288
289 if (RNA_struct_property_is_set(op->ptr, "files")) {
290 return open_exec(C, op);
291 }
292
293 if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
294 RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0);
295 }
296
297 open_init(C, op);
298
299 clip_filesel(C, op, dirpath);
300
302}
303
305{
306 /* identifiers */
307 ot->name = "Open Clip";
308 ot->description = "Load a sequence of frames or a movie file";
309 ot->idname = "CLIP_OT_open";
310
311 /* API callbacks. */
312 ot->exec = open_exec;
313 ot->invoke = open_invoke;
314 ot->cancel = open_cancel;
315
316 /* flags */
318
319 /* properties */
327}
328
330
331/* -------------------------------------------------------------------- */
334
336{
338
339 if (!clip) {
340 return OPERATOR_CANCELLED;
341 }
342
345
347
348 return OPERATOR_FINISHED;
349}
350
352{
353 /* identifiers */
354 ot->name = "Reload Clip";
355 ot->description = "Reload clip";
356 ot->idname = "CLIP_OT_reload";
357
358 /* API callbacks. */
359 ot->exec = reload_exec;
360}
361
363
364/* -------------------------------------------------------------------- */
367
368namespace {
369
370struct ViewPanData {
371 float x, y;
372 float xof, yof, xorig, yorig;
373 int launch_event;
374 bool own_cursor;
375 float *vec;
376};
377
378} // namespace
379
380static void view_pan_init(bContext *C, wmOperator *op, const wmEvent *event)
381{
382 wmWindow *win = CTX_wm_window(C);
384 ViewPanData *vpd;
385
386 op->customdata = vpd = MEM_new_zeroed<ViewPanData>("ClipViewPanData");
387
388 /* Grab will be set when running from gizmo. */
389 vpd->own_cursor = WM_cursor_modal_is_set_ok(win);
390 if (vpd->own_cursor) {
392 }
393
394 vpd->x = event->xy[0];
395 vpd->y = event->xy[1];
396
398 vpd->vec = &sc->xlockof;
399 }
400 else {
401 vpd->vec = &sc->xof;
402 }
403
404 copy_v2_v2(&vpd->xof, vpd->vec);
405 copy_v2_v2(&vpd->xorig, &vpd->xof);
406
407 vpd->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
408
410}
411
412static void view_pan_exit(bContext *C, wmOperator *op, bool cancel)
413{
414 ViewPanData *vpd = static_cast<ViewPanData *>(op->customdata);
415
416 if (cancel) {
417 copy_v2_v2(vpd->vec, &vpd->xorig);
418
420 }
421
422 if (vpd->own_cursor) {
424 }
425 MEM_delete(vpd);
426}
427
429{
431 float offset[2];
432
433 RNA_float_get_array(op->ptr, "offset", offset);
434
436 sc->xlockof += offset[0];
437 sc->ylockof += offset[1];
438 }
439 else {
440 sc->xof += offset[0];
441 sc->yof += offset[1];
442 }
443
445
446 return OPERATOR_FINISHED;
447}
448
450{
451 if (event->type == MOUSEPAN) {
453 float offset[2];
454
455 offset[0] = (event->prev_xy[0] - event->xy[0]) / sc->zoom;
456 offset[1] = (event->prev_xy[1] - event->xy[1]) / sc->zoom;
457
458 RNA_float_set_array(op->ptr, "offset", offset);
459
460 view_pan_exec(C, op);
461
462 return OPERATOR_FINISHED;
463 }
464
465 view_pan_init(C, op, event);
466
468}
469
471{
473 ViewPanData *vpd = static_cast<ViewPanData *>(op->customdata);
474 float offset[2];
475
476 switch (event->type) {
477 case MOUSEMOVE:
478 copy_v2_v2(vpd->vec, &vpd->xorig);
479 offset[0] = (vpd->x - event->xy[0]) / sc->zoom;
480 offset[1] = (vpd->y - event->xy[1]) / sc->zoom;
481 RNA_float_set_array(op->ptr, "offset", offset);
482 view_pan_exec(C, op);
483 break;
484 case EVT_ESCKEY:
485 view_pan_exit(C, op, true);
486
487 return OPERATOR_CANCELLED;
488 case EVT_SPACEKEY:
489 view_pan_exit(C, op, false);
490
491 return OPERATOR_FINISHED;
492 default:
493 if (event->type == vpd->launch_event && event->val == KM_RELEASE) {
494 view_pan_exit(C, op, false);
495
496 return OPERATOR_FINISHED;
497 }
498 break;
499 }
500
502}
503
505{
506 view_pan_exit(C, op, true);
507}
508
510{
511 /* identifiers */
512 ot->name = "Pan View";
513 ot->idname = "CLIP_OT_view_pan";
514 ot->description = "Pan the view";
515
516 /* API callbacks. */
517 ot->exec = view_pan_exec;
519 ot->modal = view_pan_modal;
522
523 /* flags */
525
526 /* properties */
528 "offset",
529 2,
530 nullptr,
531 -FLT_MAX,
532 FLT_MAX,
533 "Offset",
534 "Offset in floating-point units, 1.0 is the width and height of the image",
535 -FLT_MAX,
536 FLT_MAX);
537}
538
540
541/* -------------------------------------------------------------------- */
544
545namespace {
546
547struct ViewZoomData {
548 float x, y;
549 float zoom;
550 int launch_event;
551 float location[2];
552 wmTimer *timer;
553 double timer_lastdraw;
554 bool own_cursor;
555};
556
557} // namespace
558
559static void view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event)
560{
561 wmWindow *win = CTX_wm_window(C);
563 ARegion *region = CTX_wm_region(C);
564 ViewZoomData *vpd;
565
566 op->customdata = vpd = MEM_new_zeroed<ViewZoomData>("ClipViewZoomData");
567
568 /* Grab will be set when running from gizmo. */
569 vpd->own_cursor = WM_cursor_modal_is_set_ok(win);
570 if (vpd->own_cursor) {
572 }
573
574 if (U.viewzoom == USER_ZOOM_CONTINUE) {
575 /* needs a timer to continue redrawing */
576 vpd->timer = WM_event_timer_add(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
577 vpd->timer_lastdraw = BLI_time_now_seconds();
578 }
579
580 vpd->x = event->xy[0];
581 vpd->y = event->xy[1];
582 vpd->zoom = sc->zoom;
583 vpd->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
584
585 ED_clip_mouse_pos(sc, region, event->mval, vpd->location);
586
588}
589
590static void view_zoom_exit(bContext *C, wmOperator *op, bool cancel)
591{
593 ViewZoomData *vpd = static_cast<ViewZoomData *>(op->customdata);
594
595 if (cancel) {
596 sc->zoom = vpd->zoom;
598 }
599
600 if (vpd->timer) {
601 WM_event_timer_remove(CTX_wm_manager(C), vpd->timer->win, vpd->timer);
602 }
603
604 if (vpd->own_cursor) {
606 }
607 MEM_delete(vpd);
608}
609
611{
612 sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), nullptr, false);
613
615
616 return OPERATOR_FINISHED;
617}
618
620{
621 if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) {
622 float delta, factor;
623
624 delta = event->prev_xy[0] - event->xy[0] + event->prev_xy[1] - event->xy[1];
625
626 if (U.uiflag & USER_ZOOM_INVERT) {
627 delta *= -1;
628 }
629
630 factor = 1.0f + delta / 300.0f;
631 RNA_float_set(op->ptr, "factor", factor);
632
633 sclip_zoom_set_factor_exec(C, event, factor);
634
635 return OPERATOR_FINISHED;
636 }
637
638 view_zoom_init(C, op, event);
639
641}
642
643static void view_zoom_apply(
644 bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event, const bool zoom_to_pos)
645{
646 float factor;
647 float delta;
648
649 if (U.viewzoom != USER_ZOOM_SCALE) {
650 if (U.uiflag & USER_ZOOM_HORIZ) {
651 delta = float(event->xy[0] - vpd->x);
652 }
653 else {
654 delta = float(event->xy[1] - vpd->y);
655 }
656 }
657 else {
658 delta = event->xy[0] - vpd->x + event->xy[1] - vpd->y;
659 }
660
661 delta /= U.pixelsize;
662
663 if (U.uiflag & USER_ZOOM_INVERT) {
664 delta = -delta;
665 }
666
667 if (U.viewzoom == USER_ZOOM_CONTINUE) {
668 SpaceClip *sclip = CTX_wm_space_clip(C);
669 double time = BLI_time_now_seconds();
670 float time_step = float(time - vpd->timer_lastdraw);
671 float zfac;
672
673 zfac = 1.0f + ((delta / 20.0f) * time_step);
674 vpd->timer_lastdraw = time;
675 factor = (sclip->zoom * zfac) / vpd->zoom;
676 }
677 else {
678 factor = 1.0f + delta / 300.0f;
679 }
680
681 RNA_float_set(op->ptr, "factor", factor);
682 sclip_zoom_set(C, vpd->zoom * factor, vpd->location, zoom_to_pos);
684}
685
687{
688 ViewZoomData *vpd = static_cast<ViewZoomData *>(op->customdata);
689 const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
690 switch (event->type) {
691 case TIMER:
692 if (event->customdata == vpd->timer) {
693 view_zoom_apply(C, vpd, op, event, use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS));
694 }
695 break;
696 case MOUSEMOVE:
697 view_zoom_apply(C, vpd, op, event, use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS));
698 break;
699 default:
700 if (event->type == vpd->launch_event && event->val == KM_RELEASE) {
701 view_zoom_exit(C, op, false);
702
703 return OPERATOR_FINISHED;
704 }
705 break;
706 }
707
709}
710
712{
713 view_zoom_exit(C, op, true);
714}
715
717{
718 PropertyRNA *prop;
719
720 /* identifiers */
721 ot->name = "View Zoom";
722 ot->idname = "CLIP_OT_view_zoom";
723 ot->description = "Zoom in/out the view";
724
725 /* API callbacks. */
726 ot->exec = view_zoom_exec;
731
732 /* flags */
734
735 /* properties */
736 prop = RNA_def_float(ot->srna,
737 "factor",
738 0.0f,
739 -FLT_MAX,
740 FLT_MAX,
741 "Factor",
742 "Zoom factor, values higher than 1.0 zoom in, lower values zoom out",
743 -FLT_MAX,
744 FLT_MAX);
746
748}
749
751
752/* -------------------------------------------------------------------- */
755
757{
758 float location[2];
759
760 RNA_float_get_array(op->ptr, "location", location);
761
762 sclip_zoom_set_factor(C, powf(2.0f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS);
763
765
766 return OPERATOR_FINISHED;
767}
768
770{
772 ARegion *region = CTX_wm_region(C);
773
774 float location[2];
775
776 ED_clip_mouse_pos(sc, region, event->mval, location);
777 RNA_float_set_array(op->ptr, "location", location);
778
779 return view_zoom_in_exec(C, op);
780}
781
783{
784 PropertyRNA *prop;
785
786 /* identifiers */
787 ot->name = "Zoom In";
788 ot->idname = "CLIP_OT_view_zoom_in";
789 ot->description = "Zoom in the view";
790
791 /* API callbacks. */
795
796 /* flags */
798
799 /* properties */
800 prop = RNA_def_float_vector(ot->srna,
801 "location",
802 2,
803 nullptr,
804 -FLT_MAX,
805 FLT_MAX,
806 "Location",
807 "Cursor location in screen coordinates",
808 -10.0f,
809 10.0f);
811}
812
814{
815 float location[2];
816
817 RNA_float_get_array(op->ptr, "location", location);
818
819 sclip_zoom_set_factor(C, powf(0.5f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS);
820
822
823 return OPERATOR_FINISHED;
824}
825
827{
829 ARegion *region = CTX_wm_region(C);
830
831 float location[2];
832
833 ED_clip_mouse_pos(sc, region, event->mval, location);
834 RNA_float_set_array(op->ptr, "location", location);
835
836 return view_zoom_out_exec(C, op);
837}
838
840{
841 PropertyRNA *prop;
842
843 /* identifiers */
844 ot->name = "Zoom Out";
845 ot->idname = "CLIP_OT_view_zoom_out";
846 ot->description = "Zoom out the view";
847
848 /* API callbacks. */
852
853 /* flags */
855
856 /* properties */
857 prop = RNA_def_float_vector(ot->srna,
858 "location",
859 2,
860 nullptr,
861 -FLT_MAX,
862 FLT_MAX,
863 "Location",
864 "Cursor location in normalized (0.0 to 1.0) coordinates",
865 -10.0f,
866 10.0f);
868}
869
871
872/* -------------------------------------------------------------------- */
875
877{
879
880 sclip_zoom_set(C, RNA_float_get(op->ptr, "ratio"), nullptr, false);
881
882 /* ensure pixel exact locations for draw */
883 sc->xof = int(sc->xof);
884 sc->yof = int(sc->yof);
885
887
888 return OPERATOR_FINISHED;
889}
890
892{
893 /* identifiers */
894 ot->name = "View Zoom Ratio";
895 ot->idname = "CLIP_OT_view_zoom_ratio";
896 ot->description = "Set the zoom ratio (based on clip size)";
897
898 /* API callbacks. */
901
902 /* flags */
904
905 /* properties */
907 "ratio",
908 0.0f,
909 -FLT_MAX,
910 FLT_MAX,
911 "Ratio",
912 "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out",
913 -FLT_MAX,
914 FLT_MAX);
915}
916
918
919/* -------------------------------------------------------------------- */
922
924{
925 SpaceClip *sc;
926 ARegion *region;
927 int w, h, width, height;
928 float aspx, aspy;
929 bool fit_view = RNA_boolean_get(op->ptr, "fit_view");
930 float zoomx, zoomy;
931
932 /* retrieve state */
933 sc = CTX_wm_space_clip(C);
934 region = CTX_wm_region(C);
935
936 ED_space_clip_get_size(sc, &w, &h);
937 ED_space_clip_get_aspect(sc, &aspx, &aspy);
938
939 w = w * aspx;
940 h = h * aspy;
941
942 /* check if the image will fit in the image with zoom == 1 */
943 width = BLI_rcti_size_x(&region->winrct) + 1;
944 height = BLI_rcti_size_y(&region->winrct) + 1;
945
946 if (fit_view) {
947 const int margin = 5; /* margin from border */
948
949 zoomx = float(width) / (w + 2 * margin);
950 zoomy = float(height) / (h + 2 * margin);
951
952 sclip_zoom_set(C, min_ff(zoomx, zoomy), nullptr, false);
953 }
954 else {
955 if ((w >= width || h >= height) && (width > 0 && height > 0)) {
956 zoomx = float(width) / w;
957 zoomy = float(height) / h;
958
959 /* find the zoom value that will fit the image in the image space */
960 sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), nullptr, false);
961 }
962 else {
963 sclip_zoom_set(C, 1.0f, nullptr, false);
964 }
965 }
966
967 sc->xof = sc->yof = 0.0f;
968
969 ED_region_tag_redraw(region);
970
971 return OPERATOR_FINISHED;
972}
973
975{
976 PropertyRNA *prop;
977
978 /* identifiers */
979 ot->name = "Frame All";
980 ot->idname = "CLIP_OT_view_all";
981 ot->description = "View whole image with markers";
982
983 /* API callbacks. */
984 ot->exec = view_all_exec;
986
987 /* flags */
989
990 /* properties */
991 prop = RNA_def_boolean(ot->srna, "fit_view", false, "Fit View", "Fit frame to the viewport");
993}
994
996
997/* -------------------------------------------------------------------- */
1000
1002{
1004 ARegion *region = CTX_wm_region(C);
1005
1006 clip_view_center_to_point(sc, sc->cursor[0], sc->cursor[1]);
1007
1008 ED_region_tag_redraw(region);
1009
1010 return OPERATOR_FINISHED;
1011}
1012
1014{
1015 /* identifiers */
1016 ot->name = "Center View to Cursor";
1017 ot->description = "Center the view so that the cursor is in the middle of the view";
1018 ot->idname = "CLIP_OT_view_center_cursor";
1019
1020 /* API callbacks. */
1023}
1024
1026
1027/* -------------------------------------------------------------------- */
1030
1032{
1034 ARegion *region = CTX_wm_region(C);
1035
1036 sc->xlockof = 0.0f;
1037 sc->ylockof = 0.0f;
1038
1039 ED_clip_view_selection(C, region, true);
1040 ED_region_tag_redraw(region);
1041
1042 return OPERATOR_FINISHED;
1043}
1044
1046{
1047 /* identifiers */
1048 ot->name = "Frame Selected";
1049 ot->idname = "CLIP_OT_view_selected";
1050 ot->description = "View all selected elements";
1051
1052 /* API callbacks. */
1055
1056 /* flags */
1058}
1059
1061
1062/* -------------------------------------------------------------------- */
1065
1067{
1068 /* prevent changes during render */
1069 if (G.is_rendering) {
1070 return false;
1071 }
1072 SpaceClip *space_clip = CTX_wm_space_clip(C);
1073 return space_clip != nullptr;
1074}
1075
1077{
1078 Scene *scene = CTX_data_scene(C);
1079
1080 /* set the new frame number */
1081 scene->r.cfra = RNA_int_get(op->ptr, "frame");
1083 scene->r.subframe = 0.0f;
1084
1085 /* do updates */
1088}
1089
1091{
1092 change_frame_apply(C, op);
1093
1094 return OPERATOR_FINISHED;
1095}
1096
1097static int frame_from_event(bContext *C, const wmEvent *event)
1098{
1099 ARegion *region = CTX_wm_region(C);
1100 Scene *scene = CTX_data_scene(C);
1101 int framenr = 0;
1102
1103 if (region->regiontype == RGN_TYPE_WINDOW) {
1104 float sfra = scene->r.sfra, efra = scene->r.efra, framelen = region->winx / (efra - sfra + 1);
1105
1106 framenr = sfra + event->mval[0] / framelen;
1107 }
1108 else {
1109 float viewx, viewy;
1110
1111 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
1112
1113 framenr = round_fl_to_int(viewx);
1114 }
1115
1116 return framenr;
1117}
1118
1120{
1121 ARegion *region = CTX_wm_region(C);
1122
1123 if (region->regiontype == RGN_TYPE_WINDOW) {
1124 if (event->mval[1] > 16 * UI_SCALE_FAC) {
1125 return OPERATOR_PASS_THROUGH;
1126 }
1127 }
1128
1129 RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
1130
1131 change_frame_apply(C, op);
1132
1133 /* add temp handler */
1135
1137}
1138
1140{
1141 switch (event->type) {
1142 case EVT_ESCKEY:
1143 return OPERATOR_FINISHED;
1144
1145 case MOUSEMOVE:
1146 RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
1147 change_frame_apply(C, op);
1148 break;
1149
1150 case LEFTMOUSE:
1151 case RIGHTMOUSE:
1152 if (event->val == KM_RELEASE) {
1153 return OPERATOR_FINISHED;
1154 }
1155 break;
1156 default: {
1157 break;
1158 }
1159 }
1160
1162}
1163
1165{
1166 /* identifiers */
1167 ot->name = "Change Frame";
1168 ot->idname = "CLIP_OT_change_frame";
1169 ot->description = "Interactively change the current frame number";
1170
1171 /* API callbacks. */
1172 ot->exec = change_frame_exec;
1175 ot->poll = change_frame_poll;
1176
1177 /* flags */
1179
1180 /* rna */
1181 RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
1182}
1183
1185
1186/* -------------------------------------------------------------------- */
1189
1198
1199static void proxy_freejob(void *pjv)
1200{
1201 ProxyJob *pj = static_cast<ProxyJob *>(pjv);
1202 MEM_delete(pj);
1203}
1204
1205static int proxy_bitflag_to_array(int size_flag, int build_sizes[4], int undistort)
1206{
1207 int build_count = 0;
1208 const int size_flags[2][4] = {
1214 int size_nr = undistort ? 1 : 0;
1215
1216 if (size_flag & size_flags[size_nr][0]) {
1217 build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_25;
1218 }
1219
1220 if (size_flag & size_flags[size_nr][1]) {
1221 build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_50;
1222 }
1223
1224 if (size_flag & size_flags[size_nr][2]) {
1225 build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_75;
1226 }
1227
1228 if (size_flag & size_flags[size_nr][3]) {
1229 build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_100;
1230 }
1231
1232 return build_count;
1233}
1234
1235/* simple case for movies -- handle frame-by-frame, do threading within single frame */
1236static void do_movie_proxy(void *pjv,
1237 int * /*build_sizes*/,
1238 int /*build_count*/,
1239 const int *build_undistort_sizes,
1240 int build_undistort_count,
1241 const bool *stop,
1242 bool *do_update,
1243 float *progress)
1244{
1245 ProxyJob *pj = static_cast<ProxyJob *>(pjv);
1246 MovieClip *clip = pj->clip;
1247 MovieDistortion *distortion = nullptr;
1248
1249 if (pj->proxy_builder) {
1250 MOV_proxy_builder_process(pj->proxy_builder, stop, do_update, [&](const float new_progress) {
1251 *progress = new_progress;
1252 });
1253 }
1254
1255 if (!build_undistort_count) {
1256 if (*stop) {
1257 pj->stop = true;
1258 }
1259
1260 return;
1261 }
1262
1263 const int sfra = 1;
1264 const int efra = clip->len;
1265
1266 if (build_undistort_count) {
1267 int width, height;
1268
1269 BKE_movieclip_get_size(clip, nullptr, &width, &height);
1270
1271 distortion = BKE_tracking_distortion_new(&clip->tracking, width, height);
1272 }
1273
1274 for (int cfra = sfra; cfra <= efra; cfra++) {
1276 clip, pj->clip_flag, distortion, cfra, build_undistort_sizes, build_undistort_count, true);
1277
1278 if (*stop || G.is_break) {
1279 break;
1280 }
1281
1282 *do_update = true;
1283 *progress = (float(cfra) - sfra) / (efra - sfra);
1284 }
1285
1286 if (distortion) {
1287 BKE_tracking_distortion_free(distortion);
1288 }
1289
1290 if (*stop) {
1291 pj->stop = true;
1292 }
1293}
1294
1295/* *****
1296 * special case for sequences -- handle different frames in different threads,
1297 * loading from disk happens in critical section, decoding frame happens from
1298 * thread for maximal speed
1299 */
1300
1302 int cfra;
1303 int sfra;
1304 int efra;
1305 std::mutex mutex;
1306
1307 const bool *stop;
1309 float *progress;
1310};
1311
1318
1320 MovieClip *clip,
1321 size_t *r_size,
1322 int *r_cfra)
1323{
1324 uchar *mem = nullptr;
1325
1326 std::lock_guard lock(queue->mutex);
1327 if (!*queue->stop && queue->cfra <= queue->efra) {
1328 MovieClipUser user = {};
1329 char filepath[FILE_MAX];
1330 int file;
1331
1332 user.framenr = queue->cfra;
1333
1334 BKE_movieclip_filepath_for_frame(clip, &user, filepath);
1335
1336 file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
1337 if (file < 0) {
1338 return nullptr;
1339 }
1340
1341 const size_t size = BLI_file_descriptor_size(file);
1342 if (ELEM(size, 0, size_t(-1))) [[unlikely]] {
1343 close(file);
1344 return nullptr;
1345 }
1346
1347 mem = MEM_new_array_zeroed<uchar>(size, "movieclip proxy memory file");
1348
1349 if (BLI_read(file, mem, size) != size) {
1350 close(file);
1351 MEM_delete(mem);
1352 return nullptr;
1353 }
1354
1355 *r_size = size;
1356 *r_cfra = queue->cfra;
1357
1358 queue->cfra++;
1359 close(file);
1360
1361 *queue->do_update = true;
1362 *queue->progress = float(queue->cfra - queue->sfra) / (queue->efra - queue->sfra);
1363 }
1364 return mem;
1365}
1366
1367static void proxy_task_func(TaskPool *__restrict pool, void *task_data)
1368{
1369 ProxyThread *data = static_cast<ProxyThread *>(task_data);
1370 ProxyQueue *queue = static_cast<ProxyQueue *>(BLI_task_pool_user_data(pool));
1371 uchar *mem;
1372 size_t size;
1373 int cfra;
1374
1375 while ((mem = proxy_thread_next_frame(queue, data->clip, &size, &cfra))) {
1376 ImBuf *ibuf;
1377
1378 ibuf = IMB_load_image_from_memory(mem,
1379 size,
1381 "proxy frame",
1382 nullptr,
1383 &data->clip->colorspace_settings);
1384
1386 data->clip, ibuf, nullptr, cfra, data->build_sizes, data->build_count, false);
1387
1389 ibuf,
1390 data->distortion,
1391 cfra,
1392 data->build_undistort_sizes,
1393 data->build_undistort_count,
1394 true);
1395
1396 IMB_freeImBuf(ibuf);
1397
1398 MEM_delete(mem);
1399 }
1400}
1401
1402static void do_sequence_proxy(void *pjv,
1403 int *build_sizes,
1404 int build_count,
1405 int *build_undistort_sizes,
1406 int build_undistort_count,
1407 /* Cannot be const, because it is assigned to a non-const variable.
1408 * NOLINTNEXTLINE: readability-non-const-parameter. */
1409 bool *stop,
1410 bool *do_update,
1411 float *progress)
1412{
1413 ProxyJob *pj = static_cast<ProxyJob *>(pjv);
1414 MovieClip *clip = pj->clip;
1415 Scene *scene = pj->scene;
1416 int sfra = scene->r.sfra, efra = scene->r.efra;
1417 ProxyThread *handles;
1418 int tot_thread = BLI_task_scheduler_num_threads();
1419 int width, height;
1420
1421 if (build_undistort_count) {
1422 BKE_movieclip_get_size(clip, nullptr, &width, &height);
1423 }
1424
1425 ProxyQueue queue;
1426 queue.cfra = sfra;
1427 queue.sfra = sfra;
1428 queue.efra = efra;
1429 queue.stop = stop;
1430 queue.do_update = do_update;
1431 queue.progress = progress;
1432
1433 TaskPool *task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW);
1434 handles = MEM_new_array_zeroed<ProxyThread>(tot_thread, "proxy threaded handles");
1435 for (int i = 0; i < tot_thread; i++) {
1436 ProxyThread *handle = &handles[i];
1437
1438 handle->clip = clip;
1439
1440 handle->build_count = build_count;
1441 handle->build_sizes = build_sizes;
1442
1443 handle->build_undistort_count = build_undistort_count;
1444 handle->build_undistort_sizes = build_undistort_sizes;
1445
1446 if (build_undistort_count) {
1447 handle->distortion = BKE_tracking_distortion_new(&clip->tracking, width, height);
1448 }
1449
1450 BLI_task_pool_push(task_pool, proxy_task_func, handle, false, nullptr);
1451 }
1452
1453 BLI_task_pool_work_and_wait(task_pool);
1454 BLI_task_pool_free(task_pool);
1455
1456 if (build_undistort_count) {
1457 for (int i = 0; i < tot_thread; i++) {
1458 ProxyThread *handle = &handles[i];
1460 }
1461 }
1462
1463 MEM_delete(handles);
1464}
1465
1466static void proxy_startjob(void *pjv, wmJobWorkerStatus *worker_status)
1467{
1468 ProxyJob *pj = static_cast<ProxyJob *>(pjv);
1469 MovieClip *clip = pj->clip;
1470
1471 short size_flag;
1472 int build_sizes[4], build_count = 0;
1473 int build_undistort_sizes[4], build_undistort_count = 0;
1474
1475 size_flag = clip->proxy.build_size_flag;
1476
1477 build_count = proxy_bitflag_to_array(size_flag, build_sizes, 0);
1478 build_undistort_count = proxy_bitflag_to_array(size_flag, build_undistort_sizes, 1);
1479
1480 if (clip->source == MCLIP_SRC_MOVIE) {
1481 do_movie_proxy(pjv,
1482 build_sizes,
1483 build_count,
1484 build_undistort_sizes,
1485 build_undistort_count,
1486 &worker_status->stop,
1487 &worker_status->do_update,
1488 &worker_status->progress);
1489 }
1490 else {
1492 build_sizes,
1493 build_count,
1494 build_undistort_sizes,
1495 build_undistort_count,
1496 &worker_status->stop,
1497 &worker_status->do_update,
1498 &worker_status->progress);
1499 }
1500}
1501
1502static void proxy_endjob(void *pjv)
1503{
1504 ProxyJob *pj = static_cast<ProxyJob *>(pjv);
1505
1506 if (pj->clip->anim) {
1508 }
1509
1510 if (pj->proxy_builder) {
1512 pj->proxy_builder = nullptr;
1513 }
1514
1515 if (pj->clip->source == MCLIP_SRC_MOVIE) {
1516 /* Time-code might have changed, so do a full reload to deal with this. */
1518 }
1519 else {
1520 /* For image sequences we'll preserve original cache. */
1522 }
1523
1525}
1526
1528{
1529 wmJob *wm_job;
1530 ProxyJob *pj;
1531 Scene *scene = CTX_data_scene(C);
1532 ScrArea *area = CTX_wm_area(C);
1535
1536 if ((clip->flag & MCLIP_USE_PROXY) == 0) {
1537 return OPERATOR_CANCELLED;
1538 }
1539
1540 wm_job = WM_jobs_get(CTX_wm_manager(C),
1542 scene,
1543 "Building proxies...",
1546
1547 pj = MEM_new<ProxyJob>("proxy rebuild job");
1548 pj->scene = scene;
1549 pj->main = CTX_data_main(C);
1550 pj->clip = clip;
1552
1553 if (clip->anim) {
1556 clip->proxy.quality,
1557 true,
1558 nullptr,
1559 false);
1560 }
1561
1563 WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0);
1564 WM_jobs_callbacks(wm_job, proxy_startjob, nullptr, nullptr, proxy_endjob);
1565
1566 G.is_break = false;
1567 WM_jobs_start(CTX_wm_manager(C), wm_job);
1568
1569 ED_area_tag_redraw(area);
1570
1571 return OPERATOR_FINISHED;
1572}
1573
1575{
1576 /* identifiers */
1577 ot->name = "Rebuild Proxy";
1578 ot->idname = "CLIP_OT_rebuild_proxy";
1579 ot->description = "Rebuild all selected proxies in the background";
1580
1581 /* API callbacks. */
1584
1585 /* flags */
1586 ot->flag = OPTYPE_REGISTER;
1587}
1588
1590
1591/* -------------------------------------------------------------------- */
1594
1596{
1598 const eSpaceClip_Mode mode = eSpaceClip_Mode(RNA_enum_get(op->ptr, "mode"));
1599
1600 sc->mode = mode;
1601
1602 if (sc->mode == SC_MODE_MASKEDIT && sc->view != SC_VIEW_CLIP) {
1603 /* Make sure we are in the right view for mask editing */
1604 sc->view = SC_VIEW_CLIP;
1605 }
1606
1608
1609 return OPERATOR_FINISHED;
1610}
1611
1613{
1614 /* identifiers */
1615 ot->name = "Set Clip Mode";
1616 ot->description = "Set the clip interaction mode";
1617 ot->idname = "CLIP_OT_mode_set";
1618
1619 /* API callbacks. */
1620 ot->exec = mode_set_exec;
1621
1623
1624 /* properties */
1625 ot->prop = RNA_def_enum(
1626 ot->srna, "mode", rna_enum_clip_editor_mode_items, SC_MODE_TRACKING, "Mode", "");
1628}
1629
1631
1632#ifdef WITH_INPUT_NDOF
1633
1634/* -------------------------------------------------------------------- */
1637
1638/* Combined pan/zoom from a 3D mouse device.
1639 * Z zooms, XY pans
1640 * "view" (not "paper") control -- user moves the viewpoint, not the image being viewed
1641 * that explains the negative signs in the code below
1642 */
1643
1644static wmOperatorStatus clip_view_ndof_invoke(bContext *C,
1645 wmOperator * /*op*/,
1646 const wmEvent *event)
1647{
1648 if (event->type != NDOF_MOTION) {
1649 return OPERATOR_CANCELLED;
1650 }
1651
1653 ARegion *region = CTX_wm_region(C);
1654
1655 const wmNDOFMotionData &ndof = *static_cast<wmNDOFMotionData *>(event->customdata);
1656 const float pan_speed = NDOF_PIXELS_PER_SECOND;
1657
1658 float3 pan_vec = ndof.time_delta * WM_event_ndof_translation_get_for_navigation(ndof);
1659 mul_v2_fl(pan_vec, pan_speed / sc->zoom);
1660
1661 sclip_zoom_set_factor(C, max_ff(0.0f, 1.0f - pan_vec[2]), nullptr, false);
1662 sc->xof += pan_vec[0];
1663 sc->yof += pan_vec[1];
1664
1665 ED_region_tag_redraw(region);
1666
1667 return OPERATOR_FINISHED;
1668}
1669
1670void CLIP_OT_view_ndof(wmOperatorType *ot)
1671{
1672 /* identifiers */
1673 ot->name = "NDOF Pan/Zoom";
1674 ot->idname = "CLIP_OT_view_ndof";
1675 ot->description = "Use a 3D mouse device to pan/zoom the view";
1676
1677 /* API callbacks. */
1678 ot->invoke = clip_view_ndof_invoke;
1680
1681 /* flags */
1682 ot->flag = OPTYPE_LOCK_BYPASS;
1683}
1684
1686
1687#endif /* WITH_INPUT_NDOF */
1688
1689/* -------------------------------------------------------------------- */
1692
1694{
1695 /* no running blender, remove handler and pass through */
1698 }
1699
1700 /* running render */
1701 switch (event->type) {
1702 case EVT_ESCKEY:
1704 default: {
1705 break;
1706 }
1707 }
1708
1709 return OPERATOR_PASS_THROUGH;
1710}
1711
1713 wmOperator *op,
1714 const wmEvent * /*_event*/)
1715{
1717
1718 /* add modal handler for ESC */
1720
1722}
1723
1725{
1726 /* identifiers */
1727 ot->name = "Prefetch Frames";
1728 ot->idname = "CLIP_OT_prefetch";
1729 ot->description = "Prefetch frames from disk for faster playback/tracking";
1730
1731 /* API callbacks. */
1735}
1736
1738
1739/* -------------------------------------------------------------------- */
1742
1744{
1746 Scene *scene = CTX_data_scene(C);
1747 int clip_length;
1748
1749 if (ELEM(nullptr, scene, clip)) {
1750 return OPERATOR_CANCELLED;
1751 }
1752
1753 clip_length = BKE_movieclip_get_duration(clip);
1754
1755 scene->r.sfra = clip->start_frame;
1756 scene->r.efra = scene->r.sfra + clip_length - 1;
1757
1758 scene->r.efra = max_ii(scene->r.sfra, scene->r.efra);
1759
1761
1762 return OPERATOR_FINISHED;
1763}
1764
1766{
1767 /* identifiers */
1768 ot->name = "Set Scene Frames";
1769 ot->idname = "CLIP_OT_set_scene_frames";
1770 ot->description = "Set scene's start and end frame to match clip's start frame and length";
1771
1772 /* API callbacks. */
1775}
1776
1778
1779/* -------------------------------------------------------------------- */
1782
1784{
1785 SpaceClip *sclip = CTX_wm_space_clip(C);
1786 bool show_cursor = false;
1787
1788 show_cursor |= sclip->mode == SC_MODE_MASKEDIT;
1789 show_cursor |= sclip->around == V3D_AROUND_CURSOR;
1790
1791 if (!show_cursor) {
1792 return OPERATOR_CANCELLED;
1793 }
1794
1795 RNA_float_get_array(op->ptr, "location", sclip->cursor);
1796
1798
1799 /* Use pass-through to allow click-drag to transform the cursor. */
1801}
1802
1804 wmOperator *op,
1805 const wmEvent *event)
1806{
1807 ARegion *region = CTX_wm_region(C);
1808 SpaceClip *sclip = CTX_wm_space_clip(C);
1809 float location[2];
1810
1811 ED_clip_mouse_pos(sclip, region, event->mval, location);
1812 RNA_float_set_array(op->ptr, "location", location);
1813
1814 return clip_set_2d_cursor_exec(C, op);
1815}
1816
1818{
1819 /* identifiers */
1820 ot->name = "Set 2D Cursor";
1821 ot->description = "Set 2D cursor location";
1822 ot->idname = "CLIP_OT_cursor_set";
1823
1824 /* API callbacks. */
1828
1829 /* flags */
1831
1832 /* properties */
1834 "location",
1835 2,
1836 nullptr,
1837 -FLT_MAX,
1838 FLT_MAX,
1839 "Location",
1840 "Cursor location in normalized clip coordinates",
1841 -10.0f,
1842 10.0f);
1843}
1844
1846
1847/* -------------------------------------------------------------------- */
1850
1852{
1853 SpaceClip *space_clip = CTX_wm_space_clip(C);
1854
1855 ClipViewLockState lock_state;
1856 ED_clip_view_lock_state_store(C, &lock_state);
1857
1858 space_clip->flag ^= SC_LOCK_SELECTION;
1859
1861
1863
1864 return OPERATOR_FINISHED;
1865}
1866
1868{
1869 /* identifiers */
1870 ot->name = "Toggle Lock Selection";
1871 ot->description = "Toggle Lock Selection option of the current clip editor";
1872 ot->idname = "CLIP_OT_lock_selection_toggle";
1873
1874 /* API callbacks. */
1877
1878 /* flags */
1880}
1881
1883
1884/* -------------------------------------------------------------------- */
1887
1889{
1890 wmOperatorType *ot;
1891 wmOperatorTypeMacro *otmacro;
1892
1893 ot = WM_operatortype_append_macro("CLIP_OT_add_marker_move",
1894 "Add Marker and Move",
1895 "Add new marker and move it on movie",
1897 WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
1898 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
1899 RNA_struct_system_idprops_unset(otmacro->ptr, "release_confirm");
1900
1902 "CLIP_OT_add_marker_slide",
1903 "Add Marker and Slide",
1904 "Add new marker and slide it with mouse until mouse button release",
1906 WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
1907 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
1908 RNA_boolean_set(otmacro->ptr, "release_confirm", true);
1909}
1910
1912
1913} // namespace blender
File and directory operations.
#define O_BINARY
#define FILE_MAX
#define BLI_path_join(...)
Platform independent time functions.
#define RPT_(msgid)
#define BLT_I18NCONTEXT_ID_MOVIECLIP
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
Definition DNA_ID.h:691
#define MINAFRAME
#define MAXFRAME
#define UI_SCALE_FAC
#define FRAMENUMBER_MIN_CLAMP(cfra)
#define NDOF_PIXELS_PER_SECOND
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ND_DISPLAY
Definition WM_types.hh:534
#define NC_MOVIECLIP
Definition WM_types.hh:410
#define NC_SCENE
Definition WM_types.hh:391
#define NA_ADDED
Definition WM_types.hh:636
#define NA_EDITED
Definition WM_types.hh:634
#define ND_SPACE_CLIP
Definition WM_types.hh:582
#define ND_FRAME
Definition WM_types.hh:453
#define NC_SPACE
Definition WM_types.hh:405
volatile int lock
#define ELEM(...)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define powf(x, y)
#define FLT_MAX
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
void context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
void WM_main_add_notifier(uint type, void *reference)
UserDef U
Definition blender.cc:58
static wmOperatorStatus clip_prefetch_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition clip_ops.cc:1712
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
void ED_space_clip_get_size(const SpaceClip *sc, int *r_width, int *r_height)
void CLIP_OT_change_frame(wmOperatorType *ot)
Definition clip_ops.cc:1164
ScrArea * CTX_wm_area(const bContext *C)
static wmOperatorStatus view_pan_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:470
void ED_operatormacros_clip()
Definition clip_ops.cc:1888
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static uchar * proxy_thread_next_frame(ProxyQueue *queue, MovieClip *clip, size_t *r_size, int *r_cfra)
Definition clip_ops.cc:1319
static wmOperatorStatus view_zoom_out_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:826
static void open_cancel(bContext *, wmOperator *op)
Definition io_cache.cc:72
static void do_sequence_proxy(void *pjv, int *build_sizes, int build_count, int *build_undistort_sizes, int build_undistort_count, bool *stop, bool *do_update, float *progress)
Definition clip_ops.cc:1402
static wmOperatorStatus open_exec(bContext *C, wmOperator *op)
Definition clip_ops.cc:186
void BKE_movieclip_get_size(MovieClip *clip, const MovieClipUser *user, int *r_width, int *r_height)
MovieProxyBuilder * MOV_proxy_builder_start(MovieReader *anim, int proxy_sizes_in_use, int quality, const bool overwrite, Set< std::string > *processed_paths, bool build_only_on_bad_performance)
static wmOperatorStatus clip_rebuild_proxy_exec(bContext *C, wmOperator *)
Definition clip_ops.cc:1527
static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float factor)
Definition clip_ops.cc:138
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void WM_jobs_callbacks(wmJob *wm_job, wm_jobs_start_callback startjob, void(*initjob)(void *), void(*update)(void *), void(*endjob)(void *))
Definition wm_jobs.cc:407
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
static wmOperatorStatus view_zoom_in_exec(bContext *C, wmOperator *op)
Definition clip_ops.cc:756
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
MINLINE int round_fl_to_int(float a)
static wmOperatorStatus view_center_cursor_exec(bContext *C, wmOperator *)
Definition clip_ops.cc:1001
static wmOperatorStatus view_zoom_ratio_exec(bContext *C, wmOperator *op)
Definition clip_ops.cc:876
static void view_pan_exit(bContext *C, wmOperator *op, bool cancel)
Definition clip_ops.cc:412
PointerRNA RNA_id_pointer_create(ID *id)
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
@ TASK_PRIORITY_LOW
Definition BLI_task_c.hh:60
static wmOperatorStatus clip_prefetch_modal(bContext *C, wmOperator *, const wmEvent *event)
Definition clip_ops.cc:1693
static wmOperatorStatus clip_set_2d_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:1803
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
@ WM_JOB_TYPE_CLIP_PREFETCH
Definition WM_api.hh:2031
@ WM_JOB_TYPE_CLIP_BUILD_PROXY
Definition WM_api.hh:2028
int BLI_task_scheduler_num_threads()
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
void WM_cursor_modal_set(wmWindow *win, int val)
SpaceClip * CTX_wm_space_clip(const bContext *C)
int64_t BLI_read(int fd, void *buf, size_t nbytes)
Definition fileops_c.cc:98
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void CLIP_OT_rebuild_proxy(wmOperatorType *ot)
Definition clip_ops.cc:1574
static wmOperatorStatus mode_set_exec(bContext *C, wmOperator *op)
Definition clip_ops.cc:1595
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
static void proxy_startjob(void *pjv, wmJobWorkerStatus *worker_status)
Definition clip_ops.cc:1466
int RNA_int_get(PointerRNA *ptr, const char *name)
void CLIP_OT_view_selected(wmOperatorType *ot)
Definition clip_ops.cc:1045
wmWindow * CTX_wm_window(const bContext *C)
MINLINE int max_ii(int a, int b)
void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void(*free)(void *customdata))
Definition wm_jobs.cc:377
static void proxy_task_func(TaskPool *__restrict pool, void *task_data)
Definition clip_ops.cc:1367
bool ED_space_clip_view_clip_with_region_poll(bContext *C)
void MOV_proxy_builder_finish(MovieProxyBuilder *context, const bool stop)
@ WM_JOB_PROGRESS
Definition WM_api.hh:1997
static wmOperatorStatus view_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:619
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
static wmOperatorStatus view_pan_exec(bContext *C, wmOperator *op)
Definition clip_ops.cc:428
@ MCLIP_PROXY_RENDER_SIZE_100
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
void CLIP_OT_mode_set(wmOperatorType *ot)
Definition clip_ops.cc:1612
void ED_clip_view_lock_state_restore_no_jump(const bContext *C, const ClipViewLockState *state)
void CLIP_OT_view_zoom_in(wmOperatorType *ot)
Definition clip_ops.cc:782
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void ED_space_clip_get_aspect(const SpaceClip *sc, float *r_aspx, float *r_aspy)
static void view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:559
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
Definition wm_jobs.cc:498
static wmOperatorStatus open_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition editfont.cc:2501
void BLI_task_pool_work_and_wait(TaskPool *pool)
Definition task_pool.cc:455
static void view_zoom_exit(bContext *C, wmOperator *op, bool cancel)
Definition clip_ops.cc:590
bool ED_space_clip_poll(bContext *C)
void * BLI_task_pool_user_data(TaskPool *pool)
Definition task_pool.cc:460
void WM_operator_properties_use_cursor_init(wmOperatorType *ot)
Global G
Definition blender.cc:57
static wmOperatorStatus reload_exec(bContext *C, wmOperator *)
Definition clip_ops.cc:335
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
static void view_zoom_apply(bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event, const bool zoom_to_pos)
Definition clip_ops.cc:643
void IMB_freeImBuf(ImBuf *ibuf)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void CLIP_OT_prefetch(wmOperatorType *ot)
Definition clip_ops.cc:1724
unsigned char uchar
Definition BKE_text.h:58
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void CLIP_OT_view_center_cursor(wmOperatorType *ot)
Definition clip_ops.cc:1013
bool WM_jobs_has_running(const wmWindowManager *window_manager, const void *owner, const eWM_JobType type, const eWM_JobFlag exclude_flags)
Definition wm_jobs.cc:809
@ WM_FILESEL_DIRECTORY
Definition WM_api.hh:1330
@ WM_FILESEL_RELPATH
Definition WM_api.hh:1329
@ WM_FILESEL_FILES
Definition WM_api.hh:1333
bool ED_clip_view_selection(const bContext *C, const ARegion *region, bool fit)
wmWindowManager * CTX_wm_manager(const bContext *C)
static float frame_from_event(bContext *C, const wmEvent *event)
Definition anim_ops.cc:621
static void view_pan_init(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:380
static void view_zoom_cancel(bContext *C, wmOperator *op)
Definition clip_ops.cc:711
static wmOperatorStatus change_frame_exec(bContext *C, wmOperator *op)
Definition anim_ops.cc:611
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 WM_cursor_modal_restore(wmWindow *win)
MINLINE float power_of_2(float f)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
static wmOperatorStatus view_zoom_out_exec(bContext *C, wmOperator *op)
Definition clip_ops.cc:813
static void do_movie_proxy(void *pjv, int *, int, const int *build_undistort_sizes, int build_undistort_count, const bool *stop, bool *do_update, float *progress)
Definition clip_ops.cc:1236
MovieClip * CTX_data_edit_movieclip(const bContext *C)
static wmOperatorStatus change_frame_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition anim_ops.cc:696
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
void BKE_movieclip_clear_proxy_cache(MovieClip *clip)
bool clip_view_has_locked_selection(const bContext *C)
void CLIP_OT_open(wmOperatorType *ot)
Definition clip_ops.cc:304
static wmOperatorStatus view_zoom_in_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:769
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static void view_pan_cancel(bContext *C, wmOperator *op)
Definition clip_ops.cc:504
static void sclip_zoom_set_factor(const bContext *C, float zoomfac, const float location[2], const bool zoom_to_pos)
Definition clip_ops.cc:128
void CLIP_OT_view_zoom_out(wmOperatorType *ot)
Definition clip_ops.cc:839
void ED_clip_mouse_pos(const SpaceClip *sc, const ARegion *region, const int mval[2], float r_co[2])
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
MovieClip * BKE_movieclip_file_add_exists(Main *bmain, const char *filepath)
Definition movieclip.cc:930
@ MCLIP_PROXY_UNDISTORTED_SIZE_100
@ MCLIP_PROXY_UNDISTORTED_SIZE_50
@ MCLIP_PROXY_UNDISTORTED_SIZE_25
@ MCLIP_PROXY_UNDISTORTED_SIZE_75
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool RNA_struct_system_idprops_unset(PointerRNA *ptr, const char *identifier)
void CLIP_OT_view_zoom(wmOperatorType *ot)
Definition clip_ops.cc:716
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
static wmOperatorStatus change_frame_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition anim_ops.cc:790
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void BLI_task_pool_free(TaskPool *pool)
Definition task_pool.cc:441
void CLIP_OT_view_all(wmOperatorType *ot)
Definition clip_ops.cc:974
void CLIP_OT_view_zoom_ratio(wmOperatorType *ot)
Definition clip_ops.cc:891
static wmOperatorStatus view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:449
bool ED_space_clip_maskedit_poll(bContext *C)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
TaskPool * BLI_task_pool_create(void *userdata, eTaskPriority priority)
Definition task_pool.cc:404
bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
ImBuf * IMB_load_image_from_memory(const unsigned char *mem, size_t size, ImBufFlags flags, const char *descr, const char *filepath=nullptr, ColorManagedColorspaceSettings *colorspace_settings=nullptr)
Definition readimage.cc:132
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, 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 WM_jobs_kill_type(wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:642
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)
int BKE_movieclip_get_duration(MovieClip *clip)
static wmOperatorStatus view_zoom_exec(bContext *C, wmOperator *op)
Definition clip_ops.cc:610
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ FILE_OPENFILE
Definition WM_api.hh:1341
@ WM_CURSOR_NSEW_SCROLL
Definition wm_cursors.hh:54
Main * CTX_data_main(const bContext *C)
MovieDistortion * BKE_tracking_distortion_new(MovieTracking *tracking, int calibration_width, int calibration_height)
Definition tracking.cc:2268
void CLIP_OT_reload(wmOperatorType *ot)
Definition clip_ops.cc:351
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
static wmOperatorStatus view_all_exec(bContext *C, wmOperator *)
wmJob * WM_jobs_get(wmWindowManager *wm, wmWindow *win, const void *owner, const char *name, const eWM_JobFlag flag, const eWM_JobType job_type)
Definition wm_jobs.cc:228
static wmOperatorStatus lock_selection_toggle_exec(bContext *C, wmOperator *)
Definition clip_ops.cc:1851
MINLINE float max_ff(float a, float b)
void BKE_tracking_distortion_free(MovieDistortion *distortion)
Definition tracking.cc:2414
void BKE_movieclip_build_proxy_frame(MovieClip *clip, MovieClipFlag clip_flag, MovieDistortion *distortion, int cfra, const int *build_sizes, int build_count, bool undistorted)
@ ID_RECALC_SOURCE
Definition DNA_ID.h:1143
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1125
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
static wmOperatorStatus view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition clip_ops.cc:686
bool RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
@ KM_RELEASE
Definition WM_types.hh:325
size_t BLI_file_descriptor_size(int file) ATTR_WARN_UNUSED_RESULT
Definition storage.cc:219
double BLI_time_now_seconds()
Definition time.cc:30
static void clip_filesel(bContext *C, wmOperator *op, const char *dirpath)
Definition clip_ops.cc:162
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
static void open_init(bContext *C, wmOperator *op)
Definition clip_ops.cc:169
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_LOCK_BYPASS
Definition WM_types.hh:213
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_XY
Definition WM_types.hh:196
static void proxy_endjob(void *pjv)
Definition clip_ops.cc:1502
std::string RNA_string_get(PointerRNA *ptr, const char *name)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *clip)
void ED_clip_view_lock_state_store(const bContext *C, ClipViewLockState *state)
VecBase< float, 3 > float3
bool WM_cursor_modal_is_set_ok(const wmWindow *win)
void CLIP_OT_lock_selection_toggle(wmOperatorType *ot)
Definition clip_ops.cc:1867
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void CLIP_OT_set_scene_frames(wmOperatorType *ot)
Definition clip_ops.cc:1765
void MOV_close_proxies(MovieReader *anim)
int WM_userdef_event_type_from_keymap_type(int kmitype)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void id_us_min(ID *id)
Definition lib_id.cc:441
void BLI_task_pool_push(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
Definition task_pool.cc:446
static void proxy_freejob(void *pjv)
Definition clip_ops.cc:1199
ARegion * CTX_wm_region(const bContext *C)
void WM_jobs_timer(wmJob *wm_job, double time_step, uint note, uint endnote, void(*timer_step)(void *))
Definition wm_jobs.cc:393
const EnumPropertyItem rna_enum_clip_editor_mode_items[]
Definition rna_space.cc:590
static bool change_frame_poll(bContext *C)
Definition anim_ops.cc:116
static void sclip_zoom_set(const bContext *C, float zoom, const float location[2], const bool zoom_to_pos)
Definition clip_ops.cc:74
float RNA_float_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus view_selected_exec(bContext *C, wmOperator *)
Definition clip_ops.cc:1031
static void change_frame_apply(bContext *C, wmOperator *op, const bool always_update)
Definition anim_ops.cc:560
void CLIP_OT_cursor_set(wmOperatorType *ot)
Definition clip_ops.cc:1817
void WM_event_add_fileselect(bContext *C, wmOperator *op)
static wmOperatorStatus clip_set_2d_cursor_exec(bContext *C, wmOperator *op)
Definition clip_ops.cc:1783
bool ED_space_clip_view_clip_poll(bContext *C)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void clip_start_prefetch_job(const bContext *C)
void clip_view_center_to_point(SpaceClip *sc, float x, float y)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
static wmOperatorStatus clip_set_scene_frames_exec(bContext *C, wmOperator *)
Definition clip_ops.cc:1743
static int proxy_bitflag_to_array(int size_flag, int build_sizes[4], int undistort)
Definition clip_ops.cc:1205
void MOV_proxy_builder_process(MovieProxyBuilder *context, const bool *stop, bool *do_update, const FunctionRef< void(float progress)> set_progress_fn)
void BKE_movieclip_filepath_for_frame(MovieClip *clip, const MovieClipUser *user, char *filepath)
void CLIP_OT_view_pan(wmOperatorType *ot)
Definition clip_ops.cc:509
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eRegion_Type regiontype
char filepath[1024]
Definition BKE_main.hh:267
eMovieClipProxy_Size build_size_flag
struct MovieReader * anim
struct MovieTracking tracking
MovieClip * clip
Definition clip_ops.cc:1193
MovieClipFlag clip_flag
Definition clip_ops.cc:1194
MovieProxyBuilder * proxy_builder
Definition clip_ops.cc:1196
const bool * stop
Definition clip_ops.cc:1307
MovieDistortion * distortion
Definition clip_ops.cc:1314
struct RenderData r
eSpaceClip_Flag flag
eSpaceClip_View view
eSpaceClip_Mode mode
eView3D_Around around
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports