1 #include "lottieanimation.h"
4 using namespace lottie;
8 struct Lottie_Animation_S
10 std::unique_ptr<Animation> mAnimation;
12 std::future<Surface> mRenderTask;
19 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *file)
21 if (auto animation = Animation::loadFromFile(file) ) {
22 Lottie_Animation_S *handle = new Lottie_Animation_S();
23 handle->mAnimation = std::move(animation);
30 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key)
32 if (auto animation = Animation::loadFromData(data, key) ) {
33 Lottie_Animation_S *handle = new Lottie_Animation_S();
34 handle->mAnimation = std::move(animation);
41 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation_S *animation)
47 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation_S *animation, size_t *w, size_t *h)
49 if (!animation) return;
51 animation->mAnimation->size(*w, *h);
54 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation_S *animation)
56 if (!animation) return 0;
58 return animation->mAnimation->duration();
61 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation_S *animation)
63 if (!animation) return 0;
65 return animation->mAnimation->totalFrame();
69 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation_S *animation)
71 if (!animation) return 0;
73 return animation->mAnimation->frameRate();
76 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation_S *animation, size_t frameNo, size_t w, size_t h)
78 if (!animation) return nullptr;
80 animation->mFrameNo = frameNo;
81 animation->mWidth = w;
82 animation->mHeight = h;
83 return animation->mAnimation->renderTree(frameNo, w, h);
87 lottie_animation_render_async(Lottie_Animation_S *animation,
92 size_t bytes_per_line)
94 if (!animation) return;
96 lottie::Surface surface(buffer, width, height, bytes_per_line);
97 animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
101 lottie_animation_render_flush(Lottie_Animation_S *animation)
103 if (!animation) return;
105 if (animation->mRenderTask.valid()) {
106 animation->mRenderTask.get();