imagefmt 0.4.0

Decoders for PNG, TGA, BMP, JPEG. Encoders for PNG, TGA. 8-bit only, with conversions.
docs.rs failed to build imagefmt-0.4.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: imagefmt-4.0.0

Image loading and saving

  • Returned data is always 8-bit (Y/YA/RGB/RGBA/BGR/BGRA)
Format Decoder Encoder
png 8-bit 8-bit non-paletted non-interlaced
tga 8-bit non-paletted 8-bit non-paletted
bmp 8-bit uncompressed nope
jpeg baseline non-progressive nope
extern crate imagefmt;
use imagefmt::{ColFmt, ColType};

fn main() {
    // load and convert to bgra
    let _pic = imagefmt::read("stars.jpg", ColFmt::BGRA).unwrap();

    // convert to one of y, ya, rgb, rgba
    let pic = imagefmt::read("marbles.tga", ColFmt::Auto).unwrap();

    // write image out as grayscale
    pic.write("out.png", ColType::Gray).unwrap();

    // there's also a free function that doesn't require an Image
    imagefmt::write("out.tga", pic.w, pic.h, pic.fmt, &pic.buf,
                                                 ColType::Gray)
                                                     .unwrap();

    // get width, height and color type
    let _info = imagefmt::read_info("hiisi.png").unwrap();
}