Struct RGBA

Source
#[repr(C)]
pub struct RGBA<T, A = T> { pub r: T, pub g: T, pub b: T, pub a: A, }
Expand description

A Red + Green + Blue + Alpha pixel.

§Examples

use rgb::Rgba;

let pixel: Rgba<u8> = Rgba { r: 0, g: 0, b: 0, a: 255 };

Fields§

§r: T

Red Component

§g: T

Green Component

§b: T

Blue Component

§a: A

Alpha Component

Implementations§

Source§

impl<T> Rgba<T>
where T: Copy,

Source

pub const fn new(red: T, green: T, blue: T, alpha: T) -> Rgba<T>

Creates a new Rgba pixel type from its components.

Alternatively, you can use struct literal syntax to create the new pixel type:

use rgb::Rgba;

let pixel = Rgba {r : red, g : green, b : blue, a : alpha};
Source§

impl<T, A> Rgba<T, A>

Source

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

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, A> Rgba<T, A>
where T: Clone,

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> Rgba<T>
where T: Clone,

Source

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

Iterate over all components (length=4)

Source§

impl<T, A> Rgba<T, A>
where T: Clone,

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, A> Rgba<T, A>
where T: Copy, A: Clone,

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,

👎Deprecated: Renamed to map_colors()

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

Source

pub fn with_alpha(&self, a: A) -> Rgba<T, A>

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

Source§

type Output = Rgba<T>

The resulting type after applying the + operator.
Source§

fn add(self, r: T) -> <Rgba<T> as Add<T>>::Output

Performs the + operation. Read more
Source§

impl<T, A> Add for Rgba<T, A>
where T: Add, A: Add,

px + px

Source§

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>) -> <Rgba<T, A> as Add>::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§

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<T, A> Clone for Rgba<T, A>
where T: Clone, A: Clone,

Source§

fn clone(&self) -> Rgba<T, A>

Returns a duplicate 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, A, B> ColorComponentMap<Rgba<B, A>, T, B> for Rgba<T, A>
where T: Copy, A: Copy,

Source§

fn map_colors<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§

fn map_c<Callback>(&self, f: Callback) -> DestPixel
where Callback: FnMut(SrcComponent) -> DestComponent,

👎Deprecated: renamed to map_colors
Alias of map_colors
Source§

impl<T, B> ComponentMap<Rgba<B>, T, B> for Rgba<T>
where T: Copy,

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<T, A> Debug for Rgba<T, A>
where T: Debug, A: Debug,

Source§

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

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

impl<T, A> Default for Rgba<T, A>
where T: Default, A: Default,

Source§

fn default() -> Rgba<T, A>

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

impl<T, A> Display for Rgba<T, A>
where T: Display, A: Display,

Source§

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

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

Source§

type Output = Rgba<T>

The resulting type after applying the / operator.
Source§

fn div(self, r: T) -> <Rgba<T> as Div<T>>::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> From<[T; 4]> for Rgba<T>
where T: Copy,

Source§

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

Converts to this type from the input type.
Source§

impl<R, S> From<(R, R, R, R)> for Rgba<S>
where R: Into<S>,

Source§

fn from(value: (R, R, R, R)) -> Rgba<S>

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>) -> Rgba<T>

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>) -> Rgba<T>

Converts to this type from the input type.
Source§

impl<T> From<Bgr<T>> for Rgba<T, u16>
where T: Copy,

Assumes 65535 is opaque

Source§

fn from(other: Bgr<T>) -> Rgba<T, u16>

Converts to this type from the input type.
Source§

impl<T> From<Bgr<T>> for Rgba<T, u8>
where T: Copy,

Assumes 255 is opaque

Source§

fn from(other: Bgr<T>) -> Rgba<T, u8>

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>) -> Rgba<T>

Converts to this type from the input type.
Source§

impl<T, A> From<GrayAlpha_v08<T, A>> for Rgba<T, A>
where T: Clone,

Source§

fn from(other: GrayAlpha_v08<T, A>) -> Rgba<T, A>

Converts to this type from the input type.
Source§

impl<T> From<Gray_v08<T>> for Rgba<T, u8>
where T: Clone,

Source§

fn from(other: Gray_v08<T>) -> Rgba<T, u8>

Converts to this type from the input type.
Source§

impl<T> From<Rgb<T>> for Rgba<T, u16>
where T: Copy,

Assumes 65535 is opaque

Source§

fn from(other: Rgb<T>) -> Rgba<T, u16>

Converts to this type from the input type.
Source§

impl<T> From<Rgb<T>> for Rgba<T, u8>
where T: Copy,

Assumes 255 is opaque

Source§

fn from(other: Rgb<T>) -> Rgba<T, u8>

Converts to this type from the input type.
Source§

impl From<Rgba<f32>> for Rgba<f64>

Source§

fn from(other: Rgba<f32>) -> Rgba<f64>

Converts to this type from the input type.
Source§

impl From<Rgba<i16>> for Rgba<f32>

Source§

fn from(other: Rgba<i16>) -> Rgba<f32>

Converts to this type from the input type.
Source§

impl From<Rgba<i16>> for Rgba<f64>

Source§

fn from(other: Rgba<i16>) -> Rgba<f64>

Converts to this type from the input type.
Source§

impl From<Rgba<i32>> for Rgba<f64>

Source§

fn from(other: Rgba<i32>) -> Rgba<f64>

Converts to this type from the input type.
Source§

impl From<Rgba<u16>> for Rgba<f32>

Source§

fn from(other: Rgba<u16>) -> Rgba<f32>

Converts to this type from the input type.
Source§

impl From<Rgba<u16>> for Rgba<f64>

Source§

fn from(other: Rgba<u16>) -> Rgba<f64>

Converts to this type from the input type.
Source§

impl From<Rgba<u16>> for Rgba<i32>

Source§

fn from(other: Rgba<u16>) -> Rgba<i32>

Converts to this type from the input type.
Source§

impl From<Rgba<u16>> for Rgba<u32>

Source§

fn from(other: Rgba<u16>) -> Rgba<u32>

Converts to this type from the input type.
Source§

impl From<Rgba<u16>> for Rgba<u64>

Source§

fn from(other: Rgba<u16>) -> Rgba<u64>

Converts to this type from the input type.
Source§

impl From<Rgba<u8>> for Rgba<f32>

Source§

fn from(other: Rgba<u8>) -> Rgba<f32>

Converts to this type from the input type.
Source§

impl From<Rgba<u8>> for Rgba<f64>

Source§

fn from(other: Rgba<u8>) -> Rgba<f64>

Converts to this type from the input type.
Source§

impl From<Rgba<u8>> for Rgba<i16>

Source§

fn from(other: Rgba<u8>) -> Rgba<i16>

Converts to this type from the input type.
Source§

impl From<Rgba<u8>> for Rgba<u16>

Source§

fn from(other: Rgba<u8>) -> Rgba<u16>

Converts to this type from the input type.
Source§

impl From<Rgba<u8>> for Rgba<u32>

Source§

fn from(other: Rgba<u8>) -> Rgba<u32>

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for Rgba<T>

Source§

fn from_iter<I>(into_iter: I) -> Rgba<T>
where I: IntoIterator<Item = T>,

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

Source§

impl<T, A> Hash for Rgba<T, A>
where T: Hash, A: Hash,

Source§

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

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> Mul<T> for Rgba<T>
where T: Copy + Mul<Output = T>,

px * 1

Source§

type Output = Rgba<T>

The resulting type after applying the * operator.
Source§

fn mul(self, r: T) -> <Rgba<T> as Mul<T>>::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<T, A> Ord for Rgba<T, A>
where T: Ord, A: Ord,

Source§

fn cmp(&self, other: &Rgba<T, A>) -> Ordering

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl<T, A> PartialEq for Rgba<T, A>
where T: PartialEq, A: PartialEq,

Source§

fn eq(&self, other: &Rgba<T, A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, A> PartialOrd for Rgba<T, A>
where T: PartialOrd, A: PartialOrd,

Source§

fn partial_cmp(&self, other: &Rgba<T, A>) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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

px - 1

Source§

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

The resulting type after applying the - operator.
Source§

fn sub(self, r: T) -> <Rgba<T> as Sub<T>>::Output

Performs the - operation. Read more
Source§

impl<T, A> Sub for Rgba<T, A>
where T: Sub, A: Sub,

px - px

Source§

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>) -> <Rgba<T, A> as Sub>::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>(iter: I) -> Rgba<T, A>
where I: Iterator<Item = Rgba<T, A>>,

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,

This is unsound. You can disable as-bytes feature, enable bytemuck, and use bytemuck::cast_slice() instead.

Source§

fn zeroed() -> Rgba<T, A>

Source§

impl<T, A> Copy for Rgba<T, A>
where T: Copy, A: Copy,

Source§

impl<T, A> Eq for Rgba<T, A>
where T: Eq, A: Eq,

Source§

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

This is unsound. You can disable as-bytes feature, enable bytemuck, and use bytemuck::cast_slice() instead.

Source§

impl<T, A> StructuralPartialEq for Rgba<T, A>

Auto Trait Implementations§

§

impl<T, A> Freeze for Rgba<T, A>
where T: Freeze, A: Freeze,

§

impl<T, A> RefUnwindSafe for Rgba<T, A>

§

impl<T, A> Send for Rgba<T, A>
where T: Send, A: Send,

§

impl<T, A> Sync for Rgba<T, A>
where T: Sync, A: Sync,

§

impl<T, A> Unpin for Rgba<T, A>
where T: Unpin, A: Unpin,

§

impl<T, A> UnwindSafe for Rgba<T, A>
where T: UnwindSafe, A: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

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.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,