databending example in bong

This commit is contained in:
Breval Ferrari 2025-03-15 00:00:51 -04:00
parent 07f2a9fa38
commit bf58d2cd51
No known key found for this signature in database
GPG key ID: F71E304D6400AB8E
2 changed files with 44 additions and 2 deletions

9
bong/src/cli.rs Normal file
View 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,
}

View file

@ -1,3 +1,36 @@
fn main() {
println!("Hello, world!");
use bingus::{
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(())
}