Add initial Colormap implementation with keypoints#225
Open
kitizz wants to merge 3 commits intoemilk:mainfrom
Open
Add initial Colormap implementation with keypoints#225kitizz wants to merge 3 commits intoemilk:mainfrom
kitizz wants to merge 3 commits intoemilk:mainfrom
Conversation
…oints
- Introduce `Colormap` struct to map parameters to colors.
- Support uniform and non-uniform keypoints map inputs.
- Support for sRBG color interpolation for now.
- Add unit tests:
- Uniform and non-uniform keypoints.
- Edge cases (empty colormap, single color).
- Out-of-bounds parameter handling.
This PR is part of issue emilk#188
|
View snapshot changes at kitdiff |
kitizz
commented
Dec 28, 2025
| /// make this assumption and will only sample the colormap in this range. | ||
| /// However, this is not enforced, so feel free to go against this for your own special use-cases. | ||
| pub struct Colormap { | ||
| data: ColormapData, |
Contributor
Author
There was a problem hiding this comment.
I'm anticipating additional fields here like the interpolation function to use.
|
|
||
| /// Get color at a given position. | ||
| pub fn get(&self, t: f32) -> Color32 { | ||
| self.data.get(t, ColorInterpolation::SRGB) |
Contributor
Author
There was a problem hiding this comment.
I haven't exposed this yet because I'm wondering if it will be more efficient to store the colormap colors in the desired interpolation space. And then convert them after interpolation. In this case, the interpolation function is the same for everything, it's just a lerp. And then the functions would be the conversions to/from sRGB.
| // Internal representation of colormap data. | ||
| // May support things like functions in the future. | ||
| enum ColormapData { | ||
| Uniform(UniformKeypoints), |
Contributor
Author
There was a problem hiding this comment.
I kept these separate instead of mapping everything to non-uniform keypoints because the sampling of uniform keypoints can be made much faster.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Colormapstruct to map parameters to colors.