55 lines
1.3 KiB
Rust
55 lines
1.3 KiB
Rust
use image::io::Reader as ImageReader;
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
if let Some(filename) = std::env::args().nth(1) {
|
|
println!("{}", filename);
|
|
|
|
let img = ImageReader::open(filename)?.decode()?;
|
|
let rimage = img.to_rgb8();
|
|
|
|
let all_pixels: Vec<(u32, u32, &image::Rgb<u8>)> = rimage.enumerate_pixels().collect();
|
|
let mut iter = 0;
|
|
println!("Splitting into chunks...");
|
|
for chunk in all_pixels.chunks(100000) {
|
|
save(rimage.width(), rimage.height(), chunk, iter)?;
|
|
println!("Saved image");
|
|
iter += 1;
|
|
}
|
|
} else {
|
|
println!("Please provide a valid filename.");
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn save(
|
|
width: u32,
|
|
height: u32,
|
|
chunk: &[(u32, u32, &image::Rgb<u8>)],
|
|
iter: u32,
|
|
) -> anyhow::Result<()> {
|
|
let white = image::Rgb([255, 255, 255]);
|
|
let mut out = image::ImageBuffer::from_pixel(width, height, white);
|
|
|
|
println!("Created image");
|
|
|
|
//for x in 0..width {
|
|
// for y in 0..height {
|
|
// let foo = image::Rgb([255, 255, 255]);
|
|
// out.put_pixel(x, y, foo);
|
|
// }
|
|
//}
|
|
|
|
for (x, y, px) in chunk {
|
|
out.put_pixel(*x, *y, **px);
|
|
}
|
|
|
|
println!("Applied pixels to new image");
|
|
|
|
out.save(format!("output/{}.png", iter))?;
|
|
|
|
println!("Wrote new file to disk");
|
|
|
|
Ok(())
|
|
}
|