All checks were successful
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 10m22s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 11m30s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 11m41s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 12m32s
Build Packages / Generate python client (push) Successful in 18s
Build Packages / Build documentation (push) Successful in 54s
Build Packages / Create release (push) Has been skipped
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 9m44s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 8m53s
Build Packages / build:rpm (rocky8) (push) Successful in 9m40s
Build Packages / build:rpm (rocky9) (push) Successful in 10m37s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 9m54s
Build Packages / Unit tests (push) Successful in 1h6m33s
This is an UNSTABLE release. * jfjoch_broker: Use newer version of Google Ceres for (potential) CUDA 13 compatibility * jfjoch_broker: Improve performance of generating preview images, especially for large detectors (9M-16M) * jfjoch_viewer: Improve performance of displaying images, especially for large detectors (9M-16M) * jfjoch_viewer: Add more color schemes for better image readability * HDF5: Common mutex for reading and writing HDF5 if both operations were to happen in the same executable * HDF5: suppress warning if path (upstream group) doesn't exists when checking if leaf exists Reviewed-on: #30 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch> Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
100 lines
2.6 KiB
C++
100 lines
2.6 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#ifndef JFJOCH_COLORSCALE_H
|
|
#define JFJOCH_COLORSCALE_H
|
|
|
|
#include <vector>
|
|
#include <cstdint>
|
|
#include <algorithm>
|
|
#include <stdexcept>
|
|
|
|
struct rgb {
|
|
uint8_t r;
|
|
uint8_t g;
|
|
uint8_t b;
|
|
};
|
|
|
|
float luminance(rgb input);
|
|
|
|
enum class ColorScaleEnum : int {
|
|
Indigo = 0,
|
|
Viridis = 1,
|
|
Magma = 2,
|
|
Inferno = 3,
|
|
Heat = 4,
|
|
BW = 5,
|
|
WB = 6,
|
|
Green1 = 7,
|
|
Green2 = 8,
|
|
Green3 = 9
|
|
};
|
|
|
|
enum class ColorScaleSpecial {
|
|
Gap,
|
|
BadPixel
|
|
};
|
|
|
|
class ColorScale {
|
|
const std::vector<rgb> viridis_colormap = {
|
|
{68, 1, 84}, {71, 44, 123}, {59, 81, 139}, {44, 113, 142}, {33, 144, 141},
|
|
{39, 173, 129}, {92, 200, 99}, {170, 220, 50}, {253, 231, 37}
|
|
};
|
|
|
|
const std::vector<rgb> heat_colormap = {
|
|
{0, 0, 0}, {128, 0, 0}, {255, 0, 0}, {255, 128, 0}, {255, 255, 0}, {255, 255, 128}, {255, 255, 255}
|
|
};
|
|
|
|
const std::vector<rgb> white_to_indigo_colormap = {
|
|
{255, 255, 255}, {216, 209, 255}, {177, 162, 255}, {138, 114, 255}, {99, 67, 255}, {60, 19, 255}, {0, 0, 128}
|
|
};
|
|
|
|
const std::vector<rgb> white_to_black_colormap = {
|
|
{255, 255, 255}, {0, 0, 0}
|
|
};
|
|
|
|
const std::vector<rgb> black_to_white_colormap = {
|
|
{0, 0, 0}, {255, 255, 255}
|
|
};
|
|
|
|
const std::vector<rgb> green_colormap = {
|
|
{0, 0, 0}, {0, 255, 0}
|
|
};
|
|
|
|
const std::vector<rgb> magma_colormap = {
|
|
{0, 0, 4}, {28, 16, 68}, {79, 18, 123}, {129, 37, 129},
|
|
{181, 54, 122}, {229, 80, 100}, {251, 135, 97}, {252, 191, 125}, {252, 253, 191}
|
|
};
|
|
|
|
const std::vector<rgb> inferno_colormap = {
|
|
{0, 0, 4}, {31, 12, 72}, {85, 15, 109}, {136, 34, 106},
|
|
{186, 54, 85}, {227, 89, 51}, {249, 140, 10}, {252, 195, 63}, {252, 255, 164}
|
|
};
|
|
|
|
ColorScaleEnum current = ColorScaleEnum::Indigo;
|
|
|
|
rgb gap = {.r = 190, .g = 190, .b = 190}; // Gray
|
|
rgb bad = {.r = 255, .g = 0, .b = 255}; // Magenta
|
|
|
|
static rgb Apply(float input, const std::vector<rgb> &map);
|
|
|
|
static constexpr size_t kLutSize = 4096;
|
|
mutable std::vector<rgb> lut_;
|
|
|
|
void CalcLUT() const;
|
|
|
|
public:
|
|
ColorScale();
|
|
|
|
void Select(ColorScaleEnum val);
|
|
[[nodiscard]] rgb Apply(float input, float min = 0.0, float max = 1.0) const;
|
|
[[nodiscard]] rgb Apply(ColorScaleSpecial input) const;
|
|
const std::vector<rgb> &LUTData() const;
|
|
[[nodiscard]] rgb ApplyLUTIndex(size_t idx) const;
|
|
|
|
ColorScale &Gap(rgb input);
|
|
ColorScale &BadPixel(rgb input);
|
|
};
|
|
|
|
#endif //JFJOCH_COLORSCALE_H
|