1 unstable release
0.0.1 | Dec 23, 2022 |
---|
#5 in #pgm
30KB
284 lines
🎨 Ductr
a small struct crate for reading, writing, and simple manipulation of the portable pixelmap format family
🧠 Design
This crate was made with the focus of quick and easy debugging as its main goal. Printing byte arrays quickly to a visual file can be great when debugging basic graphics and image manipulation algorithms, and the Portable pixelmap family format is one of the quickest to set up.
In the future this crate may extend to other raster file formats, such as JPEG or BMP
🖥️ How to use:
The following crate can be used by entering the following in your project's Cargo.toml
file:
[dependencies]
ductr = "0.0.1"
⚙️ Examples
use ductr::AnymapImage;
// Creating a 100x100 black pbm image
// Prepare buffer to be written to pbm format
let buffer = vec![1; 100*100];
// Create AnymapImage object with pbm constructor
let pbm_black = AnymapImage::pbm(buffer, 100, 100).unwrap();
// Write pbm as binary file
pbm_black.write_as_binary("pbm_black_binary.pbm").expect("Error: could not to binary file.");
use ductr::AnymapImage;
// Inverting the colors of a given ppm image
// Create AnymapImage object from binary ppm image file
let mut cat = AnymapImage::read_from_binary("tests/images/cat_binary.ppm").expect("Error: could not read from binary file");
// Invert the image
cat.invert();
// Write ppm as binary file
cat.write_as_binary("tests/images/cat_inverted.pnm").expect("Error: could not write to binary file");
📌 Other Information on the format
-
@Tsoding - "Procedural Graphics in C" for highlighting the utility of a simple format such as the ppm family for easier graphics debugging
👤 Authored by
Jonathan Kocevar
📝 License
This project is licensed under the terms of the GNU General Public License v3.0.