From c7cc96a9396f67403f5102ac28dee17a4303ea61 Mon Sep 17 00:00:00 2001 From: gilzoide Date: Sat, 7 Sep 2024 09:37:10 -0300 Subject: [PATCH] Add support for rendering with "keep aspect ratio" parameter in C --- inc/rlottie_capi.h | 35 ++++++++++++++++++++++++++ src/binding/c/lottieanimation_capi.cpp | 31 +++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/inc/rlottie_capi.h b/inc/rlottie_capi.h index bf91ae41..141f92c8 100644 --- a/inc/rlottie_capi.h +++ b/inc/rlottie_capi.h @@ -233,6 +233,23 @@ RLOTTIE_API size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *ani */ RLOTTIE_API void lottie_animation_render(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t bytes_per_line); +/** + * @brief Request to render the content of the frame @p frame_num to buffer @p buffer. + * + * @param[in] animation Animation object. + * @param[in] frame_num the frame number needs to be rendered. + * @param[in] buffer surface buffer use for rendering. + * @param[in] width width of the surface + * @param[in] height height of the surface + * @param[in] bytes_per_line stride of the surface in bytes. + * @param[in] keep_aspect_ratio whether to keep the aspect ratio while scaling the content. + * + * + * @ingroup Lottie_Animation + * @internal + */ +RLOTTIE_API void lottie_animation_render_aspect(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t bytes_per_line, int keep_aspect_ratio); + /** * @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously. * @@ -250,6 +267,24 @@ RLOTTIE_API void lottie_animation_render(Lottie_Animation *animation, size_t fra */ RLOTTIE_API void lottie_animation_render_async(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t bytes_per_line); +/** + * @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously. + * + * @param[in] animation Animation object. + * @param[in] frame_num the frame number needs to be rendered. + * @param[in] buffer surface buffer use for rendering. + * @param[in] width width of the surface + * @param[in] height height of the surface + * @param[in] bytes_per_line stride of the surface in bytes. + * @param[in] keep_aspect_ratio whether to keep the aspect ratio while scaling the content. + * + * @note user must call lottie_animation_render_flush() to make sure render is finished. + * + * @ingroup Lottie_Animation + * @internal + */ +RLOTTIE_API void lottie_animation_render_async_aspect(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t bytes_per_line, int keep_aspect_ratio); + /** * @brief Request to finish the current async renderer job for this animation object. * If render is finished then this call returns immidiately. diff --git a/src/binding/c/lottieanimation_capi.cpp b/src/binding/c/lottieanimation_capi.cpp index e93b0554..b6ef48d8 100644 --- a/src/binding/c/lottieanimation_capi.cpp +++ b/src/binding/c/lottieanimation_capi.cpp @@ -168,6 +168,21 @@ lottie_animation_render(Lottie_Animation_S *animation, animation->mAnimation->renderSync(frame_number, surface); } +RLOTTIE_API void +lottie_animation_render_aspect(Lottie_Animation_S *animation, + size_t frame_number, + uint32_t *buffer, + size_t width, + size_t height, + size_t bytes_per_line, + int keep_aspect_ratio) +{ + if (!animation) return; + + rlottie::Surface surface(buffer, width, height, bytes_per_line); + animation->mAnimation->renderSync(frame_number, surface, keep_aspect_ratio); +} + RLOTTIE_API void lottie_animation_render_async(Lottie_Animation_S *animation, size_t frame_number, @@ -183,6 +198,22 @@ lottie_animation_render_async(Lottie_Animation_S *animation, animation->mBufferRef = buffer; } +RLOTTIE_API void +lottie_animation_render_async_aspect(Lottie_Animation_S *animation, + size_t frame_number, + uint32_t *buffer, + size_t width, + size_t height, + size_t bytes_per_line, + int keep_aspect_ratio) +{ + if (!animation) return; + + rlottie::Surface surface(buffer, width, height, bytes_per_line); + animation->mRenderTask = animation->mAnimation->render(frame_number, surface, keep_aspect_ratio); + animation->mBufferRef = buffer; +} + RLOTTIE_API uint32_t * lottie_animation_render_flush(Lottie_Animation_S *animation) {