RGBTriplet gamma(1.0f, 1.0f, 1.0f);
RGBTriplet gain(1.0f, 1.0f, 1.0f);
- hsv2rgb(lift_theta, lift_rad, lift_v, &lift.r, &lift.g, &lift.b);
- hsv2rgb(gamma_theta, gamma_rad, gamma_v * 2.0f, &gamma.r, &gamma.g, &gamma.b);
- hsv2rgb(gain_theta, gain_rad, gain_v * 4.0f, &gain.r, &gain.g, &gain.b);
+ hsv2rgb_normalized(lift_theta, lift_rad, lift_v, &lift.r, &lift.g, &lift.b);
+ hsv2rgb_normalized(gamma_theta, gamma_rad, gamma_v * 2.0f, &gamma.r, &gamma.g, &gamma.b);
+ hsv2rgb_normalized(gain_theta, gain_rad, gain_v * 4.0f, &gain.r, &gain.g, &gain.b);
bool ok = lift_gamma_gain_effect->set_vec3("lift", (float *)&lift);
ok = ok && lift_gamma_gain_effect->set_vec3("gamma", (float *)&gamma);
*b += m;
}
+void hsv2rgb_normalized(float h, float s, float v, float *r, float *g, float *b)
+{
+ float ref_r, ref_g, ref_b;
+ hsv2rgb(h, s, v, r, g, b);
+ hsv2rgb(h, 0.0f, v, &ref_r, &ref_g, &ref_b);
+ float lum = 0.2126 * *r + 0.7152 * *g + 0.0722 * *b;
+ float ref_lum = 0.2126 * ref_r + 0.7152 * ref_g + 0.0722 * ref_b;
+ if (lum > 1e-3) {
+ float fac = ref_lum / lum;
+ *r *= fac;
+ *g *= fac;
+ *b *= fac;
+ }
+}
+
std::string read_file(const std::string &filename)
{
static char buf[131072];
// Converts a HSV color to RGB. Assumes h in [0, 2pi> or [-pi, pi>
void hsv2rgb(float h, float s, float v, float *r, float *g, float *b);
+// Converts a HSV color to RGB, but keeps luminance constant
+// (ie. color luminance is as if S=0).
+void hsv2rgb_normalized(float h, float s, float v, float *r, float *g, float *b);
+
// Column major (same as OpenGL).
typedef double Matrix3x3[9];