#[repr(C)]pub struct LinearRgba {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
Represents a color in a linear RGBA color space using f32 components.
This struct is the standard color representation within Khora.
Using a linear color space is crucial for correct lighting, shading, and blending.
The f32 components allow for High Dynamic Range (HDR) colors, where component
values can exceed 1.0.
#[repr(C)] ensures a consistent memory layout, which is important when passing
color data to graphics APIs.
Fields§
§r: f32The red component in linear space.
g: f32The green component in linear space.
b: f32The blue component in linear space.
a: f32The alpha (opacity) component (linear, but not gamma-corrected).
Implementations§
Source§impl LinearRgba
impl LinearRgba
Sourcepub const RED: LinearRgba
pub const RED: LinearRgba
Opaque red ([1.0, 0.0, 0.0, 1.0]).
Sourcepub const GREEN: LinearRgba
pub const GREEN: LinearRgba
Opaque green ([0.0, 1.0, 0.0, 1.0]).
Sourcepub const BLUE: LinearRgba
pub const BLUE: LinearRgba
Opaque blue ([0.0, 0.0, 1.0, 1.0]).
Sourcepub const YELLOW: LinearRgba
pub const YELLOW: LinearRgba
Opaque yellow ([1.0, 1.0, 0.0, 1.0]).
Sourcepub const CYAN: LinearRgba
pub const CYAN: LinearRgba
Opaque cyan ([0.0, 1.0, 1.0, 1.0]).
Sourcepub const MAGENTA: LinearRgba
pub const MAGENTA: LinearRgba
Opaque magenta ([1.0, 0.0, 1.0, 1.0]).
Sourcepub const WHITE: LinearRgba
pub const WHITE: LinearRgba
Opaque white ([1.0, 1.0, 1.0, 1.0]).
Sourcepub const BLACK: LinearRgba
pub const BLACK: LinearRgba
Opaque black ([0.0, 0.0, 0.0, 1.0]).
Sourcepub const TRANSPARENT: LinearRgba
pub const TRANSPARENT: LinearRgba
Fully transparent black ([0.0, 0.0, 0.0, 0.0]).
Source§impl LinearRgba
impl LinearRgba
Sourcepub fn from_vec4(v: Vec4) -> LinearRgba
pub fn from_vec4(v: Vec4) -> LinearRgba
Creates a LinearRgba from a Vec4.
Sourcepub fn from_hex(hex: &str) -> LinearRgba
pub fn from_hex(hex: &str) -> LinearRgba
Creates a LinearRgba from an sRGB hex string (#RRGGBB or #RRGGBBAA).
The RGB channels are converted to linear space. Alpha is normalized but not gamma corrected.
§Panics
Panics if the hex string is malformed.
§Example
use khora_core::math::color::LinearRgba;
let color = LinearRgba::from_hex("#6495ED");Sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Converts this linear color to an sRGB hex string (#RRGGBBAA).
The RGB channels are gamma corrected to sRGB. Alpha is kept linear.
Sourcepub fn from_srgb(r: f32, g: f32, b: f32) -> LinearRgba
pub fn from_srgb(r: f32, g: f32, b: f32) -> LinearRgba
Creates a LinearRgba by converting from normalized sRGB components.
Sourcepub fn to_srgb(&self) -> LinearRgba
pub fn to_srgb(&self) -> LinearRgba
Converts this linear color to sRGB components.
Source§impl LinearRgba
impl LinearRgba
Sourcepub fn with_alpha(&self, a: f32) -> LinearRgba
pub fn with_alpha(&self, a: f32) -> LinearRgba
Returns a new color with the same RGB components but a different alpha.
Sourcepub fn lerp(start: LinearRgba, end: LinearRgba, t: f32) -> LinearRgba
pub fn lerp(start: LinearRgba, end: LinearRgba, t: f32) -> LinearRgba
Linearly interpolates between two colors.
The factor t is clamped to [0.0, 1.0].
Trait Implementations§
Source§impl Add for LinearRgba
impl Add for LinearRgba
Source§fn add(self, rhs: LinearRgba) -> <LinearRgba as Add>::Output
fn add(self, rhs: LinearRgba) -> <LinearRgba as Add>::Output
Adds two colors component-wise.
Source§type Output = LinearRgba
type Output = LinearRgba
+ operator.Source§impl Clone for LinearRgba
impl Clone for LinearRgba
Source§fn clone(&self) -> LinearRgba
fn clone(&self) -> LinearRgba
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LinearRgba
impl Debug for LinearRgba
Source§impl Default for LinearRgba
impl Default for LinearRgba
Source§fn default() -> LinearRgba
fn default() -> LinearRgba
Returns opaque white by default.
Source§impl Div<f32> for LinearRgba
impl Div<f32> for LinearRgba
Source§impl Mul<f32> for LinearRgba
impl Mul<f32> for LinearRgba
Source§impl Mul for LinearRgba
impl Mul for LinearRgba
Source§fn mul(self, rhs: LinearRgba) -> <LinearRgba as Mul>::Output
fn mul(self, rhs: LinearRgba) -> <LinearRgba as Mul>::Output
Multiplies two colors component-wise (modulation).
Source§type Output = LinearRgba
type Output = LinearRgba
* operator.Source§impl PartialEq for LinearRgba
impl PartialEq for LinearRgba
Source§impl Sub for LinearRgba
impl Sub for LinearRgba
Source§fn sub(self, rhs: LinearRgba) -> <LinearRgba as Sub>::Output
fn sub(self, rhs: LinearRgba) -> <LinearRgba as Sub>::Output
Subtracts two colors component-wise.
Source§type Output = LinearRgba
type Output = LinearRgba
- operator.impl Copy for LinearRgba
impl Pod for LinearRgba
impl StructuralPartialEq for LinearRgba
Auto Trait Implementations§
impl Freeze for LinearRgba
impl RefUnwindSafe for LinearRgba
impl Send for LinearRgba
impl Sync for LinearRgba
impl Unpin for LinearRgba
impl UnwindSafe for LinearRgba
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.