trying things, things don't work
This commit is contained in:
parent
cf3cb171c6
commit
3778703f08
2 changed files with 42 additions and 2 deletions
|
@ -13,4 +13,5 @@ keywords.workspace = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
bmp = "0.5.0"
|
bmp = "0.5.0"
|
||||||
|
dasp_sample = "0.11.0"
|
||||||
synfx-dsp = "0.5.6"
|
synfx-dsp = "0.5.6"
|
||||||
|
|
|
@ -1,10 +1,49 @@
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bmp::open;
|
use bmp::{open, Pixel};
|
||||||
|
use dasp_sample::{FromSample, Sample, ToSample, U24};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let bmp = open("bmp/sample.bmp")?;
|
dbg!((45 << 16) + (18 << 8) + 143);
|
||||||
|
let mut bmp = open("bmp/sample.bmp")?;
|
||||||
|
for y in 0..bmp.get_height() {
|
||||||
|
for x in 0..bmp.get_width() {
|
||||||
|
if x > 100 && x < 300 {
|
||||||
|
bmp.set_pixel(x, y, Pixel::new(0, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
bmp.to_writer(&mut File::create("bmp/out.bmp")?)?;
|
bmp.to_writer(&mut File::create("bmp/out.bmp")?)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rgb_to_sample<T: Sample + FromSample<U24>>(pix: Pixel) -> T {
|
||||||
|
U24::new(((pix.r as i32) << 16) + ((pix.g as i32) << 8) + (pix.b as i32))
|
||||||
|
.unwrap()
|
||||||
|
.to_sample()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sample_to_rgb<T: Sample + ToSample<U24>>(sample: T) -> Pixel {
|
||||||
|
let rgb: U24 = sample.to_sample();
|
||||||
|
let rg = rgb >> 8.try_into().unwrap();
|
||||||
|
let r = rg >> 8.try_into().unwrap();
|
||||||
|
Pixel::new(
|
||||||
|
r.inner() as u8,
|
||||||
|
(rg - r).inner() as u8,
|
||||||
|
(rgb - rg).inner() as u8,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use bmp::Pixel;
|
||||||
|
|
||||||
|
use super::{rgb_to_sample, sample_to_rgb};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rgb2s2rgb() {
|
||||||
|
let pix = Pixel::new(45, 18, 143);
|
||||||
|
assert_eq!(pix, sample_to_rgb(rgb_to_sample::<f64>(pix)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue