Crates.io | resize |
lib.rs | resize |
version | 0.8.8 |
source | src |
created_at | 2015-11-03 19:13:13.189398 |
updated_at | 2024-11-04 03:11:21.080224 |
description | Simple image resampling library in pure Rust. |
homepage | https://github.com/PistonDevelopers/resize |
repository | https://github.com/PistonDevelopers/resize.git |
max_upload_size | |
id | 3358 |
size | 48,116 |
Image resampling library in pure Rust.
use resize::Pixel::RGB8;
use resize::Type::Lanczos3;
// Downscale by 2x.
let (w1, h1) = (640, 480);
let (w2, h2) = (320, 240);
// Don't forget to fill `src` with image data (RGB8).
// This requires Vec<RGB<u8>>. If you have Vec<u8>, then use .as_rgb()/.as_rgb_mut() to reinterpret it as a slice of pixels.
let src = vec![RGB::new(0,0,0); w1*h1];
// Destination buffer. Must be mutable.
let mut dst = vec![RGB::new(0,0,0); w2*h2];
// Create reusable instance.
let mut resizer = resize::new(w1, h1, w2, h2, RGB8, Lanczos3);
// Do resize without heap allocations.
// Might be executed multiple times for different `src` or `dst`.
resizer.resize(&src, &mut dst);
See API documentation for overview of all available methods. See also this example.
Read this and this great articles on image resizing technics and resampling filters. Tldr; (with built-in filters of this library) use Lanczos3
for downscaling, use Mitchell
for upscaling. You may also want to downscale in linear colorspace (but not upscale). Gamma correction routines currently not included to the library, but actually quite simple to accomplish manually, see here for some basic theory.