diff --git a/color/src/color.rs b/color/src/color.rs index f2c3a87..0cc564d 100644 --- a/color/src/color.rs +++ b/color/src/color.rs @@ -174,7 +174,7 @@ impl OpaqueColor { /// Scale the chroma by the given amount. /// - /// See [`Colorspace::scale_chroma`] for more details. + /// See [`ColorSpace::scale_chroma`] for more details. #[must_use] pub fn scale_chroma(self, scale: f32) -> Self { Self::new(CS::scale_chroma(self.components, scale)) @@ -252,7 +252,7 @@ impl AlphaColor { /// Scale the chroma by the given amount. /// - /// See [`Colorspace::scale_chroma`] for more details. + /// See [`ColorSpace::scale_chroma`] for more details. #[must_use] pub fn scale_chroma(self, scale: f32) -> Self { let (opaque, alpha) = split_alpha(self.components); diff --git a/color/src/colorspace.rs b/color/src/colorspace.rs index 24789f2..32ecbc2 100644 --- a/color/src/colorspace.rs +++ b/color/src/colorspace.rs @@ -3,7 +3,7 @@ use core::f32; -use crate::{matmul, tagged::ColorspaceTag}; +use crate::{matmul, tagged::ColorSpaceTag}; #[cfg(all(not(feature = "std"), not(test)))] use crate::floatfuncs::FloatFuncs; @@ -36,7 +36,7 @@ pub trait ColorSpace: Clone + Copy + 'static { const LAYOUT: ColorSpaceLayout = ColorSpaceLayout::Rectangular; /// The tag corresponding to this color space, if a matching tag exists. - const TAG: Option = None; + const TAG: Option = None; /// Convert an opaque color to linear sRGB. /// @@ -101,7 +101,7 @@ pub struct LinearSrgb; impl ColorSpace for LinearSrgb { const IS_LINEAR: bool = true; - const TAG: Option = Some(ColorspaceTag::LinearSrgb); + const TAG: Option = Some(ColorSpaceTag::LinearSrgb); fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] { src @@ -145,7 +145,7 @@ fn lin_to_srgb(x: f32) -> f32 { } impl ColorSpace for Srgb { - const TAG: Option = Some(ColorspaceTag::Srgb); + const TAG: Option = Some(ColorSpaceTag::Srgb); fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] { src.map(srgb_to_lin) @@ -160,7 +160,7 @@ impl ColorSpace for Srgb { pub struct DisplayP3; impl ColorSpace for DisplayP3 { - const TAG: Option = Some(ColorspaceTag::DisplayP3); + const TAG: Option = Some(ColorSpaceTag::DisplayP3); fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] { const LINEAR_DISPLAYP3_TO_SRGB: [[f32; 3]; 3] = [ @@ -187,7 +187,7 @@ pub struct XyzD65; impl ColorSpace for XyzD65 { const IS_LINEAR: bool = true; - const TAG: Option = Some(ColorspaceTag::XyzD65); + const TAG: Option = Some(ColorSpaceTag::XyzD65); fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] { const XYZ_TO_LINEAR_SRGB: [[f32; 3]; 3] = [ @@ -239,7 +239,7 @@ const OKLAB_LMS_TO_LAB: [[f32; 3]; 3] = [ ]; impl ColorSpace for Oklab { - const TAG: Option = Some(ColorspaceTag::Oklab); + const TAG: Option = Some(ColorSpaceTag::Oklab); fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] { let lms = matmul(&OKLAB_LAB_TO_LMS, src).map(|x| x * x * x); @@ -260,7 +260,7 @@ impl ColorSpace for Oklab { pub struct Oklch; impl ColorSpace for Oklch { - const TAG: Option = Some(ColorspaceTag::Oklch); + const TAG: Option = Some(ColorSpaceTag::Oklch); const LAYOUT: ColorSpaceLayout = ColorSpaceLayout::HueThird; diff --git a/color/src/css.rs b/color/src/css.rs index 8a67578..169d6b6 100644 --- a/color/src/css.rs +++ b/color/src/css.rs @@ -5,12 +5,12 @@ use crate::{ color::{add_alpha, fixup_hues_for_interpolate, split_alpha}, - AlphaColor, Bitset, ColorSpace, ColorSpaceLayout, ColorspaceTag, HueDirection, TaggedColor, + AlphaColor, Bitset, ColorSpace, ColorSpaceLayout, ColorSpaceTag, HueDirection, TaggedColor, }; #[derive(Clone, Copy, Debug)] pub struct CssColor { - pub cs: ColorspaceTag, + pub cs: ColorSpaceTag, /// A bitmask of missing components. pub missing: Bitset, pub components: [f32; 4], @@ -26,7 +26,7 @@ pub struct Interpolator { alpha1: f32, delta_premul: [f32; 3], alpha2: f32, - cs: ColorspaceTag, + cs: ColorSpaceTag, missing: Bitset, } @@ -58,7 +58,7 @@ impl CssColor { } #[must_use] - pub fn convert(self, cs: ColorspaceTag) -> Self { + pub fn convert(self, cs: ColorSpaceTag) -> Self { if self.cs == cs { // Note: ยง12 suggests that changing powerless to missing happens // even when the color is already in the interpolation color space, @@ -105,7 +105,7 @@ impl CssColor { /// Scale the chroma by the given amount. /// - /// See [`Colorspace::scale_chroma`] for more details. + /// See [`ColorSpace::scale_chroma`] for more details. #[must_use] pub fn scale_chroma(self, scale: f32) -> Self { let (opaque, alpha) = split_alpha(self.components); @@ -157,7 +157,7 @@ impl CssColor { pub fn interpolate( self, other: Self, - cs: ColorspaceTag, + cs: ColorSpaceTag, direction: HueDirection, ) -> Interpolator { let mut a = self.convert(cs); @@ -199,7 +199,7 @@ impl CssColor { /// Blending semi-transparent colors will reduce contrast, and that /// should also be taken into account. pub fn relative_luminance(self) -> f32 { - let rgb = self.convert(ColorspaceTag::LinearSrgb).components; + let rgb = self.convert(ColorSpaceTag::LinearSrgb).components; 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2] } } diff --git a/color/src/gradient.rs b/color/src/gradient.rs index 0286ab5..620e1cf 100644 --- a/color/src/gradient.rs +++ b/color/src/gradient.rs @@ -1,7 +1,7 @@ // Copyright 2024 the Color Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -use crate::{ColorSpace, ColorspaceTag, CssColor, HueDirection, Interpolator, Oklab, PremulColor}; +use crate::{ColorSpace, ColorSpaceTag, CssColor, HueDirection, Interpolator, Oklab, PremulColor}; #[expect(missing_debug_implementations, reason = "it's an iterator")] pub struct GradientIter { @@ -19,7 +19,7 @@ pub struct GradientIter { pub fn gradient( mut color0: CssColor, mut color1: CssColor, - interp_cs: ColorspaceTag, + interp_cs: ColorSpaceTag, direction: HueDirection, tolerance: f32, ) -> GradientIter { diff --git a/color/src/lib.rs b/color/src/lib.rs index 63c79c8..3ed86b3 100644 --- a/color/src/lib.rs +++ b/color/src/lib.rs @@ -41,7 +41,7 @@ pub use colorspace::{ pub use css::{CssColor, Interpolator}; pub use gradient::{gradient, GradientIter}; pub use parse::{parse_color, Error}; -pub use tagged::{ColorspaceTag, TaggedColor}; +pub use tagged::{ColorSpaceTag, TaggedColor}; const fn u8_to_f32(x: u32) -> f32 { x as f32 * (1.0 / 255.0) diff --git a/color/src/parse.rs b/color/src/parse.rs index d11e613..bab7d85 100644 --- a/color/src/parse.rs +++ b/color/src/parse.rs @@ -6,7 +6,7 @@ use core::f64; use core::str::FromStr; -use crate::{AlphaColor, Bitset, ColorspaceTag, CssColor, Srgb, TaggedColor}; +use crate::{AlphaColor, Bitset, ColorSpaceTag, CssColor, Srgb, TaggedColor}; // TODO: proper error type, maybe include string offset pub type Error = &'static str; @@ -30,7 +30,7 @@ enum Value<'a> { clippy::cast_possible_truncation, reason = "deliberate choice of f32 for colors" )] -fn color_from_components(components: [Option; 4], cs: ColorspaceTag) -> CssColor { +fn color_from_components(components: [Option; 4], cs: ColorSpaceTag) -> CssColor { let mut missing = Bitset::default(); for (i, component) in components.iter().enumerate() { if component.is_none() { @@ -285,7 +285,7 @@ impl<'a> Parser<'a> { if !self.ch(b')') { return Err("expected closing parenthesis"); } - Ok(color_from_components([r, g, b, alpha], ColorspaceTag::Srgb)) + Ok(color_from_components([r, g, b, alpha], ColorSpaceTag::Srgb)) } fn optional_alpha(&mut self) -> Result, Error> { @@ -311,7 +311,7 @@ impl<'a> Parser<'a> { } Ok(color_from_components( [l, a, b, alpha], - ColorspaceTag::Oklab, + ColorSpaceTag::Oklab, )) } @@ -328,7 +328,7 @@ impl<'a> Parser<'a> { } Ok(color_from_components( [l, c, h, alpha], - ColorspaceTag::Oklch, + ColorSpaceTag::Oklch, )) } @@ -341,10 +341,10 @@ impl<'a> Parser<'a> { return Err("expected identifier for colorspace"); }; let cs = match id { - "srgb" => ColorspaceTag::Srgb, - "srgb-linear" => ColorspaceTag::LinearSrgb, - "display-p3" => ColorspaceTag::DisplayP3, - "xyz" | "xyz-d65" => ColorspaceTag::XyzD65, + "srgb" => ColorSpaceTag::Srgb, + "srgb-linear" => ColorSpaceTag::LinearSrgb, + "display-p3" => ColorSpaceTag::DisplayP3, + "xyz" | "xyz-d65" => ColorSpaceTag::XyzD65, _ => return Err("unknown colorspace"), }; let r = self.scaled_component(1., 0.01)?; @@ -377,7 +377,7 @@ pub fn parse_color(s: &str) -> Result { "rgb" | "rgba" => parser.rgb(), "oklab" => parser.oklab(), "oklch" => parser.oklch(), - "transparent" => Ok(color_from_components([Some(0.); 4], ColorspaceTag::Srgb)), + "transparent" => Ok(color_from_components([Some(0.); 4], ColorSpaceTag::Srgb)), "color" => parser.color(), _ => Err("unknown identifier"), } @@ -425,7 +425,7 @@ const fn color_from_4bit_hex(components: [u8; 8]) -> AlphaColor { AlphaColor::from_rgba8(r0 << 4 | r1, g0 << 4 | g1, b0 << 4 | b1, a0 << 4 | a1) } -impl FromStr for ColorspaceTag { +impl FromStr for ColorSpaceTag { type Err = &'static str; fn from_str(s: &str) -> Result { diff --git a/color/src/serialize.rs b/color/src/serialize.rs index f1fd98a..5431f32 100644 --- a/color/src/serialize.rs +++ b/color/src/serialize.rs @@ -5,7 +5,7 @@ use core::fmt::{Formatter, Result}; -use crate::{ColorspaceTag, CssColor}; +use crate::{ColorSpaceTag, CssColor}; fn write_scaled_component( color: &CssColor, @@ -57,7 +57,7 @@ fn write_color_function(color: &CssColor, name: &str, f: &mut Formatter<'_>) -> impl core::fmt::Display for CssColor { fn fmt(&self, f: &mut Formatter<'_>) -> Result { match self.cs { - ColorspaceTag::Srgb => { + ColorSpaceTag::Srgb => { // A case can be made this isn't the best serialization in general, // because CSS parsing of out-of-gamut components will clamp. let opt_a = if self.components[3] < 1.0 { "a" } else { "" }; @@ -74,13 +74,13 @@ impl core::fmt::Display for CssColor { } write!(f, ")") } - ColorspaceTag::LinearSrgb => write_color_function(self, "srgb-linear", f), - ColorspaceTag::DisplayP3 => write_color_function(self, "display-p3", f), - ColorspaceTag::XyzD65 => write_color_function(self, "xyz", f), - ColorspaceTag::Lab => write_modern_function(self, "lab", f), - ColorspaceTag::Lch => write_modern_function(self, "lch", f), - ColorspaceTag::Oklab => write_modern_function(self, "oklab", f), - ColorspaceTag::Oklch => write_modern_function(self, "oklch", f), + ColorSpaceTag::LinearSrgb => write_color_function(self, "srgb-linear", f), + ColorSpaceTag::DisplayP3 => write_color_function(self, "display-p3", f), + ColorSpaceTag::XyzD65 => write_color_function(self, "xyz", f), + ColorSpaceTag::Lab => write_modern_function(self, "lab", f), + ColorSpaceTag::Lch => write_modern_function(self, "lch", f), + ColorSpaceTag::Oklab => write_modern_function(self, "oklab", f), + ColorSpaceTag::Oklch => write_modern_function(self, "oklch", f), _ => todo!(), } } diff --git a/color/src/tagged.rs b/color/src/tagged.rs index 3f524c1..e497b18 100644 --- a/color/src/tagged.rs +++ b/color/src/tagged.rs @@ -9,7 +9,7 @@ use crate::{ XyzD65, }; -/// The colo rspace tag for tagged colors. +/// The color space tag for tagged colors. /// /// This represents a fixed set of known color spaces. The set is /// based on the CSS Color 4 spec, but might also extend to a small @@ -20,7 +20,7 @@ use crate::{ /// Note: when adding an RGB-like color space, add to `same_analogous`. #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[non_exhaustive] -pub enum ColorspaceTag { +pub enum ColorSpaceTag { Srgb, LinearSrgb, Lab, @@ -37,11 +37,11 @@ pub enum ColorspaceTag { /// [`CssColor`][crate::css::CssColor]. #[derive(Clone, Copy, Debug)] pub struct TaggedColor { - pub cs: ColorspaceTag, + pub cs: ColorSpaceTag, pub components: [f32; 4], } -impl ColorspaceTag { +impl ColorSpaceTag { pub(crate) fn layout(self) -> ColorSpaceLayout { match self { Self::Lch | Self::Oklch => ColorSpaceLayout::HueThird, @@ -54,7 +54,7 @@ impl ColorspaceTag { // in that case we wouldn't do the conversion, so this function is not // guaranteed to return the correct answer in those cases. pub(crate) fn same_analogous(self, other: Self) -> bool { - use ColorspaceTag::*; + use ColorSpaceTag::*; matches!( (self, other), ( @@ -66,7 +66,7 @@ impl ColorspaceTag { } pub(crate) fn l_missing(self, missing: Bitset) -> bool { - use ColorspaceTag::*; + use ColorSpaceTag::*; match self { Lab | Lch | Oklab | Oklch => missing.contains(0), Hsl => missing.contains(2), @@ -75,7 +75,7 @@ impl ColorspaceTag { } pub(crate) fn set_l_missing(self, missing: &mut Bitset, components: &mut [f32; 4]) { - use ColorspaceTag::*; + use ColorSpaceTag::*; match self { Lab | Lch | Oklab | Oklch => { missing.set(0); @@ -90,7 +90,7 @@ impl ColorspaceTag { } pub(crate) fn c_missing(self, missing: Bitset) -> bool { - use ColorspaceTag::*; + use ColorSpaceTag::*; match self { Lab | Lch | Oklab | Oklch | Hsl => missing.contains(1), _ => false, @@ -98,7 +98,7 @@ impl ColorspaceTag { } pub(crate) fn set_c_missing(self, missing: &mut Bitset, components: &mut [f32; 4]) { - use ColorspaceTag::*; + use ColorSpaceTag::*; match self { Lab | Lch | Oklab | Oklch | Hsl => { missing.set(1); @@ -147,7 +147,7 @@ impl ColorspaceTag { /// Scale the chroma by the given amount. /// - /// See [`Colorspace::scale_chroma`] for more details. + /// See [`ColorSpace::scale_chroma`] for more details. pub fn scale_chroma(self, src: [f32; 3], scale: f32) -> [f32; 3] { match self { Self::LinearSrgb => LinearSrgb::scale_chroma(src, scale), @@ -163,7 +163,7 @@ impl ColorspaceTag { } impl TaggedColor { - pub fn from_linear_srgb(rgba: [f32; 4], cs: ColorspaceTag) -> Self { + pub fn from_linear_srgb(rgba: [f32; 4], cs: ColorSpaceTag) -> Self { let (rgb, alpha) = split_alpha(rgba); let opaque = cs.from_linear_srgb(rgb); let components = add_alpha(opaque, alpha); @@ -179,7 +179,7 @@ impl TaggedColor { } else { let components = color.convert::().components; Self { - cs: ColorspaceTag::LinearSrgb, + cs: ColorSpaceTag::LinearSrgb, components, } } @@ -197,7 +197,7 @@ impl TaggedColor { } #[must_use] - pub fn convert(self, cs: ColorspaceTag) -> Self { + pub fn convert(self, cs: ColorSpaceTag) -> Self { if self.cs == cs { self } else {