From fcab15a2232121c0750b3a371a93dadd13b1b7a7 Mon Sep 17 00:00:00 2001 From: start1a Date: Mon, 28 Sep 2020 17:09:34 +0900 Subject: [PATCH] fix animation bitmap size to be set dynamically --- example/rlottiePlayer/Source.cpp | 8 ++++++-- example/rlottiePlayer/animation.h | 4 ++-- example/rlottiePlayer/rlottiePlayer.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/example/rlottiePlayer/Source.cpp b/example/rlottiePlayer/Source.cpp index 2eab13c..cf6d851 100644 --- a/example/rlottiePlayer/Source.cpp +++ b/example/rlottiePlayer/Source.cpp @@ -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) diff --git a/example/rlottiePlayer/animation.h b/example/rlottiePlayer/animation.h index 0b1c199..483cb3f 100644 --- a/example/rlottiePlayer/animation.h +++ b/example/rlottiePlayer/animation.h @@ -1,8 +1,8 @@ #pragma once #include -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(); diff --git a/example/rlottiePlayer/rlottiePlayer.cpp b/example/rlottiePlayer/rlottiePlayer.cpp index ed6a200..2c657a9 100644 --- a/example/rlottiePlayer/rlottiePlayer.cpp +++ b/example/rlottiePlayer/rlottiePlayer.cpp @@ -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); -- 2.34.1