Blender  V2.93
clip_draw.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2011 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "DNA_gpencil_types.h"
25 #include "DNA_movieclip_types.h"
26 #include "DNA_scene_types.h"
27 
28 #include "MEM_guardedalloc.h"
29 
30 #include "IMB_colormanagement.h"
31 #include "IMB_imbuf.h"
32 #include "IMB_imbuf_types.h"
33 
34 #include "BLI_math.h"
35 #include "BLI_math_base.h"
36 #include "BLI_rect.h"
37 #include "BLI_string.h"
38 #include "BLI_utildefines.h"
39 
40 #include "BKE_context.h"
41 #include "BKE_image.h"
42 #include "BKE_movieclip.h"
43 #include "BKE_tracking.h"
44 
45 #include "ED_clip.h"
46 #include "ED_gpencil.h"
47 #include "ED_mask.h"
48 #include "ED_screen.h"
49 #include "ED_util.h"
50 
51 #include "BIF_glutil.h"
52 
53 #include "GPU_immediate.h"
54 #include "GPU_immediate_util.h"
55 #include "GPU_matrix.h"
56 #include "GPU_state.h"
57 
58 #include "WM_types.h"
59 
60 #include "UI_interface.h"
61 #include "UI_resources.h"
62 #include "UI_view2d.h"
63 
64 #include "BLF_api.h"
65 
66 #include "clip_intern.h" /* own include */
67 
68 /*********************** main area drawing *************************/
69 
70 static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width, uint pos)
71 {
72  int height = (frame == cfra) ? 22 : 10;
73  int x = (frame - sfra) * framelen;
74 
75  if (width == 1) {
77  immVertex2i(pos, x, 0);
79  immEnd();
80  }
81  else {
82  immRecti(pos, x, 0, x + width, height * UI_DPI_FAC);
83  }
84 }
85 
87  MovieTrackingPlaneTrack *plane_track)
88 {
89  if (track) {
90  return track->markersnr;
91  }
92  if (plane_track) {
93  return plane_track->markersnr;
94  }
95 
96  return 0;
97 }
98 
100  MovieTrackingPlaneTrack *plane_track,
101  int marker_index)
102 {
103  if (track) {
104  BLI_assert(marker_index < track->markersnr);
105  return track->markers[marker_index].framenr;
106  }
107  if (plane_track) {
108  BLI_assert(marker_index < plane_track->markersnr);
109  return plane_track->markers[marker_index].framenr;
110  }
111 
112  return 0;
113 }
114 
116  MovieTrackingPlaneTrack *plane_track,
117  int marker_index)
118 {
119  if (track) {
120  BLI_assert(marker_index < track->markersnr);
121  return (track->markers[marker_index].flag & MARKER_DISABLED) == 0;
122  }
123  if (plane_track) {
124  return true;
125  }
126 
127  return false;
128 }
129 
131  MovieTrackingPlaneTrack *plane_track,
132  int marker_index)
133 {
134  if (track) {
135  BLI_assert(marker_index < track->markersnr);
136  return (track->markers[marker_index].flag & MARKER_TRACKED) == 0;
137  }
138  if (plane_track) {
139  BLI_assert(marker_index < plane_track->markersnr);
140  return (plane_track->markers[marker_index].flag & PLANE_MARKER_TRACKED) == 0;
141  }
142 
143  return false;
144 }
145 
146 static void draw_movieclip_cache(SpaceClip *sc, ARegion *region, MovieClip *clip, Scene *scene)
147 {
148  float x;
149  int *points, totseg, i, a;
150  float sfra = SFRA, efra = EFRA, framelen = region->winx / (efra - sfra + 1);
151  MovieTracking *tracking = &clip->tracking;
152  MovieTrackingObject *act_object = BKE_tracking_object_get_active(tracking);
156 
158 
159  /* cache background */
161 
162  /* cached segments -- could be useful to debug caching strategies */
163  BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
164  ED_region_cache_draw_cached_segments(region, totseg, points, sfra, efra);
165 
169 
170  /* track */
171  if (act_track || act_plane_track) {
172  for (i = sfra - clip->start_frame + 1, a = 0; i <= efra - clip->start_frame + 1; i++) {
173  int framenr;
174  int markersnr = generic_track_get_markersnr(act_track, act_plane_track);
175 
176  while (a < markersnr) {
177  int marker_framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a);
178 
179  if (marker_framenr >= i) {
180  break;
181  }
182 
183  if (a < markersnr - 1 &&
184  generic_track_get_marker_framenr(act_track, act_plane_track, a + 1) > i) {
185  break;
186  }
187 
188  a++;
189  }
190 
191  a = min_ii(a, markersnr - 1);
192 
193  if (generic_track_is_marker_enabled(act_track, act_plane_track, a)) {
194  framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a);
195 
196  if (framenr != i) {
197  immUniformColor4ub(128, 128, 0, 96);
198  }
199  else if (generic_track_is_marker_keyframed(act_track, act_plane_track, a)) {
200  immUniformColor4ub(255, 255, 0, 196);
201  }
202  else {
203  immUniformColor4ub(255, 255, 0, 96);
204  }
205 
206  immRecti(pos,
207  (i - sfra + clip->start_frame - 1) * framelen,
208  0,
209  (i - sfra + clip->start_frame) * framelen,
210  4 * UI_DPI_FAC);
211  }
212  }
213  }
214 
215  /* failed frames */
217  int n = reconstruction->camnr;
218  MovieReconstructedCamera *cameras = reconstruction->cameras;
219 
220  immUniformColor4ub(255, 0, 0, 96);
221 
222  for (i = sfra, a = 0; i <= efra; i++) {
223  bool ok = false;
224 
225  while (a < n) {
226  if (cameras[a].framenr == i) {
227  ok = true;
228  break;
229  }
230  if (cameras[a].framenr > i) {
231  break;
232  }
233 
234  a++;
235  }
236 
237  if (!ok) {
238  immRecti(pos,
239  (i - sfra + clip->start_frame - 1) * framelen,
240  0,
241  (i - sfra + clip->start_frame) * framelen,
242  8 * UI_DPI_FAC);
243  }
244  }
245  }
246 
248 
249  /* current frame */
250  x = (sc->user.framenr - sfra) / (efra - sfra + 1) * region->winx;
251 
253  immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
254 
256 
258 
261 
262  /* solver keyframes */
263  immUniformColor4ub(175, 255, 0, 255);
264  draw_keyframe(act_object->keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos);
265  draw_keyframe(act_object->keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos);
266 
268 
269  /* movie clip animation */
270  if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask_info.mask) {
271  ED_mask_draw_frames(sc->mask_info.mask, region, CFRA, sfra, efra);
272  }
273 }
274 
275 static void draw_movieclip_notes(SpaceClip *sc, ARegion *region)
276 {
277  MovieClip *clip = ED_space_clip_get_clip(sc);
278  MovieTracking *tracking = &clip->tracking;
279  char str[256] = {0};
280  bool full_redraw = false;
281 
282  if (tracking->stats) {
283  BLI_strncpy(str, tracking->stats->message, sizeof(str));
284  full_redraw = true;
285  }
286  else {
287  if (sc->flag & SC_LOCK_SELECTION) {
288  strcpy(str, "Locked");
289  }
290  }
291 
292  if (str[0]) {
293  float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.6f};
294  ED_region_info_draw(region, str, fill_color, full_redraw);
295  }
296 }
297 
298 static void draw_movieclip_muted(ARegion *region, int width, int height, float zoomx, float zoomy)
299 {
300  int x, y;
301 
304 
305  /* find window pixel coordinates of origin */
306  UI_view2d_view_to_region(&region->v2d, 0.0f, 0.0f, &x, &y);
307 
308  immUniformColor3f(0.0f, 0.0f, 0.0f);
309  immRectf(pos, x, y, x + zoomx * width, y + zoomy * height);
310 
312 }
313 
314 static void draw_movieclip_buffer(const bContext *C,
315  SpaceClip *sc,
316  ARegion *region,
317  ImBuf *ibuf,
318  int width,
319  int height,
320  float zoomx,
321  float zoomy)
322 {
323  MovieClip *clip = ED_space_clip_get_clip(sc);
324  bool use_filter = true;
325  int x, y;
326 
327  /* find window pixel coordinates of origin */
328  UI_view2d_view_to_region(&region->v2d, 0.0f, 0.0f, &x, &y);
329 
330  /* checkerboard for case alpha */
331  if (ibuf->planes == 32) {
333 
334  imm_draw_box_checker_2d(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y);
335  }
336 
337  /* non-scaled proxy shouldn't use filtering */
338  if ((clip->flag & MCLIP_USE_PROXY) == 0 ||
340  use_filter = false;
341  }
342 
343  ED_draw_imbuf_ctx(C, ibuf, x, y, use_filter, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
344 
345  if (ibuf->planes == 32) {
347  }
348 
349  if (sc->flag & SC_SHOW_METADATA) {
350  rctf frame;
351  BLI_rctf_init(&frame, 0.0f, ibuf->x, 0.0f, ibuf->y);
353  x, y, ibuf, &frame, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
354  }
355 }
356 
358  SpaceClip *sc, ARegion *region, int width, int height, float zoomx, float zoomy)
359 {
360  int x, y;
361  MovieClip *clip = ED_space_clip_get_clip(sc);
362 
363  /* find window pixel coordinates of origin */
364  UI_view2d_view_to_region(&region->v2d, 0.0f, 0.0f, &x, &y);
365 
366  /* draw boundary border for frame if stabilization is enabled */
368  const uint shdr_pos = GPU_vertformat_attr_add(
370 
371  /* Exclusive OR allows to get orig value when second operand is 0,
372  * and negative of orig value when second operand is 1. */
373  GPU_logic_op_xor_set(true);
374 
375  GPU_matrix_push();
377 
378  GPU_matrix_scale_2f(zoomx, zoomy);
379  GPU_matrix_mul(sc->stabmat);
380 
382 
383  float viewport_size[4];
384  GPU_viewport_size_get_f(viewport_size);
385  immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
386 
387  immUniform1i("colors_len", 0); /* "simple" mode */
388  immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
389  immUniform1f("dash_width", 6.0f);
390  immUniform1f("dash_factor", 0.5f);
391 
392  imm_draw_box_wire_2d(shdr_pos, 0.0f, 0.0f, width, height);
393 
395 
396  GPU_matrix_pop();
397 
398  GPU_logic_op_xor_set(false);
399  }
400 }
401 
402 enum {
404 };
405 
406 typedef struct TrachPathPoint {
407  float co[2];
410 
412  const MovieTrackingTrack *track,
413  const MovieTrackingMarker *marker,
414  TrackPathPoint *point)
415 {
416  add_v2_v2v2(point->co, marker->pos, track->offset);
417  ED_clip_point_undistorted_pos(sc, point->co, point->co);
418  point->flag = 0;
419  if ((marker->flag & MARKER_TRACKED) == 0) {
420  point->flag |= PATH_POINT_FLAG_KEYFRAME;
421  }
422 }
423 
425  MovieTrackingTrack *track,
426  int direction,
427  TrackPathPoint *path)
428 {
429  const int count = sc->path_length;
430  int current_frame = ED_space_clip_get_clip_frame_number(sc);
431  const MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, current_frame);
432  /* Check whether there is marker at exact current frame.
433  * If not, we don't have anything to be put to path. */
434  if (marker == NULL || (marker->flag & MARKER_DISABLED)) {
435  return 0;
436  }
437  /* Index inside of path array where we write data to. */
438  int point_index = count;
439  int path_length = 0;
440  for (int i = 0; i < count; ++i) {
441  marker_to_path_point(sc, track, marker, &path[point_index]);
442  /* Move to the next marker along the path segment. */
443  path_length++;
444  point_index += direction;
445  current_frame += direction;
446  marker = BKE_tracking_marker_get_exact(track, current_frame);
447  if (marker == NULL || (marker->flag & MARKER_DISABLED)) {
448  /* Reached end of tracked segment. */
449  break;
450  }
451  }
452  return path_length;
453 }
454 
455 static void draw_track_path_points(const TrackPathPoint *path,
456  uint position_attribute,
457  const int start_point,
458  const int num_points)
459 {
460  if (num_points == 0) {
461  return;
462  }
463  immBegin(GPU_PRIM_POINTS, num_points);
464  for (int i = 0; i < num_points; i++) {
465  const TrackPathPoint *point = &path[i + start_point];
466  immVertex2fv(position_attribute, point->co);
467  }
468  immEnd();
469 }
470 
472  uint position_attribute,
473  const int start_point,
474  const int num_points)
475 {
476  immBeginAtMost(GPU_PRIM_POINTS, num_points);
477  for (int i = 0; i < num_points; i++) {
478  const TrackPathPoint *point = &path[i + start_point];
479  if (point->flag & PATH_POINT_FLAG_KEYFRAME) {
480  immVertex2fv(position_attribute, point->co);
481  }
482  }
483  immEnd();
484 }
485 
486 static void draw_track_path_lines(const TrackPathPoint *path,
487  uint position_attribute,
488  const int start_point,
489  const int num_points)
490 {
491  if (num_points < 2) {
492  return;
493  }
494  immBegin(GPU_PRIM_LINE_STRIP, num_points);
495  for (int i = 0; i < num_points; i++) {
496  const TrackPathPoint *point = &path[i + start_point];
497  immVertex2fv(position_attribute, point->co);
498  }
499  immEnd();
500 }
501 
503 {
504 #define MAX_STATIC_PATH 64
505 
506  const int count = sc->path_length;
507  TrackPathPoint path_static[(MAX_STATIC_PATH + 1) * 2];
508  TrackPathPoint *path;
509  const bool tiny = (sc->flag & SC_SHOW_TINY_MARKER) != 0;
510 
511  if (count == 0) {
512  /* Early output, nothing to bother about here. */
513  return;
514  }
515 
516  /* Try to use stack allocated memory when possibly, only use heap allocation
517  * for really long paths. */
518  path = (count < MAX_STATIC_PATH) ? path_static :
519  MEM_mallocN(sizeof(*path) * (count + 1) * 2, "path");
520  /* Collect path information. */
521  const int num_points_before = track_to_path_segment(sc, track, -1, path);
522  const int num_points_after = track_to_path_segment(sc, track, 1, path);
523  if (num_points_before == 0 && num_points_after == 0) {
524  return;
525  }
526 
527  int num_all_points = num_points_before + num_points_after;
528  /* If both leading and trailing parts of the path are there the center point is counted twice. */
529  if (num_points_before != 0 && num_points_after != 0) {
530  num_all_points -= 1;
531  }
532 
533  const int path_start_index = count - num_points_before + 1;
534  const int path_center_index = count;
535 
536  const uint position_attribute = GPU_vertformat_attr_add(
539 
540  /* Draw path outline. */
541  if (!tiny) {
543  if (TRACK_VIEW_SELECTED(sc, track)) {
544  GPU_point_size(5.0f);
545  draw_track_path_points(path, position_attribute, path_start_index, num_all_points);
546  GPU_point_size(7.0f);
547  draw_track_path_keyframe_points(path, position_attribute, path_start_index, num_all_points);
548  }
549  /* Draw darker outline for actual path, all line segments at once. */
550  GPU_line_width(3.0f);
551  draw_track_path_lines(path, position_attribute, path_start_index, num_all_points);
552  }
553 
554  /* Draw all points. */
555  GPU_point_size(3.0f);
557  draw_track_path_points(path, position_attribute, path_start_index, num_points_before);
559  draw_track_path_points(path, position_attribute, path_center_index, num_points_after);
560 
561  /* Connect points with color coded segments. */
562  GPU_line_width(1);
564  draw_track_path_lines(path, position_attribute, path_start_index, num_points_before);
566  draw_track_path_lines(path, position_attribute, path_center_index, num_points_after);
567 
568  /* Draw all bigger points corresponding to keyframes. */
569  GPU_point_size(5.0f);
571  draw_track_path_keyframe_points(path, position_attribute, path_start_index, num_points_before);
573  draw_track_path_keyframe_points(path, position_attribute, path_center_index, num_points_after);
574 
575  if (path != path_static) {
576  MEM_freeN(path);
577  }
578 
580 
581 #undef MAX_STATIC_PATH
582 }
583 
585  MovieTrackingTrack *track,
586  MovieTrackingMarker *marker,
587  const float marker_pos[2],
588  int width,
589  int height,
590  uint position)
591 {
592  int tiny = sc->flag & SC_SHOW_TINY_MARKER;
593  bool show_search = false;
594  float px[2];
595 
596  px[0] = 1.0f / width / sc->zoom;
597  px[1] = 1.0f / height / sc->zoom;
598 
599  GPU_line_width(tiny ? 1.0f : 3.0f);
600 
602 
603  if ((marker->flag & MARKER_DISABLED) == 0) {
604  float pos[2];
605  float p[2];
606 
607  add_v2_v2v2(pos, marker->pos, track->offset);
608 
610 
611  sub_v2_v2v2(p, pos, marker_pos);
612 
613  if (isect_point_quad_v2(p,
614  marker->pattern_corners[0],
615  marker->pattern_corners[1],
616  marker->pattern_corners[2],
617  marker->pattern_corners[3])) {
618  GPU_point_size(tiny ? 3.0f : 4.0f);
619 
621  immVertex2f(position, pos[0], pos[1]);
622  immEnd();
623  }
624  else {
626 
627  immVertex2f(position, pos[0] + px[0] * 2, pos[1]);
628  immVertex2f(position, pos[0] + px[0] * 8, pos[1]);
629 
630  immVertex2f(position, pos[0] - px[0] * 2, pos[1]);
631  immVertex2f(position, pos[0] - px[0] * 8, pos[1]);
632 
633  immVertex2f(position, pos[0], pos[1] - px[1] * 2);
634  immVertex2f(position, pos[0], pos[1] - px[1] * 8);
635 
636  immVertex2f(position, pos[0], pos[1] + px[1] * 2);
637  immVertex2f(position, pos[0], pos[1] + px[1] * 8);
638 
639  immEnd();
640  }
641  }
642 
643  /* pattern and search outline */
644  GPU_matrix_push();
645  GPU_matrix_translate_2fv(marker_pos);
646 
647  if (sc->flag & SC_SHOW_MARKER_PATTERN) {
649  immVertex2fv(position, marker->pattern_corners[0]);
650  immVertex2fv(position, marker->pattern_corners[1]);
651  immVertex2fv(position, marker->pattern_corners[2]);
652  immVertex2fv(position, marker->pattern_corners[3]);
653  immEnd();
654  }
655 
656  show_search = (TRACK_VIEW_SELECTED(sc, track) && ((marker->flag & MARKER_DISABLED) == 0 ||
657  (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) !=
658  0;
659 
660  if (sc->flag & SC_SHOW_MARKER_SEARCH && show_search) {
661  imm_draw_box_wire_2d(position,
662  marker->search_min[0],
663  marker->search_min[1],
664  marker->search_max[0],
665  marker->search_max[1]);
666  }
667 
668  GPU_matrix_pop();
669 }
670 
671 static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3])
672 {
673  if (track->flag & TRACK_CUSTOMCOLOR) {
674  if (act) {
676  }
677  else {
678  copy_v3_v3(scol, track->color);
679  }
680 
681  mul_v3_v3fl(col, track->color, 0.5f);
682  }
683  else {
685 
686  if (act) {
688  }
689  else {
691  }
692  }
693 }
694 
695 static void draw_marker_areas(SpaceClip *sc,
696  MovieTrackingTrack *track,
697  MovieTrackingMarker *marker,
698  const float marker_pos[2],
699  int width,
700  int height,
701  int act,
702  int sel,
703  const uint shdr_pos)
704 {
705  int tiny = sc->flag & SC_SHOW_TINY_MARKER;
706  bool show_search = false;
707  float col[3], scol[3];
708  float px[2];
709 
710  track_colors(track, act, col, scol);
711 
712  px[0] = 1.0f / width / sc->zoom;
713  px[1] = 1.0f / height / sc->zoom;
714 
715  GPU_line_width(1.0f);
716 
717  /* Since we are switching solid and dashed lines in rather complex logic here,
718  * just always go with dashed shader. */
720 
722 
723  float viewport_size[4];
724  GPU_viewport_size_get_f(viewport_size);
725  immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
726 
727  immUniform1i("colors_len", 0); /* "simple" mode */
728 
729  /* marker position and offset position */
730  if ((track->flag & SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) {
731  float pos[2], p[2];
732 
733  if (track->flag & TRACK_LOCKED) {
734  if (act) {
736  }
737  else if (track->flag & SELECT) {
739  }
740  else {
742  }
743  }
744  else {
745  immUniformColor3fv((track->flag & SELECT) ? scol : col);
746  }
747 
748  add_v2_v2v2(pos, marker->pos, track->offset);
750 
751  sub_v2_v2v2(p, pos, marker_pos);
752 
753  if (isect_point_quad_v2(p,
754  marker->pattern_corners[0],
755  marker->pattern_corners[1],
756  marker->pattern_corners[2],
757  marker->pattern_corners[3])) {
758  GPU_point_size(tiny ? 1.0f : 2.0f);
759 
760  immUniform1f("dash_factor", 2.0f); /* Solid "line" */
761 
763  immVertex2f(shdr_pos, pos[0], pos[1]);
764  immEnd();
765  }
766  else {
767  immUniform1f("dash_factor", 2.0f); /* Solid line */
768 
770 
771  immVertex2f(shdr_pos, pos[0] + px[0] * 3, pos[1]);
772  immVertex2f(shdr_pos, pos[0] + px[0] * 7, pos[1]);
773 
774  immVertex2f(shdr_pos, pos[0] - px[0] * 3, pos[1]);
775  immVertex2f(shdr_pos, pos[0] - px[0] * 7, pos[1]);
776 
777  immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 3);
778  immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 7);
779 
780  immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 3);
781  immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 7);
782 
783  immEnd();
784 
785  immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
786  immUniform1f("dash_width", 6.0f);
787  immUniform1f("dash_factor", 0.5f);
788 
789  GPU_logic_op_xor_set(true);
790 
792  immVertex2fv(shdr_pos, pos);
793  immVertex2fv(shdr_pos, marker_pos);
794  immEnd();
795 
796  GPU_logic_op_xor_set(false);
797  }
798  }
799 
800  /* pattern */
801  GPU_matrix_push();
802  GPU_matrix_translate_2fv(marker_pos);
803 
804  if (track->flag & TRACK_LOCKED) {
805  if (act) {
807  }
808  else if (track->pat_flag & SELECT) {
810  }
811  else {
813  }
814  }
815  else if (marker->flag & MARKER_DISABLED) {
816  if (act) {
818  }
819  else if (track->pat_flag & SELECT) {
821  }
822  else {
824  }
825  }
826  else {
827  immUniformColor3fv((track->pat_flag & SELECT) ? scol : col);
828  }
829 
830  if (tiny) {
831  immUniform1f("dash_width", 6.0f);
832  immUniform1f("dash_factor", 0.5f);
833  }
834  else {
835  immUniform1f("dash_factor", 2.0f); /* Solid line */
836  }
837 
838  if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
840  immVertex2fv(shdr_pos, marker->pattern_corners[0]);
841  immVertex2fv(shdr_pos, marker->pattern_corners[1]);
842  immVertex2fv(shdr_pos, marker->pattern_corners[2]);
843  immVertex2fv(shdr_pos, marker->pattern_corners[3]);
844  immEnd();
845  }
846 
847  /* search */
848  show_search = (TRACK_VIEW_SELECTED(sc, track) && ((marker->flag & MARKER_DISABLED) == 0 ||
849  (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) !=
850  0;
851 
852  if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) {
853  imm_draw_box_wire_2d(shdr_pos,
854  marker->search_min[0],
855  marker->search_min[1],
856  marker->search_max[0],
857  marker->search_max[1]);
858  }
859 
860  GPU_matrix_pop();
861 
862  /* Restore default shader */
864 
867  BLI_assert(pos == shdr_pos);
869 
871 }
872 
874 {
875  float len_sq = FLT_MAX;
876 
877  for (int i = 0; i < 4; i++) {
878  int next = (i + 1) % 4;
879  float cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]);
880  len_sq = min_ff(cur_len, len_sq);
881  }
882 
883  return sqrtf(len_sq);
884 }
885 
887  float x, float y, float dx, float dy, int outline, const float px[2], uint pos)
888 {
889  float tdx, tdy;
890 
891  tdx = dx;
892  tdy = dy;
893 
894  if (outline) {
895  tdx += px[0];
896  tdy += px[1];
897  }
898 
899  immRectf(pos, x - tdx, y - tdy, x + tdx, y + tdy);
900 }
901 
903  float x, float y, float dx, float dy, int outline, const float px[2], uint pos)
904 {
905  float tdx, tdy;
906 
907  tdx = dx * 2.0f;
908  tdy = dy * 2.0f;
909 
910  if (outline) {
911  tdx += px[0];
912  tdy += px[1];
913  }
914 
916  immVertex2f(pos, x, y);
917  immVertex2f(pos, x - tdx, y);
918  immVertex2f(pos, x, y + tdy);
919  immEnd();
920 }
921 
923  MovieTrackingTrack *track,
924  MovieTrackingMarker *marker,
925  const float marker_pos[2],
926  int outline,
927  int sel,
928  int act,
929  int width,
930  int height,
931  uint pos)
932 {
933  float dx, dy, patdx, patdy, searchdx, searchdy;
934  int tiny = sc->flag & SC_SHOW_TINY_MARKER;
935  float col[3], scol[3], px[2], side;
936 
937  if ((tiny && outline) || (marker->flag & MARKER_DISABLED)) {
938  return;
939  }
940 
941  if (!TRACK_VIEW_SELECTED(sc, track) || track->flag & TRACK_LOCKED) {
942  return;
943  }
944 
945  track_colors(track, act, col, scol);
946 
947  if (outline) {
949  }
950 
951  GPU_matrix_push();
952  GPU_matrix_translate_2fv(marker_pos);
953 
954  dx = 6.0f / width / sc->zoom;
955  dy = 6.0f / height / sc->zoom;
956 
957  side = get_shortest_pattern_side(marker);
958  patdx = min_ff(dx * 2.0f / 3.0f, side / 6.0f) * UI_DPI_FAC;
959  patdy = min_ff(dy * 2.0f / 3.0f, side * width / height / 6.0f) * UI_DPI_FAC;
960 
961  searchdx = min_ff(dx, (marker->search_max[0] - marker->search_min[0]) / 6.0f) * UI_DPI_FAC;
962  searchdy = min_ff(dy, (marker->search_max[1] - marker->search_min[1]) / 6.0f) * UI_DPI_FAC;
963 
964  px[0] = 1.0f / sc->zoom / width / sc->scale;
965  px[1] = 1.0f / sc->zoom / height / sc->scale;
966 
967  if ((sc->flag & SC_SHOW_MARKER_SEARCH) && ((track->search_flag & SELECT) == sel || outline)) {
968  if (!outline) {
969  immUniformColor3fv((track->search_flag & SELECT) ? scol : col);
970  }
971 
972  /* search offset square */
974  marker->search_min[0], marker->search_max[1], searchdx, searchdy, outline, px, pos);
975 
976  /* search re-sizing triangle */
978  marker->search_max[0], marker->search_min[1], searchdx, searchdy, outline, px, pos);
979  }
980 
981  if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT) == sel || outline)) {
982  float pat_min[2], pat_max[2];
983  /* float dx = 12.0f / width, dy = 12.0f / height;*/ /* XXX UNUSED */
984  float tilt_ctrl[2];
985 
986  if (!outline) {
987  immUniformColor3fv((track->pat_flag & SELECT) ? scol : col);
988  }
989 
990  /* pattern's corners sliding squares */
991  for (int i = 0; i < 4; i++) {
993  marker->pattern_corners[i][1],
994  patdx / 1.5f,
995  patdy / 1.5f,
996  outline,
997  px,
998  pos);
999  }
1000 
1001  /* ** sliders to control overall pattern ** */
1002  add_v2_v2v2(tilt_ctrl, marker->pattern_corners[1], marker->pattern_corners[2]);
1003 
1004  BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
1005 
1006  GPU_line_width(outline ? 3.0f : 1.0f);
1007 
1009  immVertex2f(pos, 0.0f, 0.0f);
1010  immVertex2fv(pos, tilt_ctrl);
1011  immEnd();
1012 
1013  /* slider to control pattern tilt */
1014  draw_marker_slide_square(tilt_ctrl[0], tilt_ctrl[1], patdx, patdy, outline, px, pos);
1015  }
1016 
1017  GPU_matrix_pop();
1018 }
1019 
1021  MovieTrackingTrack *track,
1022  MovieTrackingMarker *marker,
1023  const float marker_pos[2],
1024  int act,
1025  int width,
1026  int height,
1027  float zoomx,
1028  float zoomy)
1029 {
1030  char str[128] = {0}, state[64] = {0};
1031  float dx = 0.0f, dy = 0.0f, fontsize, pos[3];
1032  uiStyle *style = U.uistyles.first;
1033  int fontid = style->widget.uifont_id;
1034 
1035  if (!TRACK_VIEW_SELECTED(sc, track)) {
1036  return;
1037  }
1038 
1039  BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
1040  fontsize = BLF_height_max(fontid);
1041 
1042  if (marker->flag & MARKER_DISABLED) {
1043  if (act) {
1045  }
1046  else {
1047  uchar color[4];
1049  BLF_color4ubv(fontid, color);
1050  }
1051  }
1052  else {
1054  }
1055 
1056  if ((sc->flag & SC_SHOW_MARKER_SEARCH) &&
1057  ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) {
1058  dx = marker->search_min[0];
1059  dy = marker->search_min[1];
1060  }
1061  else if (sc->flag & SC_SHOW_MARKER_PATTERN) {
1062  float pat_min[2], pat_max[2];
1063 
1064  BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
1065  dx = pat_min[0];
1066  dy = pat_min[1];
1067  }
1068 
1069  pos[0] = (marker_pos[0] + dx) * width;
1070  pos[1] = (marker_pos[1] + dy) * height;
1071  pos[2] = 0.0f;
1072 
1073  mul_m4_v3(sc->stabmat, pos);
1074 
1075  pos[0] = pos[0] * zoomx;
1076  pos[1] = pos[1] * zoomy - fontsize;
1077 
1078  if (marker->flag & MARKER_DISABLED) {
1079  strcpy(state, "disabled");
1080  }
1081  else if (marker->framenr != ED_space_clip_get_clip_frame_number(sc)) {
1082  strcpy(state, "estimated");
1083  }
1084  else if (marker->flag & MARKER_TRACKED) {
1085  strcpy(state, "tracked");
1086  }
1087  else {
1088  strcpy(state, "keyframed");
1089  }
1090 
1091  if (state[0]) {
1092  BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state);
1093  }
1094  else {
1095  BLI_strncpy(str, track->name, sizeof(str));
1096  }
1097 
1098  BLF_position(fontid, pos[0], pos[1], 0.0f);
1099  BLF_draw(fontid, str, sizeof(str));
1100  pos[1] -= fontsize;
1101 
1102  if (track->flag & TRACK_HAS_BUNDLE) {
1103  BLI_snprintf(str, sizeof(str), "Average error: %.2f px", track->error);
1104  BLF_position(fontid, pos[0], pos[1], 0.0f);
1105  BLF_draw(fontid, str, sizeof(str));
1106  pos[1] -= fontsize;
1107  }
1108 
1109  if (track->flag & TRACK_LOCKED) {
1110  BLF_position(fontid, pos[0], pos[1], 0.0f);
1111  BLF_draw(fontid, "locked", 6);
1112  }
1113 }
1114 
1115 static void plane_track_colors(bool is_active, float color[3], float selected_color[3])
1116 {
1118 
1119  UI_GetThemeColor3fv(is_active ? TH_ACT_MARKER : TH_SEL_MARKER, selected_color);
1120 }
1121 
1122 static void getArrowEndPoint(const int width,
1123  const int height,
1124  const float zoom,
1125  const float start_corner[2],
1126  const float end_corner[2],
1127  float end_point[2])
1128 {
1129  float direction[2];
1130  float max_length;
1131 
1132  sub_v2_v2v2(direction, end_corner, start_corner);
1133 
1134  direction[0] *= width;
1135  direction[1] *= height;
1136  max_length = normalize_v2(direction);
1137  mul_v2_fl(direction, min_ff(32.0f / zoom, max_length));
1138  direction[0] /= width;
1139  direction[1] /= height;
1140 
1141  add_v2_v2v2(end_point, start_corner, direction);
1142 }
1143 
1144 static void homogeneous_2d_to_gl_matrix(/*const*/ float matrix[3][3], float gl_matrix[4][4])
1145 {
1146  gl_matrix[0][0] = matrix[0][0];
1147  gl_matrix[0][1] = matrix[0][1];
1148  gl_matrix[0][2] = 0.0f;
1149  gl_matrix[0][3] = matrix[0][2];
1150 
1151  gl_matrix[1][0] = matrix[1][0];
1152  gl_matrix[1][1] = matrix[1][1];
1153  gl_matrix[1][2] = 0.0f;
1154  gl_matrix[1][3] = matrix[1][2];
1155 
1156  gl_matrix[2][0] = 0.0f;
1157  gl_matrix[2][1] = 0.0f;
1158  gl_matrix[2][2] = 1.0f;
1159  gl_matrix[2][3] = 0.0f;
1160 
1161  gl_matrix[3][0] = matrix[2][0];
1162  gl_matrix[3][1] = matrix[2][1];
1163  gl_matrix[3][2] = 0.0f;
1164  gl_matrix[3][3] = matrix[2][2];
1165 }
1166 
1168  MovieTrackingPlaneTrack *plane_track,
1169  MovieTrackingPlaneMarker *plane_marker)
1170 {
1171  Image *image = plane_track->image;
1172  ImBuf *ibuf;
1173  void *lock;
1174 
1175  if (image == NULL) {
1176  return;
1177  }
1178 
1179  ibuf = BKE_image_acquire_ibuf(image, NULL, &lock);
1180 
1181  if (ibuf) {
1182  uchar *display_buffer;
1183  void *cache_handle;
1184 
1185  if (image->flag & IMA_VIEW_AS_RENDER) {
1186  display_buffer = IMB_display_buffer_acquire(
1187  ibuf, &scene->view_settings, &scene->display_settings, &cache_handle);
1188  }
1189  else {
1190  display_buffer = IMB_display_buffer_acquire(
1191  ibuf, NULL, &scene->display_settings, &cache_handle);
1192  }
1193 
1194  if (display_buffer) {
1195  float frame_corners[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
1196  float perspective_matrix[3][3];
1197  float gl_matrix[4][4];
1198  bool transparent = false;
1200  frame_corners, plane_marker->corners, perspective_matrix);
1201 
1202  homogeneous_2d_to_gl_matrix(perspective_matrix, gl_matrix);
1203 
1204  if (plane_track->image_opacity != 1.0f || ibuf->planes == 32) {
1205  transparent = true;
1207  }
1208 
1210  "plane_marker_image", ibuf->x, ibuf->y, 1, GPU_RGBA8, NULL);
1211  GPU_texture_update(texture, GPU_DATA_UBYTE, display_buffer);
1213 
1214  GPU_matrix_push();
1215  GPU_matrix_mul(gl_matrix);
1216 
1217  GPUVertFormat *imm_format = immVertexFormat();
1218  uint pos = GPU_vertformat_attr_add(imm_format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
1219  uint texCoord = GPU_vertformat_attr_add(
1220  imm_format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
1221 
1222  /* Use 3D image for correct display of planar tracked images. */
1224 
1225  immBindTexture("image", texture);
1226  immUniform1f("alpha", plane_track->image_opacity);
1227 
1229 
1230  immAttr2f(texCoord, 0.0f, 0.0f);
1231  immVertex3f(pos, 0.0f, 0.0f, 0.0f);
1232 
1233  immAttr2f(texCoord, 1.0f, 0.0f);
1234  immVertex3f(pos, 1.0f, 0.0f, 0.0f);
1235 
1236  immAttr2f(texCoord, 1.0f, 1.0f);
1237  immVertex3f(pos, 1.0f, 1.0f, 0.0f);
1238 
1239  immAttr2f(texCoord, 0.0f, 1.0f);
1240  immVertex3f(pos, 0.0f, 1.0f, 0.0f);
1241 
1242  immEnd();
1243 
1244  immUnbindProgram();
1245 
1246  GPU_matrix_pop();
1247 
1250 
1251  if (transparent) {
1253  }
1254  }
1255 
1256  IMB_display_buffer_release(cache_handle);
1257  }
1258 
1259  BKE_image_release_ibuf(image, ibuf, lock);
1260 }
1261 
1263  Scene *scene,
1264  MovieTrackingPlaneTrack *plane_track,
1265  MovieTrackingPlaneMarker *plane_marker,
1266  bool is_active_track,
1267  bool draw_outline,
1268  int width,
1269  int height)
1270 {
1271  bool tiny = (sc->flag & SC_SHOW_TINY_MARKER) != 0;
1272  bool is_selected_track = (plane_track->flag & SELECT) != 0;
1273  const bool has_image = plane_track->image != NULL &&
1274  BKE_image_has_ibuf(plane_track->image, NULL);
1275  const bool draw_plane_quad = !has_image || plane_track->image_opacity == 0.0f;
1276  float px[2];
1277  float color[3], selected_color[3];
1278 
1279  px[0] = 1.0f / width / sc->zoom;
1280  px[1] = 1.0f / height / sc->zoom;
1281 
1282  /* Draw image */
1283  if (draw_outline == false) {
1284  draw_plane_marker_image(scene, plane_track, plane_marker);
1285  }
1286 
1287  if (draw_plane_quad || is_selected_track) {
1288  const uint shdr_pos = GPU_vertformat_attr_add(
1290 
1292 
1293  float viewport_size[4];
1294  GPU_viewport_size_get_f(viewport_size);
1295  immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
1296 
1297  immUniform1i("colors_len", 0); /* "simple" mode */
1298 
1299  if (is_selected_track) {
1300  plane_track_colors(is_active_track, color, selected_color);
1301  }
1302 
1303  if (draw_plane_quad) {
1304  const bool stipple = !draw_outline && tiny;
1305  const bool thick = draw_outline && !tiny;
1306 
1307  GPU_line_width(thick ? 3.0f : 1.0f);
1308 
1309  if (stipple) {
1310  immUniform1f("dash_width", 6.0f);
1311  immUniform1f("dash_factor", 0.5f);
1312  }
1313  else {
1314  immUniform1f("dash_factor", 2.0f); /* Solid line */
1315  }
1316 
1317  if (draw_outline) {
1319  }
1320  else {
1321  immUniformColor3fv(is_selected_track ? selected_color : color);
1322  }
1323 
1324  /* Draw rectangle itself. */
1326  immVertex2fv(shdr_pos, plane_marker->corners[0]);
1327  immVertex2fv(shdr_pos, plane_marker->corners[1]);
1328  immVertex2fv(shdr_pos, plane_marker->corners[2]);
1329  immVertex2fv(shdr_pos, plane_marker->corners[3]);
1330  immEnd();
1331 
1332  /* Draw axis. */
1333  if (!draw_outline) {
1334  float end_point[2];
1335 
1336  immUniformColor3f(1.0f, 0.0f, 0.0f);
1337 
1339 
1341  height,
1342  sc->zoom,
1343  plane_marker->corners[0],
1344  plane_marker->corners[1],
1345  end_point);
1346  immVertex2fv(shdr_pos, plane_marker->corners[0]);
1347  immVertex2fv(shdr_pos, end_point);
1348 
1349  immEnd();
1350 
1351  immUniformColor3f(0.0f, 1.0f, 0.0f);
1352 
1354 
1356  height,
1357  sc->zoom,
1358  plane_marker->corners[0],
1359  plane_marker->corners[3],
1360  end_point);
1361  immVertex2fv(shdr_pos, plane_marker->corners[0]);
1362  immVertex2fv(shdr_pos, end_point);
1363 
1364  immEnd();
1365  }
1366  }
1367  immUnbindProgram();
1368 
1369  /* Draw sliders. */
1370  if (is_selected_track) {
1372 
1373  if (draw_outline) {
1375  }
1376  else {
1377  immUniformColor3fv(selected_color);
1378  }
1379 
1380  for (int i = 0; i < 4; i++) {
1381  draw_marker_slide_square(plane_marker->corners[i][0],
1382  plane_marker->corners[i][1],
1383  3.0f * px[0],
1384  3.0f * px[1],
1385  draw_outline,
1386  px,
1387  shdr_pos);
1388  }
1389  immUnbindProgram();
1390  }
1391  }
1392 }
1393 
1395  Scene *scene,
1396  MovieTrackingPlaneTrack *plane_track,
1397  MovieTrackingPlaneMarker *plane_marker,
1398  int width,
1399  int height)
1400 {
1401  draw_plane_marker_ex(sc, scene, plane_track, plane_marker, false, true, width, height);
1402 }
1403 
1405  Scene *scene,
1406  MovieTrackingPlaneTrack *plane_track,
1407  MovieTrackingPlaneMarker *plane_marker,
1408  bool is_active_track,
1409  int width,
1410  int height)
1411 {
1413  sc, scene, plane_track, plane_marker, is_active_track, false, width, height);
1414 }
1415 
1416 static void draw_plane_track(SpaceClip *sc,
1417  Scene *scene,
1418  MovieTrackingPlaneTrack *plane_track,
1419  int framenr,
1420  bool is_active_track,
1421  int width,
1422  int height)
1423 {
1424  MovieTrackingPlaneMarker *plane_marker;
1425 
1426  plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr);
1427 
1428  draw_plane_marker_outline(sc, scene, plane_track, plane_marker, width, height);
1429  draw_plane_marker(sc, scene, plane_track, plane_marker, is_active_track, width, height);
1430 }
1431 
1432 /* Draw all kind of tracks. */
1434  Scene *scene,
1435  ARegion *region,
1436  MovieClip *clip,
1437  int width,
1438  int height,
1439  float zoomx,
1440  float zoomy)
1441 {
1442  float x, y;
1443  MovieTracking *tracking = &clip->tracking;
1444  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
1445  ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
1446  MovieTrackingTrack *track, *act_track;
1447  MovieTrackingPlaneTrack *plane_track, *active_plane_track;
1448  MovieTrackingMarker *marker;
1449  int framenr = ED_space_clip_get_clip_frame_number(sc);
1450  int undistort = sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
1451  float *marker_pos = NULL, *fp, *active_pos = NULL, cur_pos[2];
1452 
1453  /* ** find window pixel coordinates of origin ** */
1454 
1455  /* UI_view2d_view_to_region_no_clip return integer values, this could
1456  * lead to 1px flickering when view is locked to selection during playback.
1457  * to avoid this flickering, calculate base point in the same way as it happens
1458  * in UI_view2d_view_to_region_no_clip, but do it in floats here */
1459 
1460  UI_view2d_view_to_region_fl(&region->v2d, 0.0f, 0.0f, &x, &y);
1461 
1462  GPU_matrix_push();
1464 
1465  GPU_matrix_push();
1466  GPU_matrix_scale_2f(zoomx, zoomy);
1467  GPU_matrix_mul(sc->stabmat);
1469 
1470  act_track = BKE_tracking_track_get_active(tracking);
1471 
1472  /* Draw plane tracks */
1473  active_plane_track = BKE_tracking_plane_track_get_active(tracking);
1474  for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
1475  if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
1477  sc, scene, plane_track, framenr, plane_track == active_plane_track, width, height);
1478  }
1479  }
1480 
1482  int count = 0;
1483 
1484  /* count */
1485  track = tracksbase->first;
1486  while (track) {
1487  if ((track->flag & TRACK_HIDDEN) == 0) {
1488  marker = BKE_tracking_marker_get(track, framenr);
1489 
1490  if (MARKER_VISIBLE(sc, track, marker)) {
1491  count++;
1492  }
1493  }
1494 
1495  track = track->next;
1496  }
1497 
1498  /* undistort */
1499  if (count) {
1500  marker_pos = MEM_callocN(sizeof(float[2]) * count, "draw_tracking_tracks marker_pos");
1501 
1502  track = tracksbase->first;
1503  fp = marker_pos;
1504  while (track) {
1505  if ((track->flag & TRACK_HIDDEN) == 0) {
1506  marker = BKE_tracking_marker_get(track, framenr);
1507 
1508  if (MARKER_VISIBLE(sc, track, marker)) {
1509  ED_clip_point_undistorted_pos(sc, marker->pos, fp);
1510 
1511  if (track == act_track) {
1512  active_pos = fp;
1513  }
1514 
1515  fp += 2;
1516  }
1517  }
1518 
1519  track = track->next;
1520  }
1521  }
1522  }
1523 
1524  if (sc->flag & SC_SHOW_TRACK_PATH) {
1525  track = tracksbase->first;
1526  while (track) {
1527  if ((track->flag & TRACK_HIDDEN) == 0) {
1528  draw_track_path(sc, clip, track);
1529  }
1530 
1531  track = track->next;
1532  }
1533  }
1534 
1535  uint position = GPU_vertformat_attr_add(
1537 
1539 
1540  /* markers outline and non-selected areas */
1541  track = tracksbase->first;
1542  fp = marker_pos;
1543  while (track) {
1544  if ((track->flag & TRACK_HIDDEN) == 0) {
1545  marker = BKE_tracking_marker_get(track, framenr);
1546 
1547  if (MARKER_VISIBLE(sc, track, marker)) {
1548  copy_v2_v2(cur_pos, fp ? fp : marker->pos);
1549 
1550  draw_marker_outline(sc, track, marker, cur_pos, width, height, position);
1551  draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0, position);
1552  draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height, position);
1553  draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height, position);
1554 
1555  if (fp) {
1556  fp += 2;
1557  }
1558  }
1559  }
1560 
1561  track = track->next;
1562  }
1563 
1564  /* selected areas only, so selection wouldn't be overlapped by
1565  * non-selected areas */
1566  track = tracksbase->first;
1567  fp = marker_pos;
1568  while (track) {
1569  if ((track->flag & TRACK_HIDDEN) == 0) {
1570  int act = track == act_track;
1571  marker = BKE_tracking_marker_get(track, framenr);
1572 
1573  if (MARKER_VISIBLE(sc, track, marker)) {
1574  if (!act) {
1575  copy_v2_v2(cur_pos, fp ? fp : marker->pos);
1576 
1577  draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1, position);
1578  draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height, position);
1579  }
1580 
1581  if (fp) {
1582  fp += 2;
1583  }
1584  }
1585  }
1586 
1587  track = track->next;
1588  }
1589 
1590  /* active marker would be displayed on top of everything else */
1591  if (act_track) {
1592  if ((act_track->flag & TRACK_HIDDEN) == 0) {
1593  marker = BKE_tracking_marker_get(act_track, framenr);
1594 
1595  if (MARKER_VISIBLE(sc, act_track, marker)) {
1596  copy_v2_v2(cur_pos, active_pos ? active_pos : marker->pos);
1597 
1598  draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1, position);
1599  draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height, position);
1600  }
1601  }
1602  }
1603 
1604  if (sc->flag & SC_SHOW_BUNDLES) {
1606  float pos[4], vec[4], mat[4][4], aspy;
1607 
1608  GPU_point_size(3.0f);
1609 
1610  aspy = 1.0f / clip->tracking.camera.pixel_aspect;
1611  BKE_tracking_get_projection_matrix(tracking, object, framenr, width, height, mat);
1612 
1613  track = tracksbase->first;
1614  while (track) {
1615  if ((track->flag & TRACK_HIDDEN) == 0 && track->flag & TRACK_HAS_BUNDLE) {
1616  marker = BKE_tracking_marker_get(track, framenr);
1617 
1618  if (MARKER_VISIBLE(sc, track, marker)) {
1619  float npos[2];
1620  copy_v3_v3(vec, track->bundle_pos);
1621  vec[3] = 1;
1622 
1623  mul_v4_m4v4(pos, mat, vec);
1624 
1625  pos[0] = (pos[0] / (pos[3] * 2.0f) + 0.5f) * width;
1626  pos[1] = (pos[1] / (pos[3] * 2.0f) + 0.5f) * height * aspy;
1627 
1628  BKE_tracking_distort_v2(tracking, width, height, pos, npos);
1629 
1630  if (npos[0] >= 0.0f && npos[1] >= 0.0f && npos[0] <= width && npos[1] <= height * aspy) {
1631  vec[0] = (marker->pos[0] + track->offset[0]) * width;
1632  vec[1] = (marker->pos[1] + track->offset[1]) * height * aspy;
1633 
1634  sub_v2_v2(vec, npos);
1635 
1636  if (len_squared_v2(vec) < (3.0f * 3.0f)) {
1637  immUniformColor3f(0.0f, 1.0f, 0.0f);
1638  }
1639  else {
1640  immUniformColor3f(1.0f, 0.0f, 0.0f);
1641  }
1642 
1644 
1645  if (undistort) {
1646  immVertex2f(position, pos[0] / width, pos[1] / (height * aspy));
1647  }
1648  else {
1649  immVertex2f(position, npos[0] / width, npos[1] / (height * aspy));
1650  }
1651 
1652  immEnd();
1653  }
1654  }
1655  }
1656 
1657  track = track->next;
1658  }
1659  }
1660 
1661  immUnbindProgram();
1662 
1663  GPU_matrix_pop();
1664 
1665  if (sc->flag & SC_SHOW_NAMES) {
1666  /* scaling should be cleared before drawing texts, otherwise font would also be scaled */
1667  track = tracksbase->first;
1668  fp = marker_pos;
1669  while (track) {
1670  if ((track->flag & TRACK_HIDDEN) == 0) {
1671  marker = BKE_tracking_marker_get(track, framenr);
1672 
1673  if (MARKER_VISIBLE(sc, track, marker)) {
1674  int act = track == act_track;
1675 
1676  copy_v2_v2(cur_pos, fp ? fp : marker->pos);
1677 
1678  draw_marker_texts(sc, track, marker, cur_pos, act, width, height, zoomx, zoomy);
1679 
1680  if (fp) {
1681  fp += 2;
1682  }
1683  }
1684  }
1685 
1686  track = track->next;
1687  }
1688  }
1689 
1690  GPU_matrix_pop();
1691 
1692  if (marker_pos) {
1693  MEM_freeN(marker_pos);
1694  }
1695 }
1696 
1697 static void draw_distortion(SpaceClip *sc,
1698  ARegion *region,
1699  MovieClip *clip,
1700  int width,
1701  int height,
1702  float zoomx,
1703  float zoomy)
1704 {
1705  float x, y;
1706  const int n = 10;
1707  float tpos[2], grid[11][11][2];
1708  MovieTracking *tracking = &clip->tracking;
1709  bGPdata *gpd = NULL;
1710  float aspy = 1.0f / tracking->camera.pixel_aspect;
1711  float dx = (float)width / n, dy = (float)height / n * aspy;
1712  float offsx = 0.0f, offsy = 0.0f;
1713 
1714  if (!tracking->camera.focal) {
1715  return;
1716  }
1717 
1718  if ((sc->flag & SC_SHOW_GRID) == 0 && (sc->flag & SC_MANUAL_CALIBRATION) == 0) {
1719  return;
1720  }
1721 
1722  UI_view2d_view_to_region_fl(&region->v2d, 0.0f, 0.0f, &x, &y);
1723 
1724  GPU_matrix_push();
1726  GPU_matrix_scale_2f(zoomx, zoomy);
1727  GPU_matrix_mul(sc->stabmat);
1729 
1730  uint position = GPU_vertformat_attr_add(
1732 
1734 
1735  /* grid */
1736  if (sc->flag & SC_SHOW_GRID) {
1737  float val[4][2], idx[4][2];
1738  float min[2], max[2];
1739 
1740  for (int a = 0; a < 4; a++) {
1741  if (a < 2) {
1742  val[a][a % 2] = FLT_MAX;
1743  }
1744  else {
1745  val[a][a % 2] = -FLT_MAX;
1746  }
1747  }
1748 
1749  for (int i = 0; i <= n; i++) {
1750  for (int j = 0; j <= n; j++) {
1751  if (i == 0 || j == 0 || i == n || j == n) {
1752  const float pos[2] = {dx * j, dy * i};
1753  BKE_tracking_distort_v2(tracking, width, height, pos, tpos);
1754 
1755  for (int a = 0; a < 4; a++) {
1756  int ok;
1757 
1758  if (a < 2) {
1759  ok = tpos[a % 2] < val[a][a % 2];
1760  }
1761  else {
1762  ok = tpos[a % 2] > val[a][a % 2];
1763  }
1764 
1765  if (ok) {
1766  copy_v2_v2(val[a], tpos);
1767  idx[a][0] = j;
1768  idx[a][1] = i;
1769  }
1770  }
1771  }
1772  }
1773  }
1774 
1775  INIT_MINMAX2(min, max);
1776 
1777  for (int a = 0; a < 4; a++) {
1778  const float pos[2] = {idx[a][0] * dx, idx[a][1] * dy};
1779 
1780  BKE_tracking_undistort_v2(tracking, width, height, pos, tpos);
1781 
1782  minmax_v2v2_v2(min, max, tpos);
1783  }
1784 
1785  dx = (max[0] - min[0]) / n;
1786  dy = (max[1] - min[1]) / n;
1787 
1788  for (int i = 0; i <= n; i++) {
1789  for (int j = 0; j <= n; j++) {
1790  const float pos[2] = {min[0] + dx * j, min[1] + dy * i};
1791 
1792  BKE_tracking_distort_v2(tracking, width, height, pos, grid[i][j]);
1793 
1794  grid[i][j][0] /= width;
1795  grid[i][j][1] /= height * aspy;
1796  }
1797  }
1798 
1799  immUniformColor3f(1.0f, 0.0f, 0.0f);
1800 
1801  for (int i = 0; i <= n; i++) {
1802  immBegin(GPU_PRIM_LINE_STRIP, n + 1);
1803 
1804  for (int j = 0; j <= n; j++) {
1805  immVertex2fv(position, grid[i][j]);
1806  }
1807 
1808  immEnd();
1809  }
1810 
1811  for (int j = 0; j <= n; j++) {
1812  immBegin(GPU_PRIM_LINE_STRIP, n + 1);
1813 
1814  for (int i = 0; i <= n; i++) {
1815  immVertex2fv(position, grid[i][j]);
1816  }
1817 
1818  immEnd();
1819  }
1820  }
1821 
1822  if (sc->gpencil_src != SC_GPENCIL_SRC_TRACK) {
1823  gpd = clip->gpd;
1824  }
1825 
1826  if (sc->flag & SC_MANUAL_CALIBRATION && gpd) {
1827  bGPDlayer *layer = gpd->layers.first;
1828 
1829  while (layer) {
1830  bGPDframe *frame = layer->frames.first;
1831 
1832  if (layer->flag & GP_LAYER_HIDE) {
1833  layer = layer->next;
1834  continue;
1835  }
1836 
1837  immUniformColor4fv(layer->color);
1838 
1839  GPU_line_width(layer->thickness);
1840  GPU_point_size((float)(layer->thickness + 2));
1841 
1842  while (frame) {
1843  bGPDstroke *stroke = frame->strokes.first;
1844 
1845  while (stroke) {
1846  if (stroke->flag & GP_STROKE_2DSPACE) {
1847  if (stroke->totpoints > 1) {
1848  for (int i = 0; i < stroke->totpoints - 1; i++) {
1849  float pos[2], npos[2], dpos[2], len;
1850  int steps;
1851 
1852  pos[0] = (stroke->points[i].x + offsx) * width;
1853  pos[1] = (stroke->points[i].y + offsy) * height * aspy;
1854 
1855  npos[0] = (stroke->points[i + 1].x + offsx) * width;
1856  npos[1] = (stroke->points[i + 1].y + offsy) * height * aspy;
1857 
1858  len = len_v2v2(pos, npos);
1859  steps = ceil(len / 5.0f);
1860 
1861  /* we want to distort only long straight lines */
1862  if (stroke->totpoints == 2) {
1864  BKE_tracking_undistort_v2(tracking, width, height, npos, npos);
1865  }
1866 
1867  sub_v2_v2v2(dpos, npos, pos);
1868  mul_v2_fl(dpos, 1.0f / steps);
1869 
1871 
1872  for (int j = 0; j <= steps; j++) {
1873  BKE_tracking_distort_v2(tracking, width, height, pos, tpos);
1874  immVertex2f(position, tpos[0] / width, tpos[1] / (height * aspy));
1875 
1876  add_v2_v2(pos, dpos);
1877  }
1878 
1879  immEnd();
1880  }
1881  }
1882  else if (stroke->totpoints == 1) {
1884  immVertex2f(position, stroke->points[0].x + offsx, stroke->points[0].y + offsy);
1885  immEnd();
1886  }
1887  }
1888 
1889  stroke = stroke->next;
1890  }
1891 
1892  frame = frame->next;
1893  }
1894 
1895  layer = layer->next;
1896  }
1897  }
1898 
1899  immUnbindProgram();
1900 
1901  GPU_matrix_pop();
1902 }
1903 
1904 void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *region)
1905 {
1906  MovieClip *clip = ED_space_clip_get_clip(sc);
1908  ImBuf *ibuf = NULL;
1909  int width, height;
1910  float zoomx, zoomy;
1911 
1913  ED_space_clip_get_zoom(sc, region, &zoomx, &zoomy);
1914 
1915  /* if no clip, nothing to do */
1916  if (!clip) {
1917  ED_region_grid_draw(region, zoomx, zoomy, 0.0f, 0.0f);
1918  return;
1919  }
1920 
1921  if (sc->flag & SC_SHOW_STABLE) {
1922  float translation[2];
1923  float aspect = clip->tracking.camera.pixel_aspect;
1924  float smat[4][4], ismat[4][4];
1925 
1926  if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
1927  ibuf = ED_space_clip_get_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle);
1928  }
1929 
1930  if (ibuf != NULL && width != ibuf->x) {
1931  mul_v2_v2fl(translation, sc->loc, (float)width / ibuf->x);
1932  }
1933  else {
1934  copy_v2_v2(translation, sc->loc);
1935  }
1936 
1938  width, height, aspect, translation, sc->scale, sc->angle, sc->stabmat);
1939 
1940  unit_m4(smat);
1941  smat[0][0] = 1.0f / width;
1942  smat[1][1] = 1.0f / height;
1943  invert_m4_m4(ismat, smat);
1944 
1945  mul_m4_series(sc->unistabmat, smat, sc->stabmat, ismat);
1946  }
1947  else if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
1948  ibuf = ED_space_clip_get_buffer(sc);
1949 
1950  zero_v2(sc->loc);
1951  sc->scale = 1.0f;
1952  unit_m4(sc->stabmat);
1953  unit_m4(sc->unistabmat);
1954  }
1955 
1956  if (ibuf) {
1957  draw_movieclip_buffer(C, sc, region, ibuf, width, height, zoomx, zoomy);
1958  IMB_freeImBuf(ibuf);
1959  }
1960  else if (sc->flag & SC_MUTE_FOOTAGE) {
1961  draw_movieclip_muted(region, width, height, zoomx, zoomy);
1962  }
1963  else {
1964  ED_region_grid_draw(region, zoomx, zoomy, 0.0f, 0.0f);
1965  }
1966 
1967  if (width && height) {
1968  draw_stabilization_border(sc, region, width, height, zoomx, zoomy);
1969  draw_tracking_tracks(sc, scene, region, clip, width, height, zoomx, zoomy);
1970  draw_distortion(sc, region, clip, width, height, zoomx, zoomy);
1971  }
1972 }
1973 
1975 {
1977  MovieClip *clip = ED_space_clip_get_clip(sc);
1978  if (clip) {
1979  draw_movieclip_cache(sc, region, clip, scene);
1980  draw_movieclip_notes(sc, region);
1981  }
1982 }
1983 
1984 /* draw grease pencil */
1986 {
1987  SpaceClip *sc = CTX_wm_space_clip(C);
1988  MovieClip *clip = ED_space_clip_get_clip(sc);
1989 
1990  if (!clip) {
1991  return;
1992  }
1993 
1994  if (onlyv2d) {
1995  bool is_track_source = sc->gpencil_src == SC_GPENCIL_SRC_TRACK;
1996  /* if manual calibration is used then grease pencil data
1997  * associated with the clip is already drawn in draw_distortion
1998  */
1999  if ((sc->flag & SC_MANUAL_CALIBRATION) == 0 || is_track_source) {
2000  GPU_matrix_push();
2002 
2003  if (is_track_source) {
2005 
2006  if (track) {
2007  int framenr = ED_space_clip_get_clip_frame_number(sc);
2008  MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
2009 
2010  GPU_matrix_translate_2fv(marker->pos);
2011  }
2012  }
2013 
2015 
2016  GPU_matrix_pop();
2017  }
2018  }
2019  else {
2021  }
2022 }
typedef float(TangentPoint)[2]
void ED_draw_imbuf_ctx(const struct bContext *C, struct ImBuf *ibuf, float x, float y, bool use_filter, float zoom_x, float zoom_y)
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:899
void BKE_image_release_ibuf(struct Image *ima, struct ImBuf *ibuf, void *lock)
Definition: image.c:5113
bool BKE_image_has_ibuf(struct Image *ima, struct ImageUser *iuser)
Definition: image.c:5134
struct ImBuf * BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **r_lock)
Definition: image.c:5100
void BKE_movieclip_get_cache_segments(struct MovieClip *clip, struct MovieClipUser *user, int *r_totseg, int **r_points)
Definition: movieclip.c:1617
struct MovieTrackingPlaneTrack * BKE_tracking_plane_track_get_active(struct MovieTracking *tracking)
Definition: tracking.c:1821
void BKE_tracking_stabilization_data_to_mat4(int width, int height, float aspect, float translation[2], float scale, float angle, float mat[4][4])
struct ListBase * BKE_tracking_get_active_tracks(struct MovieTracking *tracking)
Definition: tracking.c:365
#define MARKER_VISIBLE(sc, track, marker)
Definition: BKE_tracking.h:506
struct MovieTrackingPlaneMarker * BKE_tracking_plane_marker_get(struct MovieTrackingPlaneTrack *plane_track, int framenr)
Definition: tracking.c:1994
struct MovieTrackingTrack * BKE_tracking_track_get_active(struct MovieTracking *tracking)
Definition: tracking.c:1170
struct MovieTrackingReconstruction * BKE_tracking_get_active_reconstruction(struct MovieTracking *tracking)
Definition: tracking.c:389
struct MovieTrackingMarker * BKE_tracking_marker_get_exact(struct MovieTrackingTrack *track, int framenr)
Definition: tracking.c:1556
struct ListBase * BKE_tracking_get_active_plane_tracks(struct MovieTracking *tracking)
Definition: tracking.c:377
void BKE_tracking_distort_v2(struct MovieTracking *tracking, int image_width, int image_height, const float co[2], float r_co[2])
Definition: tracking.c:2560
#define TRACK_VIEW_SELECTED(sc, track)
Definition: BKE_tracking.h:497
void BKE_tracking_marker_pattern_minmax(const struct MovieTrackingMarker *marker, float min[2], float max[2])
void BKE_tracking_get_projection_matrix(struct MovieTracking *tracking, struct MovieTrackingObject *object, int framenr, int winx, int winy, float mat[4][4])
Definition: tracking.c:420
struct MovieTrackingMarker * BKE_tracking_marker_get(struct MovieTrackingTrack *track, int framenr)
Definition: tracking.c:1523
void BKE_tracking_undistort_v2(struct MovieTracking *tracking, int image_width, int image_height, const float co[2], float r_co[2])
Definition: tracking.c:2583
void BKE_tracking_homography_between_two_quads(float reference_corners[4][2], float corners[4][2], float H[3][3])
struct MovieTrackingObject * BKE_tracking_object_get_active(struct MovieTracking *tracking)
Definition: tracking.c:2198
void BLF_draw(int fontid, const char *str, size_t len) ATTR_NONNULL(2)
Definition: blf.c:542
void BLF_size(int fontid, int size, int dpi)
Definition: blf.c:367
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition: blf.c:757
void BLF_color4ubv(int fontid, const unsigned char rgba[4])
Definition: blf.c:387
void BLF_position(int fontid, float x, float y, float z)
Definition: blf.c:312
#define BLI_assert(a)
Definition: BLI_assert.h:58
MINLINE int min_ii(int a, int b)
MINLINE float min_ff(float a, float b)
int isect_point_quad_v2(const float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2])
Definition: math_geom.c:1616
void mul_v4_m4v4(float r[4], const float M[4][4], const float v[4])
Definition: math_matrix.c:854
void unit_m4(float m[4][4])
Definition: rct.c:1140
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
#define mul_m4_series(...)
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v2_v2(float r[2], const float a[2])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
Definition: math_vector.c:1043
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void zero_v2(float r[2])
MINLINE float len_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v2(float r[2])
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition: rct.c:436
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
unsigned char uchar
Definition: BLI_sys_types.h:86
unsigned int uint
Definition: BLI_sys_types.h:83
#define INIT_MINMAX2(min, max)
#define UNUSED_VARS_NDEBUG(...)
#define UNUSED(x)
#define ELEM(...)
@ GP_STROKE_2DSPACE
@ GP_LAYER_HIDE
@ IMA_VIEW_AS_RENDER
@ MCLIP_PROXY_RENDER_UNDISTORT
@ MCLIP_USE_PROXY
@ MCLIP_PROXY_RENDER_SIZE_100
@ MCLIP_PROXY_RENDER_SIZE_FULL
#define CFRA
#define SFRA
#define EFRA
@ SC_MODE_MASKEDIT
@ SC_SHOW_MARKER_SEARCH
@ SC_SHOW_NAMES
@ SC_SHOW_TINY_MARKER
@ SC_LOCK_SELECTION
@ SC_SHOW_METADATA
@ SC_SHOW_GRID
@ SC_SHOW_STABLE
@ SC_MUTE_FOOTAGE
@ SC_SHOW_BUNDLES
@ SC_SHOW_MARKER_PATTERN
@ SC_MANUAL_CALIBRATION
@ SC_SHOW_TRACK_PATH
@ SC_GPENCIL_SRC_TRACK
@ TRACK_CUSTOMCOLOR
@ TRACK_HIDDEN
@ TRACK_LOCKED
@ TRACK_HAS_BUNDLE
@ PLANE_MARKER_TRACKED
@ TRACKING_RECONSTRUCTED
@ PLANE_TRACK_HIDDEN
@ MARKER_TRACKED
@ MARKER_DISABLED
@ TRACKING_2D_STABILIZATION
int ED_space_clip_get_clip_frame_number(struct SpaceClip *sc)
Definition: clip_editor.c:227
void ED_clip_point_undistorted_pos(struct SpaceClip *sc, const float co[2], float r_co[2])
Definition: clip_editor.c:459
struct ImBuf * ED_space_clip_get_buffer(struct SpaceClip *sc)
Definition: clip_editor.c:235
void ED_space_clip_get_zoom(struct SpaceClip *sc, struct ARegion *region, float *zoomx, float *zoomy)
Definition: clip_editor.c:159
void ED_space_clip_get_size(struct SpaceClip *sc, int *width, int *height)
Definition: clip_editor.c:141
struct ImBuf * ED_space_clip_get_stable_buffer(struct SpaceClip *sc, float loc[2], float *scale, float *angle)
Definition: clip_editor.c:254
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:572
void ED_mask_draw_frames(struct Mask *mask, struct ARegion *region, const int cfra, const int sfra, const int efra)
Definition: mask_draw.c:788
void ED_region_info_draw(struct ARegion *region, const char *text, float fill_color[4], const bool full_redraw)
Definition: area.c:3510
void ED_region_grid_draw(struct ARegion *region, float zoomx, float zoomy, float x0, float y0)
Definition: area.c:3538
void ED_region_cache_draw_background(struct ARegion *region)
Definition: area.c:3693
void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
Definition: area.c:3707
void ED_region_cache_draw_cached_segments(struct ARegion *region, const int num_segments, const int *points, const int sfra, const int efra)
Definition: area.c:3732
void ED_region_image_metadata_draw(int x, int y, struct ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy)
Definition: ed_draw.c:313
void immUniform2f(const char *name, float x, float y)
void immUniformColor4f(float r, float g, float b, float a)
void immUnbindProgram(void)
void immVertex2f(uint attr_id, float x, float y)
void immUniformThemeColor(int color_id)
void immUniformThemeColorShade(int color_id, int offset)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immBindTexture(const char *name, GPUTexture *tex)
void immVertex3f(uint attr_id, float x, float y, float z)
void immVertex2fv(uint attr_id, const float data[2])
void immUniform1i(const char *name, int x)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
void immVertex2i(uint attr_id, int x, int y)
void immUniform1f(const char *name, float x)
void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void immUniformColor4fv(const float rgba[4])
GPUVertFormat * immVertexFormat(void)
void immUniformColor3f(float r, float g, float b)
void immAttr2f(uint attr_id, float x, float y)
void immBegin(GPUPrimType, uint vertex_len)
void immEnd(void)
void immUniformColor3fv(const float rgb[3])
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2)
void immRecti(uint pos, int x1, int y1, int x2, int y2)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void GPU_matrix_pop(void)
Definition: gpu_matrix.cc:142
void GPU_matrix_translate_2fv(const float vec[2])
Definition: gpu_matrix.cc:199
void GPU_matrix_scale_2f(float x, float y)
Definition: gpu_matrix.cc:232
#define GPU_matrix_mul(x)
Definition: GPU_matrix.h:223
void GPU_matrix_push(void)
Definition: gpu_matrix.cc:135
void GPU_matrix_translate_2f(float x, float y)
Definition: gpu_matrix.cc:190
@ GPU_PRIM_TRI_FAN
Definition: GPU_primitive.h:41
@ GPU_PRIM_LINE_LOOP
Definition: GPU_primitive.h:39
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:36
@ GPU_PRIM_POINTS
Definition: GPU_primitive.h:35
@ GPU_PRIM_LINE_STRIP
Definition: GPU_primitive.h:38
@ GPU_PRIM_TRIS
Definition: GPU_primitive.h:37
@ GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR
Definition: GPU_shader.h:365
@ GPU_SHADER_3D_IMAGE_MODULATE_ALPHA
Definition: GPU_shader.h:260
@ GPU_SHADER_2D_UNIFORM_COLOR
Definition: GPU_shader.h:171
@ GPU_BLEND_NONE
Definition: GPU_state.h:55
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:57
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:55
void GPU_line_width(float width)
Definition: gpu_state.cc:173
void GPU_logic_op_xor_set(bool enable)
Definition: gpu_state.cc:95
void GPU_point_size(float size)
Definition: gpu_state.cc:179
void GPU_viewport_size_get_f(float coords[4])
Definition: gpu_state.cc:279
struct GPUTexture GPUTexture
Definition: GPU_texture.h:33
@ GPU_DATA_UBYTE
Definition: GPU_texture.h:175
void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:391
void GPU_texture_free(GPUTexture *tex)
Definition: gpu_texture.cc:508
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
Definition: gpu_texture.cc:468
void GPU_texture_unbind(GPUTexture *tex)
Definition: gpu_texture.cc:421
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:250
@ GPU_RGBA8
Definition: GPU_texture.h:88
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ GPU_COMP_I32
void IMB_display_buffer_release(void *cache_handle)
unsigned char * IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings, const struct ColorManagedDisplaySettings *display_settings, void **cache_handle)
void IMB_freeImBuf(struct ImBuf *ibuf)
Definition: allocimbuf.c:211
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
#define UI_DPI_FAC
Definition: UI_interface.h:309
void UI_GetThemeColor3fv(int colorid, float col[3])
Definition: resources.c:1191
@ TH_PATH_BEFORE
Definition: UI_resources.h:250
@ TH_MARKER_OUTLINE
Definition: UI_resources.h:244
@ TH_LOCK_MARKER
Definition: UI_resources.h:255
@ TH_PATH_AFTER
Definition: UI_resources.h:251
@ TH_DIS_MARKER
Definition: UI_resources.h:249
@ TH_CFRAME
Definition: UI_resources.h:113
@ TH_MARKER
Definition: UI_resources.h:245
@ TH_ACT_MARKER
Definition: UI_resources.h:246
@ TH_PATH_KEYFRAME_AFTER
Definition: UI_resources.h:253
@ TH_SEL_MARKER
Definition: UI_resources.h:247
@ TH_PATH_KEYFRAME_BEFORE
Definition: UI_resources.h:252
void UI_GetThemeColorShade4ubv(int colorid, int offset, unsigned char col[4])
Definition: resources.c:1268
void UI_FontThemeColor(int fontid, int colorid)
Definition: resources.c:1156
void UI_view2d_view_to_region_fl(const struct View2D *v2d, float x, float y, float *r_region_x, float *r_region_y) ATTR_NONNULL()
void UI_view2d_view_to_region(const struct View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
void ED_annotation_draw_2dimage(const bContext *C)
void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
unsigned int U
Definition: btGjkEpa3.h:78
static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, const float marker_pos[2], int width, int height, int act, int sel, const uint shdr_pos)
Definition: clip_draw.c:695
void clip_draw_cache_and_notes(const bContext *C, SpaceClip *sc, ARegion *region)
Definition: clip_draw.c:1974
static void draw_movieclip_notes(SpaceClip *sc, ARegion *region)
Definition: clip_draw.c:275
static void draw_movieclip_cache(SpaceClip *sc, ARegion *region, MovieClip *clip, Scene *scene)
Definition: clip_draw.c:146
static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3])
Definition: clip_draw.c:671
static void draw_movieclip_muted(ARegion *region, int width, int height, float zoomx, float zoomy)
Definition: clip_draw.c:298
static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, const float marker_pos[2], int width, int height, uint position)
Definition: clip_draw.c:584
static void draw_track_path_points(const TrackPathPoint *path, uint position_attribute, const int start_point, const int num_points)
Definition: clip_draw.c:455
static void draw_plane_marker(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track, MovieTrackingPlaneMarker *plane_marker, bool is_active_track, int width, int height)
Definition: clip_draw.c:1404
static void getArrowEndPoint(const int width, const int height, const float zoom, const float start_corner[2], const float end_corner[2], float end_point[2])
Definition: clip_draw.c:1122
struct TrachPathPoint TrackPathPoint
static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int outline, const float px[2], uint pos)
Definition: clip_draw.c:902
static void draw_track_path_keyframe_points(const TrackPathPoint *path, uint position_attribute, const int start_point, const int num_points)
Definition: clip_draw.c:471
void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *region)
Definition: clip_draw.c:1904
static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, const float marker_pos[2], int act, int width, int height, float zoomx, float zoomy)
Definition: clip_draw.c:1020
static int track_to_path_segment(SpaceClip *sc, MovieTrackingTrack *track, int direction, TrackPathPoint *path)
Definition: clip_draw.c:424
#define MAX_STATIC_PATH
static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track, MovieTrackingPlaneMarker *plane_marker, bool is_active_track, bool draw_outline, int width, int height)
Definition: clip_draw.c:1262
static void draw_plane_track(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track, int framenr, bool is_active_track, int width, int height)
Definition: clip_draw.c:1416
static void marker_to_path_point(SpaceClip *sc, const MovieTrackingTrack *track, const MovieTrackingMarker *marker, TrackPathPoint *point)
Definition: clip_draw.c:411
@ PATH_POINT_FLAG_KEYFRAME
Definition: clip_draw.c:403
static void draw_distortion(SpaceClip *sc, ARegion *region, MovieClip *clip, int width, int height, float zoomx, float zoomy)
Definition: clip_draw.c:1697
static float get_shortest_pattern_side(MovieTrackingMarker *marker)
Definition: clip_draw.c:873
static void plane_track_colors(bool is_active, float color[3], float selected_color[3])
Definition: clip_draw.c:1115
static bool generic_track_is_marker_enabled(MovieTrackingTrack *track, MovieTrackingPlaneTrack *plane_track, int marker_index)
Definition: clip_draw.c:115
static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *region, MovieClip *clip, int width, int height, float zoomx, float zoomy)
Definition: clip_draw.c:1433
static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackingTrack *track)
Definition: clip_draw.c:502
static int generic_track_get_marker_framenr(MovieTrackingTrack *track, MovieTrackingPlaneTrack *plane_track, int marker_index)
Definition: clip_draw.c:99
static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width, uint pos)
Definition: clip_draw.c:70
static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *region, ImBuf *ibuf, int width, int height, float zoomx, float zoomy)
Definition: clip_draw.c:314
void clip_draw_grease_pencil(bContext *C, int onlyv2d)
Definition: clip_draw.c:1985
static void draw_stabilization_border(SpaceClip *sc, ARegion *region, int width, int height, float zoomx, float zoomy)
Definition: clip_draw.c:357
static void draw_marker_slide_square(float x, float y, float dx, float dy, int outline, const float px[2], uint pos)
Definition: clip_draw.c:886
static void draw_track_path_lines(const TrackPathPoint *path, uint position_attribute, const int start_point, const int num_points)
Definition: clip_draw.c:486
static int generic_track_get_markersnr(MovieTrackingTrack *track, MovieTrackingPlaneTrack *plane_track)
Definition: clip_draw.c:86
static void homogeneous_2d_to_gl_matrix(float matrix[3][3], float gl_matrix[4][4])
Definition: clip_draw.c:1144
static void draw_plane_marker_image(Scene *scene, MovieTrackingPlaneTrack *plane_track, MovieTrackingPlaneMarker *plane_marker)
Definition: clip_draw.c:1167
static bool generic_track_is_marker_keyframed(MovieTrackingTrack *track, MovieTrackingPlaneTrack *plane_track, int marker_index)
Definition: clip_draw.c:130
static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, const float marker_pos[2], int outline, int sel, int act, int width, int height, uint pos)
Definition: clip_draw.c:922
static void draw_plane_marker_outline(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track, MovieTrackingPlaneMarker *plane_marker, int width, int height)
Definition: clip_draw.c:1394
#define SELECT
Scene scene
#define str(s)
uint pos
uint col
int count
const ProjectiveReconstruction & reconstruction
Definition: intersect.cc:198
#define ceilf(x)
#define sqrtf(x)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
static ulong * next
static ulong state[N]
static unsigned a[3]
Definition: RandGen.cpp:92
static const int steps
Definition: sky_nishita.cpp:28
#define min(a, b)
Definition: sort.c:51
unsigned char planes
void * first
Definition: DNA_listBase.h:47
struct Mask * mask
struct MovieTracking tracking
struct bGPdata * gpd
struct MovieTrackingPlaneTrack * next
MovieTrackingPlaneMarker * markers
MovieTrackingMarker * markers
struct MovieTrackingTrack * next
MovieTrackingStats * stats
MovieTrackingStabilization stabilization
MovieTrackingCamera camera
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
struct MovieClipUser user
float stabmat[4][4]
float unistabmat[4][4]
float loc[2]
struct MovieClip * clip
MaskSpaceInfo mask_info
float co[2]
Definition: clip_draw.c:407
struct bGPDframe * next
ListBase strokes
float color[4]
struct bGPDlayer * next
ListBase frames
bGPDspoint * points
struct bGPDstroke * next
ListBase layers
uiFontStyle widget
float max
ccl_device_inline float3 ceil(const float3 &a)
uint len