2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
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.
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.
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
19 #ifndef _LOTTIE_ANIMATION_CAPI_H_
20 #define _LOTTIE_ANIMATION_CAPI_H_
24 #include <lottiecommon.h>
30 typedef struct Lottie_Animation_S Lottie_Animation;
33 * @brief Constructs an animation object from file path.
35 * @param[in] path Lottie resource file path
37 * @return Animation object that can build the contents of the
38 * Lottie resource represented by file path.
40 * @see lottie_animation_destroy()
42 * @ingroup Lottie_Animation
45 LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
48 * @brief Constructs an animation object from JSON string data.
50 * @param[in] data The JSON string data.
51 * @param[in] key the string that will be used to cache the JSON string data.
53 * @return Animation object that can build the contents of the
54 * Lottie resource represented by JSON string data.
56 * @ingroup Lottie_Animation
59 LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key);
62 * @brief Free given Animation object resource.
64 * @param[in] animation Animation object to free.
66 * @see lottie_animation_from_file()
67 * @see lottie_animation_from_data()
69 * @ingroup Lottie_Animation
72 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation *animation);
75 * @brief Returns default viewport size of the Lottie resource.
77 * @param[in] animation Animation object.
78 * @param[out] w default width of the viewport.
79 * @param[out] h default height of the viewport.
81 * @ingroup Lottie_Animation
84 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
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().
91 * @param[in] animation Animation object.
93 * @return total animation duration in second.
94 * @c 0 if the Lottie resource has no animation.
96 * @see lottie_animation_get_totalframe()
97 * @see lottie_animation_get_framerate()
99 * @ingroup Lottie_Animation
102 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation *animation);
105 * @brief Returns total number of frames present in the Lottie resource.
107 * @param[in] animation Animation object.
109 * @return frame count of the Lottie resource.*
111 * @note frame number starts with 0.
113 * @see lottie_animation_get_duration()
114 * @see lottie_animation_get_framerate()
116 * @ingroup Lottie_Animation
119 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
122 * @brief Returns default framerate of the Lottie resource.
124 * @param[in] animation Animation object.
126 * @return framerate of the Lottie resource
128 * @ingroup Lottie_Animation
132 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation *animation);
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.
138 * @param[in] animation Animation object.
139 * @param[in] width requested snapshot viewport width.
140 * @param[in] height requested snapshot viewport height.
142 * @return Animation snapshot tree.
144 * @note: User has to traverse the tree for rendering.
149 * @ingroup Lottie_Animation
152 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *animation,
154 size_t width, size_t height);
157 * @brief Maps position to frame number and returns it.
159 * @param[in] animation Animation object.
160 * @param[in] pos position in the range [ 0.0 .. 1.0 ].
162 * @return mapped frame numbe in the range [ start_frame .. end_frame ].
163 * @c 0 if the Lottie resource has no animation.
166 * @ingroup Lottie_Animation
169 LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
172 * @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
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.
181 * @note user must call lottie_animation_render_flush() to make sure render is finished.
183 * @ingroup Lottie_Animation
187 lottie_animation_render_async(Lottie_Animation *animation,
192 size_t bytes_per_line);
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.
199 * @param[in] animation Animation object.
201 * @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
202 * in pair to get the benefit of async rendering.
204 * @return the pixel buffer it finished rendering.
206 * @ingroup Lottie_Animation
209 LOT_EXPORT uint32_t *
210 lottie_animation_render_flush(Lottie_Animation *animation);
216 #endif //_LOTTIE_ANIMATION_CAPI_H_