Skip to content

Commit

Permalink
fix: skip over creation of the tree on small palette (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
qti3e committed May 2, 2024
1 parent bc7f53f commit 144c462
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/interpolation/rbf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ impl<'a, F: RadialBasisFn> RBFRemapper<F> {
})
.collect();

let tree = if nearest > 0 && palette.len() < nearest {
// If we have to go through everything in the palette, skip creating the tree.
let tree = if nearest == 0 || palette.len() < nearest {
None
} else {
let mut tree = ColorTree::with_capacity(palette.len());
for (i, color) in palette.iter().enumerate() {
tree.add(color, i as u32);
}

Some((nearest, tree))
} else {
None
};

Self {
Expand Down Expand Up @@ -152,7 +153,7 @@ macro_rules! impl_rbf {
}

impl_rbf!(
"RBF remapper using a linear function on N nearest neighbors.
"RBF remapper using a linear function on N nearest neighbors.
It's recommended to use a low number of neighbors for this method, otherwise the results will be extremely washed out.",
LinearRemapper<LinearFn>,
Expand All @@ -173,7 +174,7 @@ impl_rbf!(
"RBF remapper using the Gaussian function on N nearest neighbors.
Lower shape values will have more of a gradient between colors, but with more washed out results.
Higher shape values will keep the colors more true, but with less gradient between them.
Higher shape values will keep the colors more true, but with less gradient between them.
Lowering the number of nearest neighbors can also mitigate washout, but may increase banding when using the LUT for corrections.",
GaussianRemapper<GaussianFn>,
|s, d| (-s.shape * d).exp(),
Expand Down

0 comments on commit 144c462

Please sign in to comment.