Blender V5.0
mask_query.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "BKE_context.hh"
12#include "BKE_mask.h"
13
14#include "BLI_listbase.h"
15#include "BLI_math_geom.h"
16#include "BLI_math_vector.h"
17
18#include "DEG_depsgraph.hh"
20
21#include "DNA_mask_types.h"
22#include "DNA_screen_types.h"
23
24#include "ED_clip.hh"
25#include "ED_image.hh"
26#include "ED_mask.hh" /* own include */
27
28#include "UI_view2d.hh"
29
30#include "mask_intern.hh" /* own include */
31
32/* -------------------------------------------------------------------- */
35
37 Mask *mask_orig,
38 const float normal_co[2],
39 int threshold,
40 bool feather,
41 float tangent[2],
42 const bool use_deform,
43 const bool use_project,
44 MaskLayer **r_mask_layer,
45 MaskSpline **r_spline,
46 MaskSplinePoint **r_point,
47 float *r_u,
48 float *r_score)
49{
50 const float threshold_sq = threshold * threshold;
51
52 ScrArea *area = CTX_wm_area(C);
53 ARegion *region = CTX_wm_region(C);
54
55 MaskLayer *point_mask_layer;
56 MaskSpline *point_spline;
57 MaskSplinePoint *point = nullptr;
58 float dist_best_sq = FLT_MAX, co[2];
59 int width, height;
60 float u = 0.0f;
61 float scalex, scaley;
62
64 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask_orig);
65
66 ED_mask_get_size(area, &width, &height);
67 ED_mask_pixelspace_factor(area, region, &scalex, &scaley);
68
69 co[0] = normal_co[0] * scalex;
70 co[1] = normal_co[1] * scaley;
71
72 for (MaskLayer *mask_layer_orig = static_cast<MaskLayer *>(mask_orig->masklayers.first),
73 *mask_layer_eval = static_cast<MaskLayer *>(mask_eval->masklayers.first);
74 mask_layer_orig != nullptr;
75 mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next)
76 {
77 if (mask_layer_orig->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
78 continue;
79 }
80
81 for (MaskSpline *spline_orig = static_cast<MaskSpline *>(mask_layer_orig->splines.first),
82 *spline_eval = static_cast<MaskSpline *>(mask_layer_eval->splines.first);
83 spline_orig != nullptr;
84 spline_orig = spline_orig->next, spline_eval = spline_eval->next)
85 {
86 int i;
87 MaskSplinePoint *cur_point_eval;
88
89 for (i = 0, cur_point_eval = use_deform ? spline_eval->points_deform : spline_eval->points;
90 i < spline_eval->tot_point;
91 i++, cur_point_eval++)
92 {
93 uint tot_diff_point;
94 float *diff_points = BKE_mask_point_segment_diff(
95 spline_eval, cur_point_eval, width, height, &tot_diff_point);
96
97 if (diff_points) {
98 int j, tot_point;
99 uint tot_feather_point;
100 float *feather_points = nullptr, *points;
101
102 if (feather) {
104 spline_eval, cur_point_eval, width, height, &tot_feather_point);
105
106 points = feather_points;
107 tot_point = tot_feather_point;
108 }
109 else {
110 points = diff_points;
111 tot_point = tot_diff_point;
112 }
113
114 for (j = 0; j < tot_point - 1; j++) {
115 float dist_sq, a[2], b[2];
116
117 a[0] = points[2 * j] * scalex;
118 a[1] = points[2 * j + 1] * scaley;
119
120 b[0] = points[2 * j + 2] * scalex;
121 b[1] = points[2 * j + 3] * scaley;
122
123 dist_sq = dist_squared_to_line_segment_v2(co, a, b);
124
125 if (dist_sq < dist_best_sq) {
126 if (tangent) {
127 sub_v2_v2v2(tangent, &diff_points[2 * j + 2], &diff_points[2 * j]);
128 }
129
130 point_mask_layer = mask_layer_orig;
131 point_spline = spline_orig;
132 point = use_deform ?
133 &spline_orig->points[(cur_point_eval - spline_eval->points_deform)] :
134 &spline_orig->points[(cur_point_eval - spline_eval->points)];
135 dist_best_sq = dist_sq;
136 u = float(j) / tot_point;
137 }
138 }
139
140 if (feather_points != nullptr) {
141 MEM_freeN(feather_points);
142 }
143 MEM_freeN(diff_points);
144 }
145 }
146 }
147 }
148
149 if (point && dist_best_sq < threshold_sq) {
150 if (r_mask_layer) {
151 *r_mask_layer = point_mask_layer;
152 }
153
154 if (r_spline) {
155 *r_spline = point_spline;
156 }
157
158 if (r_point) {
159 *r_point = point;
160 }
161
162 if (r_u) {
163 /* TODO(sergey): Projection fails in some weirdo cases. */
164 if (use_project) {
165 u = BKE_mask_spline_project_co(point_spline, point, u, normal_co, MASK_PROJ_ANY);
166 }
167
168 *r_u = u;
169 }
170
171 if (r_score) {
172 *r_score = dist_best_sq;
173 }
174
175 return true;
176 }
177
178 if (r_mask_layer) {
179 *r_mask_layer = nullptr;
180 }
181
182 if (r_spline) {
183 *r_spline = nullptr;
184 }
185
186 if (r_point) {
187 *r_point = nullptr;
188 }
189
190 return false;
191}
192
194 const eMaskWhichHandle which_handle,
195 const float scalex,
196 const float scaley,
197 float handle[2])
198{
199 BKE_mask_point_handle(point, which_handle, handle);
200 handle[0] *= scalex;
201 handle[1] *= scaley;
202}
203
205 Mask *mask_orig,
206 const float normal_co[2],
207 const float threshold,
208 MaskLayer **r_mask_layer,
209 MaskSpline **r_spline,
210 eMaskWhichHandle *r_which_handle,
211 float *r_score)
212{
213 ScrArea *area = CTX_wm_area(C);
214 ARegion *region = CTX_wm_region(C);
215
216 MaskLayer *point_mask_layer = nullptr;
217 MaskSpline *point_spline = nullptr;
218 MaskSplinePoint *point = nullptr;
219 float co[2];
220 const float threshold_sq = threshold * threshold;
221 float len_sq = FLT_MAX, scalex, scaley;
223 int width, height;
224
226 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask_orig);
227
228 ED_mask_get_size(area, &width, &height);
229 ED_mask_pixelspace_factor(area, region, &scalex, &scaley);
230
231 co[0] = normal_co[0] * scalex;
232 co[1] = normal_co[1] * scaley;
233
234 for (MaskLayer *mask_layer_orig = static_cast<MaskLayer *>(mask_orig->masklayers.first),
235 *mask_layer_eval = static_cast<MaskLayer *>(mask_eval->masklayers.first);
236 mask_layer_orig != nullptr;
237 mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next)
238 {
239
240 if (mask_layer_orig->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
241 continue;
242 }
243
244 for (MaskSpline *spline_orig = static_cast<MaskSpline *>(mask_layer_orig->splines.first),
245 *spline_eval = static_cast<MaskSpline *>(mask_layer_eval->splines.first);
246 spline_orig != nullptr;
247 spline_orig = spline_orig->next, spline_eval = spline_eval->next)
248 {
249 MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline_eval);
250
251 for (int i = 0; i < spline_orig->tot_point; i++) {
252 MaskSplinePoint *cur_point_orig = &spline_orig->points[i];
253 const MaskSplinePoint *cur_point_deform_eval = &points_array[i];
254 eMaskWhichHandle cur_which_handle = MASK_WHICH_HANDLE_NONE;
255 const BezTriple *bezt = &cur_point_deform_eval->bezt;
256 float cur_len_sq, vec[2];
257
258 vec[0] = bezt->vec[1][0] * scalex;
259 vec[1] = bezt->vec[1][1] * scaley;
260
261 cur_len_sq = len_squared_v2v2(co, vec);
262
263 if (cur_len_sq < len_sq) {
264 point_spline = spline_orig;
265 point_mask_layer = mask_layer_orig;
266 point = cur_point_orig;
267 len_sq = cur_len_sq;
268 which_handle = MASK_WHICH_HANDLE_NONE;
269 }
270
271 if (BKE_mask_point_handles_mode_get(cur_point_deform_eval) == MASK_HANDLE_MODE_STICK) {
272 float handle[2];
274 cur_point_deform_eval, MASK_WHICH_HANDLE_STICK, scalex, scaley, handle);
275 cur_len_sq = len_squared_v2v2(co, handle);
276 cur_which_handle = MASK_WHICH_HANDLE_STICK;
277 }
278 else {
279 float handle_left[2], handle_right[2];
280 float len_left_sq, len_right_sq;
282 cur_point_deform_eval, MASK_WHICH_HANDLE_LEFT, scalex, scaley, handle_left);
284 cur_point_deform_eval, MASK_WHICH_HANDLE_RIGHT, scalex, scaley, handle_right);
285
286 len_left_sq = len_squared_v2v2(co, handle_left);
287 len_right_sq = len_squared_v2v2(co, handle_right);
288 if (i == 0) {
289 if (len_left_sq <= len_right_sq) {
290 if (bezt->h1 != HD_VECT) {
291 cur_which_handle = MASK_WHICH_HANDLE_LEFT;
292 cur_len_sq = len_left_sq;
293 }
294 }
295 else if (bezt->h2 != HD_VECT) {
296 cur_which_handle = MASK_WHICH_HANDLE_RIGHT;
297 cur_len_sq = len_right_sq;
298 }
299 }
300 else {
301 if (len_right_sq <= len_left_sq) {
302 if (bezt->h2 != HD_VECT) {
303 cur_which_handle = MASK_WHICH_HANDLE_RIGHT;
304 cur_len_sq = len_right_sq;
305 }
306 }
307 else if (bezt->h1 != HD_VECT) {
308 cur_which_handle = MASK_WHICH_HANDLE_LEFT;
309 cur_len_sq = len_left_sq;
310 }
311 }
312 }
313
314 if (cur_len_sq <= len_sq && cur_which_handle != MASK_WHICH_HANDLE_NONE) {
315 point_mask_layer = mask_layer_orig;
316 point_spline = spline_orig;
317 point = cur_point_orig;
318 len_sq = cur_len_sq;
319 which_handle = cur_which_handle;
320 }
321 }
322 }
323 }
324
325 if (len_sq < threshold_sq) {
326 if (r_mask_layer) {
327 *r_mask_layer = point_mask_layer;
328 }
329
330 if (r_spline) {
331 *r_spline = point_spline;
332 }
333
334 if (r_which_handle) {
335 *r_which_handle = which_handle;
336 }
337
338 if (r_score) {
339 *r_score = sqrtf(len_sq);
340 }
341
342 return point;
343 }
344
345 if (r_mask_layer) {
346 *r_mask_layer = nullptr;
347 }
348
349 if (r_spline) {
350 *r_spline = nullptr;
351 }
352
353 if (r_which_handle) {
354 *r_which_handle = MASK_WHICH_HANDLE_NONE;
355 }
356
357 return nullptr;
358}
359
361 Mask *mask_orig,
362 const float normal_co[2],
363 const float threshold,
364 MaskLayer **r_mask_layer,
365 MaskSpline **r_spline,
366 MaskSplinePoint **r_point,
367 MaskSplinePointUW **r_uw,
368 float *r_score)
369{
370 ScrArea *area = CTX_wm_area(C);
371 ARegion *region = CTX_wm_region(C);
372
373 MaskLayer *point_mask_layer = nullptr;
374 MaskSpline *point_spline = nullptr;
375 MaskSplinePoint *point = nullptr;
376 MaskSplinePointUW *uw = nullptr;
377 const float threshold_sq = threshold * threshold;
378 float len = FLT_MAX, co[2];
379 float scalex, scaley;
380 int width, height;
381
383 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask_orig);
384
385 ED_mask_get_size(area, &width, &height);
386 ED_mask_pixelspace_factor(area, region, &scalex, &scaley);
387
388 co[0] = normal_co[0] * scalex;
389 co[1] = normal_co[1] * scaley;
390
391 for (MaskLayer *mask_layer_orig = static_cast<MaskLayer *>(mask_orig->masklayers.first),
392 *mask_layer_eval = static_cast<MaskLayer *>(mask_eval->masklayers.first);
393 mask_layer_orig != nullptr;
394 mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next)
395 {
396
397 for (MaskSpline *spline_orig = static_cast<MaskSpline *>(mask_layer_orig->splines.first),
398 *spline_eval = static_cast<MaskSpline *>(mask_layer_eval->splines.first);
399 spline_orig != nullptr;
400 spline_orig = spline_orig->next, spline_eval = spline_eval->next)
401 {
402 // MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
403
404 int i, tot_feather_point;
405 float (*feather_points)[2], (*fp)[2];
406
407 if (mask_layer_orig->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
408 continue;
409 }
410
411 feather_points = fp = BKE_mask_spline_feather_points(spline_eval, &tot_feather_point);
412
413 for (i = 0; i < spline_orig->tot_point; i++) {
414 int j;
415 MaskSplinePoint *cur_point_orig = &spline_orig->points[i];
416 MaskSplinePoint *cur_point_eval = &spline_eval->points[i];
417
418 for (j = 0; j <= cur_point_eval->tot_uw; j++) {
419 float cur_len_sq, vec[2];
420
421 vec[0] = (*fp)[0] * scalex;
422 vec[1] = (*fp)[1] * scaley;
423
424 cur_len_sq = len_squared_v2v2(vec, co);
425
426 if (point == nullptr || cur_len_sq < len) {
427 if (j == 0) {
428 uw = nullptr;
429 }
430 else {
431 uw = &cur_point_orig->uw[j - 1];
432 }
433
434 point_mask_layer = mask_layer_orig;
435 point_spline = spline_orig;
436 point = cur_point_orig;
437 len = cur_len_sq;
438 }
439
440 fp++;
441 }
442 }
443
444 MEM_freeN(feather_points);
445 }
446 }
447
448 if (len < threshold_sq) {
449 if (r_mask_layer) {
450 *r_mask_layer = point_mask_layer;
451 }
452
453 if (r_spline) {
454 *r_spline = point_spline;
455 }
456
457 if (r_point) {
458 *r_point = point;
459 }
460
461 if (r_uw) {
462 *r_uw = uw;
463 }
464
465 if (r_score) {
466 *r_score = sqrtf(len);
467 }
468
469 return true;
470 }
471
472 if (r_mask_layer) {
473 *r_mask_layer = nullptr;
474 }
475
476 if (r_spline) {
477 *r_spline = nullptr;
478 }
479
480 if (r_point) {
481 *r_point = nullptr;
482 }
483
484 return false;
485}
486
487void ED_mask_mouse_pos(ScrArea *area, ARegion *region, const int mval[2], float r_co[2])
488{
489 if (area) {
490 switch (area->spacetype) {
491 case SPACE_CLIP: {
492 SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
493 ED_clip_mouse_pos(sc, region, mval, r_co);
494 BKE_mask_coord_from_movieclip(sc->clip, &sc->user, r_co, r_co);
495 break;
496 }
497 case SPACE_SEQ: {
498 UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &r_co[0], &r_co[1]);
499 break;
500 }
501 case SPACE_IMAGE: {
502 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
503 ED_image_mouse_pos(sima, region, mval, r_co);
504 BKE_mask_coord_from_image(sima->image, &sima->iuser, r_co, r_co);
505 break;
506 }
507 default:
508 /* possible other spaces from which mask editing is available */
509 BLI_assert(0);
510 zero_v2(r_co);
511 break;
512 }
513 }
514 else {
515 BLI_assert(0);
516 zero_v2(r_co);
517 }
518}
519
520void ED_mask_point_pos(ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
521{
522 float co[2];
523
524 if (area) {
525 switch (area->spacetype) {
526 case SPACE_CLIP: {
527 SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
528 ED_clip_point_stable_pos(sc, region, x, y, &co[0], &co[1]);
529 BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
530 break;
531 }
532 case SPACE_SEQ:
533 zero_v2(co); /* MASKTODO */
534 break;
535 case SPACE_IMAGE: {
536 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
537 ED_image_point_pos(sima, region, x, y, &co[0], &co[1]);
538 BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co);
539 break;
540 }
541 default:
542 /* possible other spaces from which mask editing is available */
543 BLI_assert(0);
544 zero_v2(co);
545 break;
546 }
547 }
548 else {
549 BLI_assert(0);
550 zero_v2(co);
551 }
552
553 *r_x = co[0];
554 *r_y = co[1];
555}
556
558 ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
559{
560 float co[2];
561
562 if (area) {
563 switch (area->spacetype) {
564 case SPACE_CLIP: {
565 SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
566 co[0] = x;
567 co[1] = y;
568 BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co);
569 ED_clip_point_stable_pos__reverse(sc, region, co, co);
570 break;
571 }
572 case SPACE_SEQ:
573 zero_v2(co); /* MASKTODO */
574 break;
575 case SPACE_IMAGE: {
576 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
577 co[0] = x;
578 co[1] = y;
579 BKE_mask_coord_to_image(sima->image, &sima->iuser, co, co);
580 ED_image_point_pos__reverse(sima, region, co, co);
581 break;
582 }
583 default:
584 /* possible other spaces from which mask editing is available */
585 BLI_assert(0);
586 zero_v2(co);
587 break;
588 }
589 }
590 else {
591 BLI_assert(0);
592 zero_v2(co);
593 }
594
595 *r_x = co[0];
596 *r_y = co[1];
597}
598
600 eMaskWhichHandle which_handle,
601 bool handles_as_control_point,
602 float r_handle[2])
603{
604 if (handles_as_control_point) {
605 copy_v2_v2(r_handle, point->bezt.vec[1]);
606 return;
607 }
608 BKE_mask_point_handle(point, which_handle, r_handle);
609}
610
612 float min[2],
613 float max[2],
614 bool handles_as_control_point)
615{
618
619 bool ok = false;
620
621 if (mask == nullptr) {
622 return ok;
623 }
624
625 /* Use evaluated mask to take animation into account.
626 * The animation of splines is not "flushed" back to original, so need to explicitly
627 * use evaluated data-block here. */
628 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask);
629
631 LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask_eval->masklayers) {
632 if (mask_layer->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
633 continue;
634 }
635 LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) {
636 MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
637 for (int i = 0; i < spline->tot_point; i++) {
638 const MaskSplinePoint *point = &spline->points[i];
639 const MaskSplinePoint *deform_point = &points_array[i];
640 const BezTriple *bezt = &point->bezt;
641 float handle[2];
642 if (!MASKPOINT_ISSEL_ANY(point)) {
643 continue;
644 }
645 if (bezt->f2 & SELECT) {
646 minmax_v2v2_v2(min, max, deform_point->bezt.vec[1]);
647 ok = true;
648 }
649
652 deform_point, MASK_WHICH_HANDLE_STICK, handles_as_control_point, handle);
653 minmax_v2v2_v2(min, max, handle);
654 ok = true;
655 }
656 else {
657 if ((bezt->f1 & SELECT) && (bezt->h1 != HD_VECT)) {
659 deform_point, MASK_WHICH_HANDLE_LEFT, handles_as_control_point, handle);
660 minmax_v2v2_v2(min, max, handle);
661 ok = true;
662 }
663 if ((bezt->f3 & SELECT) && (bezt->h2 != HD_VECT)) {
665 deform_point, MASK_WHICH_HANDLE_RIGHT, handles_as_control_point, handle);
666 minmax_v2v2_v2(min, max, handle);
667 ok = true;
668 }
669 }
670 }
671 }
672 }
673 return ok;
674}
675
677 const bContext *C, ScrArea *area, float r_center[2], char mode, bool *r_has_select)
678{
679 float min[2], max[2];
680 const bool mask_selected = ED_mask_selected_minmax(C, min, max, false);
681
682 switch (mode) {
684 ED_mask_cursor_location_get(area, r_center);
685 break;
686 default:
687 mid_v2_v2v2(r_center, min, max);
688 break;
689 }
690 if (r_has_select != nullptr) {
691 *r_has_select = mask_selected;
692 }
693}
694
696
697/* -------------------------------------------------------------------- */
700
701void ED_mask_get_size(ScrArea *area, int *r_width, int *r_height)
702{
703 if (area && area->spacedata.first) {
704 switch (area->spacetype) {
705 case SPACE_CLIP: {
706 SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
707 ED_space_clip_get_size(sc, r_width, r_height);
708 break;
709 }
710 case SPACE_SEQ: {
711 // Scene *scene = CTX_data_scene(C);
712 // BKE_render_resolution(&scene->r, false, r_width, r_height);
713 break;
714 }
715 case SPACE_IMAGE: {
716 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
717 ED_space_image_get_size(sima, r_width, r_height);
718 break;
719 }
720 default:
721 /* possible other spaces from which mask editing is available */
722 BLI_assert(0);
723 *r_width = 0;
724 *r_height = 0;
725 break;
726 }
727 }
728 else {
729 BLI_assert(0);
730 *r_width = 0;
731 *r_height = 0;
732 }
733}
734
735void ED_mask_zoom(ScrArea *area, ARegion *region, float *r_zoomx, float *r_zoomy)
736{
737 if (area && area->spacedata.first) {
738 switch (area->spacetype) {
739 case SPACE_CLIP: {
740 SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
741 ED_space_clip_get_zoom(sc, region, r_zoomx, r_zoomy);
742 break;
743 }
744 case SPACE_SEQ: {
745 *r_zoomx = *r_zoomy = 1.0f;
746 break;
747 }
748 case SPACE_IMAGE: {
749 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
750 ED_space_image_get_zoom(sima, region, r_zoomx, r_zoomy);
751 break;
752 }
753 default:
754 /* possible other spaces from which mask editing is available */
755 BLI_assert(0);
756 *r_zoomx = *r_zoomy = 1.0f;
757 break;
758 }
759 }
760 else {
761 BLI_assert(0);
762 *r_zoomx = *r_zoomy = 1.0f;
763 }
764}
765
766void ED_mask_get_aspect(ScrArea *area, ARegion * /*region*/, float *r_aspx, float *r_aspy)
767{
768 if (area && area->spacedata.first) {
769 switch (area->spacetype) {
770 case SPACE_CLIP: {
771 SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
772 ED_space_clip_get_aspect(sc, r_aspx, r_aspy);
773 break;
774 }
775 case SPACE_SEQ: {
776 *r_aspx = *r_aspy = 1.0f; /* MASKTODO - render aspect? */
777 break;
778 }
779 case SPACE_IMAGE: {
780 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
781 ED_space_image_get_aspect(sima, r_aspx, r_aspy);
782 break;
783 }
784 default:
785 /* possible other spaces from which mask editing is available */
786 BLI_assert(0);
787 *r_aspx = *r_aspy = 1.0f;
788 break;
789 }
790 }
791 else {
792 BLI_assert(0);
793 *r_aspx = *r_aspy = 1.0f;
794 }
795}
796
797void ED_mask_pixelspace_factor(ScrArea *area, ARegion *region, float *r_scalex, float *r_scaley)
798{
799 if (area && area->spacedata.first) {
800 switch (area->spacetype) {
801 case SPACE_CLIP: {
802 SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
803 float aspx, aspy;
804
805 UI_view2d_scale_get(&region->v2d, r_scalex, r_scaley);
806 ED_space_clip_get_aspect(sc, &aspx, &aspy);
807
808 *r_scalex *= aspx;
809 *r_scaley *= aspy;
810 break;
811 }
812 case SPACE_SEQ: {
813 *r_scalex = *r_scaley = 1.0f; /* MASKTODO? */
814 break;
815 }
816 case SPACE_IMAGE: {
817 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
818 float aspx, aspy;
819
820 UI_view2d_scale_get(&region->v2d, r_scalex, r_scaley);
821 ED_space_image_get_aspect(sima, &aspx, &aspy);
822
823 *r_scalex *= aspx;
824 *r_scaley *= aspy;
825 break;
826 }
827 default:
828 /* possible other spaces from which mask editing is available */
829 BLI_assert(0);
830 *r_scalex = *r_scaley = 1.0f;
831 break;
832 }
833 }
834 else {
835 BLI_assert(0);
836 *r_scalex = *r_scaley = 1.0f;
837 }
838}
839
840void ED_mask_cursor_location_get(ScrArea *area, float cursor[2])
841{
842 if (area) {
843 switch (area->spacetype) {
844 case SPACE_CLIP: {
845 SpaceClip *space_clip = static_cast<SpaceClip *>(area->spacedata.first);
846 copy_v2_v2(cursor, space_clip->cursor);
847 break;
848 }
849 case SPACE_SEQ: {
850 zero_v2(cursor);
851 break;
852 }
853 case SPACE_IMAGE: {
854 SpaceImage *space_image = static_cast<SpaceImage *>(area->spacedata.first);
855 copy_v2_v2(cursor, space_image->cursor);
856 break;
857 }
858 default:
859 /* possible other spaces from which mask editing is available */
860 BLI_assert(0);
861 zero_v2(cursor);
862 break;
863 }
864 }
865 else {
866 BLI_assert(0);
867 zero_v2(cursor);
868 }
869}
870
Mask * CTX_data_edit_mask(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
@ MASK_HANDLE_MODE_STICK
Definition BKE_mask.h:37
#define MASKPOINT_ISSEL_ANY(p)
Definition BKE_mask.h:292
void BKE_mask_coord_from_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2])
eMaskWhichHandle
Definition BKE_mask.h:28
@ MASK_WHICH_HANDLE_NONE
Definition BKE_mask.h:29
@ MASK_WHICH_HANDLE_RIGHT
Definition BKE_mask.h:32
@ MASK_WHICH_HANDLE_LEFT
Definition BKE_mask.h:31
@ MASK_WHICH_HANDLE_STICK
Definition BKE_mask.h:30
float * BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct MaskSplinePoint *point, int width, int height, unsigned int *r_tot_feather_point)
@ MASK_PROJ_ANY
Definition BKE_mask.h:92
void BKE_mask_coord_to_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2])
float * BKE_mask_point_segment_diff(struct MaskSpline *spline, struct MaskSplinePoint *point, int width, int height, unsigned int *r_tot_diff_point)
void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2])
void BKE_mask_point_handle(const struct MaskSplinePoint *point, eMaskWhichHandle which_handle, float r_handle[2])
float(* BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2]
eMaskhandleMode BKE_mask_point_handles_mode_get(const struct MaskSplinePoint *point)
void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2])
float BKE_mask_spline_project_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float start_u, const float co[2], eMaskSign sign)
struct MaskSplinePoint * BKE_mask_spline_point_array(struct MaskSpline *spline)
#define BLI_assert(a)
Definition BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:291
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_v2(float r[2], const float a[2])
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
void mid_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])
unsigned int uint
#define INIT_MINMAX2(min, max)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ HD_VECT
@ MASK_HIDE_SELECT
@ MASK_HIDE_VIEW
@ SPACE_CLIP
@ SPACE_SEQ
@ SPACE_IMAGE
@ V3D_AROUND_CURSOR
void ED_clip_point_stable_pos(const SpaceClip *sc, const ARegion *region, float x, float y, float *xr, float *yr)
void ED_clip_mouse_pos(const SpaceClip *sc, const ARegion *region, const int mval[2], float r_co[2])
void ED_space_clip_get_size(const SpaceClip *sc, int *r_width, int *r_height)
void ED_space_clip_get_zoom(const SpaceClip *sc, const ARegion *region, float *r_zoomx, float *r_zoomy)
void ED_space_clip_get_aspect(const SpaceClip *sc, float *r_aspx, float *r_aspy)
void ED_clip_point_stable_pos__reverse(const SpaceClip *sc, const ARegion *region, const float co[2], float r_co[2])
the reverse of ED_clip_point_stable_pos(), gets the marker region coords. better name here?...
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
void ED_image_mouse_pos(SpaceImage *sima, const ARegion *region, const int mval[2], float co[2])
void ED_image_point_pos(SpaceImage *sima, const ARegion *region, float x, float y, float *r_x, float *r_y)
void ED_space_image_get_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
void ED_space_image_get_zoom(SpaceImage *sima, const ARegion *region, float *r_zoomx, float *r_zoomy)
void ED_image_point_pos__reverse(SpaceImage *sima, const ARegion *region, const float co[2], float r_co[2])
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
void UI_view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1912
void UI_view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1668
BPy_StructRNA * depsgraph
nullptr float
#define SELECT
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void ED_mask_mouse_pos(ScrArea *area, ARegion *region, const int mval[2], float r_co[2])
bool ED_mask_feather_find_nearest(const bContext *C, Mask *mask_orig, const float normal_co[2], const float threshold, MaskLayer **r_mask_layer, MaskSpline **r_spline, MaskSplinePoint **r_point, MaskSplinePointUW **r_uw, float *r_score)
void ED_mask_center_from_pivot_ex(const bContext *C, ScrArea *area, float r_center[2], char mode, bool *r_has_select)
void ED_mask_point_pos(ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
void ED_mask_get_aspect(ScrArea *area, ARegion *, float *r_aspx, float *r_aspy)
void ED_mask_zoom(ScrArea *area, ARegion *region, float *r_zoomx, float *r_zoomy)
MaskSplinePoint * ED_mask_point_find_nearest(const bContext *C, Mask *mask_orig, const float normal_co[2], const float threshold, MaskLayer **r_mask_layer, MaskSpline **r_spline, eMaskWhichHandle *r_which_handle, float *r_score)
static void mask_point_scaled_handle(const MaskSplinePoint *point, const eMaskWhichHandle which_handle, const float scalex, const float scaley, float handle[2])
void ED_mask_get_size(ScrArea *area, int *r_width, int *r_height)
void ED_mask_cursor_location_get(ScrArea *area, float cursor[2])
void ED_mask_point_pos__reverse(ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
bool ED_mask_selected_minmax(const bContext *C, float min[2], float max[2], bool handles_as_control_point)
static void handle_position_for_minmax(const MaskSplinePoint *point, eMaskWhichHandle which_handle, bool handles_as_control_point, float r_handle[2])
void ED_mask_pixelspace_factor(ScrArea *area, ARegion *region, float *r_scalex, float *r_scaley)
bool ED_mask_find_nearest_diff_point(const bContext *C, Mask *mask_orig, const float normal_co[2], int threshold, bool feather, float tangent[2], const bool use_deform, const bool use_project, MaskLayer **r_mask_layer, MaskSpline **r_spline, MaskSplinePoint **r_point, float *r_u, float *r_score)
Definition mask_query.cc:36
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
#define sqrtf
#define min(a, b)
Definition sort.cc:36
#define FLT_MAX
Definition stdcycles.h:14
float vec[3][3]
void * first
struct MaskLayer * next
MaskSplinePointUW * uw
struct MaskSpline * next
ListBase masklayers
ListBase spacedata
struct MovieClipUser user
float cursor[2]
struct MovieClip * clip
float cursor[2]
struct ImageUser iuser
struct Image * image
i
Definition text_draw.cc:230
max
Definition text_draw.cc:251
uint len