MCPcopy Create free account
hub / github.com/ImageOptim/libimagequant / search

Method search

src/nearest.rs:37–61  ·  view source on GitHub ↗
(&self, px: &f_pixel, likely_colormap_index: PalIndex)

Source from the content-addressed store, hash-verified

35impl Nearest<'_> {
36 #[inline]
37 pub fn search(&self, px: &f_pixel, likely_colormap_index: PalIndex) -> (PalIndex, f32) {
38 // The index may be invalid, so it needs to be checked
39 let mut best_candidate = if let Some(pal_px) = self.palette.as_slice().get(likely_colormap_index as usize) {
40 let guess_diff = px.diff(pal_px);
41 if guess_diff < self.nearest_other_color_dist[likely_colormap_index as usize] {
42 return (likely_colormap_index, guess_diff);
43 }
44 Visitor {
45 distance: guess_diff.sqrt(),
46 distance_squared: guess_diff,
47 idx: likely_colormap_index,
48 exclude: None,
49 }
50 } else {
51 Visitor {
52 distance: f32::INFINITY,
53 distance_squared: f32::INFINITY,
54 idx: 0,
55 exclude: None,
56 }
57 };
58
59 vp_search_node(&self.root, px, &mut best_candidate);
60 (best_candidate.idx, best_candidate.distance_squared)
61 }
62}
63
64pub(crate) struct Nearest<'pal> {

Callers 5

remap_to_paletteFunction · 0.80
remap_to_palette_floydFunction · 0.80
dither_rowFunction · 0.80
iterate_batchMethod · 0.80
replace_unused_colorsFunction · 0.80

Calls 3

vp_search_nodeFunction · 0.85
diffMethod · 0.80
as_sliceMethod · 0.45

Tested by

no test coverage detected