Clean up code
This commit is contained in:
parent
f5fa17059e
commit
80b03efbf5
43
src/main.rs
43
src/main.rs
|
@ -37,52 +37,35 @@ fn save(
|
||||||
|
|
||||||
println!("Created image");
|
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 {
|
for (x, y, px) in chunk {
|
||||||
out.put_pixel(*x, *y, **px);
|
out.put_pixel(*x, *y, **px);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Applied pixels to new image");
|
println!("Applied pixels to new image");
|
||||||
|
|
||||||
// out.save(format!("output/{}.jpg", iter))?;
|
let bytes: Vec<u8> = out.into_raw();
|
||||||
|
|
||||||
// let mut bytes: Vec<u8> = Vec::new();
|
if let Err(e) = std::panic::catch_unwind(|| {
|
||||||
// out.write_to(&mut bytes, image::ImageOutputFormat::Jpeg);
|
let mut comp = mozjpeg::Compress::new(mozjpeg::ColorSpace::JCS_RGB);
|
||||||
let bytes: Vec<u8> = out.into_raw();
|
|
||||||
|
|
||||||
if let Err(e) = std::panic::catch_unwind(|| {
|
comp.set_size(width as usize, height as usize);
|
||||||
let mut comp = mozjpeg::Compress::new(mozjpeg::ColorSpace::JCS_RGB);
|
comp.set_mem_dest();
|
||||||
|
comp.start_compress();
|
||||||
|
|
||||||
comp.set_size(width as usize, height as usize);
|
assert!(comp.write_scanlines(&bytes[..]));
|
||||||
comp.set_mem_dest();
|
|
||||||
comp.start_compress();
|
|
||||||
|
|
||||||
assert!(comp.write_scanlines(&bytes[..]));
|
comp.finish_compress();
|
||||||
|
if let Ok(bytes) = comp.data_to_vec() {
|
||||||
comp.finish_compress();
|
|
||||||
if let Ok(bytes) = comp.data_to_vec() {
|
|
||||||
println!("Compressed image");
|
println!("Compressed image");
|
||||||
if let Ok(()) = std::fs::write(format!("output/{}.jpg", iter), bytes) {
|
if let Ok(()) = std::fs::write(format!("output/{}.jpg", iter), bytes) {
|
||||||
println!("Wrote new file to disk");
|
println!("Wrote new file to disk");
|
||||||
} else {
|
} else {
|
||||||
panic!("Error: could not save the file to disk.");
|
panic!("Error: could not save the file to disk.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}) {
|
||||||
|
panic!("Error: {:?}", e);
|
||||||
|
}
|
||||||
}) {
|
|
||||||
panic!("Error: {:?}", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue