simplify lib towards simple wrapper

This commit is contained in:
Breval Ferrari 2024-07-14 17:35:44 +02:00
parent a0d82499c0
commit c56b0b6227
No known key found for this signature in database
GPG key ID: CEAB625B75A836B2
3 changed files with 45 additions and 94 deletions

View file

@ -1,7 +1,7 @@
use std::path::PathBuf;
use anyhow::{Context, Result};
use bingus::rawdata::rgbimage::RawImage;
use bingus::rawdata::RawData;
use dasp_sample::{Sample, U24};
use derive_new::new;
use dirs::{download_dir, home_dir, picture_dir};
@ -67,34 +67,39 @@ impl Files {
fn main() -> Result<()> {
let dp = DataPath::new(Files::prompt()?);
let img = RawImage::from(
let img = RawData::<RgbImage>::new(
ImageReader::open(dp.files.input)?
.decode()
.context("can't use this picture")?,
.context("can't use this picture")?
.into_rgb8(),
);
let processed = RawImage::new(
*img.metadata(),
img.par_chunks_exact(3)
.progress_count((img.metadata().width() * img.metadata().height()).into())
.with_style(ProgressStyle::with_template(
"[{eta}] {bar:40.green/red} {pos}/{len} pixels",
)?)
.map(|px: &[u8]| (px[2] as i32) | ((px[1] as i32) << 8) | ((px[0] as i32) << 16))
.map(U24::new_unchecked)
.map(|x| uparc(x.to_sample()))
.flat_map(|sample: f32| {
let rgb: U24 = sample.to_sample();
let rgo = ((rgb) >> 8.into()) << 8.into();
let roo = ((rgo) >> 16.into()) << 16.into();
[
((roo) >> 16.into()).inner() as u8,
((rgo - roo) >> 8.into()).inner() as u8,
(rgb - rgo).inner() as u8,
]
})
.collect(),
let processed = RawData::<RgbImage>::new(
RgbImage::from_raw(
img.width(),
img.height(),
img.par_chunks_exact(3)
.progress_count((img.width() * img.height()).into())
.with_style(ProgressStyle::with_template(
"[{eta}] {bar:40.green/red} {pos}/{len} pixels",
)?)
.map(|px: &[u8]| (px[2] as i32) | ((px[1] as i32) << 8) | ((px[0] as i32) << 16))
.map(U24::new_unchecked)
.map(|x| uparc(x.to_sample()))
.flat_map(|sample: f32| {
let rgb: U24 = sample.to_sample();
let rgo = ((rgb) >> 8.into()) << 8.into();
let roo = ((rgo) >> 16.into()) << 16.into();
[
((roo) >> 16.into()).inner() as u8,
((rgo - roo) >> 8.into()).inner() as u8,
(rgb - rgo).inner() as u8,
]
})
.collect(),
)
.unwrap(),
);
RgbImage::from(processed).save(dp.files.output)?;
processed.save(dp.files.output)?;
// let bytes: Vec<u8> = (1u8..7).into_iter().collect();
// assert_eq!(