Create greyscale example
This commit is contained in:
1 parent
937b20bb87
commit
96d1af5b78
1 file changed
+12
-16
@@ -1,10 +1,14 @@
|
|||||||
use ccvl::{image::*, kernel::*};
|
use ccvl::image::*;
|
||||||
|
|
||||||
|
fn filter(img: Image<SRGBA>) -> Image<SRGBA> {
|
||||||
|
img.map(|p| Luminance::from(p).into())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> std::process::ExitCode {
|
fn main() -> std::process::ExitCode {
|
||||||
let args = std::env::args().collect::<Vec<String>>();
|
let args = std::env::args().collect::<Vec<String>>();
|
||||||
if args.len() != 3 {
|
if args.len() != 3 {
|
||||||
println!("Usage: {} IN OUT", args[0].as_str());
|
println!("Usage: {} IN OUT", args[0].as_str());
|
||||||
return std::process::ExitCode::FAILURE;
|
return std::process::ExitCode::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
let input_path = args[1].as_str();
|
let input_path = args[1].as_str();
|
||||||
@@ -19,20 +23,12 @@ fn main() -> std::process::ExitCode {
|
|||||||
println!("I/O error loading image {}: {}", input_path, err);
|
println!("I/O error loading image {}: {}", input_path, err);
|
||||||
std::process::ExitCode::FAILURE
|
std::process::ExitCode::FAILURE
|
||||||
}
|
}
|
||||||
Ok(img) => {
|
Ok(img) => match filter(img).save::<Farbfeld>(output_path) {
|
||||||
let kernel =
|
Err(err) => {
|
||||||
[[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]];
|
println!("I/O error saving image {}: {}", output_path, err);
|
||||||
let result = kernel.convolve(&img);
|
std::process::ExitCode::FAILURE
|
||||||
match result.save::<Farbfeld>(output_path) {
|
|
||||||
Err(err) => {
|
|
||||||
println!(
|
|
||||||
"I/O error saving image {}: {}",
|
|
||||||
output_path, err
|
|
||||||
);
|
|
||||||
std::process::ExitCode::FAILURE
|
|
||||||
}
|
|
||||||
Ok(()) => std::process::ExitCode::SUCCESS,
|
|
||||||
}
|
}
|
||||||
}
|
Ok(()) => std::process::ExitCode::SUCCESS,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user