lottie/parser: fix a crash when the color string is empty.
[platform/core/uifw/lottie-player.git] / inc / lottiecommon.h
1 /* 
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  * 
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  * 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #ifndef _LOTTIE_COMMON_H_
20 #define _LOTTIE_COMMON_H_
21
22 #ifdef _WIN32
23 #ifdef LOT_BUILD
24 #ifdef DLL_EXPORT
25 #define LOT_EXPORT __declspec(dllexport)
26 #else
27 #define LOT_EXPORT
28 #endif
29 #else
30 #define LOT_EXPORT __declspec(dllimport)
31 #endif
32 #else
33 #ifdef __GNUC__
34 #if __GNUC__ >= 4
35 #define LOT_EXPORT __attribute__((visibility("default")))
36 #else
37 #define LOT_EXPORT
38 #endif
39 #else
40 #define LOT_EXPORT
41 #endif
42 #endif
43
44
45 /**
46  * @defgroup Lottie_Animation Lottie_Animation
47  *
48  * Lottie Animation is a modern style vector based animation design. Its animation
49  * resource(within json format) could be generated by Adobe After Effect using
50  * bodymovin plugin. You can find a good examples in Lottie Community which
51  * shares many free resources(see: www.lottiefiles.com).
52  *
53  * This Lottie_Animation is a common engine to manipulate, control Lottie
54  * Animation from the Lottie resource - json file. It provides a scene-graph
55  * node tree per frames by user demand as well as rasterized frame images.
56  *
57  */
58
59 /**
60  * @ingroup Lottie_Animation
61  */
62
63
64 /**
65  * @brief Enumeration for Lottie Player error code.
66  */
67 typedef enum
68 {
69    //TODO: Coding convention??
70     LOT_ANIMATION_ERROR_NONE = 0,
71     LOT_ANIMATION_ERROR_NOT_PERMITTED,
72     LOT_ANIMATION_ERROR_OUT_OF_MEMORY,
73     LOT_ANIMATION_ERROR_INVALID_PARAMETER,
74     LOT_ANIMATION_ERROR_RESULT_OUT_OF_RANGE,
75     LOT_ANIMATION_ERROR_ALREADY_IN_PROGRESS,
76     LOT_ANIMATION_ERROR_UNKNOWN
77 } LOTErrorType;
78
79 typedef enum
80 {
81     BrushSolid = 0,
82     BrushGradient
83 } LOTBrushType;
84
85 typedef enum
86 {
87     FillEvenOdd = 0,
88     FillWinding
89 } LOTFillRule;
90
91 typedef enum
92 {
93     JoinMiter = 0,
94     JoinBevel,
95     JoinRound
96 } LOTJoinStyle;
97
98 typedef enum
99 {
100     CapFlat = 0,
101     CapSquare,
102     CapRound
103 } LOTCapStyle;
104
105 typedef enum
106 {
107     GradientLinear = 0,
108     GradientRadial
109 } LOTGradientType;
110
111 typedef struct LOTGradientStop
112 {
113     float         pos;
114     unsigned char r, g, b, a;
115 } LOTGradientStop;
116
117 typedef enum
118 {
119     MaskModeAdd = 0,
120     MaskModeSubstract,
121     MaskModeIntersect,
122     MaskModeDifference
123 } LOTMaskMode;
124
125 typedef struct LOTMask {
126     struct {
127         const float *ptPtr;
128         int          ptCount;
129         const char*  elmPtr;
130         int          elmCount;
131     } mPath;
132     LOTMaskMode mMode;
133 }LOTMask;
134
135 typedef enum
136 {
137     MatteNone = 0,
138     MatteAlpha,
139     MatteAlphaInv,
140     MatteLuma,
141     MatteLumaInv
142 } LOTMatteType;
143
144 typedef struct LOTNode {
145
146 #define ChangeFlagNone 0x0000
147 #define ChangeFlagPath 0x0001
148 #define ChangeFlagPaint 0x0010
149 #define ChangeFlagAll (ChangeFlagPath & ChangeFlagPaint)
150
151     struct {
152         const float *ptPtr;
153         int          ptCount;
154         const char*  elmPtr;
155         int          elmCount;
156     } mPath;
157
158     struct {
159         unsigned char r, g, b, a;
160     } mColor;
161
162     struct {
163         unsigned char  enable;
164         int       width;
165         LOTCapStyle  cap;
166         LOTJoinStyle join;
167         int       meterLimit;
168         float*    dashArray;
169         int       dashArraySize;
170     } mStroke;
171
172     struct {
173         LOTGradientType type;
174         LOTGradientStop *stopPtr;
175         unsigned int stopCount;
176         struct {
177             float x, y;
178         } start, end, center, focal;
179         float cradius;
180         float fradius;
181     } mGradient;
182
183     int       mFlag;
184     LOTBrushType mBrushType;
185     LOTFillRule  mFillRule;
186 } LOTNode;
187
188
189
190 typedef struct LOTLayerNode {
191
192     struct {
193         LOTMask        *ptr;
194         unsigned int    size;
195     } mMaskList;
196
197     struct {
198         const float *ptPtr;
199         int          ptCount;
200         const char*  elmPtr;
201         int          elmCount;
202     } mClipPath;
203
204     struct {
205         struct LOTLayerNode   **ptr;
206         unsigned int          size;
207     } mLayerList;
208
209     struct {
210         LOTNode       **ptr;
211         unsigned int   size;
212     } mNodeList;
213
214     LOTMatteType mMatte;
215     int          mVisible;
216
217 } LOTLayerNode;
218
219 /**
220  * @}
221  */
222
223 #endif  // _LOTTIE_COMMON_H_