Clean up code

This commit is contained in:
Yash Karandikar 2021-09-11 16:36:21 -05:00
parent f5fa17059e
commit 80b03efbf5
Signed by: karx
GPG key ID: A794DA2529474BA5

View file

@ -37,52 +37,35 @@ fn save(
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/{}.jpg", iter))?;
let bytes: Vec<u8> = out.into_raw();
// let mut bytes: Vec<u8> = Vec::new();
// out.write_to(&mut bytes, image::ImageOutputFormat::Jpeg);
let bytes: Vec<u8> = out.into_raw();
if let Err(e) = std::panic::catch_unwind(|| {
let mut comp = mozjpeg::Compress::new(mozjpeg::ColorSpace::JCS_RGB);
if let Err(e) = std::panic::catch_unwind(|| {
let mut comp = mozjpeg::Compress::new(mozjpeg::ColorSpace::JCS_RGB);
comp.set_size(width as usize, height as usize);
comp.set_mem_dest();
comp.start_compress();
comp.set_size(width as usize, height as usize);
comp.set_mem_dest();
comp.start_compress();
assert!(comp.write_scanlines(&bytes[..]));
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");
if let Ok(()) = std::fs::write(format!("output/{}.jpg", iter), bytes) {
println!("Wrote new file to disk");
} else {
panic!("Error: could not save the file to disk.");
}
}
}) {
panic!("Error: {:?}", e);
}
}
}) {
panic!("Error: {:?}", e);
}
Ok(())
}