lottie/parser: fix a crash when the color string is empty.
[platform/core/uifw/lottie-player.git] / inc / lottieanimation_capi.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_ANIMATION_CAPI_H_
20 #define _LOTTIE_ANIMATION_CAPI_H_
21
22 #include <stddef.h>
23 #include <stdint.h>
24 #include <lottiecommon.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 typedef struct Lottie_Animation_S Lottie_Animation;
31
32 /**
33  *  @brief Constructs an animation object from file path.
34  *
35  *  @param[in] path Lottie resource file path
36  *
37  *  @return Animation object that can build the contents of the
38  *          Lottie resource represented by file path.
39  *
40  *  @see lottie_animation_destroy()
41  *
42  *  @ingroup Lottie_Animation
43  *  @internal
44  */
45 LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
46
47 /**
48  *  @brief Constructs an animation object from JSON string data.
49  *
50  *  @param[in] data The JSON string data.
51  *  @param[in] key the string that will be used to cache the JSON string data.
52  *
53  *  @return Animation object that can build the contents of the
54  *          Lottie resource represented by JSON string data.
55  *
56  *  @ingroup Lottie_Animation
57  *  @internal
58  */
59 LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key);
60
61 /**
62  *  @brief Free given Animation object resource.
63  *
64  *  @param[in] animation Animation object to free.
65  *
66  *  @see lottie_animation_from_file()
67  *  @see lottie_animation_from_data()
68  *
69  *  @ingroup Lottie_Animation
70  *  @internal
71  */
72 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation *animation);
73
74 /**
75  *  @brief Returns default viewport size of the Lottie resource.
76  *
77  *  @param[in] animation Animation object.
78  *  @param[out] w default width of the viewport.
79  *  @param[out] h default height of the viewport.
80  *
81  *  @ingroup Lottie_Animation
82  *  @internal
83  */
84 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
85
86 /**
87  *  @brief Returns total animation duration of Lottie resource in second.
88  *         it uses totalFrame() and frameRate() to calculate the duration.
89  *         duration = totalFrame() / frameRate().
90  *
91  *  @param[in] animation Animation object.
92  *
93  *  @return total animation duration in second.
94  *          @c 0 if the Lottie resource has no animation.
95  *
96  *  @see lottie_animation_get_totalframe()
97  *  @see lottie_animation_get_framerate()
98  *
99  *  @ingroup Lottie_Animation
100  *  @internal
101  */
102 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation *animation);
103
104 /**
105  *  @brief Returns total number of frames present in the Lottie resource.
106  *
107  *  @param[in] animation Animation object.
108  *
109  *  @return frame count of the Lottie resource.*
110  *
111  *  @note frame number starts with 0.
112  *
113  *  @see lottie_animation_get_duration()
114  *  @see lottie_animation_get_framerate()
115  *
116  *  @ingroup Lottie_Animation
117  *  @internal
118  */
119 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
120
121 /**
122  *  @brief Returns default framerate of the Lottie resource.
123  *
124  *  @param[in] animation Animation object.
125  *
126  *  @return framerate of the Lottie resource
127  *
128  *  @ingroup Lottie_Animation
129  *  @internal
130  *
131  */
132 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation *animation);
133
134 /**
135  *  @brief Get the render tree which contains the snapshot of the animation object
136  *         at frame = @c frame_num, the content of the animation in that frame number.
137  *
138  *  @param[in] animation Animation object.
139  *  @param[in] width requested snapshot viewport width.
140  *  @param[in] height requested snapshot viewport height.
141  *
142  *  @return Animation snapshot tree.
143  *
144  * @note: User has to traverse the tree for rendering.
145  *
146  * @see LOTLayerNode
147  * @see LOTNode
148  *
149  *  @ingroup Lottie_Animation
150  *  @internal
151  */
152 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *animation,
153                                                              size_t frame_num,
154                                                              size_t width, size_t height);
155
156 /**
157  *  @brief Maps position to frame number and returns it.
158  *
159  *  @param[in] animation Animation object.
160  *  @param[in] pos position in the range [ 0.0 .. 1.0 ].
161  *
162  *  @return mapped frame numbe in the range [ start_frame .. end_frame ].
163  *          @c 0 if the Lottie resource has no animation.
164  *
165  *
166  *  @ingroup Lottie_Animation
167  *  @internal
168  */
169 LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
170
171 /**
172  *  @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
173  *
174  *  @param[in] animation Animation object.
175  *  @param[in] frame_num the frame number needs to be rendered.
176  *  @param[in] buffer surface buffer use for rendering.
177  *  @param[in] width width of the surface
178  *  @param[in] height height of the surface
179  *  @param[in] bytes_per_line stride of the surface in bytes.
180  *
181  *  @note user must call lottie_animation_render_flush() to make sure render is finished.
182  *
183  *  @ingroup Lottie_Animation
184  *  @internal
185  */
186 LOT_EXPORT void
187 lottie_animation_render_async(Lottie_Animation *animation,
188                               size_t frame_num,
189                               uint32_t *buffer,
190                               size_t width,
191                               size_t height,
192                               size_t bytes_per_line);
193
194 /**
195  *  @brief Request to finish the current async renderer job for this animation object.
196  *  If render is finished then this call returns immidiately.
197  *  If not, it waits till render job finish and then return.
198  *
199  *  @param[in] animation Animation object.
200  *
201  *  @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
202  *  in pair to get the benefit of async rendering.
203  *
204  *  @return the pixel buffer it finished rendering.
205  *
206  *  @ingroup Lottie_Animation
207  *  @internal
208  */
209 LOT_EXPORT uint32_t *
210 lottie_animation_render_flush(Lottie_Animation *animation);
211
212 #ifdef __cplusplus
213 }
214 #endif
215
216 #endif //_LOTTIE_ANIMATION_CAPI_H_
217