Coder Social home page Coder Social logo

libwebp-sys's Introduction

libwebp-sys

bindgen'd FFI bindings to libwebp.

libwebp is built with the cc crate. It needs a C compiler, but cmake is not used.

Set TARGET_CPU env var to native or your desired CPU architecture to optimize the C code for it.

Usage

Add the following to the Cargo.toml in your project:

[dependencies]
libwebp-sys = "0.9"

or to require newer CPUs with SIMD support:

[dependencies]
libwebp-sys = { version = "0.9", features = ["avx2", "sse41", "neon"] }

or to require no_std support:

libwebp-sys = { version = "0.9", default-features = false, features = ["parallel", "neon"] }

Examples

Encode

pub fn encode_webp(input_image: &[u8], width: u32, height: u32, quality: i32) -> Result<Vec<u8>> {
    unsafe {
	    let mut out_buf = std::ptr::null_mut();
	    let stride = width as i32 * 4;
	    let len = WebPEncodeRGBA(input_image.as_ptr(), width as i32, height as i32, stride, quality as f32, &mut out_buf);
	    Ok(std::slice::from_raw_parts(out_buf, len as usize).into())
    }
}

Decode

pub fn decode_webp(buf: &[u8]) -> Result<Vec<u8>> {
	let mut width = 0;
	let mut height = 0;
	let len = buf.len();
	unsafe {
		WebPGetInfo(buf.as_ptr(), len, &mut width, &mut height);
		let out_buf = WebPDecodeRGBA(buf.as_ptr(), len, &mut width, &mut height);
	}
	Ok(std::slice::::from_raw_parts(out_buf, width * height * 4).into())
}

libwebp-sys's People

Contributors

brooooooklyn avatar clazex avatar kornelski avatar kozakura913 avatar mseele avatar noxf avatar vstroebel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

libwebp-sys's Issues

Issues building on Apple M1 chips

Hello,

I tried building this in an Apple Silicon chip and got this error

Compiling tokio-native-tls v0.3.0
The following warnings were emitted during compilation:

warning: clang: error: the clang compiler does not support '-march=native'
warning: clang: error: the clang compiler does not support '-march=native'

error: failed to run custom build command for `libwebp-sys v0.6.0`

Caused by:
  process didn't exit successfully: `/Users/christian/Developer/cmnh/imageflow/target/release/build/libwebp-sys-647a8e6d13b44bda/build-script-build` (exit status: 1)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("aarch64-apple-darwin")
  HOST = Some("aarch64-apple-darwin")
  CC_aarch64-apple-darwin = None
  CC_aarch64_apple_darwin = None
  HOST_CC = None
  CC = None
  CFLAGS_aarch64-apple-darwin = None
  CFLAGS_aarch64_apple_darwin = None
  HOST_CFLAGS = None
  CFLAGS = Some(" -march=native -O3")
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh")
  CC_aarch64-apple-darwin = None
  CC_aarch64_apple_darwin = None
  HOST_CC = None
  CC = None
  CFLAGS_aarch64-apple-darwin = None
  CFLAGS_aarch64_apple_darwin = None
  HOST_CFLAGS = None
  CFLAGS = Some(" -march=native -O3")
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh")
  running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-march=native" "-O3" "-I" "/Users/christian/.cargo/registry/src/github.com-1ecc6299db9ec823/libwebp-sys-0.6.0/vendor" "-fvisibility=hidden" "-DNDEBUG=1" "-D_THREAD_SAFE=1" "-DWEBP_HAVE_NEON=1" "-o" "/Users/christian/Developer/cmnh/imageflow/target/release/build/libwebp-sys-0c4a95c8caa884c9/out/alpha_dec.o" "-c" "/Users/christian/.cargo/registry/src/github.com-1ecc6299db9ec823/libwebp-sys-0.6.0/vendor/src/dec/alpha_dec.c"
  cargo:warning=clang: error: the clang compiler does not support '-march=native'
  exit status: 1
  running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-march=native" "-O3" "-I" "/Users/christian/.cargo/registry/src/github.com-1ecc6299db9ec823/libwebp-sys-0.6.0/vendor" "-fvisibility=hidden" "-DNDEBUG=1" "-D_THREAD_SAFE=1" "-DWEBP_HAVE_NEON=1" "-o" "/Users/christian/Developer/cmnh/imageflow/target/release/build/libwebp-sys-0c4a95c8caa884c9/out/buffer_dec.o" "-c" "/Users/christian/.cargo/registry/src/github.com-1ecc6299db9ec823/libwebp-sys-0.6.0/vendor/src/dec/buffer_dec.c"
  cargo:warning=clang: error: the clang compiler does not support '-march=native'
  exit status: 1

  --- stderr

Any workaround or indication about how to build/run this on this arch. Thanks

[bug] test failure on 32-bit arches

I upload the webp-sys crate to debian today. Some bindgen tests fail on 32-bit arches (arm, x86):

running 19 tests
test ffi::bindgen_test_layout_WebPAnimDecoderOptions ... ok
test ffi::bindgen_test_layout_WebPAnimEncoderOptions ... ok
test ffi::bindgen_test_layout_WebPAnimInfo ... ok
test ffi::bindgen_test_layout_WebPAuxStats ... ok
test ffi::bindgen_test_layout_WebPBitstreamFeatures ... ok
test ffi::bindgen_test_layout_WebPConfig ... ok
test ffi::bindgen_test_layout_WebPDecBuffer ... FAILED
test ffi::bindgen_test_layout_WebPChunkIterator ... FAILED
test ffi::bindgen_test_layout_WebPDecBuffer__bindgen_ty_1 ... FAILED
test ffi::bindgen_test_layout_WebPDecoderOptions ... ok
test ffi::bindgen_test_layout_WebPData ... FAILED
test ffi::bindgen_test_layout_WebPDecoderConfig ... FAILED
test ffi::bindgen_test_layout_WebPIterator ... FAILED
test ffi::bindgen_test_layout_WebPMemoryWriter ... FAILED
test ffi::bindgen_test_layout_WebPMuxAnimParams ... ok
test ffi::bindgen_test_layout_WebPMuxFrameInfo ... FAILED
test ffi::bindgen_test_layout_WebPYUVABuffer ... FAILED
test ffi::bindgen_test_layout_WebPRGBABuffer ... FAILED
test ffi::bindgen_test_layout_WebPPicture ... FAILED

failures:

---- ffi::bindgen_test_layout_WebPDecBuffer stdout ----
thread 'ffi::bindgen_test_layout_WebPDecBuffer' panicked at 'assertion failed: `(left == right)`
  left: `84`,
 right: `120`: Size of: WebPDecBuffer', src/ffi.rs:1710:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPDecBuffer
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:1710:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPDecBuffer::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:1707:40
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPChunkIterator stdout ----
thread 'ffi::bindgen_test_layout_WebPChunkIterator' panicked at 'assertion failed: `(left == right)`
  left: `44`,
 right: `56`: Size of: WebPChunkIterator', src/ffi.rs:2978:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPChunkIterator
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2978:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPChunkIterator::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2975:44
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPDecBuffer__bindgen_ty_1 stdout ----
thread 'ffi::bindgen_test_layout_WebPDecBuffer__bindgen_ty_1' panicked at 'assertion failed: `(left == right)`
  left: `48`,
 right: `80`: Size of: WebPDecBuffer__bindgen_ty_1', src/ffi.rs:1670:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPDecBuffer__bindgen_ty_1
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:1670:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPDecBuffer__bindgen_ty_1::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:1666:54
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPData stdout ----
thread 'ffi::bindgen_test_layout_WebPData' panicked at 'assertion failed: `(left == right)`
  left: `8`,
 right: `16`: Size of: WebPData', src/ffi.rs:2291:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPData
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2291:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPData::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2288:35
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPDecoderConfig stdout ----
thread 'ffi::bindgen_test_layout_WebPDecoderConfig' panicked at 'assertion failed: `(left == right)`
  left: `200`,
 right: `240`: Size of: WebPDecoderConfig', src/ffi.rs:2189:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPDecoderConfig
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2189:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPDecoderConfig::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2186:44
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPIterator stdout ----
thread 'ffi::bindgen_test_layout_WebPIterator' panicked at 'assertion failed: `(left == right)`
  left: `64`,
 right: `80`: Size of: WebPIterator', src/ffi.rs:2798:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPIterator
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2798:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPIterator::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2795:39
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPMemoryWriter stdout ----
thread 'ffi::bindgen_test_layout_WebPMemoryWriter' panicked at 'assertion failed: `(left == right)`
  left: `16`,
 right: `32`: Size of: WebPMemoryWriter', src/ffi.rs:714:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPMemoryWriter
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:714:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPMemoryWriter::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:711:43
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPMuxFrameInfo stdout ----
thread 'ffi::bindgen_test_layout_WebPMuxFrameInfo' panicked at 'assertion failed: `(left == right)`
  left: `36`,
 right: `48`: Size of: WebPMuxFrameInfo', src/ffi.rs:2405:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPMuxFrameInfo
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2405:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPMuxFrameInfo::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:2402:43
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPYUVABuffer stdout ----
thread 'ffi::bindgen_test_layout_WebPYUVABuffer' panicked at 'assertion failed: `(left == right)`
  left: `48`,
 right: `80`: Size of: WebPYUVABuffer', src/ffi.rs:1517:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPYUVABuffer
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:1517:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPYUVABuffer::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:1514:41
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPRGBABuffer stdout ----
thread 'ffi::bindgen_test_layout_WebPRGBABuffer' panicked at 'assertion failed: `(left == right)`
  left: `12`,
 right: `24`: Size of: WebPRGBABuffer', src/ffi.rs:1456:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPRGBABuffer
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:1456:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPRGBABuffer::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:1453:41
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- ffi::bindgen_test_layout_WebPPicture stdout ----
thread 'ffi::bindgen_test_layout_WebPPicture' panicked at 'assertion failed: `(left == right)`
  left: `172`,
 right: `256`: Size of: WebPPicture', src/ffi.rs:848:5
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.67.1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.67.1/library/core/src/panicking.rs:199:5
   4: libwebp_sys::ffi::bindgen_test_layout_WebPPicture
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:848:5
   5: libwebp_sys::ffi::bindgen_test_layout_WebPPicture::{{closure}}
             at /usr/share/cargo/registry/libwebp-sys-0.9.2/src/ffi.rs:845:38
   6: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
   7: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.67.1/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    ffi::bindgen_test_layout_WebPChunkIterator
    ffi::bindgen_test_layout_WebPData
    ffi::bindgen_test_layout_WebPDecBuffer
    ffi::bindgen_test_layout_WebPDecBuffer__bindgen_ty_1
    ffi::bindgen_test_layout_WebPDecoderConfig
    ffi::bindgen_test_layout_WebPIterator
    ffi::bindgen_test_layout_WebPMemoryWriter
    ffi::bindgen_test_layout_WebPMuxFrameInfo
    ffi::bindgen_test_layout_WebPPicture
    ffi::bindgen_test_layout_WebPRGBABuffer
    ffi::bindgen_test_layout_WebPYUVABuffer

test result: FAILED. 8 passed; 11 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s


not available in wasm

...

  cargo:warning=#include <assert.h>
  cargo:warning=         ^~~~~~~~~~
  cargo:warning=1 error generated.
  exit status: 1

  --- stderr


  error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/Users/leping/.cargo/registry/src/github.com-1ecc6299db9ec823/libwebp-sys-0.4.2/vendor" "-Wall" "-Wextra" "-fvisibility=hidden" "-DNDEBUG=1" "-D_THREAD_SAFE=1" "-o" "/Users/leping/Desktop/online-webp-tool/target/wasm32-unknown-unknown/release/build/libwebp-sys-a70f591a50f6f57f/out/alpha_dec.o" "-c" "/Users/leping/.cargo/registry/src/github.com-1ecc6299db9ec823/libwebp-sys-0.4.2/vendor/src/dec/alpha_dec.c" with args "clang" did not execute successfully (status code exit status: 1).


Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

Investigate `libwebp` CVE-2023-1999

A double free (CVE-2023-1999) was fixed in libwebp in Firefox 112 and apparently Chrome, but there is not a lot of public info about this. Ubuntu 23.04 just updated the libwebp package to fix this issue. The same fix was applied upstream in February.

I would suggest applying this patch in libwebp-sys, too. Surprisingly, there is no 1.3.1 release yet, but the upstream 1.3.0 branch contains the fix and two other fixes (apparently for memleaks). Last update to that branch was in March without a release since then.

(I filed the same issue in libwebp-sys2)

Possible UB in examples/tests

I believe making a Vec from the data allocated by llibwebp is unsound since that will try to free it with the rust allocator. I think they should be making slices, and then freeing the buffers using libwebp_sys::WebPFree (Or maybe another of the free functions).

I'm specifically referring to the decoding examples.

wasm support ?

image-rs is depending on this crate, when i try to compile image-rs into wasm, this crate seems compile failed.

memory leak when encoding an image

Valgrind shows the following:

==215198== 90,096 bytes in 3 blocks are definitely lost in loss record 11 of 11
==215198==    at 0x4841848: malloc (vg_replace_malloc.c:431)
==215198==    by 0x525C15: WebPMemoryWrite (in /home/kavin/Workspace/piped-proxy/target/release/piped-proxy)
==215198==    by 0x53FC5E: VP8EncWrite (in /home/kavin/Workspace/piped-proxy/target/release/piped-proxy)
==215198==    by 0x526F64: WebPEncode (in /home/kavin/Workspace/piped-proxy/target/release/piped-proxy)
==215198==    by 0x526357: Encode (in /home/kavin/Workspace/piped-proxy/target/release/piped-proxy)
==215198==    by 0x5263A4: WebPEncodeRGB (in /home/kavin/Workspace/piped-proxy/target/release/piped-proxy)

Code:

                let image = image::load_from_memory(&resp_bytes).unwrap();
                let width = image.width();
                let height = image.height();

                let quality = 85;

                let data = image.as_rgb8().unwrap().as_raw();

                let bytes: Vec<u8> = unsafe {
                    let mut out_buf = std::ptr::null_mut();
                    let stride = width as i32 * 3;
                    let len: usize = WebPEncodeRGB(data.as_ptr(), width as i32, height as i32, stride, quality as f32, &mut out_buf);
                    std::slice::from_raw_parts(out_buf, len).into()
                };

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.