tinyppm

Simple .ppm loader written in Rust.

This is more of a toy project, I have written, to be able to easy reuse it for some of my experiments with 2d graphics in Rust.

Usage

v.0.20.0 Note: This version introduces proper error handling. Earlier tinyppm was a bit of pain as it exited when something unexpected happened (unrecognized header, unsupported color depth, non-existing/unreadable file specified...). Currently tinyppm returns an error in case some problem occurs. It is responsibility of the consumer to decide if this is critical or not, and take appropriate action.

Note: the above change will require some slight modification of code that relies on tinyppm 0.1.x.

  1. Add tinyppm to your Cargo.toml
  2. Call read_image_data:

```rust extern crate tinyppm;

fn myfunction(filename: &String) { let ppmimageresult = tinyppm::ppmloader::readimagedata(filename); let ppmimage = match ppmimage_result { Ok(image) => image, _ => panic!("unable to read specified image file!"), }; // ppm_image is now a struct containing image with, height and pixels }

```

The structure returned is defined as follows:

rust pub struct PPMImage { height: usize, width: usize, pixels: Vec<u32>, } and it exposes 3 public methods:

```rust pub fn height() -> usize { // returns image height }

pub fn width() -> usize {
    // returns image width
}

pub fn pixels() -> &Vec<u32> {
    // returns reference to buffer containing pixels
}

```

Details:

Additional examples:

If you want to check how it works, please have a look at ppm_viewer which is simple image viewer written in Rust: https://github.com/MaciekTalaska/2deffects/tree/master/ppmviewer

License

This code is released under the MIT license.