rgb

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: Copy> Rgba<T>

source

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

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) -> 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,

👎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) -> 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

source§

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

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>) -> 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§

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

source§

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

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

source§

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

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

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

source§

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

Returns the “default value” for a type. 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

source§

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<R, S> From<(R, R, R, R)> for Rgba<S>
where R: Into<S>,

source§

fn from(value: (R, R, R, R)) -> 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, A> From<GrayAlpha_v08<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: Clone> From<Gray_v08<T>> for Rgba<T, u8>

source§

fn from(other: Gray<T>) -> 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<R, S> From<Rgba<R>> for (S, S, S, S)
where R: Into<S>,

source§

fn from(value: Rgba<R>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Rgba<T>> for [T; 4]

source§

fn from(value: RGBA<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<T: Hash, A: Hash> Hash for Rgba<T, A>

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> 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) -> 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<T: Ord, A: Ord> Ord for Rgba<T, A>

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

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

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) -> Self::Output

Performs the - operation. Read more
source§

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

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

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() -> Self

source§

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

source§

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

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, dst: *mut T)

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

source§

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 T
where 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 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,