1 #ifndef _LOTTIE_ANIMATION_CAPI_H_
2 #define _LOTTIE_ANIMATION_CAPI_H_
6 #include <lottiecommon.h>
12 typedef struct Lottie_Animation_S Lottie_Animation;
15 * @brief Constructs an animation object from file path.
17 * @param[in] path Lottie resource file path
19 * @return Animation object that can build the contents of the
20 * Lottie resource represented by file path.
22 * @see lottie_animation_destroy()
24 * @ingroup Lottie_Animation
27 LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
30 * @brief Constructs an animation object from JSON string data.
32 * @param[in] data The JSON string data.
33 * @param[in] key the string that will be used to cache the JSON string data.
35 * @return Animation object that can build the contents of the
36 * Lottie resource represented by JSON string data.
38 * @ingroup Lottie_Animation
41 LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key);
44 * @brief Free given Animation object resource.
46 * @param[in] animation Animation object to free.
48 * @see lottie_animation_from_file()
49 * @see lottie_animation_from_data()
51 * @ingroup Lottie_Animation
54 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation *animation);
57 * @brief Returns default viewport size of the Lottie resource.
59 * @param[in] animation Animation object.
60 * @param[out] w default width of the viewport.
61 * @param[out] h default height of the viewport.
63 * @ingroup Lottie_Animation
66 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
69 * @brief Returns total animation duration of Lottie resource in second.
70 * it uses totalFrame() and frameRate() to calculate the duration.
71 * duration = totalFrame() / frameRate().
73 * @param[in] animation Animation object.
75 * @return total animation duration in second.
76 * @c 0 if the Lottie resource has no animation.
78 * @see lottie_animation_get_totalframe()
79 * @see lottie_animation_get_framerate()
81 * @ingroup Lottie_Animation
84 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation *animation);
87 * @brief Returns total number of frames present in the Lottie resource.
89 * @param[in] animation Animation object.
91 * @return frame count of the Lottie resource.*
93 * @note frame number starts with 0.
95 * @see lottie_animation_get_duration()
96 * @see lottie_animation_get_framerate()
98 * @ingroup Lottie_Animation
101 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
104 * @brief Returns default framerate of the Lottie resource.
106 * @param[in] animation Animation object.
108 * @return framerate of the Lottie resource
110 * @ingroup Lottie_Animation
114 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation *animation);
117 * @brief Get the render tree which contains the snapshot of the animation object
118 * at frame = @c frame_num, the content of the animation in that frame number.
120 * @param[in] animation Animation object.
121 * @param[in] width requested snapshot viewport width.
122 * @param[in] height requested snapshot viewport height.
124 * @return Animation snapshot tree.
126 * @note: User has to traverse the tree for rendering.
131 * @ingroup Lottie_Animation
134 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *animation,
136 size_t width, size_t height);
139 * @brief Maps position to frame number and returns it.
141 * @param[in] animation Animation object.
142 * @param[in] pos position in the range [ 0.0 .. 1.0 ].
144 * @return mapped frame numbe in the range [ start_frame .. end_frame ].
145 * @c 0 if the Lottie resource has no animation.
148 * @ingroup Lottie_Animation
151 LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
154 * @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
156 * @param[in] animation Animation object.
157 * @param[in] frame_num the frame number needs to be rendered.
158 * @param[in] buffer surface buffer use for rendering.
159 * @param[in] width width of the surface
160 * @param[in] height height of the surface
161 * @param[in] bytes_per_line stride of the surface in bytes.
163 * @note user must call lottie_animation_render_flush() to make sure render is finished.
165 * @ingroup Lottie_Animation
169 lottie_animation_render_async(Lottie_Animation *animation,
174 size_t bytes_per_line);
177 * @brief Request to finish the current async renderer job for this animation object.
178 * If render is finished then this call returns immidiately.
179 * If not, it waits till render job finish and then return.
181 * @param[in] animation Animation object.
183 * @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
184 * in pair to get the benefit of async rendering.
186 * @return the pixel buffer it finished rendering.
188 * @ingroup Lottie_Animation
191 LOT_EXPORT uint32_t *
192 lottie_animation_render_flush(Lottie_Animation *animation);
198 #endif //_LOTTIE_ANIMATION_CAPI_H_