Struct colstodian::Color [−][src]
#[repr(transparent)]pub struct Color<Spc, St> { pub raw: Vec3, // some fields omitted }
Expand description
A strongly typed color, parameterized by a color space and state.
See crate-level docs as well as ColorSpace
and State
for more.
Fields
raw: Vec3
The raw values of the color. Be careful when modifying this directly.
Implementations
Creates a Color
with the internal color elements el1
, el2
, el3
.
Get the maximum element of self
Get the minimum element of self
pub fn convert_to<Query>(self) -> Color<Query::DstSpace, St> where
Query: ColorConversionQuery<SrcSpace, St>,
pub fn convert_to<Query>(self) -> Color<Query::DstSpace, St> where
Query: ColorConversionQuery<SrcSpace, St>,
Converts self
from one color space to another while retaining the same State
.
This works the same as convert
except there is only one type parameter, the
“Query”.
The query is meant to be one of:
- A
ColorSpace
- A
Color
(in which case it will be converted to that color’s space).
This query is slightly more generic than the ones on convert
, which
means that the Rust type system is usually not able to infer the query without you explicitly giving one.
This can be useful in conjunction with defined type aliases for predefined Color
types.
Interprets this color as DstSpace
. This assumes you have done an external computation/conversion such that this
cast is valid.
Interprets this color as DstSpace
and DstState
. This assumes you have done an external computation/conversion such that this
cast is valid.
Decode self
into its decoded (working) color space,
which allows many more operations to be performed.
Convert self
into the closest linear color space.
If self
is already in a linear color space, this is a no-op.
Converts this color from one state to another.
This conversion is usecase and even instance dependent.
For example, converting a material’s emissive texture value, a Display
-referred color, to a Scene
-referred
color might take the form of a multiplication which scales the power of said emission into Scene
-referred irradiance. On the other hand,
converting a final Scene
-referred color to a Display
-referred color should be done with some kind of tonemapping
operator. For more, see the tonemap
module.
Note that the conversion function gives a raw color value, as the state of the color during the intermediate steps of the conversion is not really well defined. Therefore it’s easier to just work on the raw values without type safety.
Changes this color’s State. This assumes that you have done some kind of conversion externally, or that the proper conversion is simply a noop.
Converts self
to a ColorAlpha
with Separate
alpha state by adding a component. This is probably what you want.
Converts self
to a ColorAlpha
with specified AlphaState
by adding an alpha component. Make sure you choose the
correct alpha state! If you’re not sure, you probably want Color::with_alpha
.
Trait Implementations
Upcasts self
into a DynamicColor
impl<SrcSpace, DstSpace, St> ColorConversionQuery<SrcSpace, St> for Color<DstSpace, St> where
SrcSpace: ColorSpace,
DstSpace: ConvertFromRaw<SrcSpace>,
St: State,
impl<SrcSpace, DstSpace, St> ColorConversionQuery<SrcSpace, St> for Color<DstSpace, St> where
SrcSpace: ColorSpace,
DstSpace: ConvertFromRaw<SrcSpace>,
St: State,
type DstSpace = DstSpace
impl<SrcSpace, DstSpace, St> ColorInto<Color<DstSpace, St>> for Color<SrcSpace, St> where
DstSpace: ConvertFromRaw<SrcSpace>,
SrcSpace: ColorSpace,
St: State,
impl<SrcSpace, DstSpace, St> ColorInto<Color<DstSpace, St>> for Color<SrcSpace, St> where
DstSpace: ConvertFromRaw<SrcSpace>,
SrcSpace: ColorSpace,
St: State,
impl<Spc, St> Debug for Color<Spc, St> where
Spc: ColorSpace,
St: State,
Color<Spc, St>: Deref<Target = Spc::ComponentStruct>,
impl<Spc, St> Debug for Color<Spc, St> where
Spc: ColorSpace,
St: State,
Color<Spc, St>: Deref<Target = Spc::ComponentStruct>,
type Target = <LinearSrgb as ColorSpace>::ComponentStruct
type Target = <LinearSrgb as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <EncodedSrgb as ColorSpace>::ComponentStruct
type Target = <EncodedSrgb as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <EncodedAcesCgSrgb as ColorSpace>::ComponentStruct
type Target = <EncodedAcesCgSrgb as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <Aces2065 as ColorSpace>::ComponentStruct
type Target = <Aces2065 as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <DisplayP3 as ColorSpace>::ComponentStruct
type Target = <DisplayP3 as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <EncodedDisplayP3 as ColorSpace>::ComponentStruct
type Target = <EncodedDisplayP3 as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <CieXYZ as ColorSpace>::ComponentStruct
type Target = <CieXYZ as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <Bt2020 as ColorSpace>::ComponentStruct
type Target = <Bt2020 as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <EncodedBt2020 as ColorSpace>::ComponentStruct
type Target = <EncodedBt2020 as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <EncodedBt2100PQ as ColorSpace>::ComponentStruct
type Target = <EncodedBt2100PQ as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <ICtCpPQ as ColorSpace>::ComponentStruct
type Target = <ICtCpPQ as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <Oklab as ColorSpace>::ComponentStruct
type Target = <Oklab as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <Oklch as ColorSpace>::ComponentStruct
type Target = <Oklch as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
type Target = <AcesCg as ColorSpace>::ComponentStruct
type Target = <AcesCg as ColorSpace>::ComponentStruct
The resulting type after dereferencing.
impl<Spc, St> Display for Color<Spc, St> where
Spc: ColorSpace,
St: State,
Color<Spc, St>: Deref<Target = Spc::ComponentStruct>,
impl<Spc, St> Display for Color<Spc, St> where
Spc: ColorSpace,
St: State,
Color<Spc, St>: Deref<Target = Spc::ComponentStruct>,
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
impl<Spc, A> From<ColorAlpha<Spc, A>> for Color<Spc, Display> where
Spc: ColorSpace,
A: AlphaState,
Premultiplied: ConvertFromAlphaRaw<A>,
impl<Spc, A> From<ColorAlpha<Spc, A>> for Color<Spc, Display> where
Spc: ColorSpace,
A: AlphaState,
Premultiplied: ConvertFromAlphaRaw<A>,
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Convert a reference to the inner type into a reference to the wrapper type. Read more
Convert a mutable reference to the inner type into a mutable reference to the wrapper type. Read more
Convert a slice to the inner type into a slice to the wrapper type.
Convert a mutable slice to the inner type into a mutable slice to the wrapper type. Read more
Convert a reference to the wrapper type into a reference to the inner type. Read more
Convert a mutable reference to the wrapper type into a mutable reference to the inner type. Read more
Convert a slice to the wrapped type into a slice to the inner type.
Convert a mutable slice to the wrapped type into a mutable slice to the inner type. Read more
Auto Trait Implementations
impl<Spc, St> RefUnwindSafe for Color<Spc, St> where
Spc: RefUnwindSafe,
St: RefUnwindSafe,
impl<Spc, St> UnwindSafe for Color<Spc, St> where
Spc: UnwindSafe,
St: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<SrcAlpha, DstAlpha> ConvertToAlphaRaw<DstAlpha> for SrcAlpha where
DstAlpha: ConvertFromAlphaRaw<SrcAlpha>,
impl<SrcAlpha, DstAlpha> ConvertToAlphaRaw<DstAlpha> for SrcAlpha where
DstAlpha: ConvertFromAlphaRaw<SrcAlpha>,
pub fn downcast<Spc, St>(&Self) -> Result<Color<Spc, St>, ColorError> where
Spc: ColorSpace,
St: State,
pub fn downcast<Spc, St>(&Self) -> Result<Color<Spc, St>, ColorError> where
Spc: ColorSpace,
St: State,
Attempt to convert to a typed Color
. Returns an error if self
’s color space and state do not match
the given types.
Convert to a typed Color
without checking if the color space and state types
match this color’s space and state. Use only if you are sure that this color
is in the correct format.