#image #png #jpeg #bmp #tga

imagefmt

Image decoders: PNG, TGA, BMP, JPEG. Encoders: PNG, TGA, BMP.

19 releases (11 stable)

Uses old Rust 2015

4.0.0 Apr 23, 2016
3.0.1 Feb 12, 2016
3.0.0 Jan 22, 2016
2.1.1 Dec 16, 2015
0.5.1 Jun 14, 2015

#5 in #bmp

Download history 132/week @ 2021-06-07 116/week @ 2021-06-14 130/week @ 2021-06-21 122/week @ 2021-06-28 82/week @ 2021-07-05 108/week @ 2021-07-12 108/week @ 2021-07-19 146/week @ 2021-07-26 180/week @ 2021-08-02 193/week @ 2021-08-09 80/week @ 2021-08-16 150/week @ 2021-08-23 60/week @ 2021-08-30 111/week @ 2021-09-06 123/week @ 2021-09-13 88/week @ 2021-09-20

452 downloads per month
Used in 5 crates

MIT license

125KB
3K SLoC

imagefmt Build Status

  • Documentation
  • Returned data can be converted to Y, YA, RGB, RGBA, etc.
  • All formats are optional via Cargo features (all enabled by default)
  • Requires Rust 1.6 or newer
Format Decoder Encoder
png 8-bit, 16-bit 8-bit non-paletted non-interlaced
tga 8-bit non-paletted 8-bit non-paletted
bmp 8-bit uncompressed 8-bit non-paletted uncompressed
jpeg baseline non-progressive nope

lib.rs:

Example

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
    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();
}

There are also format specific read and write functions which are more flexible. With the write functions, set the last argument to None to write the whole image or see source code for write_region for an example to write only a region. Use std::io::Cursor to read and write in-memory images.

Dependencies

~110KB