#load-image

load_image

Load PNG or JPEG with color profile support

2 stable releases

2.12.1 Jul 6, 2020
2.12.0 Mar 3, 2019
Download history 108/week @ 2021-01-12 95/week @ 2021-01-19 81/week @ 2021-01-26 133/week @ 2021-02-02 149/week @ 2021-02-09 116/week @ 2021-02-16 102/week @ 2021-02-23 97/week @ 2021-03-02 118/week @ 2021-03-09 137/week @ 2021-03-16 144/week @ 2021-03-23 115/week @ 2021-03-30 171/week @ 2021-04-06 249/week @ 2021-04-13 632/week @ 2021-04-20 169/week @ 2021-04-27

731 downloads per month
Used in 2 crates (via dssim)

GPL-3.0+

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