Skip to content

Conversation

@kitizz
Copy link
Contributor

@kitizz kitizz commented Dec 28, 2025

  • 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

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
Contributor Author

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
Contributor Author

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
Contributor Author

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.

@kitizz kitizz mentioned this pull request Dec 28, 2025
@kitizz kitizz marked this pull request as ready for review December 28, 2025 03:20
Sign up for free to 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