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")))
35 class LOT_EXPORT Surface {
38 * @brief Surface object constructor.
40 * @param[in] buffer surface buffer.
41 * @param[in] width surface width.
42 * @param[in] height surface height.
43 * @param[in] bytesPerLine number of bytes in a surface scanline.
45 * @note Default surface format is ARGB32_Premultiplied.
47 Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine);
50 * @brief Returns width of the surface.
52 * @return surface width
54 size_t width() const {return mWidth;}
57 * @brief Returns height of the surface.
59 * @return surface height
61 size_t height() const {return mHeight;}
64 * @brief Returns number of bytes in the surface scanline.
66 * @return number of bytes in scanline.
68 size_t bytesPerLine() const {return mBytesPerLine;}
71 * @brief Returns buffer attached tp the surface.
73 * @return buffer attaced to the Surface.
75 uint32_t *buffer() const {return mBuffer;}
78 * @brief Default constructor.
88 class LOT_EXPORT Animation {
92 * @brief Constructs an animation object from filepath.
94 * @param[in] path Lottie resource file path
96 * @return Animation object that can render the contents of the
97 * lottie resource represented by file path.
99 static std::unique_ptr<Animation>
100 loadFromFile(const std::string &path);
103 * @brief Constructs an animation object from json string data.
105 * @param[in] jsonData The JSON string data.
106 * @param[in] key the string that will be used to cache the JSON string data.
108 * @return Animation object that can render the contents of the
109 * lottie resource represented by JSON string data.
111 static std::unique_ptr<Animation>
112 loadFromData(const char *jsonData, const char *key);
115 * @brief Returns default framerate of the lottie resource.
117 * @return framerate of the lottie resource
120 double frameRate() const;
123 * @brief Returns total number of frames present in the lottie resource.
125 * @return frame count of the lottie resource.
127 * @note frame number starts with 0.
129 size_t totalFrame() const;
132 * @brief Returns default viewport size of the lottie resource.
134 * @param[out] width default width of the viewport.
135 * @param[out] height default height of the viewport.
138 void size(size_t &width, size_t &height) const;
141 * @brief Returns total animation duration of lottie resource in second.
142 * it uses totalFrame() and frameRate() to calcualte the duration.
143 * duration = totalFrame() / frameRate().
145 * @return total animation duration in second.
146 * @retval 0 if the lottie resource has no animation.
151 double duration() const;
154 * @brief Returns frame number for a given position.
155 * this function helps to map the position value retuned
156 * by the animator to a frame number in side the lottie resource.
157 * frame_number = lerp(start_frame, endframe, pos);
159 * @param[in] pos normalized position value [0 ... 1]
161 * @return frame numer maps to the position value [startFrame .... endFrame]
164 size_t frameAtPos(double pos);
167 * @brief Renders the content to surface Asynchronously.
168 * it gives a future in return to get the result of the
169 * rendering at a future point.
170 * To get best performance user has to start rendering as soon as
171 * it finds that content at {frameNo} has to be rendered and get the
172 * result from the future at the last moment when the surface is needed
173 * to draw into the screen.
176 * @param[in] frameNo Content corresponds to the frameno needs to be drawn
177 * @param[in] surface Surface in which content will be drawn
179 * @return future that will hold the result when rendering finished.
181 * for Synchronus rendering @see renderSync
184 std::future<Surface> render(size_t frameNo, Surface surface);
187 * @brief Renders the content to surface synchronously.
188 * for performance use the asyn rendering @see render
190 * @param[in] frameNo Content corresponds to the frameno needs to be drawn
191 * @param[in] surface Surface in which content will be drawn
193 void renderSync(size_t frameNo, Surface surface);
196 * @brief Returns list of rendering nodes that that represents the
197 * content of the lottie resource at frame number {frameNo}.
199 * @param[in] frameNo Content corresponds to the frameno needs to be extracted.
200 * @param[in] width content viewbox width
201 * @param[in] height content viewbox height
203 * @return render node list.
205 const std::vector<LOTNode *> &renderList(size_t frameNo, size_t width, size_t height) const;
208 * @brief default destructor
213 * @brief default constructor
215 * @note user should never construct animation object.
216 * they should call the one of the factory method instead.
218 * @see loadFromFile()
219 * @see loadFromData()
223 std::unique_ptr<AnimationImpl> d;
226 } // namespace lotplayer
228 #endif // _LOTTIE_ANIMATION_H_