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.
48 Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine);
51 * @brief Returns width of the surface.
53 * @return surface width
55 size_t width() const {return mWidth;}
58 * @brief Returns height of the surface.
60 * @return surface height
62 size_t height() const {return mHeight;}
65 * @brief Returns number of bytes in the surface scanline.
67 * @return number of bytes in scanline.
69 size_t bytesPerLine() const {return mBytesPerLine;}
72 * @brief Returns buffer attached tp the surface.
74 * @return buffer attaced to the Surface.
76 uint32_t *buffer() const {return mBuffer;}
79 * @brief Default constructor.
89 class LOT_EXPORT Animation {
93 * @brief Constructs an animation object from filepath.
95 * @param[in] path Lottie resource file path
97 * @return Animation object that can render the contents of the
98 * lottie resource represented by file path.
100 static std::unique_ptr<Animation>
101 loadFromFile(const std::string &path);
104 * @brief Constructs an animation object from json string data.
106 * @param[in] jsonData The JSON string data.
107 * @param[in] key the string that will be used to cache the JSON string data.
109 * @return Animation object that can render the contents of the
110 * lottie resource represented by JSON string data.
112 static std::unique_ptr<Animation>
113 loadFromData(std::string jsonData, const std::string &key);
116 * @brief Returns default framerate of the lottie resource.
118 * @return framerate of the lottie resource
121 double frameRate() const;
124 * @brief Returns total number of frames present in the lottie resource.
126 * @return frame count of the lottie resource.
128 * @note frame number starts with 0.
130 size_t totalFrame() const;
133 * @brief Returns default viewport size of the lottie resource.
135 * @param[out] width default width of the viewport.
136 * @param[out] height default height of the viewport.
139 void size(size_t &width, size_t &height) const;
142 * @brief Returns total animation duration of lottie resource in second.
143 * it uses totalFrame() and frameRate() to calcualte the duration.
144 * duration = totalFrame() / frameRate().
146 * @return total animation duration in second.
147 * @retval 0 if the lottie resource has no animation.
152 double duration() const;
155 * @brief Returns frame number for a given position.
156 * this function helps to map the position value retuned
157 * by the animator to a frame number in side the lottie resource.
158 * frame_number = lerp(start_frame, endframe, pos);
160 * @param[in] pos normalized position value [0 ... 1]
162 * @return frame numer maps to the position value [startFrame .... endFrame]
165 size_t frameAtPos(double pos);
168 * @brief Renders the content to surface Asynchronously.
169 * it gives a future in return to get the result of the
170 * rendering at a future point.
171 * To get best performance user has to start rendering as soon as
172 * it finds that content at {frameNo} has to be rendered and get the
173 * result from the future at the last moment when the surface is needed
174 * to draw into the screen.
177 * @param[in] frameNo Content corresponds to the frameno needs to be drawn
178 * @param[in] surface Surface in which content will be drawn
180 * @return future that will hold the result when rendering finished.
182 * for Synchronus rendering @see renderSync
185 std::future<Surface> render(size_t frameNo, Surface surface);
188 * @brief Renders the content to surface synchronously.
189 * for performance use the asyn rendering @see render
191 * @param[in] frameNo Content corresponds to the frameno needs to be drawn
192 * @param[in] surface Surface in which content will be drawn
194 void renderSync(size_t frameNo, Surface surface);
197 * @brief Returns list of rendering nodes that that represents the
198 * content of the lottie resource at frame number {frameNo}.
200 * @param[in] frameNo Content corresponds to the frameno needs to be extracted.
201 * @param[in] width content viewbox width
202 * @param[in] height content viewbox height
204 * @return render node list.
206 const std::vector<LOTNode *> &renderList(size_t frameNo, size_t width, size_t height) const;
209 * @brief Returns root layer of the composition updated with
210 * content of the lottie resource at frame number {frameNo}.
212 * @param[in] frameNo Content corresponds to the frameno needs to be extracted.
213 * @param[in] width content viewbox width
214 * @param[in] height content viewbox height
216 * @return Root layer node.
218 const LOTLayerNode * renderTree(size_t frameNo, size_t width, size_t height) const;
221 * @brief default destructor
227 * @brief default constructor
231 std::unique_ptr<AnimationImpl> d;
234 } // namespace lotplayer
236 #endif // _LOTTIE_ANIMATION_H_