pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
pub unclipped: Option<[f32; 3]>,
}Expand description
Stores a premultiplied color, with all four channels ranging from 0..1.
Fields§
§r: f32§g: f32§b: f32§a: f32§unclipped: Option<[f32; 3]>A color outside sRGB: its straight red, green and blue before r, g
and b clipped them to 0..1, which interpolation reads (the style
spec’s unclippedRgb). None inside sRGB.
Implementations§
Source§impl Color
impl Color
pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self
Sourcepub const fn new_unchecked(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn new_unchecked(r: f32, g: f32, b: f32, a: f32) -> Self
Internal constructor without range asserts (interpolation can transiently leave 0..1 in the same way the C++ aggregate init does).
pub const fn black() -> Self
pub const fn white() -> Self
pub const fn red() -> Self
pub const fn green() -> Self
pub const fn blue() -> Self
Sourcepub fn parse(s: &str) -> Option<Color>
pub fn parse(s: &str) -> Option<Color>
Parse a CSS color string as the style spec does, returning a premultiplied Color. Unlike the C++ core, it keeps the channels’ precision rather than rounding them to 8 bits.
Sourcepub fn parse_straight(s: &str) -> Option<[f64; 4]>
pub fn parse_straight(s: &str) -> Option<[f64; 4]>
The straight [r, g, b, a] of a CSS color string, as the style spec
parses it: red, green and blue are 0..1 inside sRGB and unclipped
outside it.
pub fn interpolate(from: &Color, to: &Color, t: f64, space: ColorSpace) -> Color
pub fn to_float_array(&self) -> [f32; 4]
pub fn stringify(&self) -> String
Sourcepub fn serialize(&self) -> Value
pub fn serialize(&self) -> Value
Emit as an rgba expression array for expression serialization (avoids “Bare objects invalid” parse errors in expression round trips).
Port-only: when the C++ values (to_array) don’t make this color
again (the “rgba” expression premultiplies them back), it writes
values that do. to_array divides in float, so a serialized layer
could parse back to slightly other colors, and a tile worker in
another wasm instance, which gets its layers that way, would write
other colors into its buckets.
Trait Implementations§
impl Copy for Color
Source§impl Interpolate for Color
Channel-wise lerp of the premultiplied channels
(this is what ColorSpace::RGB means).
impl Interpolate for Color
Channel-wise lerp of the premultiplied channels
(this is what ColorSpace::RGB means).
fn interpolate(&self, to: &Self, t: f64) -> Self
Source§fn interpolate_f32(&self, to: &Self, t: f32) -> Self
fn interpolate_f32(&self, to: &Self, t: f32) -> Self
t. Defaults to promoting t, which is
what C++ does for specializations without a float overload.