Skip to content

Add initial Colormap implementation with keypoints - #225

Open
kitizz wants to merge 4 commits into
emilk:mainfrom
kitizz:colormap/0_init
Open

Add initial Colormap implementation with keypoints#225
kitizz wants to merge 4 commits into
emilk:mainfrom
kitizz:colormap/0_init

Conversation

@kitizz

@kitizzkitizz commented Dec 28, 2025

Copy link
Copy Markdown
Contributor
  • 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.

…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
@github-actions

Copy link
Copy Markdown

View snapshot changes at kitdiff

/// 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,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept these separate instead of mapping everything to non-uniform keypoints because the sampling of uniform keypoints can be made much faster.

@kitizzkitizz mentioned this pull request Dec 28, 2025
@kitizz
kitizz marked this pull request as ready for review December 28, 2025 03:20
@kitizz

Copy link
Copy Markdown
ContributorAuthor

Hi @michalsustr,
This is ready for review. I don't have the ability to set the label properly or add you as a reviewer.
Let me know what you think!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@kitizz