Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BKE_mask.h « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d126d706c661c0b7343bd239b90e0dff06e8e883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2012 Blender Foundation. All rights reserved. */

#pragma once

/** \file
 * \ingroup bke
 */

#ifdef __cplusplus
extern "C" {
#endif

struct Depsgraph;
struct Image;
struct ImageUser;
struct ListBase;
struct Main;
struct Mask;
struct MaskLayer;
struct MaskLayerShape;
struct MaskParent;
struct MaskSpline;
struct MaskSplinePoint;
struct MaskSplinePointUW;
struct MovieClip;
struct MovieClipUser;

/* mask_ops.c */
typedef enum {
  MASK_WHICH_HANDLE_NONE = 0,
  MASK_WHICH_HANDLE_STICK = 1,
  MASK_WHICH_HANDLE_LEFT = 2,
  MASK_WHICH_HANDLE_RIGHT = 3,
  MASK_WHICH_HANDLE_BOTH = 4,
} eMaskWhichHandle;

typedef enum {
  MASK_HANDLE_MODE_STICK = 1,
  MASK_HANDLE_MODE_INDIVIDUAL_HANDLES = 2,
} eMaskhandleMode;

/* -------------------------------------------------------------------- */
/** \name Mask Layers
 * \{ */

struct MaskLayer *BKE_mask_layer_new(struct Mask *mask, const char *name);
/**
 * \note The returned mask-layer may be hidden, caller needs to check.
 */
struct MaskLayer *BKE_mask_layer_active(struct Mask *mask);
void BKE_mask_layer_active_set(struct Mask *mask, struct MaskLayer *masklay);
void BKE_mask_layer_remove(struct Mask *mask, struct MaskLayer *masklay);

/** \brief Free all animation keys for a mask layer.
 */
void BKE_mask_layer_free_shapes(struct MaskLayer *masklay);
void BKE_mask_layer_free(struct MaskLayer *masklay);
void BKE_mask_layer_free_list(struct ListBase *masklayers);
void BKE_mask_spline_free(struct MaskSpline *spline);
void BKE_mask_spline_free_list(struct ListBase *splines);
struct MaskSpline *BKE_mask_spline_copy(const struct MaskSpline *spline);
void BKE_mask_point_free(struct MaskSplinePoint *point);

void BKE_mask_layer_unique_name(struct Mask *mask, struct MaskLayer *masklay);
void BKE_mask_layer_rename(struct Mask *mask,
                           struct MaskLayer *masklay,
                           char *oldname,
                           char *newname);

struct MaskLayer *BKE_mask_layer_copy(const struct MaskLayer *masklay);
void BKE_mask_layer_copy_list(struct ListBase *masklayers_new, const struct ListBase *masklayers);

/** \} */

/* -------------------------------------------------------------------- */
/** \name Splines
 * \{ */

struct MaskSplinePoint *BKE_mask_spline_point_array(struct MaskSpline *spline);
struct MaskSplinePoint *BKE_mask_spline_point_array_from_point(
    struct MaskSpline *spline, const struct MaskSplinePoint *point_ref);

struct MaskSpline *BKE_mask_spline_add(struct MaskLayer *masklay);
bool BKE_mask_spline_remove(struct MaskLayer *mask_layer, struct MaskSpline *spline);
void BKE_mask_point_direction_switch(struct MaskSplinePoint *point);
void BKE_mask_spline_direction_switch(struct MaskLayer *masklay, struct MaskSpline *spline);

struct BezTriple *BKE_mask_spline_point_next_bezt(struct MaskSpline *spline,
                                                  struct MaskSplinePoint *points_array,
                                                  struct MaskSplinePoint *point);

typedef enum {
  MASK_PROJ_NEG = -1,
  MASK_PROJ_ANY = 0,
  MASK_PROJ_POS = 1,
} eMaskSign;
float BKE_mask_spline_project_co(struct MaskSpline *spline,
                                 struct MaskSplinePoint *point,
                                 float start_u,
                                 const float co[2],
                                 eMaskSign sign);

/** \} */

/* -------------------------------------------------------------------- */
/** \name Point
 * \{ */

eMaskhandleMode BKE_mask_point_handles_mode_get(const struct MaskSplinePoint *point);
void BKE_mask_point_handle(const struct MaskSplinePoint *point,
                           eMaskWhichHandle which_handle,
                           float r_handle[2]);
void BKE_mask_point_set_handle(struct MaskSplinePoint *point,
                               eMaskWhichHandle which_handle,
                               float loc[2],
                               bool keep_direction,
                               float orig_handle[2],
                               float orig_vec[3][3]);

void BKE_mask_point_segment_co(struct MaskSpline *spline,
                               struct MaskSplinePoint *point,
                               float u,
                               float co[2]);
void BKE_mask_point_normal(struct MaskSpline *spline,
                           struct MaskSplinePoint *point,
                           float u,
                           float n[2]);
float BKE_mask_point_weight_scalar(struct MaskSpline *spline,
                                   struct MaskSplinePoint *point,
                                   float u);
float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *point, float u);
struct MaskSplinePointUW *BKE_mask_point_sort_uw(struct MaskSplinePoint *point,
                                                 struct MaskSplinePointUW *uw);
void BKE_mask_point_add_uw(struct MaskSplinePoint *point, float u, float w);

void BKE_mask_point_select_set(struct MaskSplinePoint *point, bool do_select);
void BKE_mask_point_select_set_handle(struct MaskSplinePoint *point,
                                      eMaskWhichHandle which_handle,
                                      bool do_select);

/** \} */

/* -------------------------------------------------------------------- */
/** \name General
 * \{ */

struct Mask *BKE_mask_new(struct Main *bmain, const char *name);

void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]);
void BKE_mask_coord_from_movieclip(struct MovieClip *clip,
                                   struct MovieClipUser *user,
                                   float r_co[2],
                                   const float co[2]);
void BKE_mask_coord_from_image(struct Image *image,
                               struct ImageUser *iuser,
                               float r_co[2],
                               const float co[2]);
/**
 * Inverse of #BKE_mask_coord_from_image.
 */
void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]);
void BKE_mask_coord_to_movieclip(struct MovieClip *clip,
                                 struct MovieClipUser *user,
                                 float r_co[2],
                                 const float co[2]);
void BKE_mask_coord_to_image(struct Image *image,
                             struct ImageUser *iuser,
                             float r_co[2],
                             const float co[2]);

/** \} */

/* -------------------------------------------------------------------- */
/** \name Parenting
 * \{ */

void BKE_mask_evaluate(struct Mask *mask, float ctime, bool do_newframe);
void BKE_mask_layer_evaluate(struct MaskLayer *masklay, float ctime, bool do_newframe);
void BKE_mask_parent_init(struct MaskParent *parent);
void BKE_mask_calc_handle_adjacent_interp(struct MaskSpline *spline,
                                          struct MaskSplinePoint *point,
                                          float u);
/**
 * Calculates the tangent of a point by its previous and next
 * (ignoring handles - as if its a poly line).
 */
void BKE_mask_calc_tangent_polyline(struct MaskSpline *spline,
                                    struct MaskSplinePoint *point,
                                    float t[2]);
void BKE_mask_calc_handle_point(struct MaskSpline *spline, struct MaskSplinePoint *point);
/**
 * \brief Resets auto handles even for non-auto bezier points
 *
 * Useful for giving sane defaults.
 */
void BKE_mask_calc_handle_point_auto(struct MaskSpline *spline,
                                     struct MaskSplinePoint *point,
                                     bool do_recalc_length);
void BKE_mask_get_handle_point_adjacent(struct MaskSpline *spline,
                                        struct MaskSplinePoint *point,
                                        struct MaskSplinePoint **r_point_prev,
                                        struct MaskSplinePoint **r_point_next);
void BKE_mask_layer_calc_handles(struct MaskLayer *masklay);
void BKE_mask_spline_ensure_deform(struct MaskSpline *spline);
void BKE_mask_point_parent_matrix_get(struct MaskSplinePoint *point,
                                      float ctime,
                                      float parent_matrix[3][3]);

/** \} */

/* -------------------------------------------------------------------- */
/** \name Animation
 * \{ */

int BKE_mask_layer_shape_totvert(struct MaskLayer *masklay);
/**
 * Inverse of #BKE_mask_layer_shape_to_mask
 */
void BKE_mask_layer_shape_from_mask(struct MaskLayer *masklay,
                                    struct MaskLayerShape *masklay_shape);
/**
 * Inverse of #BKE_mask_layer_shape_from_mask
 */
void BKE_mask_layer_shape_to_mask(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape);
/**
 * \note Linear interpolation only.
 */
void BKE_mask_layer_shape_to_mask_interp(struct MaskLayer *masklay,
                                         struct MaskLayerShape *masklay_shape_a,
                                         struct MaskLayerShape *masklay_shape_b,
                                         float fac);
struct MaskLayerShape *BKE_mask_layer_shape_find_frame(struct MaskLayer *masklay, int frame);
/**
 * When returning 2 - the frame isn't found but before/after frames are.
 */
int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay,
                                          float frame,
                                          struct MaskLayerShape **r_masklay_shape_a,
                                          struct MaskLayerShape **r_masklay_shape_b);
/**
 * \note Does *not* add to the list.
 */
struct MaskLayerShape *BKE_mask_layer_shape_alloc(struct MaskLayer *masklay, int frame);
void BKE_mask_layer_shape_free(struct MaskLayerShape *masklay_shape);
struct MaskLayerShape *BKE_mask_layer_shape_verify_frame(struct MaskLayer *masklay, int frame);
struct MaskLayerShape *BKE_mask_layer_shape_duplicate(struct MaskLayerShape *masklay_shape);
void BKE_mask_layer_shape_unlink(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape);
void BKE_mask_layer_shape_sort(struct MaskLayer *masklay);

bool BKE_mask_layer_shape_spline_from_index(struct MaskLayer *masklay,
                                            int index,
                                            struct MaskSpline **r_masklay_shape,
                                            int *r_index);
int BKE_mask_layer_shape_spline_to_index(struct MaskLayer *masklay, struct MaskSpline *spline);

/**
 * When a new points added, resizing all shape-key arrays.
 */
void BKE_mask_layer_shape_changed_add(struct MaskLayer *masklay,
                                      int index,
                                      bool do_init,
                                      bool do_init_interpolate);

/**
 * Move array elements to account for removed point.
 */
void BKE_mask_layer_shape_changed_remove(struct MaskLayer *masklay, int index, int count);

int BKE_mask_get_duration(struct Mask *mask);

/** \} */

/* -------------------------------------------------------------------- */
/** \name Clipboard
 * \{ */

/**
 * Free the clipboard.
 */
void BKE_mask_clipboard_free(void);
/**
 * Copy selected visible splines from the given layer to clipboard.
 */
void BKE_mask_clipboard_copy_from_layer(struct MaskLayer *mask_layer);
/**
 * Check clipboard is empty.
 */
bool BKE_mask_clipboard_is_empty(void);
/**
 * Paste the contents of clipboard to given mask layer.
 */
void BKE_mask_clipboard_paste_to_layer(struct Main *bmain, struct MaskLayer *mask_layer);

#define MASKPOINT_ISSEL_ANY(p) ((((p)->bezt.f1 | (p)->bezt.f2 | (p)->bezt.f3) & SELECT) != 0)
#define MASKPOINT_ISSEL_KNOT(p) (((p)->bezt.f2 & SELECT) != 0)

#define MASKPOINT_ISSEL_HANDLE(point, which_handle) \
  ((((which_handle) == MASK_WHICH_HANDLE_STICK) ? \
        ((((point)->bezt.f1 | (point)->bezt.f3) & SELECT)) : \
        (((which_handle) == MASK_WHICH_HANDLE_LEFT) ? ((point)->bezt.f1 & SELECT) : \
                                                      ((point)->bezt.f3 & SELECT))) != 0)

#define MASKPOINT_SEL_ALL(p) \
  { \
    (p)->bezt.f1 |= SELECT; \
    (p)->bezt.f2 |= SELECT; \
    (p)->bezt.f3 |= SELECT; \
  } \
  (void)0
#define MASKPOINT_DESEL_ALL(p) \
  { \
    (p)->bezt.f1 &= ~SELECT; \
    (p)->bezt.f2 &= ~SELECT; \
    (p)->bezt.f3 &= ~SELECT; \
  } \
  (void)0
#define MASKPOINT_INVSEL_ALL(p) \
  { \
    (p)->bezt.f1 ^= SELECT; \
    (p)->bezt.f2 ^= SELECT; \
    (p)->bezt.f3 ^= SELECT; \
  } \
  (void)0

/** \} */

/* -------------------------------------------------------------------- */
/** \name Evaluation
 * \{ */

#define MASK_RESOL_MAX 128

/* mask_evaluate.c */

unsigned int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height);
unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height);
int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline, unsigned int resol);

float (*BKE_mask_spline_differentiate_with_resolution(struct MaskSpline *spline,
                                                      unsigned int resol,
                                                      unsigned int *r_tot_diff_point))[2];
void BKE_mask_spline_feather_collapse_inner_loops(struct MaskSpline *spline,
                                                  float (*feather_points)[2],
                                                  unsigned int tot_feather_point);
float (*BKE_mask_spline_differentiate(
    struct MaskSpline *spline, int width, int height, unsigned int *r_tot_diff_point))[2];
/**
 * values align with #BKE_mask_spline_differentiate_with_resolution
 * when \a resol arguments match.
 */
float (*BKE_mask_spline_feather_differentiated_points_with_resolution(
    struct MaskSpline *spline,
    unsigned int resol,
    bool do_feather_isect,
    unsigned int *r_tot_feather_point))[2];

/* *** mask point functions which involve evaluation *** */

float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2];

float *BKE_mask_point_segment_diff(struct MaskSpline *spline,
                                   struct MaskSplinePoint *point,
                                   int width,
                                   int height,
                                   unsigned int *r_tot_diff_point);

/* *** mask point functions which involve evaluation *** */

float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline,
                                           struct MaskSplinePoint *point,
                                           int width,
                                           int height,
                                           unsigned int *tot_feather_point);

void BKE_mask_layer_evaluate_animation(struct MaskLayer *masklay, float ctime);
void BKE_mask_layer_evaluate_deform(struct MaskLayer *masklay, float ctime);

void BKE_mask_eval_animation(struct Depsgraph *depsgraph, struct Mask *mask);
void BKE_mask_eval_update(struct Depsgraph *depsgraph, struct Mask *mask);

/** \} */

/* -------------------------------------------------------------------- */
/** \name Rasterization
 * \{ */

/* mask_rasterize.c */

struct MaskRasterHandle;
typedef struct MaskRasterHandle MaskRasterHandle;

MaskRasterHandle *BKE_maskrasterize_handle_new(void);
void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle);
void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
                                   struct Mask *mask,
                                   int width,
                                   int height,
                                   bool do_aspect_correct,
                                   bool do_mask_aa,
                                   bool do_feather);
float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2]);

/**
 * \brief Rasterize a buffer from a single mask (threaded execution).
 */
void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
                              unsigned int width,
                              unsigned int height,
                              float *buffer);

/** \} */

#ifdef __cplusplus
}
#endif