diff --git a/gemma_m0_lights/src/lib.rs b/gemma_m0_lights/src/lib.rs index 981a13f..e470c0c 100644 --- a/gemma_m0_lights/src/lib.rs +++ b/gemma_m0_lights/src/lib.rs @@ -15,11 +15,11 @@ use hal::{ Peripherals }; use lights::{ - gamma::CorrectedRgb, + HardwareRgb, Lights }; -pub fn boot() -> impl Lights { +pub fn boot() -> impl Lights { let mut peripherals = Peripherals::take().unwrap(); let _clock = GenericClockController::with_internal_32kosc( peripherals.GCLK, @@ -69,10 +69,10 @@ impl NeopixelLights { } impl Lights for NeopixelLights { - type Pixel = CorrectedRgb; + type Pixel = HardwareRgb; #[inline] - fn render(&mut self, rgb: &CorrectedRgb) { + fn render(&mut self, rgb: &HardwareRgb) { // GRB pixel order self.byte(rgb.1); self.byte(rgb.0); diff --git a/lights/src/gamma.rs b/lights/src/gamma.rs index 19380c5..475c610 100644 --- a/lights/src/gamma.rs +++ b/lights/src/gamma.rs @@ -3,14 +3,9 @@ //! Gamma correction adjusts the color ramp to look *perceptually* linear //! (LEDs with pulse-width modulation are pretty good at giving physically linear results already) -use crate::Lights; +use crate::{Lights, HardwareRgb}; use crate::rgb::Rgb; -/// An RGB value that has been gamma-corrected from perceptual to physical color. -/// At this point it should probably be passed on to an LED for display, not operated on. -#[derive(Clone, Copy)] -pub struct CorrectedRgb(pub u8, pub u8, pub u8); - static GAMMA_LOOKUP: &[u8] = &[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, @@ -31,8 +26,8 @@ static GAMMA_LOOKUP: &[u8] = &[ ]; #[inline] -pub fn correct(rgb: &Rgb) -> CorrectedRgb { - CorrectedRgb( +pub fn correct(rgb: &Rgb) -> HardwareRgb { + HardwareRgb( GAMMA_LOOKUP[rgb.0 as usize], GAMMA_LOOKUP[rgb.1 as usize], GAMMA_LOOKUP[rgb.2 as usize] @@ -42,7 +37,7 @@ pub fn correct(rgb: &Rgb) -> CorrectedRgb { pub struct GammaCorrector(pub T); impl Lights for GammaCorrector - where T: Lights + where T: Lights { type Pixel = Rgb; diff --git a/lights/src/lib.rs b/lights/src/lib.rs index d59b2ff..2665235 100644 --- a/lights/src/lib.rs +++ b/lights/src/lib.rs @@ -5,6 +5,12 @@ pub mod rgb; use core::borrow::Borrow; +/// An RGB value in physical color space, which should be passed on to an LED for display. +/// Not suitable for color operations, since its values won't be perceptually linear. +/// See the [rgb] module for the former, and the [gamma] module to convert into this. +#[derive(Clone, Copy)] +pub struct HardwareRgb(pub u8, pub u8, pub u8); + pub trait Lights { type Pixel;