Skip to content

Commit

Permalink
Apply slanted profile to contrast values
Browse files Browse the repository at this point in the history
  • Loading branch information
averne committed Nov 5, 2024
1 parent 03d4c3b commit 3149127
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion application/src/gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void render_preview(FizeauSettings &settings, Component components, Component fi
coeffs = dot(coeffs, m);

// Apply contrast multiplier
m[0] = m[4] = m[8] = settings.contrast;
m[0] = m[4] = m[8] = contrast_slant(settings.contrast);
coeffs = dot(coeffs, m);

// Apply saturation
Expand Down
2 changes: 1 addition & 1 deletion application/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void draw_graph_window(Config &ctx) {
std::array<std::uint16_t, 256> lut1;
std::array<std::uint16_t, 960> lut2;

float off = (1.0f - set.contrast) / 2.0f;
float off = (1.0f - contrast_slant(set.contrast)) / 2.0f;
degamma_ramp(lut1.data(), lut1.size(), DEFAULT_GAMMA, 8);
regamma_ramp(lut2.data(), lut2.size(), set.gamma, 8, 0.0f, 1.0f, off);

Expand Down
1 change: 1 addition & 0 deletions common/include/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ std::tuple<float, float, float> whitepoint(Temperature temperature);
ColorMatrix hue_matrix(Hue hue);
ColorMatrix saturation_matrix(Saturation sat);

Contrast contrast_slant(Contrast c);
float degamma(float x, Gamma gamma);
float regamma(float x, Gamma gamma);

Expand Down
5 changes: 5 additions & 0 deletions common/src/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ ColorMatrix saturation_matrix(Saturation sat) {
};
}

Contrast contrast_slant(Contrast c) {
c -= 1.0f;
return c * c * c + 1.0f;
}

float degamma(float x, Gamma gamma) {
if (x <= 0.040045f) // x * pow((0.040045 + 0.055) / (1.0 + 0.055), gamma) / 0.040045;
return x * 24.972f * std::pow(0.090f, gamma);
Expand Down
5 changes: 3 additions & 2 deletions sysmodule/src/nvdisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Cmu calculate_cmu(FizeauSettings &settings, Component components, Component filt
coeffs = dot(coeffs, m);

// Apply contrast multiplier
m[0] = m[4] = m[8] = settings.contrast;
auto c = contrast_slant(settings.contrast);
m[0] = m[4] = m[8] = c;
coeffs = dot(coeffs, m);

// Apply saturation
Expand All @@ -58,7 +59,7 @@ Cmu calculate_cmu(FizeauSettings &settings, Component components, Component filt
std::copy_n(coeffs.begin() + 6, 3, &cmu.krb);

// Calculate gamma ramps, with contrast offset
float off = (1.0f - settings.contrast) / 2.0f;
float off = (1.0f - c) / 2.0f;
degamma_ramp(cmu.lut_1.data(), cmu.lut_1.size(), DEFAULT_GAMMA, 12); // Set the LUT1 with a fixed gamma corresponding to the incoming data
regamma_ramp(cmu.lut_2.data(), 512, settings.gamma, 8, 0.0f, 0.125f, off); // Set the first part of LUT2 (more precision in darker components)
regamma_ramp(cmu.lut_2.data() + 512, cmu.lut_2.size() - 512, settings.gamma, 8, 0.125f, 1.0f, off); // Set the second part of LUT2 (less precision in brighter components)
Expand Down

0 comments on commit 3149127

Please sign in to comment.