Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip over creation of the tree on small palette #18

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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