Skip to main content

Srgba

Struct Srgba 

Source
pub struct Srgba {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}
Expand description

A unified sRGBA color type for use across all render backends.

Srgba provides a single type that can create colors for any renderer: SVG (CSS hex), ANSI (escape codes), EPS/PDF (0.0–1.0 arrays), image (Rgba<u8>).

§Example

use qrcode_render::colors::Srgba;

let c = Srgba::from_hex("#ff0080").unwrap();
assert_eq!(c.to_hex(), "#ff0080");
assert_eq!(c.to_css(), "rgba(255,0,128,255)");
let arr = c.to_array();
assert!((arr[0] - 1.0).abs() < 0.001);

Fields§

§r: u8

Red component.

§g: u8

Green component.

§b: u8

Blue component.

§a: u8

Alpha component (0 = transparent, 255 = opaque).

Implementations§

Source§

impl Srgba

Source

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

Creates a new sRGBA color.

Source

pub const fn rgb(r: u8, g: u8, b: u8) -> Self

Creates a fully opaque sRGBA color.

Source

pub fn from_hex(hex: &str) -> Option<Self>

Parses a hex color string (#rgb, #rgba, #rrggbb, #rrggbbaa).

Source

pub fn to_hex(self) -> String

Converts to a CSS hex string (e.g., "#ff0080" or "#ff0080c0" if alpha < 255).

Source

pub fn to_css(self) -> String

Converts to a CSS rgba() function string.

Source

pub fn to_ansi_fg(self) -> String

Converts to an ANSI foreground escape sequence (\x1b[38;2;R;G;Bm).

Source

pub fn to_ansi_bg(self) -> String

Converts to an ANSI background escape sequence (\x1b[48;2;R;G;Bm).

Source

pub fn to_array(self) -> [f64; 3]

Converts to a [f64; 3] array with values in 0.0–1.0, suitable for EPS/PDF renderers.

Source

pub fn lerp(self, other: Self, t: f32) -> Self

Linearly interpolates between self and other.

t = 0.0 returns self, t = 1.0 returns other.

Trait Implementations§

Source§

impl Clone for Srgba

Source§

fn clone(&self) -> Srgba

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Srgba

Source§

impl Debug for Srgba

Source§

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

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

impl Eq for Srgba

Source§

impl From<(u8, u8, u8)> for Srgba

Source§

fn from((r, g, b): (u8, u8, u8)) -> Self

Converts to this type from the input type.
Source§

impl From<(u8, u8, u8, u8)> for Srgba

Source§

fn from((r, g, b, a): (u8, u8, u8, u8)) -> Self

Converts to this type from the input type.
Source§

impl From<RgbColor> for Srgba

Source§

fn from(color: RgbColor) -> Self

Converts to this type from the input type.
Source§

impl From<Srgba> for RgbColor

Source§

fn from(color: Srgba) -> Self

Converts to this type from the input type.
Source§

impl From<Srgba> for (u8, u8, u8, u8)

Source§

fn from(c: Srgba) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Srgba

Source§

fn eq(&self, other: &Srgba) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Srgba

Auto Trait Implementations§

§

impl Freeze for Srgba

§

impl RefUnwindSafe for Srgba

§

impl Send for Srgba

§

impl Sync for Srgba

§

impl Unpin for Srgba

§

impl UnsafeUnpin for Srgba

§

impl UnwindSafe for Srgba

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