Struct ColorMap

Source
#[repr(C)]
pub struct ColorMap { pub table: Vec<TupleInt>, }
Expand description

Represents a map of colors and pixels.

Fields§

§table: Vec<TupleInt>

Implementations§

Source§

impl ColorMap

Source

pub const fn new() -> Self

Creates a new ColorMap.

Source

pub fn with_capacity(cap: usize) -> Self

Creates a new ColorMap with the provided capacity.

Source

pub fn with_colors_and_depth(colors: usize, depth: usize) -> Self

Creates a new ColorMap with colors TupleInts, that each have depth entries.

Source

pub fn table(&self) -> &[TupleInt]

Gets a reference to the ColorMap table.

Source

pub fn len(&self) -> usize

Gets the length of the ColorMap.

Source

pub fn is_empty(&self) -> bool

Gets whether the ColorMap is empty.

Source

pub fn compute_from_input( data: &[u8], depth: usize, req_colors: usize, method_for_largest: MethodForLargest, method_for_rep: MethodForRep, quality_mode: QualityMode, orig_colors: &mut usize, ) -> Result<Self>

Produce a colormap containing the best colors to represent the image stream in file ‘ifP’. Figure it out using the median cut technique.

The colormap will have ‘reqcolors’ or fewer colors in it, unless ‘allcolors’ is true, in which case it will have all the colors that are in the input.

The colormap has the same maxval as the input.

Put the colormap in newly allocated storage as a tupletable2 and return its address as *colormapP. Return the number of colors in it as *colorsP and its maxval as *colormapMaxvalP.

Return the characteristics of the input file as *formatP and *freqPamP. (This information is not really relevant to our colormap mission; just a fringe benefit).

Source

pub fn compute_histogram( data: &[u8], depth: usize, quality_mode: QualityMode, ) -> Result<Self>

Computes a histogram for a ColorMap.

Source

pub fn median_cut( &mut self, depth: usize, new_colors: usize, method_for_largest: MethodForLargest, method_for_rep: MethodForRep, ) -> Result<Self>

Compute a set of only new_colors colors that best represent an image whose pixels are summarized by the histogram color_freq_table. Each tuple in that table has depth depth. color_freq_table.table[i] tells the number of pixels in the subject image have a particular color.

As a side effect, sort color_freq_table.

Source

pub fn split_box( &mut self, bv: &mut BoxVector, boxes: usize, bi: usize, depth: usize, method_for_largest: MethodForLargest, ) -> Result<usize>

Split Box ‘bi’ in the box vector bv (so that bv contains one more box than it did as input). Split it so that each new box represents about half of the pixels in the distribution given by ‘colorfreqtable’ for the colors in the original box, but with distinct colors in each of the two new boxes.

Assume the box contains at least two colors.

Source

pub fn from_bv( &self, bv: &BoxVector, boxes: usize, depth: usize, new_colors: usize, method_for_rep: MethodForRep, ) -> Result<Self>

Creates a ColorMap from a BoxVector.

From libsixel comments:

Ok, we've got enough boxes.  Now choose a representative color for
each box.  There are a number of possible ways to make this choice.
One would be to choose the center of the box; this ignores any structure
within the boxes.  Another method would be to average all the colors in
the box - this is the method specified in Heckbert's paper.  A third
method is to average all the pixels in the box.
Source

pub fn find_box_boundaries( &self, depth: usize, box_start: usize, min_val: &mut [Sample], max_val: &mut [Sample], ) -> Result<()>

Find the boundary of a box of pixels.

From the libsixel docs:

Go through the box finding the minimum and maximum of each
component - the boundaries of the box.
Source

pub fn center_box( &self, box_start: usize, box_size: usize, depth: usize, ) -> Result<Tuple>

Finds the center of the box values.

Source

pub fn average_colors( &self, box_start: usize, box_size: usize, depth: usize, ) -> Result<Tuple>

Averages color values in a ColorMap.

Source

pub fn average_pixels( &self, box_start: usize, box_size: usize, depth: usize, ) -> Result<Tuple>

Averages pixel values in a ColorMap.

Trait Implementations§

Source§

impl Clone for ColorMap

Source§

fn clone(&self) -> ColorMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ColorMap

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ColorMap

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ColorMap

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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

Source§

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.