databending example in bong
This commit is contained in:
parent
07f2a9fa38
commit
bf58d2cd51
2 changed files with 44 additions and 2 deletions
9
bong/src/cli.rs
Normal file
9
bong/src/cli.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
pub(super) struct Cli {
|
||||||
|
pub(super) input_file: PathBuf,
|
||||||
|
pub(super) output_file: PathBuf,
|
||||||
|
}
|
|
@ -1,3 +1,36 @@
|
||||||
fn main() {
|
use bingus::{
|
||||||
println!("Hello, world!");
|
img::{Dimensions, RgbImage},
|
||||||
|
snd::{RawSamples, Sample},
|
||||||
|
Bendable, DynamicBendable, OpenError,
|
||||||
|
};
|
||||||
|
use clap::Parser;
|
||||||
|
use cli::Cli;
|
||||||
|
|
||||||
|
mod cli;
|
||||||
|
|
||||||
|
fn main() -> Result<(), OpenError> {
|
||||||
|
let args = Cli::parse();
|
||||||
|
if let DynamicBendable::Image(i) =
|
||||||
|
bingus::open(args.input_file)?.expect("could not open this file.")
|
||||||
|
{
|
||||||
|
let dimensions = Dimensions {
|
||||||
|
width: i.width(),
|
||||||
|
height: i.height(),
|
||||||
|
};
|
||||||
|
RawSamples::from(
|
||||||
|
RawSamples::<u16>::bend_from(i, (), bingus::Crop::End)
|
||||||
|
.unwrap()
|
||||||
|
.as_ref()
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.to_sample::<u8>().to_sample())
|
||||||
|
.collect::<Vec<u16>>(),
|
||||||
|
)
|
||||||
|
.bend_into::<RgbImage>(dimensions, bingus::Crop::End)
|
||||||
|
.unwrap()
|
||||||
|
.save(args.output_file)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
println!("Not an image! Sorry!");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue