Documentation
  • Coverage
  • 5.45%
    6 out of 110 items documented1 out of 65 items with examples
  • Size
  • Source code size: 166.88 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.38 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • TimeEngineer/devpng
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TimeEngineer

DevPNG

devpng Documentation License: MIT

Note

For the moment, this crate is in construction.

If you need something, you can tell me:

If you encounter some issues, tell me.

Examples

Want to modify an image ?

use devpng::prelude::PNG;

fn main() -> Result<(), String> {
    // Load.
    let mut buf = std::fs::read("img.png")
        .expect("Couldn't read the file.");
    let mut png = PNG::load(&mut buf)?;
    // Access image.
    let img = png.image();
    // Modify image.
    for x in img.iter_mut() {
        *x = !*x;
    }
    // Store.
    png.store("img.png")?;
    Ok(())
}

Want to create an image ?

use devpng::prelude::{ColourType, Image, PNG, Point};

fn main() -> Result<(), String> {
    let mut data = vec![255; 800 * 200];
    let img = Image::new(&mut data[..])
        .set_ncol(800) // 200
        .set_nrow(200)
        .set_depth(8)
        .set_colour(ColourType::RGBA);
    let mut buf = Vec::new();

    let mut png = PNG::from_image(&mut buf, &img);
    let mut img = png.image();

    for i in 0..50 {
        let center = Point { x: 100, y: 100 };
        let radius = 80 - i as i32;
        let colour = &[0, (255 - i * 5) as u8, (255 - i * 5) as u8, 255];
        img.plot_circle(center, radius, colour);
    }

    // Store.
    png.store("img.png")?;
    Ok(())
}

alt text

Want low level access ?

use devpng::prelude::DataStreamMut;

fn main() -> Result<(), String> {
    // Load.
    let mut buf = std::fs::read("img.png")
        .expect("Couldn't read the file.");
    let mut datastream = DataStreamMut::from(&mut buf)?;
    // Access image.
    let mut cache = datastream.idat()?;
    let img = cache.image();
   
    // Modify image.
    for x in img.iter_mut() {
        *x = !*x;
    }
    // Store.
    let png = datastream.rebuild(&mut Some(&mut cache));
    std::fs::write("img.png", png)
        .expect("Couldn't write the file.");
    Ok(())
}

Images

alt text alt text alt text alt text alt text alt text

Documentation

See RustDoc Documentation.

Installation

Add following lines to your Cargo.toml:

[dependencies]
devpng = "0"

References