ppmwriter

Crates.ioppmwriter
lib.rsppmwriter
version0.1.2
sourcesrc
created_at2022-11-20 03:22:36.530082
updated_at2022-11-20 04:07:23.340436
descriptionPPM writer for the binary PPM format
homepage
repositoryhttps://github.com/SOROM2/ppmwriter
max_upload_size
id718881
size42,511
(Mordinel)

documentation

README

ppmwriter

Usage

use std::fs::File;
use std::io::Write;
use std::path::Path;

use ppmwriter::Writer;

fn main() {
    let name = "image.ppm";
    let mut ppm = Writer::new(69, 35, 2301).unwrap();
    
    for n in 0..ppm.size {
        if n % 2 == 0 {
            ppm.write_pixel(ppm.maxval, 0, ppm.maxval);
        } else {
            ppm.write_pixel(0, 0, 0);
        }
    }

    let path = Path::new(name);
    let mut file = match File::create(path) {
        Err(why) => panic!("Couldn't create {}: {}", path.display(), why),
        Ok(file) => file,
    };

    if let Err(why) = file.write_all(ppm.borrow_buffer()) {
        panic!("Couldn't write to {}: {}", path.display(), why)
    }
}
Commit count: 0

cargo fmt