Type Alias palette::rgb::Rgba

source ·
pub type Rgba<S = Srgb, T = f32> = Alpha<Rgb<S, T>, T>;
Expand description

Generic RGB with an alpha component. See the Rgba implementation in Alpha.

Aliased Type§

struct Rgba<S = Srgb, T = f32> {
    pub color: Rgb<S, T>,
    pub alpha: T,
}

Fields§

§color: Rgb<S, T>

The color.

§alpha: T

The transparency component. 0.0 (or 0u8) is fully transparent and 1.0 (or 255u8) is fully opaque.

Implementations§

source§

impl<S> Rgba<S, u8>

source

pub fn into_u32<O>(self) -> u32
where O: ComponentOrder<Rgba<S, u8>, u32>,

Convert to a packed u32 with with specifiable component order.

use palette::{rgb, Srgba};

let integer = Srgba::new(96u8, 127, 0, 255).into_u32::<rgb::channels::Argb>();
assert_eq!(0xFF607F00, integer);

It’s also possible to use From and Into, which defaults to the 0xRRGGBBAA component order:

use palette::Srgba;

let integer = u32::from(Srgba::new(96u8, 127, 0, 255));
assert_eq!(0x607F00FF, integer);

See Packed for more details.

source

pub fn from_u32<O>(color: u32) -> Self
where O: ComponentOrder<Rgba<S, u8>, u32>,

Convert from a packed u32 with specifiable component order.

use palette::{rgb, Srgba};

let rgba = Srgba::from_u32::<rgb::channels::Argb>(0xFF607F00);
assert_eq!(Srgba::new(96u8, 127, 0, 255), rgba);

It’s also possible to use From and Into, which defaults to the 0xRRGGBBAA component order:

use palette::Srgba;

let rgba = Srgba::from(0x607F00FF);
assert_eq!(Srgba::new(96u8, 127, 0, 255), rgba);

See Packed for more details.

Trait Implementations§

source§

impl<S> From<Alpha<Rgb<S>, f32>> for Rgba<S, f64>

source§

fn from(color: Rgba<S, f32>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Alpha<Rgb<S>, f32>> for Rgba<S, u8>

source§

fn from(color: Rgba<S, f32>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Alpha<Rgb<S, f64>, f64>> for Rgba<S, f32>

source§

fn from(color: Rgba<S, f64>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Alpha<Rgb<S, f64>, f64>> for Rgba<S, u8>

source§

fn from(color: Rgba<S, f64>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Alpha<Rgb<S, u8>, u8>> for Rgba<S, f32>

source§

fn from(color: Rgba<S, u8>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Alpha<Rgb<S, u8>, u8>> for Rgba<S, f64>

source§

fn from(color: Rgba<S, u8>) -> Self

Converts to this type from the input type.
source§

impl<S, T, O, P> From<Packed<O, P>> for Rgba<S, T>
where O: ComponentOrder<Rgba<S, T>, P>,

source§

fn from(packed: Packed<O, P>) -> Self

Converts to this type from the input type.
source§

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

source§

fn from(color: u32) -> Self

Converts to this type from the input type.
source§

impl<S> FromStr for Rgba<S, u8>

source§

fn from_str(hex: &str) -> Result<Self, Self::Err>

Parses a color hex code of format ‘#ff00bbff’ or ‘#abcd’ (with or without the leading ‘#’) into a Rgba<S, u8> instance.

§

type Err = FromHexError

The associated error which can be returned from parsing.