Move CorrectedRgb into crate root & rename it to HardwareRgb
This commit is contained in:
parent
1614184575
commit
4f08a72d70
3 changed files with 14 additions and 13 deletions
|
@ -15,11 +15,11 @@ use hal::{
|
||||||
Peripherals
|
Peripherals
|
||||||
};
|
};
|
||||||
use lights::{
|
use lights::{
|
||||||
gamma::CorrectedRgb,
|
HardwareRgb,
|
||||||
Lights
|
Lights
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn boot() -> impl Lights<Pixel = CorrectedRgb> {
|
pub fn boot() -> impl Lights<Pixel = HardwareRgb> {
|
||||||
let mut peripherals = Peripherals::take().unwrap();
|
let mut peripherals = Peripherals::take().unwrap();
|
||||||
let _clock = GenericClockController::with_internal_32kosc(
|
let _clock = GenericClockController::with_internal_32kosc(
|
||||||
peripherals.GCLK,
|
peripherals.GCLK,
|
||||||
|
@ -69,10 +69,10 @@ impl<T: OutputPin> NeopixelLights<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: OutputPin> Lights for NeopixelLights<T> {
|
impl<T: OutputPin> Lights for NeopixelLights<T> {
|
||||||
type Pixel = CorrectedRgb;
|
type Pixel = HardwareRgb;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render(&mut self, rgb: &CorrectedRgb) {
|
fn render(&mut self, rgb: &HardwareRgb) {
|
||||||
// GRB pixel order
|
// GRB pixel order
|
||||||
self.byte(rgb.1);
|
self.byte(rgb.1);
|
||||||
self.byte(rgb.0);
|
self.byte(rgb.0);
|
||||||
|
|
|
@ -3,14 +3,9 @@
|
||||||
//! Gamma correction adjusts the color ramp to look *perceptually* linear
|
//! Gamma correction adjusts the color ramp to look *perceptually* linear
|
||||||
//! (LEDs with pulse-width modulation are pretty good at giving physically linear results already)
|
//! (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;
|
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] = &[
|
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, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
|
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]
|
#[inline]
|
||||||
pub fn correct(rgb: &Rgb) -> CorrectedRgb {
|
pub fn correct(rgb: &Rgb) -> HardwareRgb {
|
||||||
CorrectedRgb(
|
HardwareRgb(
|
||||||
GAMMA_LOOKUP[rgb.0 as usize],
|
GAMMA_LOOKUP[rgb.0 as usize],
|
||||||
GAMMA_LOOKUP[rgb.1 as usize],
|
GAMMA_LOOKUP[rgb.1 as usize],
|
||||||
GAMMA_LOOKUP[rgb.2 as usize]
|
GAMMA_LOOKUP[rgb.2 as usize]
|
||||||
|
@ -42,7 +37,7 @@ pub fn correct(rgb: &Rgb) -> CorrectedRgb {
|
||||||
pub struct GammaCorrector<T>(pub T);
|
pub struct GammaCorrector<T>(pub T);
|
||||||
|
|
||||||
impl<T> Lights for GammaCorrector<T>
|
impl<T> Lights for GammaCorrector<T>
|
||||||
where T: Lights<Pixel = CorrectedRgb>
|
where T: Lights<Pixel = HardwareRgb>
|
||||||
{
|
{
|
||||||
type Pixel = Rgb;
|
type Pixel = Rgb;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,12 @@ pub mod rgb;
|
||||||
|
|
||||||
use core::borrow::Borrow;
|
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 {
|
pub trait Lights {
|
||||||
type Pixel;
|
type Pixel;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue