Constructs a color value from hue, saturation, and lightness values (HSL model)
color-hsl
@/color-hsl
Constructs a color value from hue, saturation, and lightness values (HSL model)
Hnumber
0 is for red, 0.33 for green, 0.66 for blue, and 0.99 is for red again. Some systems use degrees for the hue component. The value of 1.0 corresponds to 360° of such systems. When out out of [0; 1) range only the fractional part is taken into account
Snumber
Saturation. Should be in the range [0, 1]. 0.0 corresponds to fully-gray shade and 1.0 to saturated color shade. Values out of the range are truncated to 0 or 1
Lnumber
Lightness. Should be in the range [0, 1]. 0.0 corresponds to black; 0.5 to pure color; 1.0 to white. Values out of the range are truncated to 0 or 1
OUT@/color
To use the node in your project you should have the gabbapeople/color library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
struct State {
};
// clang-format off
{{ GENERATED_CODE }}
// clang-format on
float HueToRGB(float v1, float v2, float vH) {
if (vH < 0)
vH += 1;
if (vH > 1)
vH -= 1;
if ((6 * vH) < 1)
return (v1 + (v2 - v1) * 6 * vH);
if ((2 * vH) < 1)
return v2;
if ((3 * vH) < 2)
return (v1 + (v2 - v1) * ((2.0f / 3) - vH) * 6);
return v1;
}
void evaluate(Context ctx){
float H = 360 * getValue<input_H>(ctx);
float S = getValue<input_S>(ctx);
float L = getValue<input_L>(ctx);
uint8_t r, g, b;
if (S == 0) {
r = g = b = L * 255;
} else {
float hue = (float) H / 360;
float v2 = (L < 0.5) ? (L * (1 + S)) : ((L + S) - (L * S));
float v1 = 2 * L - v2;
r = (uint8_t)(255 * HueToRGB(v1, v2, hue + (1.0f / 3)));
g = (uint8_t)(255 * HueToRGB(v1, v2, hue));
b = (uint8_t)(255 * HueToRGB(v1, v2, hue - (1.0f / 3)));
}
ValueType<output_OUT>::T obj;
obj = { r, g, b };
emitValue<output_OUT>(ctx, obj);
}