[][src]Struct pix::Palette

pub struct Palette { /* fields omitted */ }

Color table for use with indexed Rasters.

Methods

impl Palette[src]

pub fn new(capacity: usize) -> Self[src]

Create a new color Palette.

  • capacity Maximum number of entries.

pub fn len(&self) -> usize[src]

Get the number of entries.

pub fn is_empty(&self) -> bool[src]

Check if the palette is empty.

pub fn set_threshold_fn(&mut self, threshold_fn: fn(_: usize) -> SRgb8)[src]

Set the threshold function for matching entries.

  • threshold_fn Called when checking whether a color matches an existing entry. The parameter is the palette table size. Returns the maximum Channel-wise difference to match.

pub fn colors(&self) -> &[SRgb8][src]

Get a slice of all colors.

pub fn entry(&self, i: usize) -> Option<SRgb8>[src]

Get a Palette entry.

  • i Index of entry.

pub fn set_entry(&mut self, clr: SRgb8) -> Option<usize>[src]

Set a Palette entry.

The table is searched for the best matching color within the threshold. If none found, a new entry is added.

  • clr Color to lookup or add.

Returns

Index of best matching or added entry if successful. Otherwise, when no matches are found and the table is full, None is returned.

pub fn replace_entry(&mut self, i: usize, clr: SRgb8) -> Option<SRgb8>[src]

Replace a Palette entry.

  • i Index of entry.
  • clr Color to replace entry with.

Returns

Previous entry, or None if index is larger than table size.

pub fn histogram<T>(&self, ent: &[T]) -> Option<Vec<usize>> where
    T: Copy,
    usize: From<T>, 
[src]

Create a histogram of Palette entries.

  • ent Slice of entry indices (pixel values).

Trait Implementations

impl Clone for Palette[src]

Auto Trait Implementations

impl RefUnwindSafe for Palette

impl Send for Palette

impl Sync for Palette

impl Unpin for Palette

impl UnwindSafe for Palette

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.