reorganize lib, use it in the funny zone

This commit is contained in:
Breval Ferrari 2024-07-14 07:57:40 +02:00
parent 825bcfa5a1
commit a0d82499c0
No known key found for this signature in database
GPG key ID: CEAB625B75A836B2
6 changed files with 106 additions and 103 deletions

View file

@ -1,11 +1,12 @@
use std::path::PathBuf;
use anyhow::{Context, Result};
use bingus::rawdata::rgbimage::RawImage;
use dasp_sample::{Sample, U24};
use derive_new::new;
use dirs::{download_dir, home_dir, picture_dir};
use fundsp::math::uparc;
use image::{io::Reader as ImageReader, ImageBuffer, ImageFormat, Rgb};
use image::{io::Reader as ImageReader, ImageFormat, RgbImage};
use indicatif::{ParallelProgressIterator, ProgressStyle};
use rayon::{iter::ParallelIterator, slice::ParallelSlice};
use rfd::FileDialog;
@ -66,17 +67,15 @@ impl Files {
fn main() -> Result<()> {
let dp = DataPath::new(Files::prompt()?);
let img = ImageReader::open(dp.files.input)?
.decode()
.context("can't use this picture")?
.to_rgb8();
let (width, height) = (img.width(), img.height());
let processed: ImageBuffer<Rgb<u8>, Vec<u8>> = ImageBuffer::from_raw(
width,
height,
img.into_raw()
.par_chunks_exact(3)
.progress_count((width * height).into())
let img = RawImage::from(
ImageReader::open(dp.files.input)?
.decode()
.context("can't use this picture")?,
);
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",
)?)
@ -94,9 +93,8 @@ fn main() -> Result<()> {
]
})
.collect(),
)
.unwrap();
processed.save(dp.files.output)?;
);
RgbImage::from(processed).save(dp.files.output)?;
// let bytes: Vec<u8> = (1u8..7).into_iter().collect();
// assert_eq!(