Implement white-balancing
This commit is contained in:
parent
7455a35053
commit
bc018751c8
1 changed files with 8 additions and 2 deletions
|
@ -9,12 +9,18 @@ use lights::rgb::Rgb;
|
|||
const PORCH_BACK_LEN: usize = 150;
|
||||
const PORCH_FRONT_LEN: usize = 150;
|
||||
|
||||
const PORCH_WHITE: Rgb = Rgb(255, 208, 160);
|
||||
|
||||
pub struct Harrogate<PB, PF> {
|
||||
pub porch_back: PB,
|
||||
pub porch_front: PF,
|
||||
}
|
||||
|
||||
fn white_balance(HardwareRgb(r, g, b): HardwareRgb, white: Rgb) -> HardwareRgb {
|
||||
let Rgb(r, g, b) = Rgb(r, g, b) * white;
|
||||
HardwareRgb(r, g, b)
|
||||
}
|
||||
|
||||
impl<PB, PF> Harrogate<PB, PF>
|
||||
where
|
||||
PB: IntoIterator<Item = Rgb>,
|
||||
|
@ -24,10 +30,10 @@ where
|
|||
let mut buffer = [HardwareRgb(255,0,255); PORCH_BACK_LEN + PORCH_FRONT_LEN];
|
||||
|
||||
for (i, pixel) in self.porch_back.into_iter().take(PORCH_BACK_LEN).enumerate() {
|
||||
buffer[PORCH_BACK_LEN - i] = correct(&pixel);
|
||||
buffer[PORCH_BACK_LEN - i] = white_balance(correct(&pixel), PORCH_WHITE);
|
||||
}
|
||||
for (i, pixel) in self.porch_front.into_iter().take(PORCH_FRONT_LEN).enumerate() {
|
||||
buffer[PORCH_BACK_LEN + i] = correct(&pixel);
|
||||
buffer[PORCH_BACK_LEN + i] = white_balance(correct(&pixel), PORCH_WHITE);
|
||||
}
|
||||
|
||||
buffer.iter().render_to(lights);
|
||||
|
|
Loading…
Reference in a new issue