#image-resizing #resize #scale

pic-scale-safe

Fast and safe performance image scaling

3 releases

new 0.1.2 Oct 20, 2024
0.1.1 Oct 20, 2024
0.1.0 Oct 17, 2024

#342 in Images

Download history 474/week @ 2024-10-17

474 downloads per month

BSD-3-Clause OR Apache-2.0

240KB
4.5K SLoC

Fast and safe image scaling in Rust

This crate provides zero unsafe fast rescaling.

Example

let img = ImageReader::open("./assets/nasa-4928x3279.png")
    .unwrap()
    .decode()
    .unwrap();
let dimensions = img.dimensions();
let transient = img.to_rgb8();

let start = Instant::now();

let src_size = ImageSize::new(dimensions.0 as usize, dimensions.1 as usize);
let dst_size = ImageSize::new(dimensions.0 as usize / 4, dimensions.1 as usize / 4);

let resized = resize_rgb8(&transient, src_size, dst_size, 
                          ResamplingFunction::Lanczos3).unwrap();

Example comparison time for downscale RGBA 4928x3279 8 bit image in 4 times.

cargo bench --bench resize_rgba --manifest-path ./app/Cargo.toml
Lanczos3 Bilinear
image(aarch64) 121.19 48.89
pic-scale(aarch64) 26.90 15.13
fir(aarch64) 25.93 11.30
image(x86) 192.52 88.63
pic-scale(x86) 49.79 35.98
pic-scale(x86-cpu-native) 27.21 20.48
fir(x86) 42.89 24.13
fir(x86-cpu-native) 41.17 23.62

Example comparison time for downscale RGB 4928x3279 8 bit image in 4 times.

cargo bench --bench resize_rgb --manifest-path ./app/Cargo.toml
Lanczos3 Bilinear
image(aarch64) 123.85 51.30
pic-scale(aarch64) 31.73 18.20
fir(aarch64) 24.04 11.37
image(x86) 201.52 90.82
pic-scale(x86) 34.54 25.05
fir(x86) 41.97 25.21

Example comparison time for downscale RGBA 4928x3279 16 bit image in 4 times.

cargo bench --bench resize_rgba_u16 --manifest-path ./app/Cargo.toml
Lanczos3 Bilinear
image(aarch64) 123.27 52.91
pic-scale(aarch64) 28.041 18.89
fir(aarch64) 149.87 50.08
image(x86) 196.28 194.75
pic-scale(x86) 59.89 57.99
pic-scale(x86-cpu-native) 44.07 57.99
fir(x86) 52.73 28.35

Example comparison time for downscale RGB 4928x3279 16 bit image in 4 times.

cargo bench --bench resize_rgb_u16 --manifest-path ./app/Cargo.toml
Lanczos3 Bilinear
image(aarch64) 130.45 61.06
pic-scale(aarch64) 36.10 23.80
fir(aarch64) 122.01 43.36

Example comparison time for downscale RGBA 4928x3279 f32 image in 4 times.

cargo bench --bench resize_rgba_f32 --manifest-path ./app/Cargo.toml
Lanczos3 Bilinear
image(aarch64) 100.16 51.21
pic-scale(aarch64) 43.04 19.16
fir(aarch64) 114.35 37.75
image(x86) 164.04 98.90
pic-scale(x86) 57.39 43.84
fir(x86) 60.30 29.92

This project is licensed under either of

  • BSD-3-Clause License (see LICENSE)
  • Apache License, Version 2.0 (see LICENSE)

at your option.

Dependencies

~93–415KB