This library is absolutely amazing!!
I'm processing some large images (so I'm pushing it!) and manage to get a panic during resize.
- 65536 to 65536/2 = Panic
- 65537 to 65536/2 = Fine
use fast_image_resize::{PixelType, Resizer, images::Image};
fn main() {
let w_h = 65536;
let buffer = vec![0u8; w_h * w_h * 4];
let src_image = Image::from_vec_u8(w_h as u32, w_h as u32, buffer, PixelType::U8x4).unwrap();
let new_w_h = 32768;
println!(
"Resizing image from {}x{} to {}x{}",
w_h, w_h, new_w_h, new_w_h
);
let mut dst_image = Image::new(new_w_h as u32, new_w_h as u32, PixelType::U8x4);
Resizer::new()
.resize(&src_image, &mut dst_image, None)
.unwrap();
println!("Resizing completed successfully.");
}
user@box:~/resizer/resizer$ cargo run --release --
>Resizing image from 65536x65536 to 32768x32768
>thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/fast_image_resize-5.2.1/src/threading.rs:68:22:
>attempt to divide by zero
>note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
user@box:~/resizer/resizer$ cargo run --release --
> Resizing image from 65537x65537 to 32768x32768
>Resizing completed successfully
This method seems to be the issue, I haven't had a chance to fix it yet.
/// It is not optimal to split images on too small parts.
/// We have to calculate minimal height of one part.
/// For small images, it is equal to `constant / area`.
/// For tall images, it is equal to `height / 256`.
fn calculate_max_h_parts_number(width: u32, height: u32) -> u32 {
if width == 0 || height == 0 {
return 1;
}
let area = height * height.max(width);
let min_height = ((1 << 14) / area).max(height / 256).max(1);
height / min_height.max(1)
}
This library is absolutely amazing!!
I'm processing some large images (so I'm pushing it!) and manage to get a panic during resize.
This method seems to be the issue, I haven't had a chance to fix it yet.