Struct rdenticon::Rgb

source ·
pub struct Rgb {
    pub r: u8,
    pub g: u8,
    pub b: u8,
}
Expand description

Represents an RGB pixel.

Fields§

§r: u8

The red component of the pixel.

§g: u8

The green component of the pixel.

§b: u8

The blue component of the pixel.

Implementations§

source§

impl Rgb

source

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

Creates a new RGB pixel.

source

pub fn from_hex(hex: impl AsRef<str>) -> Result<Rgb, Error>

Parses an RGB pixel from a hex value.

The hex value can be in one of the following formats:

  • RRGGBB
  • RGB

These can be optionally padded with #, for example “#FF0000” is the same as as “FF0000”.

Errors
  • Received a malformed hex code.
source

pub const fn black() -> Rgb

Creates a completely black pixel.

source

pub const fn white() -> Rgb

Creates a completely white pixel.

Trait Implementations§

source§

impl Clone for Rgb

source§

fn clone(&self) -> Rgb

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 Debug for Rgb

source§

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

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

impl Default for Rgb

source§

fn default() -> Rgb

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

impl From<BitPixel> for Rgb

source§

fn from(pixel: BitPixel) -> Rgb

Converts to this type from the input type.
source§

impl From<Dynamic> for Rgb

source§

fn from(pixel: Dynamic) -> Rgb

Converts to this type from the input type.
source§

impl From<L> for Rgb

source§

fn from(_: L) -> Rgb

Converts to this type from the input type.
source§

impl From<PalettedRgb<'_>> for Rgb

source§

fn from(pixel: PalettedRgb<'_>) -> Rgb

Converts to this type from the input type.
source§

impl From<PalettedRgba<'_>> for Rgb

source§

fn from(pixel: PalettedRgba<'_>) -> Rgb

Converts to this type from the input type.
source§

impl From<Rgb> for Rgba

source§

fn from(_: Rgb) -> Rgba

Converts to this type from the input type.
source§

impl From<Rgba> for Rgb

source§

fn from(_: Rgba) -> Rgb

Converts to this type from the input type.
source§

impl Hash for Rgb

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 PartialEq<Rgb> for Rgb

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Pixel for Rgb

source§

const COLOR_TYPE: ColorType = ColorType::Rgb

The color type of the pixel.
source§

const BIT_DEPTH: u8 = 8u8

The bit depth of the pixel.
§

type Subpixel = u8

The type of a single component in the pixel.
§

type Color = Rgb

The resolved color type of the palette. This is Self for non-paletted pixels.
§

type Data = [u8; 3]

The iterator type this pixel uses.
source§

fn inverted(&self) -> Rgb

Returns the inverted value of this pixel. Read more
source§

fn map_subpixels<F, A>(self, f: F, _: A) -> Rgbwhere
    F: Fn(<Rgb as Pixel>::Subpixel) -> <Rgb as Pixel>::Subpixel,
    A: Fn(<Rgb as Pixel>::Subpixel) -> <Rgb as Pixel>::Subpixel,

Maps the pixel’s components and returns a new pixel with the mapped components. Read more
source§

fn from_raw_parts_paletted<P>(
    color_type: ColorType,
    bit_depth: u8,
    data: &[u8],
    palette: Option<&[P]>
) -> Result<Rgb, Error>where
    P: Pixel,

Creates this pixel from the given color type, bit depth, data, and possibly a color palette. This may require a lossy xonversion. Read more
source§

fn from_bytes(bytes: &[u8]) -> Rgb

Creates this pixel from a raw bytes. This is used internally and is unchecked - it panics if the data is not of the correct length.
source§

fn as_bytes(&self) -> <Rgb as Pixel>::Data

Turns this pixel into bytes.
source§

fn merge_with_alpha(self, other: Rgb, alpha: u8) -> Rgb

Merges this pixel with the given overlay pixel, where the alpha of the overlay pixel is known. This is used in anti-aliasing.
source§

fn from_dynamic(dynamic: Dynamic) -> Rgb

Creates this pixel from any dynamic pixel, dynamically at runtime. Different from the From/Into traits.
source§

fn as_rgb(&self) -> Rgb

Returns this pixel as RGB despite its type. This can panic on some pixel types, you must be sure this pixel is able to be converted into RGB before using this. Read more
source§

fn as_rgba(&self) -> Rgba

Returns this pixel as RGBA despite its type. This can panic on some pixel types, you must be sure this pixel is able to be converted into RGBA before using this. Read more
source§

fn color_type(&self) -> ColorType

Resolves the color type of this pixel at runtime. This is used for dynamic color types. If you are certain the pixel is not dynamic, you can use the Self::COLOR_TYPE constant instead.
source§

fn luminance(&self) -> u8where
    Self: Into<L>,

The luminance of the pixel.
source§

fn from_raw_parts(
    color_type: ColorType,
    bit_depth: u8,
    data: &[u8]
) -> Result<Self, Error>

Creates this pixel from the given color type, bit depth, and data. This may require a lossy conversion. Read more
source§

fn from_arbitrary_palette<P>(palette: &[P], index: usize) -> Result<Self, Error>where
    P: Pixel,

Creates this pixel from the given palette and index, but the conversion is done at runtime. Read more
source§

fn merge(self, other: Self) -> Self

Merges this pixel with the given overlay pixel, taking into account alpha.
source§

fn overlay(self, other: Self, mode: OverlayMode) -> Self

Overlays this pixel with the given overlay pixel, abiding by the given overlay mode.
source§

fn overlay_with_alpha(self, other: Self, mode: OverlayMode, alpha: u8) -> Self

Overlays this pixel with the given overlay pixel, abiding by the given overlay mode with the given alpha. Read more
source§

impl Copy for Rgb

source§

impl Eq for Rgb

source§

impl StructuralEq for Rgb

source§

impl StructuralPartialEq for Rgb

Auto Trait Implementations§

§

impl RefUnwindSafe for Rgb

§

impl Send for Rgb

§

impl Sync for Rgb

§

impl Unpin for Rgb

§

impl UnwindSafe for Rgb

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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<P> IntoFill for Pwhere
    P: Pixel,

§

type Pixel = P

§

type Fill = SolidFill<<P as IntoFill>::Pixel>

source§

fn into_fill(self) -> <P as IntoFill>::Fill

source§

impl<T> ToOwned for Twhere
    T: Clone,

§

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<P> TrueColor for Pwhere
    P: Pixel + Copy + From<Rgb> + From<Rgba> + Into<Rgb> + Into<Rgba>,

source§

fn as_rgb_tuple(&self) -> (u8, u8, u8)

Returns the pixel as an (r, g, b) tuple.
source§

fn as_rgba_tuple(&self) -> (u8, u8, u8, u8)

Returns the pixel as an (r, g, b, a) tuple.
source§

fn from_rgb_tuple(_: (u8, u8, u8)) -> P

Creates a new pixel from an (r, g, b) tuple.
source§

fn from_rgba_tuple(_: (u8, u8, u8, u8)) -> P

Creates a new pixel from an (r, g, b, a) tuple.
source§

fn into_rgb(self) -> Rgb

Returns the pixel casted into an Rgb pixel.
source§

fn into_rgba(self) -> Rgba

Returns the pixel casted into an Rgba pixel.
source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.