use crate::util::component::Component;
use super::{
ColorCorrection, FromColor, GammaSrgb, LedChannels, LedColor, Lms, Okhsl, Okhsv, Oklab, Srgb,
Xyz,
};
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct LinearSrgb {
pub red: f32,
pub green: f32,
pub blue: f32,
}
impl LinearSrgb {
pub fn new(red: f32, green: f32, blue: f32) -> Self {
LinearSrgb {
red: red.clamp(0.0, 1.0),
green: green.clamp(0.0, 1.0),
blue: blue.clamp(0.0, 1.0),
}
}
pub fn to_srgb(self) -> Srgb {
Srgb::from_linear_srgb(self)
}
pub fn to_gamma_srgb(self, gamma: f32) -> GammaSrgb {
GammaSrgb::from_linear_srgb(self, gamma)
}
pub fn to_led<C: Component>(
self,
channels: LedChannels,
brightness: f32,
correction: ColorCorrection,
) -> LedColor<C> {
LedColor::from_linear_srgb(self, channels, brightness, correction)
}
}
impl FromColor<GammaSrgb> for LinearSrgb {
fn from_color(color: GammaSrgb) -> Self {
color.to_linear_srgb()
}
}
impl FromColor<Lms> for LinearSrgb {
fn from_color(color: Lms) -> Self {
color.to_linear_srgb()
}
}
impl FromColor<Okhsv> for LinearSrgb {
fn from_color(color: Okhsv) -> Self {
color.to_linear_srgb()
}
}
impl FromColor<Okhsl> for LinearSrgb {
fn from_color(color: Okhsl) -> Self {
color.to_linear_srgb()
}
}
impl FromColor<Oklab> for LinearSrgb {
fn from_color(color: Oklab) -> Self {
color.to_linear_srgb()
}
}
impl FromColor<Srgb> for LinearSrgb {
fn from_color(color: Srgb) -> Self {
color.to_linear_srgb()
}
}
impl FromColor<Xyz> for LinearSrgb {
fn from_color(color: Xyz) -> Self {
color.to_linear_srgb()
}
}