2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _LOTTIE_ANIMATION_CAPI_H_
18 #define _LOTTIE_ANIMATION_CAPI_H_
22 #include <lottiecommon.h>
28 typedef struct Lottie_Animation_S Lottie_Animation;
31 * @brief Constructs an animation object from file path.
33 * @param[in] path Lottie resource file path
35 * @return Animation object that can build the contents of the
36 * Lottie resource represented by file path.
38 * @see lottie_animation_destroy()
40 * @ingroup Lottie_Animation
43 LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
46 * @brief Constructs an animation object from JSON string data.
48 * @param[in] data The JSON string data.
49 * @param[in] key the string that will be used to cache the JSON string data.
51 * @return Animation object that can build the contents of the
52 * Lottie resource represented by JSON string data.
54 * @ingroup Lottie_Animation
57 LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key);
60 * @brief Free given Animation object resource.
62 * @param[in] animation Animation object to free.
64 * @see lottie_animation_from_file()
65 * @see lottie_animation_from_data()
67 * @ingroup Lottie_Animation
70 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation *animation);
73 * @brief Returns default viewport size of the Lottie resource.
75 * @param[in] animation Animation object.
76 * @param[out] w default width of the viewport.
77 * @param[out] h default height of the viewport.
79 * @ingroup Lottie_Animation
82 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
85 * @brief Returns total animation duration of Lottie resource in second.
86 * it uses totalFrame() and frameRate() to calculate the duration.
87 * duration = totalFrame() / frameRate().
89 * @param[in] animation Animation object.
91 * @return total animation duration in second.
92 * @c 0 if the Lottie resource has no animation.
94 * @see lottie_animation_get_totalframe()
95 * @see lottie_animation_get_framerate()
97 * @ingroup Lottie_Animation
100 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation *animation);
103 * @brief Returns total number of frames present in the Lottie resource.
105 * @param[in] animation Animation object.
107 * @return frame count of the Lottie resource.*
109 * @note frame number starts with 0.
111 * @see lottie_animation_get_duration()
112 * @see lottie_animation_get_framerate()
114 * @ingroup Lottie_Animation
117 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
120 * @brief Returns default framerate of the Lottie resource.
122 * @param[in] animation Animation object.
124 * @return framerate of the Lottie resource
126 * @ingroup Lottie_Animation
130 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation *animation);
133 * @brief Get the render tree which contains the snapshot of the animation object
134 * at frame = @c frame_num, the content of the animation in that frame number.
136 * @param[in] animation Animation object.
137 * @param[in] width requested snapshot viewport width.
138 * @param[in] height requested snapshot viewport height.
140 * @return Animation snapshot tree.
142 * @note: User has to traverse the tree for rendering.
147 * @ingroup Lottie_Animation
150 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *animation,
152 size_t width, size_t height);
155 * @brief Maps position to frame number and returns it.
157 * @param[in] animation Animation object.
158 * @param[in] pos position in the range [ 0.0 .. 1.0 ].
160 * @return mapped frame numbe in the range [ start_frame .. end_frame ].
161 * @c 0 if the Lottie resource has no animation.
164 * @ingroup Lottie_Animation
167 LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
170 * @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
172 * @param[in] animation Animation object.
173 * @param[in] frame_num the frame number needs to be rendered.
174 * @param[in] buffer surface buffer use for rendering.
175 * @param[in] width width of the surface
176 * @param[in] height height of the surface
177 * @param[in] bytes_per_line stride of the surface in bytes.
179 * @note user must call lottie_animation_render_flush() to make sure render is finished.
181 * @ingroup Lottie_Animation
185 lottie_animation_render_async(Lottie_Animation *animation,
190 size_t bytes_per_line);
193 * @brief Request to finish the current async renderer job for this animation object.
194 * If render is finished then this call returns immidiately.
195 * If not, it waits till render job finish and then return.
197 * @param[in] animation Animation object.
199 * @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
200 * in pair to get the benefit of async rendering.
202 * @return the pixel buffer it finished rendering.
204 * @ingroup Lottie_Animation
207 LOT_EXPORT uint32_t *
208 lottie_animation_render_flush(Lottie_Animation *animation);
214 #endif //_LOTTIE_ANIMATION_CAPI_H_