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) 2012 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup DNA
22  *
23  * Mask data-blocks are collections of 2D curves to be used
24  * for image masking in the compositor and sequencer.
25  */
26 
27 #pragma once
28 
29 #include "DNA_ID.h"
30 #include "DNA_curve_types.h"
31 #include "DNA_defs.h"
32 #include "DNA_listBase.h"
33 
34 typedef struct Mask {
35   ID id;
36   struct AnimData *adt;
37   /** Mask layers. */
38   ListBase masklayers;
39   /** Index of active mask layer (-1 == None). */
40   int masklay_act;
41   /** Total number of mask layers. */
42   int masklay_tot;
43 
44   /** Frames, used by the sequencer. */
45   int sfra, efra;
46 
47   /** For anim info. */
48   int flag;
49   char _pad[4];
50 } Mask;
51 
52 typedef struct MaskParent {
53   //* /* Parenting flags */ /* not used. */
54   // int flag;
55   /** Type of parenting. */
56   int id_type;
57   /** Type of parenting. */
58   int type;
59   /**
60    * ID block of entity to which mask/spline is parented to
61    * in case of parenting to movie tracking data set to MovieClip datablock.
62    */
63   ID *id;
64   /**
65    * Entity of parent to which parenting happened
66    * in case of parenting to movie tracking data contains name of layer.
67    */
68   char parent[64];
69   /**
70    * Sub-entity of parent to which parenting happened
71    * in case of parenting to movie tracking data contains name of track.
72    */
73   char sub_parent[64];
74   /**
75    * Track location at the moment of parenting,
76    * stored in mask space.
77    */
78   float parent_orig[2];
79 
80   /** Original corners of plane track at the moment of parenting. */
81   float parent_corners_orig[4][2];
82 } MaskParent;
83 
84 typedef struct MaskSplinePointUW {
85   /** U coordinate along spline segment and weight of this point. */
86   float u, w;
87   /** Different flags of this point. */
88   int flag;
89 } MaskSplinePointUW;
90 
91 typedef struct MaskSplinePoint {
92   /** Actual point coordinates and its handles . */
93   BezTriple bezt;
94   char _pad[4];
95   /** Number of uv feather values. */
96   int tot_uw;
97   /** Feather UV values. */
98   MaskSplinePointUW *uw;
99   /** Parenting information of particular spline point. */
100   MaskParent parent;
101 } MaskSplinePoint;
102 
103 typedef struct MaskSpline {
104   struct MaskSpline *next, *prev;
105 
106   /** Different spline flag (closed, ...). */
107   short flag;
108   /** Feather offset method. */
109   char offset_mode;
110   /** Weight interpolation. */
111   char weight_interp;
112 
113   /** Total number of points. */
114   int tot_point;
115   /** Points which defines spline itself. */
116   MaskSplinePoint *points;
117   /** Parenting information of the whole spline. */
118   MaskParent parent;
119 
120   /** Deformed copy of 'points' BezTriple data - not saved. */
121   MaskSplinePoint *points_deform;
122 } MaskSpline;
123 
124 /* one per frame */
125 typedef struct MaskLayerShape {
126   struct MaskLayerShape *next, *prev;
127 
128   /** U coordinate along spline segment and weight of this point. */
129   float *data;
130   /** To ensure no buffer overruns's: alloc size is (tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE). */
131   int tot_vert;
132   /** Different flags of this point. */
133   int frame;
134   /** Animation flag. */
135   char flag;
136   char _pad[7];
137 } MaskLayerShape;
138 
139 /* cast to this for convenience, not saved */
140 #define MASK_OBJECT_SHAPE_ELEM_SIZE 8 /* 3x 2D points + weight + radius == 8 */
141 
142 #
143 #
144 typedef struct MaskLayerShapeElem {
145   float value[MASK_OBJECT_SHAPE_ELEM_SIZE];
146 } MaskLayerShapeElem;
147 
148 typedef struct MaskLayer {
149   struct MaskLayer *next, *prev;
150 
151   /** Name of the mask layer (64 = MAD_ID_NAME - 2). */
152   char name[64];
153 
154   /** List of splines which defines this mask layer. */
155   ListBase splines;
156   ListBase splines_shapes;
157 
158   /** Active spline. */
159   struct MaskSpline *act_spline;
160   /** Active point. */
161   struct MaskSplinePoint *act_point;
162 
163   /* blending options */
164   float alpha;
165   char blend;
166   char blend_flag;
167   char falloff;
168   char _pad[7];
169 
170   /** For animation. */
171   char flag;
172   /** Matching 'Object' flag of the same name - eventually use in the outliner . */
173   char restrictflag;
174 } MaskLayer;
175 
176 /* MaskParent->flag */
177 /* #define MASK_PARENT_ACTIVE  (1 << 0) */ /* UNUSED */
178 
179 /* MaskParent->type */
180 enum {
181   MASK_PARENT_POINT_TRACK = 0, /* parenting happens to point track */
182   MASK_PARENT_PLANE_TRACK = 1, /* parenting happens to plane track */
183 };
184 
185 /* MaskSpline->flag */
186 /* reserve (1 << 0) for SELECT */
187 enum {
188   MASK_SPLINE_CYCLIC = (1 << 1),
189   MASK_SPLINE_NOFILL = (1 << 2),
190   MASK_SPLINE_NOINTERSECT = (1 << 3),
191 };
192 
193 /* MaskSpline->weight_interp */
194 enum {
195   MASK_SPLINE_INTERP_LINEAR = 1,
196   MASK_SPLINE_INTERP_EASE = 2,
197 };
198 
199 /* MaskSpline->offset_mode */
200 enum {
201   MASK_SPLINE_OFFSET_EVEN = 0,
202   MASK_SPLINE_OFFSET_SMOOTH = 1,
203 };
204 
205 /* ob->restrictflag */
206 #define MASK_RESTRICT_VIEW (1 << 0)
207 #define MASK_RESTRICT_SELECT (1 << 1)
208 #define MASK_RESTRICT_RENDER (1 << 2)
209 
210 /* SpaceClip->mask_draw_flag */
211 #define MASK_DRAWFLAG_SMOOTH (1 << 0)
212 #define MASK_DRAWFLAG_OVERLAY (1 << 1)
213 
214 /* copy of eSpaceImage_UVDT */
215 /* SpaceClip->mask_draw_type */
216 enum {
217   MASK_DT_OUTLINE = 0,
218   MASK_DT_DASH = 1,
219   MASK_DT_BLACK = 2,
220   MASK_DT_WHITE = 3,
221 };
222 
223 /* MaskSpaceInfo->overlay_mode */
224 enum {
225   MASK_OVERLAY_ALPHACHANNEL = 0,
226   MASK_OVERLAY_COMBINED = 1,
227 };
228 
229 /* masklay->blend */
230 enum {
231   MASK_BLEND_ADD = 0,
232   MASK_BLEND_SUBTRACT = 1,
233   MASK_BLEND_LIGHTEN = 2,
234   MASK_BLEND_DARKEN = 3,
235   MASK_BLEND_MUL = 4,
236   MASK_BLEND_REPLACE = 5,
237   MASK_BLEND_DIFFERENCE = 6,
238   MASK_BLEND_MERGE_ADD = 7,
239   MASK_BLEND_MERGE_SUBTRACT = 8,
240 };
241 
242 /* masklay->blend_flag */
243 enum {
244   MASK_BLENDFLAG_INVERT = (1 << 0),
245 };
246 
247 /* masklay->flag */
248 enum {
249   MASK_LAYERFLAG_LOCKED = (1 << 4),
250   MASK_LAYERFLAG_SELECT = (1 << 5),
251 
252   /* no holes */
253   MASK_LAYERFLAG_FILL_DISCRETE = (1 << 6),
254   MASK_LAYERFLAG_FILL_OVERLAP = (1 << 7),
255 };
256 
257 /* masklay_shape->flag */
258 enum {
259   MASK_SHAPE_SELECT = (1 << 0),
260 };
261 
262 /* mask->flag */
263 enum {
264   MASK_ANIMF_EXPAND = (1 << 4),
265 };
266