Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mask.c
| Show All 26 Lines | |||||
| /** \file blender/blenkernel/intern/mask.c | /** \file blender/blenkernel/intern/mask.c | ||||
| * \ingroup bke | * \ingroup bke | ||||
| */ | */ | ||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "CLG_log.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_string_utils.h" | #include "BLI_string_utils.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| Show All 15 Lines | |||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "BKE_sequencer.h" | #include "BKE_sequencer.h" | ||||
| #include "BKE_tracking.h" | #include "BKE_tracking.h" | ||||
| #include "BKE_movieclip.h" | #include "BKE_movieclip.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "DEG_depsgraph_build.h" | #include "DEG_depsgraph_build.h" | ||||
| static CLG_LogRef LOG = {"bke.mask"}; | |||||
| static struct { | static struct { | ||||
| ListBase splines; | ListBase splines; | ||||
| struct GHash *id_hash; | struct GHash *id_hash; | ||||
| } mask_clipboard = {{NULL}}; | } mask_clipboard = {{NULL}}; | ||||
| static MaskSplinePoint *mask_spline_point_next(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) | static MaskSplinePoint *mask_spline_point_next(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) | ||||
| { | { | ||||
| if (point == &points_array[spline->tot_point - 1]) { | if (point == &points_array[spline->tot_point - 1]) { | ||||
| ▲ Show 20 Lines • Show All 1,410 Lines • ▼ Show 20 Lines | for (spline = masklay->splines.first; spline; spline = spline->next) { | ||||
| int i; | int i; | ||||
| for (i = 0; i < spline->tot_point; i++) { | for (i = 0; i < spline->tot_point; i++) { | ||||
| mask_layer_shape_from_mask_point(&spline->points[i].bezt, fp); | mask_layer_shape_from_mask_point(&spline->points[i].bezt, fp); | ||||
| fp += MASK_OBJECT_SHAPE_ELEM_SIZE; | fp += MASK_OBJECT_SHAPE_ELEM_SIZE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: vert mismatch %d != %d (frame %d)\n", | CLOG_ERROR(&LOG, "vert mismatch %d != %d (frame %d)", | ||||
| __func__, masklay_shape->tot_vert, tot, masklay_shape->frame); | masklay_shape->tot_vert, tot, masklay_shape->frame); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_mask_layer_shape_to_mask(MaskLayer *masklay, MaskLayerShape *masklay_shape) | void BKE_mask_layer_shape_to_mask(MaskLayer *masklay, MaskLayerShape *masklay_shape) | ||||
| { | { | ||||
| int tot = BKE_mask_layer_shape_totvert(masklay); | int tot = BKE_mask_layer_shape_totvert(masklay); | ||||
| if (masklay_shape->tot_vert == tot) { | if (masklay_shape->tot_vert == tot) { | ||||
| float *fp = masklay_shape->data; | float *fp = masklay_shape->data; | ||||
| MaskSpline *spline; | MaskSpline *spline; | ||||
| for (spline = masklay->splines.first; spline; spline = spline->next) { | for (spline = masklay->splines.first; spline; spline = spline->next) { | ||||
| int i; | int i; | ||||
| for (i = 0; i < spline->tot_point; i++) { | for (i = 0; i < spline->tot_point; i++) { | ||||
| mask_layer_shape_to_mask_point(&spline->points[i].bezt, fp); | mask_layer_shape_to_mask_point(&spline->points[i].bezt, fp); | ||||
| fp += MASK_OBJECT_SHAPE_ELEM_SIZE; | fp += MASK_OBJECT_SHAPE_ELEM_SIZE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: vert mismatch %d != %d (frame %d)\n", | CLOG_ERROR(&LOG, "vert mismatch %d != %d (frame %d)", | ||||
| __func__, masklay_shape->tot_vert, tot, masklay_shape->frame); | masklay_shape->tot_vert, tot, masklay_shape->frame); | ||||
| } | } | ||||
| } | } | ||||
| BLI_INLINE void interp_v2_v2v2_flfl(float target[2], const float a[2], const float b[2], | BLI_INLINE void interp_v2_v2v2_flfl(float target[2], const float a[2], const float b[2], | ||||
| const float t, const float s) | const float t, const float s) | ||||
| { | { | ||||
| target[0] = s * a[0] + t * b[0]; | target[0] = s * a[0] + t * b[0]; | ||||
| target[1] = s * a[1] + t * b[1]; | target[1] = s * a[1] + t * b[1]; | ||||
| Show All 21 Lines | for (spline = masklay->splines.first; spline; spline = spline->next) { | ||||
| interp_v2_v2v2_flfl(bezt->vec[1], fp_a, fp_b, fac, ifac); fp_a += 2; fp_b += 2; | interp_v2_v2v2_flfl(bezt->vec[1], fp_a, fp_b, fac, ifac); fp_a += 2; fp_b += 2; | ||||
| interp_v2_v2v2_flfl(bezt->vec[2], fp_a, fp_b, fac, ifac); fp_a += 2; fp_b += 2; | interp_v2_v2v2_flfl(bezt->vec[2], fp_a, fp_b, fac, ifac); fp_a += 2; fp_b += 2; | ||||
| bezt->weight = (fp_a[0] * ifac) + (fp_b[0] * fac); | bezt->weight = (fp_a[0] * ifac) + (fp_b[0] * fac); | ||||
| bezt->radius = (fp_a[1] * ifac) + (fp_b[1] * fac); fp_a += 2; fp_b += 2; | bezt->radius = (fp_a[1] * ifac) + (fp_b[1] * fac); fp_a += 2; fp_b += 2; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: vert mismatch %d != %d != %d (frame %d - %d)\n", | CLOG_ERROR(&LOG, "vert mismatch %d != %d != %d (frame %d - %d)", | ||||
| __func__, masklay_shape_a->tot_vert, masklay_shape_b->tot_vert, tot, | masklay_shape_a->tot_vert, masklay_shape_b->tot_vert, tot, | ||||
| masklay_shape_a->frame, masklay_shape_b->frame); | masklay_shape_a->frame, masklay_shape_b->frame); | ||||
| } | } | ||||
| } | } | ||||
| MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, const int frame) | MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, const int frame) | ||||
| { | { | ||||
| MaskLayerShape *masklay_shape; | MaskLayerShape *masklay_shape; | ||||
| for (masklay_shape = masklay->splines_shapes.first; | for (masklay_shape = masklay->splines_shapes.first; | ||||
| ▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | for (masklay_shape = masklay->splines_shapes.first; | ||||
| 0, | 0, | ||||
| sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE); | sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE); | ||||
| } | } | ||||
| MEM_freeN(masklay_shape->data); | MEM_freeN(masklay_shape->data); | ||||
| masklay_shape->data = data_resized; | masklay_shape->data = data_resized; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: vert mismatch %d != %d (frame %d)\n", | CLOG_ERROR(&LOG, "vert mismatch %d != %d (frame %d)", | ||||
| __func__, masklay_shape->tot_vert, tot, masklay_shape->frame); | masklay_shape->tot_vert, tot, masklay_shape->frame); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* move array to account for removed point */ | /* move array to account for removed point */ | ||||
| void BKE_mask_layer_shape_changed_remove(MaskLayer *masklay, int index, int count) | void BKE_mask_layer_shape_changed_remove(MaskLayer *masklay, int index, int count) | ||||
| Show All 23 Lines | if (tot == masklay_shape->tot_vert - count) { | ||||
| masklay_shape->data + ((index + count) * MASK_OBJECT_SHAPE_ELEM_SIZE), | masklay_shape->data + ((index + count) * MASK_OBJECT_SHAPE_ELEM_SIZE), | ||||
| (masklay_shape->tot_vert - index) * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE); | (masklay_shape->tot_vert - index) * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE); | ||||
| } | } | ||||
| MEM_freeN(masklay_shape->data); | MEM_freeN(masklay_shape->data); | ||||
| masklay_shape->data = data_resized; | masklay_shape->data = data_resized; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: vert mismatch %d != %d (frame %d)\n", | CLOG_ERROR(&LOG, "vert mismatch %d != %d (frame %d)", | ||||
| __func__, masklay_shape->tot_vert - count, tot, masklay_shape->frame); | masklay_shape->tot_vert - count, tot, masklay_shape->frame); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| int BKE_mask_get_duration(Mask *mask) | int BKE_mask_get_duration(Mask *mask) | ||||
| { | { | ||||
| return max_ii(1, mask->efra - mask->sfra); | return max_ii(1, mask->efra - mask->sfra); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||