1 #ifndef _LOTTIE_ANIMATION_H_
2 #define _LOTTIE_ANIMATION_H_
11 #define LOT_EXPORT __declspec(dllexport)
16 #define LOT_EXPORT __declspec(dllimport)
21 #define LOT_EXPORT __attribute__((visibility("default")))
36 class LOT_EXPORT Surface {
39 * @brief Surface object constructor.
41 * @param[in] buffer surface buffer.
42 * @param[in] width surface width.
43 * @param[in] height surface height.
44 * @param[in] bytesPerLine number of bytes in a surface scanline.
46 * @note Default surface format is ARGB32_Premultiplied.
50 Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine);
53 * @brief Returns width of the surface.
55 * @return surface width
60 size_t width() const {return mWidth;}
63 * @brief Returns height of the surface.
65 * @return surface height
69 size_t height() const {return mHeight;}
72 * @brief Returns number of bytes in the surface scanline.
74 * @return number of bytes in scanline.
78 size_t bytesPerLine() const {return mBytesPerLine;}
81 * @brief Returns buffer attached tp the surface.
83 * @return buffer attaced to the Surface.
87 uint32_t *buffer() const {return mBuffer;}
90 * @brief Default constructor.
100 class LOT_EXPORT Animation {
104 * @brief Constructs an animation object from file path.
106 * @param[in] path Lottie resource file path
108 * @return Animation object that can render the contents of the
109 * Lottie resource represented by file path.
113 static std::unique_ptr<Animation>
114 loadFromFile(const std::string &path);
117 * @brief Constructs an animation object from JSON string data.
119 * @param[in] jsonData The JSON string data.
120 * @param[in] key the string that will be used to cache the JSON string data.
122 * @return Animation object that can render the contents of the
123 * Lottie resource represented by JSON string data.
127 static std::unique_ptr<Animation>
128 loadFromData(std::string jsonData, const std::string &key);
131 * @brief Returns default framerate of the Lottie resource.
133 * @return framerate of the Lottie resource
138 double frameRate() const;
141 * @brief Returns total number of frames present in the Lottie resource.
143 * @return frame count of the Lottie resource.
145 * @note frame number starts with 0.
149 size_t totalFrame() const;
152 * @brief Returns default viewport size of the Lottie resource.
154 * @param[out] width default width of the viewport.
155 * @param[out] height default height of the viewport.
160 void size(size_t &width, size_t &height) const;
163 * @brief Returns total animation duration of Lottie resource in second.
164 * it uses totalFrame() and frameRate() to calculate the duration.
165 * duration = totalFrame() / frameRate().
167 * @return total animation duration in second.
168 * @retval 0 if the Lottie resource has no animation.
175 double duration() const;
178 * @brief Returns frame number for a given position.
179 * this function helps to map the position value retuned
180 * by the animator to a frame number in side the Lottie resource.
181 * frame_number = lerp(start_frame, endframe, pos);
183 * @param[in] pos normalized position value [0 ... 1]
185 * @return frame numer maps to the position value [startFrame .... endFrame]
189 size_t frameAtPos(double pos);
192 * @brief Renders the content to surface Asynchronously.
193 * it gives a future in return to get the result of the
194 * rendering at a future point.
195 * To get best performance user has to start rendering as soon as
196 * it finds that content at {frameNo} has to be rendered and get the
197 * result from the future at the last moment when the surface is needed
198 * to draw into the screen.
201 * @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
202 * @param[in] surface Surface in which content will be drawn
204 * @return future that will hold the result when rendering finished.
206 * for Synchronus rendering @see renderSync
211 std::future<Surface> render(size_t frameNo, Surface surface);
214 * @brief Renders the content to surface synchronously.
215 * for performance use the async rendering @see render
217 * @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
218 * @param[in] surface Surface in which content will be drawn
222 void renderSync(size_t frameNo, Surface surface);
225 * @brief Returns root layer of the composition updated with
226 * content of the Lottie resource at frame number @p frameNo.
228 * @param[in] frameNo Content corresponds to the @p frameNo needs to be extracted.
229 * @param[in] width content viewbox width
230 * @param[in] height content viewbox height
232 * @return Root layer node.
236 const LOTLayerNode * renderTree(size_t frameNo, size_t width, size_t height) const;
239 * @brief default destructor
247 * @brief default constructor
253 std::unique_ptr<AnimationImpl> d;
256 } // namespace lotplayer
258 #endif // _LOTTIE_ANIMATION_H_