9f112cb1129cb3a65b338aee6d3a402afde7e137
[platform/core/uifw/lottie-player.git] / example / rlottiePlayer / Source.cpp
1 #include "rlottie.h"
2 using namespace rlottie;
3
4 std::unique_ptr<Animation> anim;
5 uint32_t *buffer;
6 size_t width, height;
7 size_t bytesPerLine;
8 uint32_t curColor = UINT32_MAX;
9
10 void initAnimation(size_t w, size_t h)
11 {
12         width = w;
13         height = h;
14         bytesPerLine = width * sizeof(uint32_t);
15         buffer = (uint32_t*)calloc(bytesPerLine * height, sizeof(uint32_t));
16 }
17
18 void setAnimation(char* path, size_t w, size_t h)
19 {
20         anim = Animation::loadFromFile(path);
21 }
22
23 uint32_t* renderRLottieAnimation(uint32_t frameNum)
24 {
25         static Surface surface = Surface(buffer, width, height, bytesPerLine);
26         anim->renderSync(frameNum, surface);
27         // background color
28         for (int i = 0; i < height; i++)
29                 for (int j = 0; j < width; ++j)
30                 {
31                         uint32_t* v = buffer + i * width + j;
32                         if (*v == 0) *v = curColor;
33                 }
34         return buffer;
35 }
36
37 void setAnimationColor(int r, int g, int b)
38 {
39         curColor = ((255 << 16) * r) + ((255 << 8) * g) + 255 * b;
40 }
41
42 size_t getTotalFrame()
43 {
44         return anim->totalFrame();
45 }
46
47 bool isAnimNULL()
48 {
49         return anim == NULL;
50 }