2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
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:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
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
23 #ifndef _RLOTTIE_CAPI_H_
24 #define _RLOTTIE_CAPI_H_
28 #include <rlottiecommon.h>
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;
47 typedef struct Lottie_Animation_S Lottie_Animation;
50 * @brief Constructs an animation object from file path.
52 * @param[in] path Lottie resource file path
54 * @return Animation object that can build the contents of the
55 * Lottie resource represented by file path.
57 * @see lottie_animation_destroy()
59 * @ingroup Lottie_Animation
62 RLOTTIE_API Lottie_Animation *lottie_animation_from_file(const char *path);
65 * @brief Constructs an animation object from JSON string data.
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.
71 * @return Animation object that can build the contents of the
72 * Lottie resource represented by JSON string data.
74 * @ingroup Lottie_Animation
77 RLOTTIE_API Lottie_Animation *lottie_animation_from_data(const char *data, const char *key, const char *resource_path);
80 * @brief Free given Animation object resource.
82 * @param[in] animation Animation object to free.
84 * @see lottie_animation_from_file()
85 * @see lottie_animation_from_data()
87 * @ingroup Lottie_Animation
90 RLOTTIE_API void lottie_animation_destroy(Lottie_Animation *animation);
93 * @brief Returns default viewport size of the Lottie resource.
95 * @param[in] animation Animation object.
96 * @param[out] w default width of the viewport.
97 * @param[out] h default height of the viewport.
99 * @ingroup Lottie_Animation
102 RLOTTIE_API void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
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().
109 * @param[in] animation Animation object.
111 * @return total animation duration in second.
112 * @c 0 if the Lottie resource has no animation.
114 * @see lottie_animation_get_totalframe()
115 * @see lottie_animation_get_framerate()
117 * @ingroup Lottie_Animation
120 RLOTTIE_API double lottie_animation_get_duration(const Lottie_Animation *animation);
123 * @brief Returns total number of frames present in the Lottie resource.
125 * @param[in] animation Animation object.
127 * @return frame count of the Lottie resource.*
129 * @note frame number starts with 0.
131 * @see lottie_animation_get_duration()
132 * @see lottie_animation_get_framerate()
134 * @ingroup Lottie_Animation
137 RLOTTIE_API size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
140 * @brief Returns default framerate of the Lottie resource.
142 * @param[in] animation Animation object.
144 * @return framerate of the Lottie resource
146 * @ingroup Lottie_Animation
150 RLOTTIE_API double lottie_animation_get_framerate(const Lottie_Animation *animation);
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.
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.
161 * @return Animation snapshot tree.
163 * @note: User has to traverse the tree for rendering.
168 * @ingroup Lottie_Animation
171 RLOTTIE_API const LOTLayerNode *lottie_animation_render_tree(Lottie_Animation *animation, size_t frame_num, size_t width, size_t height);
174 * @brief Maps position to frame number and returns it.
176 * @param[in] animation Animation object.
177 * @param[in] pos position in the range [ 0.0 .. 1.0 ].
179 * @return mapped frame numbe in the range [ start_frame .. end_frame ].
180 * @c 0 if the Lottie resource has no animation.
183 * @ingroup Lottie_Animation
186 RLOTTIE_API size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
189 * @brief Request to render the content of the frame @p frame_num to buffer @p buffer.
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.
199 * @ingroup Lottie_Animation
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);
205 * @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
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.
214 * @note user must call lottie_animation_render_flush() to make sure render is finished.
216 * @ingroup Lottie_Animation
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);
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.
226 * @param[in] animation Animation object.
228 * @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
229 * in pair to get the benefit of async rendering.
231 * @return the pixel buffer it finished rendering.
233 * @ingroup Lottie_Animation
236 RLOTTIE_API uint32_t *lottie_animation_render_flush(Lottie_Animation *animation);
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(*)
244 * To change fillcolor property of fill1 object in the layer1->group1->fill1 hirarchy to RED color
246 * lottie_animation_property_override(animation, LOTTIE_ANIMATION_PROPERTY_FILLCOLOR, "layer1.group1.fill1", 1.0, 0.0, 0.0);
248 * if all the color property inside group1 needs to be changed to GREEN color
250 * lottie_animation_property_override(animation, LOTTIE_ANIMATION_PROPERTY_FILLCOLOR, "**.group1.**", 1.0, 0.0, 0.0);
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.
257 * @ingroup Lottie_Animation
260 RLOTTIE_API void lottie_animation_property_override(Lottie_Animation *animation, const Lottie_Animation_Property type, const char *keypath, ...);
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.
268 * @param[in] animation Animation object.
270 * @return The list of marker. If there is no marker, return null.
272 * @ingroup Lottie_Animation
275 RLOTTIE_API const LOTMarkerList* lottie_animation_get_markerlist(Lottie_Animation *animation);
281 #endif //_RLOTTIE_CAPI_H_