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

webp anim decode demo #27

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
63 changes: 63 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ pub unsafe fn WebPDataClear(data: &mut WebPData) {
WebPDataInit(data);
}

pub unsafe fn WebPAnimDecoderOptionsInit(arg1: *mut WebPAnimDecoderOptions) -> core::ffi::c_int {
WebPAnimDecoderOptionsInitInternal(arg1, ffi::WEBP_DEMUX_ABI_VERSION as _)
}

pub unsafe fn WebPAnimDecoderNew(
arg1: *const WebPData,
arg2: *const WebPAnimDecoderOptions,
) -> *mut WebPAnimDecoder {
WebPAnimDecoderNewInternal(arg1, arg2, ffi::WEBP_DEMUX_ABI_VERSION as _)
}

impl Default for WebPAnimInfo {
fn default() -> Self {
WebPAnimInfo {
canvas_width: 0,
canvas_height: 0,
loop_count: 0,
bgcolor: 0,
frame_count: 0,
pad: [0u32; 4usize],
}
}
}

#[cfg(all(test, feature = "std"))]
mod tests {
use super::*;
Expand Down Expand Up @@ -281,4 +305,43 @@ mod tests {
WebPFree(decoded as *mut _);
}
}

#[test]
fn test_decode_anim() {
let mut buf = Vec::new();
let len = File::open("./tests/test_anim.webp")
.unwrap()
.read_to_end(&mut buf)
.unwrap();

unsafe {
let mut width = 0;
let mut height = 0;
WebPGetInfo(buf.as_ptr(), len, &mut width, &mut height);
assert!(width == 400);
assert!(height == 400);

let data = WebPData {
bytes: buf.as_ptr(),
size: len,
};

let mut options = std::mem::zeroed();
// WebPAnimDecoderOptionsInitInternal(&mut options, WebPGetDemuxABIVersion());
// let decoder = WebPAnimDecoderNewInternal(&data, &options, WebPGetDemuxABIVersion());
WebPAnimDecoderOptionsInit(&mut options);
let decoder = WebPAnimDecoderNew(&data, &options);

let mut anim_info = WebPAnimInfo::default();
WebPAnimDecoderGetInfo(decoder, &mut anim_info);

while WebPAnimDecoderHasMoreFrames(decoder) > 0 {
let mut frame_buf = std::ptr::null_mut();
let mut timestamp = 0;
WebPAnimDecoderGetNext(decoder, &mut frame_buf as *mut *mut u8, &mut timestamp);
}

WebPAnimDecoderDelete(decoder);
}
}
}
Binary file added tests/test_anim.webp
Binary file not shown.
Loading