Skip to main content

ColorMode

Enum ColorMode 

Source
pub enum ColorMode {
Show 13 variants Rgb, Rgba, Bgr, Bgra, Argb, Rgba4444, Rgb565, PremultipliedRgba, PremultipliedBgra, PremultipliedArgb, PremultipliedRgba4444, Yuv, Yuva,
}
Expand description

The layout of the decoded samples (C: WEBP_CSP_MODE, in its order).

Names give the byte order of a pixel; the Premultiplied modes multiply red, green and blue by alpha.

§Examples

use webp::api::decode::ColorMode;

assert_eq!(ColorMode::Bgra.bytes_per_pixel(), Some(4));
assert_eq!(ColorMode::Rgb565.bytes_per_pixel(), Some(2));
assert_eq!(ColorMode::Yuva.bytes_per_pixel(), None);
assert!(ColorMode::PremultipliedArgb.is_premultiplied());

Variants§

§

Rgb

Red, green, blue (C: MODE_RGB).

§

Rgba

Red, green, blue, straight alpha (C: MODE_RGBA).

§

Bgr

Blue, green, red (C: MODE_BGR).

§

Bgra

Blue, green, red, straight alpha (C: MODE_BGRA).

§

Argb

Straight alpha, red, green, blue (C: MODE_ARGB).

§

Rgba4444

Red and green, then blue and straight alpha, 4 bits each, in two bytes (C: MODE_RGBA_4444).

§

Rgb565

Red (5 bits) and green (6 bits), then blue (5 bits), in two bytes (C: MODE_RGB_565).

§

PremultipliedRgba

ColorMode::Rgba with premultiplied alpha (C: MODE_rgbA).

§

PremultipliedBgra

ColorMode::Bgra with premultiplied alpha (C: MODE_bgrA).

§

PremultipliedArgb

ColorMode::Argb with premultiplied alpha (C: MODE_Argb).

§

PremultipliedRgba4444

ColorMode::Rgba4444 with premultiplied alpha (C: MODE_rgbA_4444).

§

Yuv

Y, U and V planes, 4:2:0, limited range (C: MODE_YUV).

§

Yuva

Y, U, V and straight alpha planes (C: MODE_YUVA).

Implementations§

Source§

impl ColorMode

Source

pub const fn bytes_per_pixel(self) -> Option<usize>

The bytes of a pixel in the RGB modes (libwebp’s kModeBpp), or None for the planar YUV modes.

§Examples
use webp::api::decode::ColorMode;

assert_eq!(ColorMode::Rgb.bytes_per_pixel(), Some(3));
assert_eq!(ColorMode::Yuv.bytes_per_pixel(), None);
Source

pub const fn has_alpha(self) -> bool

Whether the output holds alpha (C: WebPIsAlphaMode).

§Examples
use webp::api::decode::ColorMode;

assert!(ColorMode::Yuva.has_alpha());
assert!(!ColorMode::Rgb565.has_alpha());
Source

pub const fn is_premultiplied(self) -> bool

Whether red, green and blue are multiplied by alpha (C: WebPIsPremultipliedMode).

§Examples
use webp::api::decode::ColorMode;

assert!(ColorMode::PremultipliedRgba4444.is_premultiplied());
assert!(!ColorMode::Rgba.is_premultiplied());
Source

pub const fn is_yuv(self) -> bool

Whether the output is planar Y'CbCr (ColorMode::Yuv, ColorMode::Yuva) rather than packed RGB rows.

§Examples
use webp::api::decode::ColorMode;

assert!(ColorMode::Yuv.is_yuv());
assert!(!ColorMode::Argb.is_yuv());

Trait Implementations§

Source§

impl Clone for ColorMode

Source§

fn clone(&self) -> Self

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 ColorMode

Source§

impl Debug for ColorMode

Source§

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

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

impl Eq for ColorMode

Source§

impl Hash for ColorMode

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

Source§

fn eq(&self, other: &Self) -> 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 ColorMode

Auto Trait Implementations§

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.