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_H_
20 #define _LOTTIE_ANIMATION_H_
29 #define LOT_EXPORT __declspec(dllexport)
34 #define LOT_EXPORT __declspec(dllimport)
39 #define LOT_EXPORT __attribute__((visibility("default")))
54 class LOT_EXPORT Surface {
57 * @brief Surface object constructor.
59 * @param[in] buffer surface buffer.
60 * @param[in] width surface width.
61 * @param[in] height surface height.
62 * @param[in] bytesPerLine number of bytes in a surface scanline.
64 * @note Default surface format is ARGB32_Premultiplied.
68 Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine);
71 * @brief Returns width of the surface.
73 * @return surface width
78 size_t width() const {return mWidth;}
81 * @brief Returns height of the surface.
83 * @return surface height
87 size_t height() const {return mHeight;}
90 * @brief Returns number of bytes in the surface scanline.
92 * @return number of bytes in scanline.
96 size_t bytesPerLine() const {return mBytesPerLine;}
99 * @brief Returns buffer attached tp the surface.
101 * @return buffer attaced to the Surface.
105 uint32_t *buffer() const {return mBuffer;}
108 * @brief Default constructor.
112 uint32_t *mBuffer{nullptr};
115 size_t mBytesPerLine{0};
118 class LOT_EXPORT Animation {
122 * @brief Constructs an animation object from file path.
124 * @param[in] path Lottie resource file path
126 * @return Animation object that can render the contents of the
127 * Lottie resource represented by file path.
131 static std::unique_ptr<Animation>
132 loadFromFile(const std::string &path);
135 * @brief Constructs an animation object from JSON string data.
137 * @param[in] jsonData The JSON string data.
138 * @param[in] key the string that will be used to cache the JSON string data.
140 * @return Animation object that can render the contents of the
141 * Lottie resource represented by JSON string data.
145 static std::unique_ptr<Animation>
146 loadFromData(std::string jsonData, const std::string &key);
149 * @brief Returns default framerate of the Lottie resource.
151 * @return framerate of the Lottie resource
156 double frameRate() const;
159 * @brief Returns total number of frames present in the Lottie resource.
161 * @return frame count of the Lottie resource.
163 * @note frame number starts with 0.
167 size_t totalFrame() const;
170 * @brief Returns default viewport size of the Lottie resource.
172 * @param[out] width default width of the viewport.
173 * @param[out] height default height of the viewport.
178 void size(size_t &width, size_t &height) const;
181 * @brief Returns total animation duration of Lottie resource in second.
182 * it uses totalFrame() and frameRate() to calculate the duration.
183 * duration = totalFrame() / frameRate().
185 * @return total animation duration in second.
186 * @retval 0 if the Lottie resource has no animation.
193 double duration() const;
196 * @brief Returns frame number for a given position.
197 * this function helps to map the position value retuned
198 * by the animator to a frame number in side the Lottie resource.
199 * frame_number = lerp(start_frame, endframe, pos);
201 * @param[in] pos normalized position value [0 ... 1]
203 * @return frame numer maps to the position value [startFrame .... endFrame]
207 size_t frameAtPos(double pos);
210 * @brief Renders the content to surface Asynchronously.
211 * it gives a future in return to get the result of the
212 * rendering at a future point.
213 * To get best performance user has to start rendering as soon as
214 * it finds that content at {frameNo} has to be rendered and get the
215 * result from the future at the last moment when the surface is needed
216 * to draw into the screen.
219 * @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
220 * @param[in] surface Surface in which content will be drawn
222 * @return future that will hold the result when rendering finished.
224 * for Synchronus rendering @see renderSync
229 std::future<Surface> render(size_t frameNo, Surface surface);
232 * @brief Renders the content to surface synchronously.
233 * for performance use the async rendering @see render
235 * @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
236 * @param[in] surface Surface in which content will be drawn
240 void renderSync(size_t frameNo, Surface surface);
243 * @brief Returns root layer of the composition updated with
244 * content of the Lottie resource at frame number @p frameNo.
246 * @param[in] frameNo Content corresponds to the @p frameNo needs to be extracted.
247 * @param[in] width content viewbox width
248 * @param[in] height content viewbox height
250 * @return Root layer node.
254 const LOTLayerNode * renderTree(size_t frameNo, size_t width, size_t height) const;
257 * @brief default destructor
265 * @brief default constructor
271 std::unique_ptr<AnimationImpl> d;
274 } // namespace lotplayer
276 #endif // _LOTTIE_ANIMATION_H_