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");
|
||||
|
||||
//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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue