Move CorrectedRgb into crate root & rename it to HardwareRgb

This commit is contained in:
Tangent 128 2019-03-09 17:02:12 -05:00
parent 1614184575
commit 4f08a72d70
3 changed files with 14 additions and 13 deletions

View file

@ -15,11 +15,11 @@ use hal::{
Peripherals
};
use lights::{
gamma::CorrectedRgb,
HardwareRgb,
Lights
};
pub fn boot() -> impl Lights<Pixel = CorrectedRgb> {
pub fn boot() -> impl Lights<Pixel = HardwareRgb> {
let mut peripherals = Peripherals::take().unwrap();
let _clock = GenericClockController::with_internal_32kosc(
peripherals.GCLK,
@ -69,10 +69,10 @@ impl<T: OutputPin> NeopixelLights<T> {
}
impl<T: OutputPin> Lights for NeopixelLights<T> {
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);

View file

@ -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<T>(pub T);
impl<T> Lights for GammaCorrector<T>
where T: Lights<Pixel = CorrectedRgb>
where T: Lights<Pixel = HardwareRgb>
{
type Pixel = Rgb;

View file

@ -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;