Struct color_quant::NeuQuant
source · pub struct NeuQuant { /* private fields */ }
Implementations§
source§impl NeuQuant
impl NeuQuant
sourcepub fn new(samplefac: i32, colors: usize, pixels: &[u8]) -> Self
pub fn new(samplefac: i32, colors: usize, pixels: &[u8]) -> Self
Creates a new neuronal network and trains it with the supplied data.
Pixels are assumed to be in RGBA format.
colors
should be $>=64$. samplefac
determines the faction of
the sample that will be used to train the network. Its value must be in the
range $[1, 30]$. A value of $1$ thus produces the best result but is also
slowest. $10$ is a good compromise between speed and quality.
sourcepub fn init(&mut self, pixels: &[u8])
pub fn init(&mut self, pixels: &[u8])
Initializes the neuronal network and trains it with the supplied data.
This method gets called by Self::new
.
sourcepub fn map_pixel(&self, pixel: &mut [u8])
pub fn map_pixel(&self, pixel: &mut [u8])
Maps the rgba-pixel in-place to the best-matching color in the color map.
sourcepub fn index_of(&self, pixel: &[u8]) -> usize
pub fn index_of(&self, pixel: &[u8]) -> usize
Finds the best-matching index in the color map.
pixel
is assumed to be in RGBA format.
sourcepub fn lookup(&self, idx: usize) -> Option<[u8; 4]>
pub fn lookup(&self, idx: usize) -> Option<[u8; 4]>
Lookup pixel values for color at idx
in the colormap.
sourcepub fn color_map_rgba(&self) -> Vec<u8>
pub fn color_map_rgba(&self) -> Vec<u8>
Returns the RGBA color map calculated from the sample.
sourcepub fn color_map_rgb(&self) -> Vec<u8>
pub fn color_map_rgb(&self) -> Vec<u8>
Returns the RGBA color map calculated from the sample.