image-rs / imageproc

Image processing operations
MIT License
755 stars 148 forks source link

flag to disable rayon multithreading for wasm #465

Closed maninkari closed 3 years ago

maninkari commented 3 years ago

Is there a way to disable rayon multithreading when using this library? My code keeps breaking because of rayon, not sure if it is because of trying to run multithreading in wasm. Thanks!

let w = 200;
let h = 200;

let img = ImageBuffer::from_fn(w, h, |x, y| {
    let i = ((x + y) % 256) as u8;
    if (x + y) % 3 == 0 {
        image::Rgba([255, 0, 0, 255])
    } else {
        image::Rgba([i, i, i, 255])
    }
});
let (cx, cy) = (120.0, 140.0);

let c_rotation = Projection::translate(cx, cy)
* Projection::rotate(PI / 6.0)
* Projection::translate(-cx, -cy);

let _warped = warp(
    &img,
    &c_rotation,
    Interpolation::Bilinear,
    Rgba([0 as u8; 4])
);
Screenshot 2021-05-06 at 01 28 45
theotherphil commented 3 years ago

There’s a ‘rayon’ feature flag that should do this - see https://github.com/image-rs/imageproc/pull/419

maninkari commented 3 years ago

Thank you, I managed to get rid of the error by doing this in Cargo.toml imageproc = { version = "0.22", default-features = false }