From 6fdb5619052ff68face6ad06b4423776ce8bd4f2 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 5 Sep 2023 22:37:10 -0400 Subject: rename to minipng --- examples/wasm-minipng/.cargo/config.toml | 2 ++ examples/wasm-minipng/Cargo.toml | 14 ++++++++++++++ examples/wasm-minipng/src/lib.rs | 15 +++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 examples/wasm-minipng/.cargo/config.toml create mode 100644 examples/wasm-minipng/Cargo.toml create mode 100644 examples/wasm-minipng/src/lib.rs (limited to 'examples/wasm-minipng') diff --git a/examples/wasm-minipng/.cargo/config.toml b/examples/wasm-minipng/.cargo/config.toml new file mode 100644 index 0000000..f4e8c00 --- /dev/null +++ b/examples/wasm-minipng/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/examples/wasm-minipng/Cargo.toml b/examples/wasm-minipng/Cargo.toml new file mode 100644 index 0000000..ac51c8b --- /dev/null +++ b/examples/wasm-minipng/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "wasm-minipng" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +minipng = { path = "../.." } + +[profile.release] +opt-level = "z" +lto = true diff --git a/examples/wasm-minipng/src/lib.rs b/examples/wasm-minipng/src/lib.rs new file mode 100644 index 0000000..aebf88b --- /dev/null +++ b/examples/wasm-minipng/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 input = core::slice::from_raw_parts(input, input_len); + let output = core::slice::from_raw_parts_mut(output, output_len); + let Ok(header) = minipng::decode_png_header(input) else { + return 0; + }; + let required_bytes = header.required_bytes(); + if output_len >= required_bytes { + if minipng::decode_png(input, output).is_err() { + return 0; + } + } + required_bytes +} -- cgit v1.2.3