2019-10-31 03:56:09 +00:00
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
use lights::HardwareRgb;
|
|
|
|
use lights::gamma::correct;
|
|
|
|
use lights::Lights;
|
|
|
|
use lights::PixelIterator;
|
|
|
|
use lights::rgb::Rgb;
|
|
|
|
|
2020-10-07 23:38:26 +00:00
|
|
|
pub const PORCH_BACK_LEN: usize = 150;
|
|
|
|
pub const PORCH_FRONT_LEN: usize = 150;
|
2019-10-31 03:56:09 +00:00
|
|
|
|
2019-11-07 00:33:55 +00:00
|
|
|
const PORCH_WHITE: Rgb = Rgb(255, 208, 160);
|
2019-10-31 03:56:09 +00:00
|
|
|
|
2019-11-23 22:45:34 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2019-10-31 03:56:09 +00:00
|
|
|
pub struct Harrogate<PB, PF> {
|
|
|
|
pub porch_back: PB,
|
|
|
|
pub porch_front: PF,
|
|
|
|
}
|
|
|
|
|
2019-11-07 00:47:45 +00:00
|
|
|
#[inline]
|
2019-11-07 00:33:55 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:56:09 +00:00
|
|
|
impl<PB, PF> Harrogate<PB, PF>
|
|
|
|
where
|
|
|
|
PB: IntoIterator<Item = Rgb>,
|
|
|
|
PF: IntoIterator<Item = Rgb>,
|
|
|
|
{
|
2019-11-07 00:47:45 +00:00
|
|
|
#[inline]
|
2019-10-31 03:56:09 +00:00
|
|
|
pub fn render_to<L: Lights<Pixel = HardwareRgb>>(self, lights: &mut L) {
|
|
|
|
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() {
|
2019-11-07 00:33:55 +00:00
|
|
|
buffer[PORCH_BACK_LEN - i] = white_balance(correct(&pixel), PORCH_WHITE);
|
2019-10-31 03:56:09 +00:00
|
|
|
}
|
|
|
|
for (i, pixel) in self.porch_front.into_iter().take(PORCH_FRONT_LEN).enumerate() {
|
2019-11-07 00:33:55 +00:00
|
|
|
buffer[PORCH_BACK_LEN + i] = white_balance(correct(&pixel), PORCH_WHITE);
|
2019-10-31 03:56:09 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 05:20:53 +00:00
|
|
|
buffer.iter().render_to(lights);
|
2019-10-31 03:56:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
// #[test]
|
|
|
|
}
|