diff options
author | pommicket <pommicket@gmail.com> | 2023-09-05 01:31:24 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-09-05 01:31:24 -0400 |
commit | 08db1dc9428ea5bc9604b229d686af1414d461af (patch) | |
tree | e6b38e0e8a0f7c0beeb53a893c908e22f2d4de09 /examples/wasm-tiny-png/src | |
parent | ebf696d4757b6cb040fbd7799149413cf2cfef9b (diff) |
little size compeitino
Diffstat (limited to 'examples/wasm-tiny-png/src')
-rw-r--r-- | examples/wasm-tiny-png/src/lib.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/wasm-tiny-png/src/lib.rs b/examples/wasm-tiny-png/src/lib.rs new file mode 100644 index 0000000..ff553f1 --- /dev/null +++ b/examples/wasm-tiny-png/src/lib.rs @@ -0,0 +1,15 @@ +#[no_mangle] +pub unsafe fn decode_png(input: *const u8, input_len: usize, output: *mut u8, output_len: usize) -> usize { + let mut input = core::slice::from_raw_parts(input, input_len); + let output = core::slice::from_raw_parts_mut(output, output_len); + let Ok(header) = tiny_png::read_png_header(&mut input) else { + return 0; + }; + let required_bytes = header.required_bytes(); + if output_len >= required_bytes { + if tiny_png::read_png(&mut input, Some(&header), output).is_err() { + return 0; + } + } + required_bytes +} |