2 stable releases
2.12.1 | Jul 6, 2020 |
---|---|
2.12.0 | Mar 3, 2019 |
731 downloads per month
Used in 2 crates
(via dssim)
420KB
788 lines
Load image as sRGB
Glue code for a few libraries that correctly loads a JPEG or PNG image into memory, taking into accout color profile metadata in PNG chunks, EXIF data and app markers. Converts CMYK to RGB if needed.
For Rust 1.43 or later.
[dependencies]
load_image = "2"
fn main() {
let path = std::env::args().nth(1).expect("File name");
// the flag is for removing alpha channel
let img = load_image::load_image(path, false).unwrap();
}
The returned Image
is:
struct Image {
pub width: usize,
pub height: usize,
pub bitmap: enum ImageData {
RGB8(Vec<RGB8>),
RGBA8(Vec<RGBA8>),
RGB16(Vec<RGB16>),
RGBA16(Vec<RGBA16>),
GRAY8(Vec<GRAY8>),
GRAY16(Vec<GRAY16>),
GRAYA8(Vec<GRAYA8>),
GRAYA16(Vec<GRAYA16>),
}
}
The bitmap is packed, so x + y * width
gives the pixel at x,y
.
The load_image
function doesn't panic, but it uses unwinding internally. Error handling won't work in crates compiled with the panic = "abort"
option.
Dependencies
~8MB
~165K SLoC