pub struct PaletteCounts<Color> { /* private fields */ }Expand description
A palette of colors and their corresponding counts.
Certain algorithms are faster when operating on deduplicated data,
in which case PaletteCounts will be a supported input. To create
a PaletteCounts, see the dedup module or PaletteCounts::new.
Implementations§
Source§impl<Color> PaletteCounts<Color>
impl<Color> PaletteCounts<Color>
Sourcepub fn new(
palette: Vec<Color>,
counts: Vec<u32>,
) -> Result<Self, CreatePaletteCountsError<Color>>
pub fn new( palette: Vec<Color>, counts: Vec<u32>, ) -> Result<Self, CreatePaletteCountsError<Color>>
Create a new PaletteCounts from a Vec of palette colors
and a Vec of corresponding counts.
§Errors
The provided palette and counts are returned as an Err if any of the following are true:
- The length of
paletteandcountsdo not match. - The sum of
countsis greater thanMAX_PIXELS(overflows au32).
Sourcepub fn into_parts(self) -> (Vec<Color>, Vec<u32>)
pub fn into_parts(self) -> (Vec<Color>, Vec<u32>)
Consume a PaletteCounts and return the inner Vec of palette colors
and Vec of counts.
Sourcepub fn palette(&self) -> &[Color]
pub fn palette(&self) -> &[Color]
Returns a slice of the inner palette colors.
To get a mutable slice, see palette_mut.
To get an owned Vec, see into_parts.
Sourcepub fn palette_mut(&mut self) -> &mut [Color]
pub fn palette_mut(&mut self) -> &mut [Color]
Returns a mutable slice of the inner palette colors.
To get an immutable slice, see palette.
To get an owned Vec, see into_parts.
Sourcepub fn counts(&self) -> &[u32]
pub fn counts(&self) -> &[u32]
Returns a slice of the inner counts.
To get an owned Vec, see into_parts.
Sourcepub fn total_count(&self) -> u32
pub fn total_count(&self) -> u32
Returns the sum of the counts for all palette colors.
This operation is O(1). The total count is calculated on creation and never changes.
Sourcepub fn replace_palette<NewColor>(
self,
palette: Vec<NewColor>,
) -> Result<(PaletteCounts<NewColor>, Vec<Color>), (Self, Vec<NewColor>)>
pub fn replace_palette<NewColor>( self, palette: Vec<NewColor>, ) -> Result<(PaletteCounts<NewColor>, Vec<Color>), (Self, Vec<NewColor>)>
Replace the palette of a PaletteCounts to a different color type (or to new colors
of the same type).
§Errors
If the length of the provided palette does not match the length of the current palette
in the PaletteCounts, then self and palette are returned as an Err. Otherwise,
the new PaletteCounts is returned alongside the old palette.
Sourcepub fn map<NewColor>(
self,
mapping: impl FnOnce(Vec<Color>) -> Vec<NewColor>,
) -> PaletteCounts<NewColor>
pub fn map<NewColor>( self, mapping: impl FnOnce(Vec<Color>) -> Vec<NewColor>, ) -> PaletteCounts<NewColor>
Map the palette of a PaletteCounts, reusing the existing counts.
See map_ref to instead clone the existing counts
and retain the original PaletteCounts.
Rather than being a function from Color -> NewColor, mapping takes the whole palette
as input and returns a new palette. This is to allow batch or parallel mappings.
§Examples
It is recommended to do batch mappings for efficiency where it makes sense. E.g., using the
color space conversion functions from the color_space module.
use quantette::color_space::srgb8_to_oklab;
let srgb_counts = PaletteCounts::<Srgb<u8>>::default();
let oklab_counts = srgb_counts.map(|palette| srgb8_to_oklab(&palette));To instead map each color one at a time, use into_iter, map, and collect like normal:
let srgb_counts = PaletteCounts::<Srgb<u8>>::default();
let lin_srgb_counts: PaletteCounts<LinSrgb> =
srgb_counts.map(|palette| palette.into_iter().map(|srgb| srgb.into_linear()).collect());§Panics
Panics if mapping returns a palette with a different length than the original palette.
Sourcepub fn map_ref<NewColor>(
&self,
mapping: impl FnOnce(&[Color]) -> Vec<NewColor>,
) -> PaletteCounts<NewColor>
pub fn map_ref<NewColor>( &self, mapping: impl FnOnce(&[Color]) -> Vec<NewColor>, ) -> PaletteCounts<NewColor>
Map the palette colors of a PaletteCounts to a new PaletteCounts,
cloning the counts in the process.
See map to instead consume the original PaletteCounts
and avoid a clone of the counts.
Rather than being a function from Color -> NewColor, mapping takes the whole palette
as input and returns a new palette. This is to allow batch or parallel mappings.
§Examples
It is recommended to do batch mappings for efficiency where it makes sense. E.g., using the
color space conversion functions from the color_space module.
use quantette::color_space::srgb8_to_oklab;
let srgb_counts = PaletteCounts::<Srgb<u8>>::default();
let oklab_counts = srgb_counts.map_ref(srgb8_to_oklab);To instead map each color one at a time, use iter, map, and collect like normal:
let srgb_counts = PaletteCounts::<Srgb<u8>>::default();
let lin_srgb_counts: PaletteCounts<LinSrgb> =
srgb_counts.map_ref(|palette| palette.iter().map(|srgb| srgb.into_linear()).collect());§Panics
Panics if mapping returns a palette with a different length than the original palette.
Trait Implementations§
Source§impl<Color: Clone> Clone for PaletteCounts<Color>
impl<Color: Clone> Clone for PaletteCounts<Color>
Source§fn clone(&self) -> PaletteCounts<Color>
fn clone(&self) -> PaletteCounts<Color>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Color: Debug> Debug for PaletteCounts<Color>
impl<Color: Debug> Debug for PaletteCounts<Color>
Source§impl<Color> Default for PaletteCounts<Color>
impl<Color> Default for PaletteCounts<Color>
Source§impl<Color: Hash> Hash for PaletteCounts<Color>
impl<Color: Hash> Hash for PaletteCounts<Color>
Source§impl<Color: PartialEq> PartialEq for PaletteCounts<Color>
impl<Color: PartialEq> PartialEq for PaletteCounts<Color>
impl<Color: Eq> Eq for PaletteCounts<Color>
impl<Color> StructuralPartialEq for PaletteCounts<Color>
Auto Trait Implementations§
impl<Color> Freeze for PaletteCounts<Color>
impl<Color> RefUnwindSafe for PaletteCounts<Color>where
Color: RefUnwindSafe,
impl<Color> Send for PaletteCounts<Color>where
Color: Send,
impl<Color> Sync for PaletteCounts<Color>where
Color: Sync,
impl<Color> Unpin for PaletteCounts<Color>where
Color: Unpin,
impl<Color> UnwindSafe for PaletteCounts<Color>where
Color: UnwindSafe,
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more