fix animation bitmap size to be set dynamically
authorstart1a <start3a@gmail.com>
Mon, 28 Sep 2020 08:09:34 +0000 (17:09 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Sun, 11 Oct 2020 21:09:32 +0000 (06:09 +0900)
example/rlottiePlayer/Source.cpp
example/rlottiePlayer/animation.h
example/rlottiePlayer/rlottiePlayer.cpp

index 2eab13c..cf6d851 100644 (file)
@@ -8,17 +8,21 @@ size_t width, height;
 size_t bytesPerLine;
 uint32_t curColor = UINT32_MAX;
 
-void initAnimation(size_t w, size_t h)
+void setAnimationSize(size_t w, size_t h)
 {
        width = w;
        height = h;
        bytesPerLine = width * sizeof(uint32_t);
+
+    if (buffer != NULL) freeAnimation();
        buffer = (uint32_t*)calloc(bytesPerLine * height, sizeof(uint32_t));
 }
 
-void setAnimation(char* path, size_t w, size_t h)
+void setAnimation(char* path, size_t* w, size_t* h)
 {
        anim = Animation::loadFromFile(path);
+    anim->size(*w, *h);
+    setAnimationSize(*w, *h);
 }
 
 uint32_t* renderRLottieAnimation(uint32_t frameNum)
index 0b1c199..483cb3f 100644 (file)
@@ -1,8 +1,8 @@
 #pragma once
 #include <stdint.h>
 
-void      setAnimation(char* path, size_t w, size_t h);
-void      initAnimation(size_t w, size_t h);
+void      setAnimation(char* path, size_t* w, size_t* h);
+void      setAnimationSize(size_t w, size_t h);
 uint32_t* renderRLottieAnimation(uint32_t frameNum);
 size_t    getTotalFrame();
 bool      isAnimNULL();
index ed6a200..2c657a9 100644 (file)
@@ -19,6 +19,7 @@ HWND hSliderPlay, hSliderCanvasResize;
 UINT curFrame = 0;
 RlottieBitmap anim;                                          // rendered Animation Bitmap
 RECT animRect, backRect;
+size_t animWidth, animHeight;
 Gdiplus::Color backColor(255, 255, 255, 255);
 Gdiplus::Color borderColor(255, 0, 0, 0);
 bool isBackgroundChanged = false;
@@ -159,7 +160,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     case WM_CREATE:
     {
         initUIControl(hWnd);
-        initAnimation(BMP_MAX_LEN, BMP_MAX_LEN);
         break;
     }
     case WM_TIMER:
@@ -325,7 +325,7 @@ void openJSONFileDialog(HWND hDlg)
         USES_CONVERSION;
         LPSTR path = W2A(ofn.lpstrFile);
 
-        setAnimation(path, BMP_MAX_LEN, BMP_MAX_LEN);
+        setAnimation(path, &animWidth, &animHeight);
         // init play slider
         SendMessage(hSliderPlay, TBM_SETRANGE, FALSE, MAKELPARAM(0, getTotalFrame()));
         SendMessage(hSliderPlay, TBM_SETPOS, TRUE, 0);
@@ -365,8 +365,8 @@ Bitmap* CreateBitmap(void* data, unsigned int width, unsigned int height)
     memset(&Info, 0, sizeof(Info));
 
     Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-    Info.bmiHeader.biWidth = 500;
-    Info.bmiHeader.biHeight = 500;
+    Info.bmiHeader.biWidth = width;
+    Info.bmiHeader.biHeight = height;
     Info.bmiHeader.biPlanes = 1;
     Info.bmiHeader.biBitCount = 32;
     Info.bmiHeader.biCompression = BI_RGB;
@@ -384,7 +384,7 @@ void renderAnimation(UINT frameNum)
 
     // render
     UINT* resRender = renderRLottieAnimation(curFrame);
-    anim.image = CreateBitmap(resRender, BMP_MAX_LEN, BMP_MAX_LEN);
+    anim.image = CreateBitmap(resRender, animWidth, animHeight);
     anim.image->RotateFlip(RotateNoneFlipY);
     // call WM_PAINT message
     InvalidateRect(mainWindow, &animRect, FALSE);