2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2012 Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Blender Foundation,
25 * ***** END GPL LICENSE BLOCK *****
28 #ifndef __BKE_MASK_H__
29 #define __BKE_MASK_H__
42 struct MaskLayerShape;
44 struct MaskSplinePoint;
45 struct MaskSplinePointUW;
52 MASK_WHICH_HANDLE_NONE = 0,
53 MASK_WHICH_HANDLE_STICK = 1,
54 MASK_WHICH_HANDLE_LEFT = 2,
55 MASK_WHICH_HANDLE_RIGHT = 3,
56 MASK_WHICH_HANDLE_BOTH = 4,
60 MASK_HANDLE_MODE_STICK = 1,
61 MASK_HANDLE_MODE_INDIVIDUAL_HANDLES = 2,
64 struct MaskSplinePoint *BKE_mask_spline_point_array(struct MaskSpline *spline);
65 struct MaskSplinePoint *BKE_mask_spline_point_array_from_point(struct MaskSpline *spline, struct MaskSplinePoint *point_ref);
68 struct MaskLayer *BKE_mask_layer_new(struct Mask *mask, const char *name);
69 struct MaskLayer *BKE_mask_layer_active(struct Mask *mask);
70 void BKE_mask_layer_active_set(struct Mask *mask, struct MaskLayer *masklay);
71 void BKE_mask_layer_remove(struct Mask *mask, struct MaskLayer *masklay);
73 void BKE_mask_layer_free_shapes(struct MaskLayer *masklay);
74 void BKE_mask_layer_free(struct MaskLayer *masklay);
75 void BKE_mask_layer_free_list(struct ListBase *masklayers);
76 void BKE_mask_spline_free(struct MaskSpline *spline);
77 void BKE_mask_spline_free_list(struct ListBase *splines);
78 struct MaskSpline *BKE_mask_spline_copy(struct MaskSpline *spline);
79 void BKE_mask_point_free(struct MaskSplinePoint *point);
81 void BKE_mask_layer_unique_name(struct Mask *mask, struct MaskLayer *masklay);
83 struct MaskLayer *BKE_mask_layer_copy(struct MaskLayer *layer);
84 void BKE_mask_layer_copy_list(struct ListBase *masklayers_new, struct ListBase *masklayers);
87 struct MaskSpline *BKE_mask_spline_add(struct MaskLayer *masklay);
88 bool BKE_mask_spline_remove(struct MaskLayer *mask_layer, struct MaskSpline *spline);
89 void BKE_mask_point_direction_switch(struct MaskSplinePoint *point);
90 void BKE_mask_spline_direction_switch(struct MaskLayer *masklay, struct MaskSpline *spline);
92 struct BezTriple *BKE_mask_spline_point_next_bezt(struct MaskSpline *spline, struct MaskSplinePoint *points_array,
93 struct MaskSplinePoint *point);
100 float BKE_mask_spline_project_co(struct MaskSpline *spline, struct MaskSplinePoint *point,
101 float start_u, const float co[2], const eMaskSign sign);
104 eMaskhandleMode BKE_mask_point_handles_mode_get(struct MaskSplinePoint *point);
105 void BKE_mask_point_handle(struct MaskSplinePoint *point, eMaskWhichHandle which_handle, float handle[2]);
106 void BKE_mask_point_set_handle(struct MaskSplinePoint *point, eMaskWhichHandle which_handle, float loc[2], bool keep_direction,
107 float orig_handle[2], float orig_vec[3][3]);
109 void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2]);
110 void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point,
111 float u, float n[2]);
112 float BKE_mask_point_weight_scalar(struct MaskSpline *spline, struct MaskSplinePoint *point, const float u);
113 float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *point, const float u);
114 struct MaskSplinePointUW *BKE_mask_point_sort_uw(struct MaskSplinePoint *point, struct MaskSplinePointUW *uw);
115 void BKE_mask_point_add_uw(struct MaskSplinePoint *point, float u, float w);
117 void BKE_mask_point_select_set(struct MaskSplinePoint *point, const bool do_select);
118 void BKE_mask_point_select_set_handle(struct MaskSplinePoint *point, const eMaskWhichHandle which_handle, const bool do_select);
121 struct Mask *BKE_mask_new(struct Main *bmain, const char *name);
122 struct Mask *BKE_mask_copy_nolib(struct Mask *mask);
123 struct Mask *BKE_mask_copy(struct Mask *mask);
125 void BKE_mask_free_nolib(struct Mask *mask);
126 void BKE_mask_free(struct Main *bmain, struct Mask *mask);
128 void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]);
129 void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]);
130 void BKE_mask_coord_from_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2]);
131 void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]);
132 void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]);
133 void BKE_mask_coord_to_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2]);
137 void BKE_mask_update_display(struct Mask *mask, float ctime);
139 void BKE_mask_evaluate_all_masks(struct Main *bmain, float ctime, const bool do_newframe);
140 void BKE_mask_evaluate(struct Mask *mask, const float ctime, const bool do_newframe);
141 void BKE_mask_layer_evaluate(struct MaskLayer *masklay, const float ctime, const bool do_newframe);
142 void BKE_mask_update_scene(struct Main *bmain, struct Scene *scene);
143 void BKE_mask_parent_init(struct MaskParent *parent);
144 void BKE_mask_calc_handle_adjacent_interp(struct MaskSpline *spline, struct MaskSplinePoint *point, const float u);
145 void BKE_mask_calc_tangent_polyline(struct MaskSpline *spline, struct MaskSplinePoint *point, float t[2]);
146 void BKE_mask_calc_handle_point(struct MaskSpline *spline, struct MaskSplinePoint *point);
147 void BKE_mask_calc_handle_point_auto(struct MaskSpline *spline, struct MaskSplinePoint *point,
148 const bool do_recalc_length);
149 void BKE_mask_get_handle_point_adjacent(struct MaskSpline *spline, struct MaskSplinePoint *point,
150 struct MaskSplinePoint **r_point_prev, struct MaskSplinePoint **r_point_next);
151 void BKE_mask_layer_calc_handles(struct MaskLayer *masklay);
152 void BKE_mask_spline_ensure_deform(struct MaskSpline *spline);
153 void BKE_mask_point_parent_matrix_get(struct MaskSplinePoint *point, float ctime, float parent_matrix[3][3]);
156 int BKE_mask_layer_shape_totvert(struct MaskLayer *masklay);
157 void BKE_mask_layer_shape_from_mask(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape);
158 void BKE_mask_layer_shape_to_mask(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape);
159 void BKE_mask_layer_shape_to_mask_interp(struct MaskLayer *masklay,
160 struct MaskLayerShape *masklay_shape_a,
161 struct MaskLayerShape *masklay_shape_b,
163 struct MaskLayerShape *BKE_mask_layer_shape_find_frame(struct MaskLayer *masklay, const int frame);
164 int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay, const float frame,
165 struct MaskLayerShape **r_masklay_shape_a,
166 struct MaskLayerShape **r_masklay_shape_b);
167 struct MaskLayerShape *BKE_mask_layer_shape_alloc(struct MaskLayer *masklay, const int frame);
168 void BKE_mask_layer_shape_free(struct MaskLayerShape *masklay_shape);
169 struct MaskLayerShape *BKE_mask_layer_shape_verify_frame(struct MaskLayer *masklay, const int frame);
170 struct MaskLayerShape *BKE_mask_layer_shape_duplicate(struct MaskLayerShape *masklay_shape);
171 void BKE_mask_layer_shape_unlink(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape);
172 void BKE_mask_layer_shape_sort(struct MaskLayer *masklay);
174 bool BKE_mask_layer_shape_spline_from_index(struct MaskLayer *masklay, int index,
175 struct MaskSpline **r_masklay_shape, int *r_index);
176 int BKE_mask_layer_shape_spline_to_index(struct MaskLayer *masklay, struct MaskSpline *spline);
178 void BKE_mask_layer_shape_changed_add(struct MaskLayer *masklay, int index,
179 bool do_init, bool do_init_interpolate);
181 void BKE_mask_layer_shape_changed_remove(struct MaskLayer *masklay, int index, int count);
183 int BKE_mask_get_duration(struct Mask *mask);
186 void BKE_mask_clipboard_free(void);
187 void BKE_mask_clipboard_copy_from_layer(struct MaskLayer *mask_layer);
188 bool BKE_mask_clipboard_is_empty(void);
189 void BKE_mask_clipboard_paste_to_layer(struct Main *bmain, struct MaskLayer *mask_layer);
191 #define MASKPOINT_ISSEL_ANY(p) ( ((p)->bezt.f1 | (p)->bezt.f2 | (p)->bezt.f3) & SELECT)
192 #define MASKPOINT_ISSEL_KNOT(p) ( (p)->bezt.f2 & SELECT)
194 #define MASKPOINT_ISSEL_HANDLE(point, which_handle) \
195 ((which_handle == MASK_WHICH_HANDLE_STICK) ? \
196 ((((point)->bezt.f1 | (point)->bezt.f3) & SELECT)) : \
197 ((which_handle == MASK_WHICH_HANDLE_LEFT) ? \
198 ((point)->bezt.f1 & SELECT) : \
199 ((point)->bezt.f3 & SELECT)))
201 #define MASKPOINT_SEL_ALL(p) { (p)->bezt.f1 |= SELECT; (p)->bezt.f2 |= SELECT; (p)->bezt.f3 |= SELECT; } (void)0
202 #define MASKPOINT_DESEL_ALL(p) { (p)->bezt.f1 &= ~SELECT; (p)->bezt.f2 &= ~SELECT; (p)->bezt.f3 &= ~SELECT; } (void)0
203 #define MASKPOINT_INVSEL_ALL(p) { (p)->bezt.f1 ^= SELECT; (p)->bezt.f2 ^= SELECT; (p)->bezt.f3 ^= SELECT; } (void)0
205 #define MASK_RESOL_MAX 128
208 /* mask_evaluate.c */
209 unsigned int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height);
210 unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height);
211 int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline, const unsigned int resol);
213 float (*BKE_mask_spline_differentiate_with_resolution(struct MaskSpline *spline, unsigned int *tot_diff_point,
214 const unsigned int resol))[2];
215 void BKE_mask_spline_feather_collapse_inner_loops(struct MaskSpline *spline, float (*feather_points)[2], const unsigned int tot_feather_point);
216 float (*BKE_mask_spline_differentiate(struct MaskSpline *spline, int width, int height, unsigned int *tot_diff_point))[2];
217 float (*BKE_mask_spline_feather_differentiated_points_with_resolution(struct MaskSpline *spline, unsigned int *tot_feather_point,
218 const unsigned int resol, const bool do_feather_isect))[2];
220 /* *** mask point functions which involve evaluation *** */
221 float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2];
223 float *BKE_mask_point_segment_diff(struct MaskSpline *spline, struct MaskSplinePoint *point,
224 int width, int height,
225 unsigned int *tot_diff_point);
227 float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct MaskSplinePoint *point,
228 int width, int height,
229 unsigned int *tot_feather_point);
231 /* mask_rasterize.c */
232 struct MaskRasterHandle;
233 typedef struct MaskRasterHandle MaskRasterHandle;
235 MaskRasterHandle *BKE_maskrasterize_handle_new(void);
236 void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle);
237 void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask,
238 const int width, const int height,
239 const bool do_aspect_correct, const bool do_mask_aa,
240 const bool do_feather);
241 float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2]);
243 void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
244 const unsigned int width, const unsigned int height,
247 #endif /* __BKE_MASK_H__ */