#[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
impl ColorMap
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates a new ColorMap with the provided capacity.
Sourcepub fn with_colors_and_depth(colors: usize, depth: usize) -> Self
pub fn with_colors_and_depth(colors: usize, depth: usize) -> Self
Sourcepub 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>
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).
Sourcepub fn compute_histogram(
data: &[u8],
depth: usize,
quality_mode: QualityMode,
) -> Result<Self>
pub fn compute_histogram( data: &[u8], depth: usize, quality_mode: QualityMode, ) -> Result<Self>
Computes a histogram for a ColorMap.
Sourcepub fn median_cut(
&mut self,
depth: usize,
new_colors: usize,
method_for_largest: MethodForLargest,
method_for_rep: MethodForRep,
) -> Result<Self>
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
.
Sourcepub fn split_box(
&mut self,
bv: &mut BoxVector,
boxes: usize,
bi: usize,
depth: usize,
method_for_largest: MethodForLargest,
) -> Result<usize>
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.
Sourcepub fn from_bv(
&self,
bv: &BoxVector,
boxes: usize,
depth: usize,
new_colors: usize,
method_for_rep: MethodForRep,
) -> Result<Self>
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.
Sourcepub fn find_box_boundaries(
&self,
depth: usize,
box_start: usize,
min_val: &mut [Sample],
max_val: &mut [Sample],
) -> Result<()>
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.
Sourcepub fn center_box(
&self,
box_start: usize,
box_size: usize,
depth: usize,
) -> Result<Tuple>
pub fn center_box( &self, box_start: usize, box_size: usize, depth: usize, ) -> Result<Tuple>
Finds the center of the box values.