Struct colstodian::ColorAlpha [−][src]
#[repr(C)]pub struct ColorAlpha<Spc, A> { pub raw: Vec4, // some fields omitted }
Expand description
A strongly typed color with an alpha channel, parameterized by a color space and alpha state.
A color with an alpha channel is always in display-referred state. The alpha channel is always linear [0..1].
See crate-level docs as well as ColorSpace
and AlphaState
for more.
Fields
raw: Vec4
The raw values of the color. Be careful when modifying this directly.
Implementations
Creates a ColorAlpha
with the raw internal color elements el1
, el2
, el3
and alpha value alpha
.
Creates a ColorAlpha
with raw values contained in raw
.
Get the maximum element of self
Get the minimum element of self
impl<SrcSpace, SrcAlpha> ColorAlpha<SrcSpace, SrcAlpha> where
SrcSpace: ColorSpace,
SrcAlpha: AlphaState,
impl<SrcSpace, SrcAlpha> ColorAlpha<SrcSpace, SrcAlpha> where
SrcSpace: ColorSpace,
SrcAlpha: AlphaState,
pub fn convert<DstSpace, DstAlpha>(self) -> ColorAlpha<DstSpace, DstAlpha> where
DstSpace: ConvertFromRaw<SrcSpace>,
DstAlpha: AlphaState,
pub fn convert<DstSpace, DstAlpha>(self) -> ColorAlpha<DstSpace, DstAlpha> where
DstSpace: ConvertFromRaw<SrcSpace>,
DstAlpha: AlphaState,
Converts from one color space and state to another.
- If converting from Premultiplied to Separate, you must ensure that
self.alpha != 0.0
, otherwise a divide by 0 will occur andInf
s will result.
pub fn convert_to<Query>(self) -> ColorAlpha<Query::DstSpace, Query::DstAlpha> where
Query: ColorAlphaConversionQuery<SrcSpace, SrcAlpha>,
pub fn convert_to<Query>(self) -> ColorAlpha<Query::DstSpace, Query::DstAlpha> where
Query: ColorAlphaConversionQuery<SrcSpace, SrcAlpha>,
Converts from one color space and state to another.
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
AlphaState
- A
ColorAlpha
(in which case it will be converted to that color’s space and alpha state)
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 ColorAlpha
types.
pub fn convert_alpha<DstAlpha: ConvertFromAlphaRaw<SrcAlpha> + AlphaState>(
self
) -> ColorAlpha<SrcSpace, DstAlpha>
pub fn convert_alpha<DstAlpha: ConvertFromAlphaRaw<SrcAlpha> + AlphaState>(
self
) -> ColorAlpha<SrcSpace, DstAlpha>
Converts self
to the provided DstAlpha
AlphaState
.
- If converting to the same state, this is a no-op.
- If converting from Premultiplied to Separate, you must ensure that
self.alpha != 0.0
, otherwise a divide by 0 will occur andInf
s will result.
Interprets this color as DstSpace
. This assumes you have done an external computation/conversion such that this
cast is valid.
Changes this color’s alpha state. This assumes that you have done some kind of computation/conversion such that this cast is valid.
pub fn cast<DstSpace: ColorSpace, DstAlpha: AlphaState>(
self
) -> ColorAlpha<DstSpace, DstAlpha>
pub fn cast<DstSpace: ColorSpace, DstAlpha: AlphaState>(
self
) -> ColorAlpha<DstSpace, DstAlpha>
Changes this color’s alpha state. This assumes that you have done some kind of computation/conversion such that this cast is valid.
pub fn blend(
self,
other: ColorAlpha<Spc, Separate>,
factor: f32
) -> ColorAlpha<Spc, Separate>
pub fn blend(
self,
other: ColorAlpha<Spc, Separate>,
factor: f32
) -> ColorAlpha<Spc, Separate>
Blend self
’s color values with the color values from other
. Does not blend alpha.
pub fn blend_alpha(
self,
other: ColorAlpha<Spc, Separate>,
factor: f32
) -> ColorAlpha<Spc, Separate>
pub fn blend_alpha(
self,
other: ColorAlpha<Spc, Separate>,
factor: f32
) -> ColorAlpha<Spc, Separate>
Blend self
’s color values with the color values from other
. Also blends alpha.
impl<Spc: LinearColorSpace, A: AlphaState> ColorAlpha<Spc, A> where
Premultiplied: ConvertFromAlphaRaw<A>,
impl<Spc: LinearColorSpace, A: AlphaState> ColorAlpha<Spc, A> where
Premultiplied: ConvertFromAlphaRaw<A>,
Premultiplies self
by multiplying its color components by its alpha. Does nothing if self
is already premultiplied.
impl<Spc: LinearColorSpace, A: AlphaState> ColorAlpha<Spc, A> where
Separate: ConvertFromAlphaRaw<A>,
impl<Spc: LinearColorSpace, A: AlphaState> ColorAlpha<Spc, A> where
Separate: ConvertFromAlphaRaw<A>,
Separates self
by dividing its color components by its alpha. Does nothing if self
is already separate.
- You must ensure that
self.alpha != 0.0
, otherwise a divide by 0 will occur andInf
s will result.
Convert self
into the closest linear color space.
Decode self
into its decoded (working) color space,
which allows many more operations to be performed.
Converts self
to a Color
by stripping off the alpha component.
impl<Spc, A> ColorAlpha<Spc, A> where
Spc: ColorSpace,
A: AlphaState,
Premultiplied: ConvertFromAlphaRaw<A>,
impl<Spc, A> ColorAlpha<Spc, A> where
Spc: ColorSpace,
A: AlphaState,
Premultiplied: ConvertFromAlphaRaw<A>,
Converts self
to a Color
by first premultiplying self
(if premultiplying makes sense for the current color space)
and then stripping off the alpha component.
Trait Implementations
type Output = ColorAlpha<Spc, A>
type Output = ColorAlpha<Spc, A>
The resulting type after applying the +
operator.
Performs the +
operation. Read more
impl<SrcSpace, DstSpc, SrcAlpha, DstAlpha> ColorAlphaConversionQuery<SrcSpace, SrcAlpha> for ColorAlpha<DstSpc, DstAlpha> where
SrcSpace: ColorSpace,
DstSpc: ConvertFromRaw<SrcSpace>,
SrcAlpha: AlphaState,
DstAlpha: ConvertFromAlphaRaw<SrcAlpha> + AlphaState,
impl<SrcSpace, DstSpc, SrcAlpha, DstAlpha> ColorAlphaConversionQuery<SrcSpace, SrcAlpha> for ColorAlpha<DstSpc, DstAlpha> where
SrcSpace: ColorSpace,
DstSpc: ConvertFromRaw<SrcSpace>,
SrcAlpha: AlphaState,
DstAlpha: ConvertFromAlphaRaw<SrcAlpha> + AlphaState,
type CintTy = PremultipliedAlpha<LinearSrgb<f32>>
type CintTy = PremultipliedAlpha<EncodedBt2100PQ<f32>>
type CintTy = PremultipliedAlpha<EncodedDisplayP3<f32>>
type CintTy = PremultipliedAlpha<EncodedSrgb<f32>>
type CintTy = PremultipliedAlpha<EncodedBt2020<f32>>
impl<SrcSpace, DstSpace, SrcAlpha, DstAlpha> ColorInto<ColorAlpha<DstSpace, DstAlpha>> for ColorAlpha<SrcSpace, SrcAlpha> where
DstSpace: ConvertFromRaw<SrcSpace>,
SrcSpace: ColorSpace,
DstAlpha: ConvertFromAlphaRaw<SrcAlpha> + AlphaState,
SrcAlpha: AlphaState,
impl<SrcSpace, DstSpace, SrcAlpha, DstAlpha> ColorInto<ColorAlpha<DstSpace, DstAlpha>> for ColorAlpha<SrcSpace, SrcAlpha> where
DstSpace: ConvertFromRaw<SrcSpace>,
SrcSpace: ColorSpace,
DstAlpha: ConvertFromAlphaRaw<SrcAlpha> + AlphaState,
SrcAlpha: AlphaState,
impl<Spc, A> Debug for ColorAlpha<Spc, A> where
Spc: ColorSpace,
A: AlphaState,
ColorAlpha<Spc, A>: Deref<Target = ColAlpha<Spc::ComponentStruct>>,
impl<Spc, A> Debug for ColorAlpha<Spc, A> where
Spc: ColorSpace,
A: AlphaState,
ColorAlpha<Spc, A>: Deref<Target = ColAlpha<Spc::ComponentStruct>>,
type Target = ColAlpha<<LinearSrgb as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<LinearSrgb as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<EncodedSrgb as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<EncodedSrgb as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<EncodedAcesCgSrgb as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<EncodedAcesCgSrgb as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<Aces2065 as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<Aces2065 as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<DisplayP3 as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<DisplayP3 as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<EncodedDisplayP3 as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<EncodedDisplayP3 as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<CieXYZ as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<CieXYZ as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<Bt2020 as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<Bt2020 as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<EncodedBt2020 as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<EncodedBt2020 as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<EncodedBt2100PQ as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<EncodedBt2100PQ as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<ICtCpPQ as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<ICtCpPQ as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<Oklab as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<Oklab as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<Oklch as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<Oklch as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
type Target = ColAlpha<<AcesCg as ColorSpace>::ComponentStruct>
type Target = ColAlpha<<AcesCg as ColorSpace>::ComponentStruct>
The resulting type after dereferencing.
impl<Spc, A> Display for ColorAlpha<Spc, A> where
Spc: ColorSpace,
A: AlphaState,
ColorAlpha<Spc, A>: Deref<Target = ColAlpha<Spc::ComponentStruct>>,
impl<Spc, A> Display for ColorAlpha<Spc, A> where
Spc: ColorSpace,
A: AlphaState,
ColorAlpha<Spc, A>: Deref<Target = ColAlpha<Spc::ComponentStruct>>,
type Output = ColorAlpha<Spc, A>
type Output = ColorAlpha<Spc, A>
The resulting type after applying the /
operator.
Performs the /
operation. Read more
type Output = ColorAlpha<Spc, A>
type Output = ColorAlpha<Spc, A>
The resulting type after applying the /
operator.
Performs the /
operation. Read more
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
fn from(
color: ColorAlpha<EncodedBt2020, Premultiplied>
) -> PremultipliedAlpha<EncodedBt2020<f32>>
fn from(
color: ColorAlpha<EncodedBt2020, Premultiplied>
) -> PremultipliedAlpha<EncodedBt2020<f32>>
Performs the conversion.
Performs the conversion.
fn from(
color: ColorAlpha<EncodedBt2100PQ, Premultiplied>
) -> PremultipliedAlpha<EncodedBt2100PQ<f32>>
fn from(
color: ColorAlpha<EncodedBt2100PQ, Premultiplied>
) -> PremultipliedAlpha<EncodedBt2100PQ<f32>>
Performs the conversion.
Performs the conversion.
fn from(
color: ColorAlpha<EncodedDisplayP3, Premultiplied>
) -> PremultipliedAlpha<EncodedDisplayP3<f32>>
fn from(
color: ColorAlpha<EncodedDisplayP3, Premultiplied>
) -> PremultipliedAlpha<EncodedDisplayP3<f32>>
Performs the conversion.
Performs the conversion.
fn from(
color: ColorAlpha<EncodedSrgb, Premultiplied>
) -> PremultipliedAlpha<EncodedSrgb<f32>>
fn from(
color: ColorAlpha<EncodedSrgb, Premultiplied>
) -> PremultipliedAlpha<EncodedSrgb<f32>>
Performs the conversion.
Performs the conversion.
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.
fn from(
color: PremultipliedAlpha<EncodedBt2020<f32>>
) -> ColorAlpha<EncodedBt2020, Premultiplied>
fn from(
color: PremultipliedAlpha<EncodedBt2020<f32>>
) -> ColorAlpha<EncodedBt2020, Premultiplied>
Performs the conversion.
fn from(
color: PremultipliedAlpha<EncodedBt2100PQ<f32>>
) -> ColorAlpha<EncodedBt2100PQ, Premultiplied>
fn from(
color: PremultipliedAlpha<EncodedBt2100PQ<f32>>
) -> ColorAlpha<EncodedBt2100PQ, Premultiplied>
Performs the conversion.
fn from(
color: PremultipliedAlpha<EncodedDisplayP3<f32>>
) -> ColorAlpha<EncodedDisplayP3, Premultiplied>
fn from(
color: PremultipliedAlpha<EncodedDisplayP3<f32>>
) -> ColorAlpha<EncodedDisplayP3, Premultiplied>
Performs the conversion.
fn from(
color: PremultipliedAlpha<EncodedSrgb<f32>>
) -> ColorAlpha<EncodedSrgb, Premultiplied>
fn from(
color: PremultipliedAlpha<EncodedSrgb<f32>>
) -> ColorAlpha<EncodedSrgb, Premultiplied>
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
type Output = ColorAlpha<Spc, A>
type Output = ColorAlpha<Spc, A>
The resulting type after applying the *
operator.
Performs the *
operation. Read more
type Output = ColorAlpha<Spc, A>
type Output = ColorAlpha<Spc, A>
The resulting type after applying the *
operator.
Performs the *
operation. Read more
type Output = ColorAlpha<Spc, A>
type Output = ColorAlpha<Spc, A>
The resulting type after applying the -
operator.
Performs the -
operation. Read more
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, A> RefUnwindSafe for ColorAlpha<Spc, A> where
A: RefUnwindSafe,
Spc: RefUnwindSafe,
impl<Spc, A> Send for ColorAlpha<Spc, A> where
A: Send,
Spc: Send,
impl<Spc, A> Sync for ColorAlpha<Spc, A> where
A: Sync,
Spc: Sync,
impl<Spc, A> Unpin for ColorAlpha<Spc, A> where
A: Unpin,
Spc: Unpin,
impl<Spc, A> UnwindSafe for ColorAlpha<Spc, A> where
A: UnwindSafe,
Spc: 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>,