Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for rendering with "keep aspect ratio" parameter in the C bindings #566

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions inc/rlottie_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions src/binding/c/lottieanimation_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
{
Expand Down