Created
November 11, 2020 03:20
-
-
Save maluoi/1c4e1ebd34c4837313dff32992a10183 to your computer and use it in GitHub Desktop.
Converts cubehelix HSL to RGB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference here: http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/ | |
skg_color128_t skg_col_helix128(float h, float s, float l, float alpha) { | |
const float tau = 6.28318f; | |
l = fminf(1,l); | |
float angle = tau * (h+(1/3.f)); | |
float amp = s * l * (1.f - l); | |
float a_cos = cosf(angle); | |
float a_sin = sinf(angle); | |
float r = l + amp * (-0.14861f * a_cos + 1.78277f * a_sin); | |
float g = l + amp * (-0.29227f * a_cos - 0.90649f * a_sin); | |
float b = l + amp * ( 1.97294f * a_cos); | |
r = fmax(0,fminf(1, r)); | |
g = fmax(0,fminf(1, g)); | |
b = fmax(0,fminf(1, b)); | |
return { r, g, b, alpha }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment