add rlottiePlayer Project
[platform/core/uifw/lottie-player.git] / example / rlottiePlayer / rlottie_capi.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
3
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 #ifndef _RLOTTIE_CAPI_H_
24 #define _RLOTTIE_CAPI_H_
25
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <rlottiecommon.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 typedef enum {
35     LOTTIE_ANIMATION_PROPERTY_FILLCOLOR,      /*!< Color property of Fill object , value type is float [0 ... 1] */
36     LOTTIE_ANIMATION_PROPERTY_FILLOPACITY,    /*!< Opacity property of Fill object , value type is float [ 0 .. 100] */
37     LOTTIE_ANIMATION_PROPERTY_STROKECOLOR,    /*!< Color property of Stroke object , value type is float [0 ... 1] */
38     LOTTIE_ANIMATION_PROPERTY_STROKEOPACITY,  /*!< Opacity property of Stroke object , value type is float [ 0 .. 100] */
39     LOTTIE_ANIMATION_PROPERTY_STROKEWIDTH,    /*!< stroke with property of Stroke object , value type is float */
40     LOTTIE_ANIMATION_PROPERTY_TR_ANCHOR,      /*!< Transform Anchor property of Layer and Group object , value type is int */
41     LOTTIE_ANIMATION_PROPERTY_TR_POSITION,    /*!< Transform Position property of Layer and Group object , value type is int */
42     LOTTIE_ANIMATION_PROPERTY_TR_SCALE,       /*!< Transform Scale property of Layer and Group object , value type is float range[0 ..100] */
43     LOTTIE_ANIMATION_PROPERTY_TR_ROTATION,    /*!< Transform Scale property of Layer and Group object , value type is float. range[0 .. 360] in degrees*/
44     LOTTIE_ANIMATION_PROPERTY_TR_OPACITY      /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */
45 }Lottie_Animation_Property;
46
47 typedef struct Lottie_Animation_S Lottie_Animation;
48
49 /**
50  *  @brief Constructs an animation object from file path.
51  *
52  *  @param[in] path Lottie resource file path
53  *
54  *  @return Animation object that can build the contents of the
55  *          Lottie resource represented by file path.
56  *
57  *  @see lottie_animation_destroy()
58  *
59  *  @ingroup Lottie_Animation
60  *  @internal
61  */
62 RLOTTIE_API Lottie_Animation *lottie_animation_from_file(const char *path);
63
64 /**
65  *  @brief Constructs an animation object from JSON string data.
66  *
67  *  @param[in] data The JSON string data.
68  *  @param[in] key the string that will be used to cache the JSON string data.
69  *  @param[in] resource_path the path that will be used to load external resource needed by the JSON data.
70  *
71  *  @return Animation object that can build the contents of the
72  *          Lottie resource represented by JSON string data.
73  *
74  *  @ingroup Lottie_Animation
75  *  @internal
76  */
77 RLOTTIE_API Lottie_Animation *lottie_animation_from_data(const char *data, const char *key, const char *resource_path);
78
79 /**
80  *  @brief Free given Animation object resource.
81  *
82  *  @param[in] animation Animation object to free.
83  *
84  *  @see lottie_animation_from_file()
85  *  @see lottie_animation_from_data()
86  *
87  *  @ingroup Lottie_Animation
88  *  @internal
89  */
90 RLOTTIE_API void lottie_animation_destroy(Lottie_Animation *animation);
91
92 /**
93  *  @brief Returns default viewport size of the Lottie resource.
94  *
95  *  @param[in] animation Animation object.
96  *  @param[out] w default width of the viewport.
97  *  @param[out] h default height of the viewport.
98  *
99  *  @ingroup Lottie_Animation
100  *  @internal
101  */
102 RLOTTIE_API void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
103
104 /**
105  *  @brief Returns total animation duration of Lottie resource in second.
106  *         it uses totalFrame() and frameRate() to calculate the duration.
107  *         duration = totalFrame() / frameRate().
108  *
109  *  @param[in] animation Animation object.
110  *
111  *  @return total animation duration in second.
112  *          @c 0 if the Lottie resource has no animation.
113  *
114  *  @see lottie_animation_get_totalframe()
115  *  @see lottie_animation_get_framerate()
116  *
117  *  @ingroup Lottie_Animation
118  *  @internal
119  */
120 RLOTTIE_API double lottie_animation_get_duration(const Lottie_Animation *animation);
121
122 /**
123  *  @brief Returns total number of frames present in the Lottie resource.
124  *
125  *  @param[in] animation Animation object.
126  *
127  *  @return frame count of the Lottie resource.*
128  *
129  *  @note frame number starts with 0.
130  *
131  *  @see lottie_animation_get_duration()
132  *  @see lottie_animation_get_framerate()
133  *
134  *  @ingroup Lottie_Animation
135  *  @internal
136  */
137 RLOTTIE_API size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
138
139 /**
140  *  @brief Returns default framerate of the Lottie resource.
141  *
142  *  @param[in] animation Animation object.
143  *
144  *  @return framerate of the Lottie resource
145  *
146  *  @ingroup Lottie_Animation
147  *  @internal
148  *
149  */
150 RLOTTIE_API double lottie_animation_get_framerate(const Lottie_Animation *animation);
151
152 /**
153  *  @brief Get the render tree which contains the snapshot of the animation object
154  *         at frame = @c frame_num, the content of the animation in that frame number.
155  *
156  *  @param[in] animation Animation object.
157  *  @param[in] frame_num Content corresponds to the @p frame_num needs to be drawn
158  *  @param[in] width requested snapshot viewport width.
159  *  @param[in] height requested snapshot viewport height.
160  *
161  *  @return Animation snapshot tree.
162  *
163  * @note: User has to traverse the tree for rendering.
164  *
165  * @see LOTLayerNode
166  * @see LOTNode
167  *
168  *  @ingroup Lottie_Animation
169  *  @internal
170  */
171 RLOTTIE_API const LOTLayerNode *lottie_animation_render_tree(Lottie_Animation *animation, size_t frame_num, size_t width, size_t height);
172
173 /**
174  *  @brief Maps position to frame number and returns it.
175  *
176  *  @param[in] animation Animation object.
177  *  @param[in] pos position in the range [ 0.0 .. 1.0 ].
178  *
179  *  @return mapped frame numbe in the range [ start_frame .. end_frame ].
180  *          @c 0 if the Lottie resource has no animation.
181  *
182  *
183  *  @ingroup Lottie_Animation
184  *  @internal
185  */
186 RLOTTIE_API size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
187
188 /**
189  *  @brief Request to render the content of the frame @p frame_num to buffer @p buffer.
190  *
191  *  @param[in] animation Animation object.
192  *  @param[in] frame_num the frame number needs to be rendered.
193  *  @param[in] buffer surface buffer use for rendering.
194  *  @param[in] width width of the surface
195  *  @param[in] height height of the surface
196  *  @param[in] bytes_per_line stride of the surface in bytes.
197  *
198  *
199  *  @ingroup Lottie_Animation
200  *  @internal
201  */
202 RLOTTIE_API void lottie_animation_render(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t bytes_per_line);
203
204 /**
205  *  @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
206  *
207  *  @param[in] animation Animation object.
208  *  @param[in] frame_num the frame number needs to be rendered.
209  *  @param[in] buffer surface buffer use for rendering.
210  *  @param[in] width width of the surface
211  *  @param[in] height height of the surface
212  *  @param[in] bytes_per_line stride of the surface in bytes.
213  *
214  *  @note user must call lottie_animation_render_flush() to make sure render is finished.
215  *
216  *  @ingroup Lottie_Animation
217  *  @internal
218  */
219 RLOTTIE_API void lottie_animation_render_async(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t bytes_per_line);
220
221 /**
222  *  @brief Request to finish the current async renderer job for this animation object.
223  *  If render is finished then this call returns immidiately.
224  *  If not, it waits till render job finish and then return.
225  *
226  *  @param[in] animation Animation object.
227  *
228  *  @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
229  *  in pair to get the benefit of async rendering.
230  *
231  *  @return the pixel buffer it finished rendering.
232  *
233  *  @ingroup Lottie_Animation
234  *  @internal
235  */
236 RLOTTIE_API uint32_t *lottie_animation_render_flush(Lottie_Animation *animation);
237
238
239 /**
240  *  @brief Request to change the properties of this animation object.
241  *  Keypath should conatin object names separated by (.) and can handle globe(**) or wildchar(*)
242  *
243  *  @usage
244  *  To change fillcolor property of fill1 object in the layer1->group1->fill1 hirarchy to RED color
245  *
246  *      lottie_animation_property_override(animation, LOTTIE_ANIMATION_PROPERTY_FILLCOLOR, "layer1.group1.fill1", 1.0, 0.0, 0.0);
247  *
248  *  if all the color property inside group1 needs to be changed to GREEN color
249  *
250  *      lottie_animation_property_override(animation, LOTTIE_ANIMATION_PROPERTY_FILLCOLOR, "**.group1.**", 1.0, 0.0, 0.0);
251  *
252  *  @param[in] animation Animation object.
253  *  @param[in] type Property type. (@p Lottie_Animation_Property)
254  *  @param[in] keypath Specific content of target.
255  *  @param[in] ... Property values.
256  *
257  *  @ingroup Lottie_Animation
258  *  @internal
259  * */
260 RLOTTIE_API void lottie_animation_property_override(Lottie_Animation *animation, const Lottie_Animation_Property type, const char *keypath, ...);
261
262
263 /**
264  *  @brief Returns list of markers in the Lottie resource
265  *  @p LOTMarkerList has a @p LOTMarker list and size of list
266  *  @p LOTMarker has the marker's name, start frame, and end frame.
267  *
268  *  @param[in] animation Animation object.
269  *
270  *  @return The list of marker. If there is no marker, return null.
271  *
272  *  @ingroup Lottie_Animation
273  *  @internal
274  * */
275 RLOTTIE_API const LOTMarkerList* lottie_animation_get_markerlist(Lottie_Animation *animation);
276
277 #ifdef __cplusplus
278 }
279 #endif
280
281 #endif //_RLOTTIE_CAPI_H_
282