jfjoch_viewer: Add more color modes - white on black and 3 green schemes

This commit is contained in:
2026-01-30 11:03:52 +01:00
parent 8fd02c47d4
commit 12c8a45595
3 changed files with 70 additions and 8 deletions
+51 -6
View File
@@ -5,6 +5,26 @@
#include "ColorScale.h"
#include "JFJochException.h"
static inline float Clamp01(float x) {
return (x < 0.0f) ? 0.0f : (x > 1.0f ? 1.0f : x);
}
// Gamma-mapped green (recommended gamma = 0.7)
static inline rgb GreenGamma(float f, float gamma = 0.7f) {
f = Clamp01(f);
const float g = std::pow(f, gamma);
const uint8_t G = static_cast<uint8_t>(std::lround(255.0f * g));
return {.r = 0, .g = G, .b = 0};
}
// Asinh-mapped green (recommended k = 8.0)
static inline rgb GreenAsinh(float f, float k = 8.0f) {
f = Clamp01(f);
const float g = std::asinh(k * f) / std::asinh(k);
const uint8_t G = static_cast<uint8_t>(std::lround(255.0f * g));
return {.r = 0, .g = G, .b = 0};
}
float luminance(rgb input) {
return 0.2126f * input.r + 0.7152f * input.g + 0.0722f * input.b;
}
@@ -26,18 +46,43 @@ void ColorScale::CalcLUT() const {
const std::vector<rgb>* map = nullptr;
switch (current) {
case ColorScaleEnum::Viridis: map = &viridis_colormap; break;
case ColorScaleEnum::Heat: map = &heat_colormap; break;
case ColorScaleEnum::Indigo: map = &white_to_indigo_colormap; break;
case ColorScaleEnum::BW: map = &white_to_black_colormap; break;
case ColorScaleEnum::Heat: map = &heat_colormap;
break;
case ColorScaleEnum::Indigo: map = &white_to_indigo_colormap;
break;
case ColorScaleEnum::BW: map = &white_to_black_colormap;
break;
case ColorScaleEnum::WB: map = &black_to_white_colormap;
break;
case ColorScaleEnum::Green1:
case ColorScaleEnum::Green2:
map = nullptr;
break; // handled below
case ColorScaleEnum::Green3:
map = &green_colormap;
break;
default:
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"Color scale unknown");
}
for (size_t i = 0; i < kLutSize; ++i) {
const float f = static_cast<float>(i) / static_cast<float>(kLutSize - 1);
lut_[i] = Apply(f, *map);
if (current == ColorScaleEnum::Green1) {
for (size_t i = 0; i < kLutSize; ++i) {
const float f = static_cast<float>(i) / static_cast<float>(kLutSize - 1);
lut_[i] = GreenGamma(f, 0.7f);
}
} else if (current == ColorScaleEnum::Green2) {
for (size_t i = 0; i < kLutSize; ++i) {
const float f = static_cast<float>(i) / static_cast<float>(kLutSize - 1);
lut_[i] = GreenAsinh(f, 8.0f);
}
} else {
for (size_t i = 0; i < kLutSize; ++i) {
const float f = static_cast<float>(i) / static_cast<float>(kLutSize - 1);
lut_[i] = Apply(f, *map);
}
}
}
rgb ColorScale::Apply(float input, const std::vector<rgb> &map) {