Struct pix::Palette

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

Color table for use with indexed Rasters.

Implementations

Create a new color Palette.

  • capacity Maximum number of entries.

Get the number of entries.

Check if the palette is empty.

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.

Get a slice of all colors.

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.

Create a histogram of Palette entries.

  • ent Slice of entry indices (pixel values).

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.