Struct rgb::RGBA[][src]

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

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

impl<T> RGBA<T>[src]

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

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

impl<T, A> RGBA<T, A>[src]

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

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

impl<T, A> RGBA<T, A>[src]

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

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

impl<T: Clone, A> RGBA<T, A>[src]

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

Copy RGB components out of the RGBA struct

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

impl<T: Clone> RGBA<T>[src]

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

Iterate over all components (length=4)

impl<T: Clone, A> RGBA<T, A>[src]

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

Copy RGB components out of the RGBA struct

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

impl<T: Copy, A: Clone> RGBA<T, A>[src]

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

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

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

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

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

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

impl<T: Add, A: Add> Add<RGBA<T, A>> for RGBA<T, A>[src]

px + px

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

The resulting type after applying the + operator.

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

Performs the + operation. Read more

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

px + 1

type Output = RGBA<T>

The resulting type after applying the + operator.

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

Performs the + operation. Read more

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

px + px

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

Performs the += operation. Read more

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

px + 1

fn add_assign(&mut self, r: T)[src]

Performs the += operation. Read more

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

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

Performs the conversion.

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

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

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

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

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

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

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

Performs the conversion.

impl<ComponentType: Clone, AlphaComponentType: Clone> Clone for RGBA<ComponentType, AlphaComponentType>[src]

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

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

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

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

impl<T: Copy, B> ComponentMap<RGBA<B, B>, T, B> for RGBA<T>[src]

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

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

impl<T> ComponentSlice<T> for RGBA<T>[src]

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

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

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

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

impl<ComponentType: Debug, AlphaComponentType: Debug> Debug for RGBA<ComponentType, AlphaComponentType>[src]

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

Formats the value using the given formatter. Read more

impl<ComponentType: Default, AlphaComponentType: Default> Default for RGBA<ComponentType, AlphaComponentType>[src]

fn default() -> RGBA<ComponentType, AlphaComponentType>[src]

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

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

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

Deserialize this value from the given Serde deserializer. Read more

impl<T: Display, A: Display> Display for RGBA<T, A>[src]

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

Formats the value using the given formatter. Read more

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

px / 1

type Output = RGBA<T>

The resulting type after applying the / operator.

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

Performs the / operation. Read more

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

px * 1

fn div_assign(&mut self, r: T)[src]

Performs the /= operation. Read more

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

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

Performs the conversion.

impl<T, A> From<(T, T, T, A)> for RGBA<T, A>[src]

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

Performs the conversion.

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

Assumes 255 is opaque

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

Performs the conversion.

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

Assumes 65535 is opaque

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

Performs the conversion.

impl<T> From<BGRA<T, T>> for RGBA<T>[src]

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

Performs the conversion.

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

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

Performs the conversion.

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

Assumes 255 is opaque

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

Performs the conversion.

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

Assumes 65535 is opaque

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

Performs the conversion.

impl<T> From<RGBA<T, T>> for BGRA<T>[src]

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

Performs the conversion.

impl From<RGBA<f32, f32>> for RGBA<f64>[src]

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

Performs the conversion.

impl From<RGBA<i16, i16>> for RGBA<f32>[src]

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

Performs the conversion.

impl From<RGBA<i16, i16>> for RGBA<f64>[src]

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

Performs the conversion.

impl From<RGBA<i32, i32>> for RGBA<f64>[src]

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

Performs the conversion.

impl From<RGBA<u16, u16>> for RGBA<i32>[src]

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

Performs the conversion.

impl From<RGBA<u16, u16>> for RGBA<f32>[src]

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

Performs the conversion.

impl From<RGBA<u16, u16>> for RGBA<f64>[src]

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

Performs the conversion.

impl From<RGBA<u8, u8>> for RGBA<f32>[src]

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

Performs the conversion.

impl From<RGBA<u8, u8>> for RGBA<f64>[src]

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

Performs the conversion.

impl<T> FromIterator<T> for RGBA<T>[src]

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

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

impl<ComponentType: Hash, AlphaComponentType: Hash> Hash for RGBA<ComponentType, AlphaComponentType>[src]

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

Feeds this value into the given Hasher. Read more

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

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

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

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

Performs the conversion.

impl<T, A> Into<(T, T, T, A)> for RGBA<T, A>[src]

fn into(self) -> (T, T, T, A)[src]

Performs the conversion.

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

px * 1

type Output = RGBA<T>

The resulting type after applying the * operator.

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

Performs the * operation. Read more

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

px * 1

fn mul_assign(&mut self, r: T)[src]

Performs the *= operation. Read more

impl<ComponentType: Ord, AlphaComponentType: Ord> Ord for RGBA<ComponentType, AlphaComponentType>[src]

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<ComponentType: PartialEq, AlphaComponentType: PartialEq> PartialEq<RGBA<ComponentType, AlphaComponentType>> for RGBA<ComponentType, AlphaComponentType>[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &RGBA<ComponentType, AlphaComponentType>) -> bool[src]

This method tests for !=.

impl<ComponentType: PartialOrd, AlphaComponentType: PartialOrd> PartialOrd<RGBA<ComponentType, AlphaComponentType>> for RGBA<ComponentType, AlphaComponentType>[src]

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

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<ComponentType, AlphaComponentType> Serialize for RGBA<ComponentType, AlphaComponentType> where
    ComponentType: Serialize,
    AlphaComponentType: Serialize
[src]

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

Serialize this value into the given Serde serializer. Read more

impl<T: Sub, A: Sub> Sub<RGBA<T, A>> for RGBA<T, A>[src]

px - px

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

The resulting type after applying the - operator.

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

Performs the - operation. Read more

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

px - 1

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

The resulting type after applying the - operator.

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

Performs the - operation. Read more

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

px - px

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

Performs the -= operation. Read more

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

px - 1

fn sub_assign(&mut self, r: T)[src]

Performs the -= operation. Read more

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

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

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

impl<T, A> Zeroable for RGBA<T, A> where
    T: Zeroable,
    A: Zeroable
[src]

fn zeroed() -> Self[src]

impl<ComponentType: Copy, AlphaComponentType: Copy> Copy for RGBA<ComponentType, AlphaComponentType>[src]

impl<ComponentType: Eq, AlphaComponentType: Eq> Eq for RGBA<ComponentType, AlphaComponentType>[src]

impl<T, A> Pod for RGBA<T, A> where
    T: Pod,
    A: Pod
[src]

impl<ComponentType, AlphaComponentType> StructuralEq for RGBA<ComponentType, AlphaComponentType>[src]

impl<ComponentType, AlphaComponentType> StructuralPartialEq for RGBA<ComponentType, AlphaComponentType>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]