Struct pix::Palette

source ·
pub struct Palette { /* private fields */ }
Expand description

Color table for use with indexed Rasters.

Implementations§

source§

impl Palette

source

pub fn new(capacity: usize) -> Self

Create a new color Palette.

  • capacity Maximum number of entries.
source

pub fn len(&self) -> usize

Get the number of entries.

source

pub fn is_empty(&self) -> bool

Check if the palette is empty.

source

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

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

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

Get a slice of all colors.

source

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

Get a Palette entry.

  • i Index of entry.
source

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

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.

source

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

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.

source

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

Create a histogram of Palette entries.

  • ent Slice of entry indices (pixel values).
source

pub fn make_indexed<S>(&mut self, raster: Raster<S>) -> Raster<Gray8>where S: Pixel<Chan = Ch8>, <Pix3<Ch8, Rgb, Straight, Srgb> as Pixel>::Chan: From<S::Chan>,

Make an indexed raster

Trait Implementations§

source§

impl Clone for Palette

source§

fn clone(&self) -> Palette

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

Auto Trait Implementations§

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 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<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.