Struct rgb::RGBA

source ·
#[repr(C)]
pub struct RGBA<ComponentType, AlphaComponentType = ComponentType> { pub r: ComponentType, pub g: ComponentType, pub b: ComponentType, pub a: AlphaComponentType, }
Expand description

The RGBA pixel

The component type can be u8 (aliased as RGBA8), u16 (aliased as RGBA16), or any other type (but simple copyable types are recommended.)

You can specify a different type for alpha, but it’s only for special cases (e.g. if you use a newtype like RGBA<LinearLight<u16>, u16>).

Fields§

§r: ComponentType

Red

§g: ComponentType

Green

§b: ComponentType

Blue

§a: AlphaComponentType

Alpha

Implementations§

source§

impl<T> RGBA<T>

source

pub const fn new(r: T, g: T, b: T, a: T) -> Self

Convenience function for creating a new pixel The order of arguments is R,G,B,A

source§

impl<T, A> RGBA<T, A>

source

pub const fn new_alpha(r: T, g: T, b: T, a: A) -> Self

Convenience function for creating a new pixel The order of arguments is R,G,B,A

source§

impl<T, A> RGBA<T, A>

source

pub fn rgb_mut(&mut self) -> &mut RGB<T>

Provide a mutable view of only RGB components (leaving out alpha). Useful to change color without changing opacity.

source§

impl<T: Clone, A> RGBA<T, A>

source

pub fn rgb(&self) -> RGB<T>

Copy RGB components out of the RGBA struct

Note: you can use .into() to convert between other types

source§

impl<T: Clone> RGBA<T>

source

pub fn iter(&self) -> Cloned<Iter<'_, T>>

Iterate over all components (length=4)

source§

impl<T: Clone, A> RGBA<T, A>

source

pub fn bgr(&self) -> BGR<T>

Copy RGB components out of the RGBA struct

Note: you can use .into() to convert between other types

source§

impl<T: Copy, A: Clone> RGBA<T, A>

source

pub fn map_rgb<F, U, B>(&self, f: F) -> RGBA<U, B>where F: FnMut(T) -> U, U: Clone, B: From<A> + Clone,

Create new RGBA with the same alpha value, but different RGB values

source

pub fn alpha(&self, a: A) -> Self

Create a new RGBA with the new alpha value, but same RGB values

source

pub fn map_alpha<F, B>(&self, f: F) -> RGBA<T, B>where F: FnOnce(A) -> B,

Create a new RGBA with a new alpha value created by the callback. Allows changing of the type used for the alpha channel.

Trait Implementations§

source§

impl<T> Add<T> for RGBA<T>where T: Copy + Add<Output = T>,

px + 1

§

type Output = RGBA<T>

The resulting type after applying the + operator.
source§

fn add(self, r: T) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Add, A: Add> Add for RGBA<T, A>

px + px

§

type Output = RGBA<<T as Add>::Output, <A as Add>::Output>

The resulting type after applying the + operator.
source§

fn add(self, other: RGBA<T, A>) -> Self::Output

Performs the + operation. Read more
source§

impl<T> AddAssign<T> for RGBA<T>where T: Copy + Add<Output = T>,

px + 1

source§

fn add_assign(&mut self, r: T)

Performs the += operation. Read more
source§

impl<T, A> AddAssign for RGBA<T, A>where T: Add<Output = T> + Copy, A: Add<Output = A> + Copy,

px + px

source§

fn add_assign(&mut self, other: RGBA<T, A>)

Performs the += operation. Read more
source§

impl<T> AsMut<[T]> for RGBA<T>

source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T> AsPixels<RGBA<T>> for [T]

source§

fn as_pixels(&self) -> &[RGBA<T>]

Reinterpret the slice as a read-only/shared slice of pixels. Multiple consecutive elements in the slice are intepreted as a single pixel (depending on format, e.g. 3 for RGB, 4 for RGBA). Read more
source§

fn as_pixels_mut(&mut self) -> &mut [RGBA<T>]

Reinterpret the slice as a mutable/exclusive slice of pixels. Multiple consecutive elements in the slice are intepreted as a single pixel (depending on format, e.g. 3 for RGB, 4 for RGBA). Read more
source§

impl<T> AsRef<[T]> for RGBA<T>

source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<ComponentType: Clone, AlphaComponentType: Clone> Clone for RGBA<ComponentType, AlphaComponentType>

source§

fn clone(&self) -> RGBA<ComponentType, AlphaComponentType>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Copy, A: Copy, B> ColorComponentMap<RGBA<B, A>, T, B> for RGBA<T, A>

source§

fn map_c<F>(&self, f: F) -> RGBA<B, A>where F: FnMut(T) -> B,

Convenience function for applying the same formula to every rgb/gray component, but skipping the alpha component. Read more
source§

impl<T: Copy, B> ComponentMap<RGBA<B>, T, B> for RGBA<T>

source§

fn map<F>(&self, f: F) -> RGBA<B>where F: FnMut(T) -> B,

Convenience function (equivalent of self.iter().map().collect()) for applying the same formula to every component. Read more
source§

impl<T> ComponentSlice<T> for RGBA<T>

source§

fn as_slice(&self) -> &[T]

The components interpreted as an array, e.g. one RGB expands to 3 elements. Read more
source§

fn as_mut_slice(&mut self) -> &mut [T]

The components interpreted as a mutable array, e.g. one RGB expands to 3 elements. Read more
source§

impl<ComponentType: Debug, AlphaComponentType: Debug> Debug for RGBA<ComponentType, AlphaComponentType>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<ComponentType: Default, AlphaComponentType: Default> Default for RGBA<ComponentType, AlphaComponentType>

source§

fn default() -> RGBA<ComponentType, AlphaComponentType>

Returns the “default value” for a type. Read more
source§

impl<'de, ComponentType, AlphaComponentType> Deserialize<'de> for RGBA<ComponentType, AlphaComponentType>where ComponentType: Deserialize<'de>, AlphaComponentType: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: Display, A: Display> Display for RGBA<T, A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Div<T> for RGBA<T>where T: Copy + Div<Output = T>,

px / 1

§

type Output = RGBA<T>

The resulting type after applying the / operator.
source§

fn div(self, r: T) -> Self::Output

Performs the / operation. Read more
source§

impl<T> DivAssign<T> for RGBA<T>where T: Copy + Div<Output = T>,

px * 1

source§

fn div_assign(&mut self, r: T)

Performs the /= operation. Read more
source§

impl<T: Copy> From<[T; 4]> for RGBA<T>

source§

fn from(other: [T; 4]) -> Self

Converts to this type from the input type.
source§

impl<T, A> From<(T, T, T, A)> for RGBA<T, A>

source§

fn from(other: (T, T, T, A)) -> Self

Converts to this type from the input type.
source§

impl<T> From<ABGR<T>> for RGBA<T>where T: Clone,

source§

fn from(other: ABGR<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<ARGB<T>> for RGBA<T>where T: Clone,

source§

fn from(other: ARGB<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Copy> From<BGR<T>> for RGBA<T, u16>

Assumes 65535 is opaque

source§

fn from(other: BGR<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Copy> From<BGR<T>> for RGBA<T, u8>

Assumes 255 is opaque

source§

fn from(other: BGR<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<BGRA<T>> for RGBA<T>where T: Clone,

source§

fn from(other: BGRA<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Clone> From<Gray<T>> for RGBA<T, u8>

source§

fn from(other: Gray<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Clone, A> From<GrayAlpha<T, A>> for RGBA<T, A>

source§

fn from(other: GrayAlpha<T, A>) -> Self

Converts to this type from the input type.
source§

impl<T: Copy> From<RGB<T>> for RGBA<T, u16>

Assumes 65535 is opaque

source§

fn from(other: RGB<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Copy> From<RGB<T>> for RGBA<T, u8>

Assumes 255 is opaque

source§

fn from(other: RGB<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<RGBA<T>> for ABGR<T>where T: Clone,

source§

fn from(other: RGBA<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<RGBA<T>> for ARGB<T>where T: Clone,

source§

fn from(other: RGBA<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<RGBA<T>> for BGRA<T>where T: Clone,

source§

fn from(other: RGBA<T>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<f32>> for RGBA<f64>

source§

fn from(other: RGBA<f32>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<i16>> for RGBA<f32>

source§

fn from(other: RGBA<i16>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<i16>> for RGBA<f64>

source§

fn from(other: RGBA<i16>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<i32>> for RGBA<f64>

source§

fn from(other: RGBA<i32>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u16>> for RGBA<f32>

source§

fn from(other: RGBA<u16>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u16>> for RGBA<f64>

source§

fn from(other: RGBA<u16>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u16>> for RGBA<i32>

source§

fn from(other: RGBA<u16>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u16>> for RGBA<u32>

source§

fn from(other: RGBA<u16>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u16>> for RGBA<u64>

source§

fn from(other: RGBA<u16>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u8>> for RGBA<f32>

source§

fn from(other: RGBA<u8>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u8>> for RGBA<f64>

source§

fn from(other: RGBA<u8>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u8>> for RGBA<i16>

source§

fn from(other: RGBA<u8>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u8>> for RGBA<u16>

source§

fn from(other: RGBA<u8>) -> Self

Converts to this type from the input type.
source§

impl From<RGBA<u8>> for RGBA<u32>

source§

fn from(other: RGBA<u8>) -> Self

Converts to this type from the input type.
source§

impl<T> FromIterator<T> for RGBA<T>

source§

fn from_iter<I: IntoIterator<Item = T>>(into_iter: I) -> Self

Takes exactly 4 elements from the iterator and creates a new instance. Panics if there are fewer elements in the iterator.

source§

impl<ComponentType: Hash, AlphaComponentType: Hash> Hash for RGBA<ComponentType, AlphaComponentType>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T> Into<[T; 4]> for RGBA<T>

source§

fn into(self) -> [T; 4]

Converts this type into the (usually inferred) input type.
source§

impl<T, A> Into<(T, T, T, A)> for RGBA<T, A>

source§

fn into(self) -> (T, T, T, A)

Converts this type into the (usually inferred) input type.
source§

impl<T> Mul<T> for RGBA<T>where T: Copy + Mul<Output = T>,

px * 1

§

type Output = RGBA<T>

The resulting type after applying the * operator.
source§

fn mul(self, r: T) -> Self::Output

Performs the * operation. Read more
source§

impl<T> MulAssign<T> for RGBA<T>where T: Copy + Mul<Output = T>,

px * 1

source§

fn mul_assign(&mut self, r: T)

Performs the *= operation. Read more
source§

impl<ComponentType: Ord, AlphaComponentType: Ord> Ord for RGBA<ComponentType, AlphaComponentType>

source§

fn cmp(&self, other: &RGBA<ComponentType, AlphaComponentType>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<ComponentType: PartialEq, AlphaComponentType: PartialEq> PartialEq for RGBA<ComponentType, AlphaComponentType>

source§

fn eq(&self, other: &RGBA<ComponentType, AlphaComponentType>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<ComponentType: PartialOrd, AlphaComponentType: PartialOrd> PartialOrd for RGBA<ComponentType, AlphaComponentType>

source§

fn partial_cmp( &self, other: &RGBA<ComponentType, AlphaComponentType> ) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<ComponentType, AlphaComponentType> Serialize for RGBA<ComponentType, AlphaComponentType>where ComponentType: Serialize, AlphaComponentType: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T> Sub<T> for RGBA<T>where T: Copy + Sub<Output = T>,

px - 1

§

type Output = RGBA<<T as Sub>::Output>

The resulting type after applying the - operator.
source§

fn sub(self, r: T) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Sub, A: Sub> Sub for RGBA<T, A>

px - px

§

type Output = RGBA<<T as Sub>::Output, <A as Sub>::Output>

The resulting type after applying the - operator.
source§

fn sub(self, other: RGBA<T, A>) -> Self::Output

Performs the - operation. Read more
source§

impl<T> SubAssign<T> for RGBA<T>where T: Copy + Sub<Output = T>,

px - 1

source§

fn sub_assign(&mut self, r: T)

Performs the -= operation. Read more
source§

impl<T, A> SubAssign for RGBA<T, A>where T: Sub<Output = T> + Copy, A: Sub<Output = A> + Copy,

px - px

source§

fn sub_assign(&mut self, other: RGBA<T, A>)

Performs the -= operation. Read more
source§

impl<T, A> Sum for RGBA<T, A>where T: Default + Add<Output = T>, A: Default + Add<Output = A>,

source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl<T, A> Zeroable for RGBA<T, A>where T: Zeroable, A: Zeroable,

source§

fn zeroed() -> Self

source§

impl<ComponentType: Copy, AlphaComponentType: Copy> Copy for RGBA<ComponentType, AlphaComponentType>

source§

impl<ComponentType: Eq, AlphaComponentType: Eq> Eq for RGBA<ComponentType, AlphaComponentType>

source§

impl<T, A> Pod for RGBA<T, A>where T: Pod, A: Pod,

source§

impl<ComponentType, AlphaComponentType> StructuralEq for RGBA<ComponentType, AlphaComponentType>

source§

impl<ComponentType, AlphaComponentType> StructuralPartialEq for RGBA<ComponentType, AlphaComponentType>

Auto Trait Implementations§

§

impl<ComponentType, AlphaComponentType> RefUnwindSafe for RGBA<ComponentType, AlphaComponentType>where AlphaComponentType: RefUnwindSafe, ComponentType: RefUnwindSafe,

§

impl<ComponentType, AlphaComponentType> Send for RGBA<ComponentType, AlphaComponentType>where AlphaComponentType: Send, ComponentType: Send,

§

impl<ComponentType, AlphaComponentType> Sync for RGBA<ComponentType, AlphaComponentType>where AlphaComponentType: Sync, ComponentType: Sync,

§

impl<ComponentType, AlphaComponentType> Unpin for RGBA<ComponentType, AlphaComponentType>where AlphaComponentType: Unpin, ComponentType: Unpin,

§

impl<ComponentType, AlphaComponentType> UnwindSafe for RGBA<ComponentType, AlphaComponentType>where AlphaComponentType: UnwindSafe, ComponentType: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,