Enum ExtendedColorType

#[non_exhaustive]
pub enum ExtendedColorType

An enumeration of color types encountered in image formats.

This is not exhaustive over all existing image formats but should be granular enough to allow round tripping of decoding and encoding as much as possible. The variants will be extended as necessary to enable this.

Another purpose is to advise users of a rough estimate of the accuracy and effort of the decoding from and encoding to such an image format.

Variants

A8

Pixel is 8-bit alpha

L1

Pixel is 1-bit luminance

La1

Pixel is 1-bit luminance with an alpha channel

Rgb1

Pixel contains 1-bit R, G and B channels

Rgba1

Pixel is 1-bit RGB with an alpha channel

L2

Pixel is 2-bit luminance

La2

Pixel is 2-bit luminance with an alpha channel

Rgb2

Pixel contains 2-bit R, G and B channels

Rgba2

Pixel is 2-bit RGB with an alpha channel

L4

Pixel is 4-bit luminance

La4

Pixel is 4-bit luminance with an alpha channel

Rgb4

Pixel contains 4-bit R, G and B channels

Rgba4

Pixel is 4-bit RGB with an alpha channel

Rgb5x1

Pixel contains 5-bit R, G and B channels packed into 2 bytes

L8

Pixel is 8-bit luminance

La8

Pixel is 8-bit luminance with an alpha channel

Rgb8

Pixel contains 8-bit R, G and B channels

Rgba8

Pixel is 8-bit RGB with an alpha channel

L16

Pixel is 16-bit luminance

La16

Pixel is 16-bit luminance with an alpha channel

Rgb16

Pixel contains 16-bit R, G and B channels

Rgba16

Pixel is 16-bit RGB with an alpha channel

Bgr8

Pixel contains 8-bit B, G and R channels

Bgra8

Pixel is 8-bit BGR with an alpha channel

Rgb32F

Pixel is 32-bit float RGB

Rgba32F

Pixel is 32-bit float RGBA

Cmyk8

Pixel is 8-bit CMYK

Cmyk16

Pixel is 16-bit CMYK

Unknown(u8)

Pixel is of unknown color type with the specified bits per pixel. This can apply to pixels which are associated with an external palette. In that case, the pixel value is an index into the palette.

Implementations

impl ExtendedColorType

fn channel_count(self) -> u8

Get the number of channels for colors of this type.

Note that the Unknown variant returns a value of 1 since pixels can only be treated as an opaque datum by the library.

fn bits_per_pixel(&self) -> u16

Returns the number of bits per pixel for this color type.

fn color_type(&self) -> Option<ColorType>

Returns the ColorType that is equivalent to this ExtendedColorType.

Example

use image::{ColorType, ExtendedColorType};

assert_eq!(Some(ColorType::L8), ExtendedColorType::L8.color_type());
assert_eq!(None, ExtendedColorType::L1.color_type());

The method is equivalent to converting via the TryFrom/TryInto traits except for the error path. Choose the more ergonomic option in your usage.

use image::{ColorType, ExtendedColorType, ImageError};

fn handle_errors() -> Result<(), ImageError> {
    let color: ColorType = ExtendedColorType::L8.try_into()?;
    assert_eq!(color, ColorType::L8);
    # Ok(())
}

Trait Implementations

impl Clone for ExtendedColorType

fn clone(&self) -> ExtendedColorType

impl Copy for ExtendedColorType

impl Debug for ExtendedColorType

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

impl Eq for ExtendedColorType

impl From<ColorType> for ExtendedColorType

fn from(c: ColorType) -> Self

impl Hash for ExtendedColorType

fn hash<__H: Hasher>(&self, state: &mut __H)

impl PartialEq for ExtendedColorType

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

impl StructuralPartialEq for ExtendedColorType

Auto Trait Implementations

impl Freeze for ExtendedColorType

impl RefUnwindSafe for ExtendedColorType

impl Send for ExtendedColorType

impl Sync for ExtendedColorType

impl Unpin for ExtendedColorType

impl UnsafeUnpin for ExtendedColorType

impl UnwindSafe for ExtendedColorType

Blanket Implementations

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for ExtendedColorType where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for ExtendedColorType where ST: ?Sized, DT: ?Sized,

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ExtendedColorType where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ExtendedColorType where T: ?Sized,

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

impl<T> CloneToUninit for ExtendedColorType where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for ExtendedColorType

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> IntoEither for ExtendedColorType

impl<T> Pointable for ExtendedColorType

const ALIGN: usize = _;
type Init = T;
unsafe fn init(init: <T as Pointable>::Init) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)

impl<T> Read<Exclusive, BecauseExclusive> for ExtendedColorType where T: ?Sized,

impl<T> ToOwned for ExtendedColorType where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for ExtendedColorType where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for ExtendedColorType where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for ExtendedColorType where U: TryFrom<T>,

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