Last active
August 29, 2015 14:20
-
-
Save datenwolf/4e54335d86e350388fff to your computer and use it in GitHub Desktop.
Cubehelix LUT generator
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
void | |
cubehelix( | |
size_t const n_steps, | |
uint8_t * const out_lut, /* 3 * n_steps elements, r8b8g8 */ | |
double const start, /* start color */ | |
double const rotations, | |
double const hue, | |
double const gamma ) | |
{ | |
size_t i; | |
for(i = 0; i < n_steps; ++i) { | |
double const fract = (double)i / (double)n_steps; | |
double const angle = M_PI*2 * (start/M_PI + 1.0 + rotations * fract); | |
double const amp = hue*fract*(1.0 - fract)/2.0; | |
double const red = clampf(0.0, 1.0, | |
(fract + amp*(-0.14861*cos(angle) + 1.78277*sin(angle))) ); | |
double const green = clampf(0.0, 1.0, | |
(fract + amp*(-0.29227*cos(angle) - 0.90649*sin(angle))) ); | |
double const blue = clampf(0.0, 1.0, | |
(fract + amp*(+1.97294*cos(angle))) ); | |
double const k = pow( hypot(red, hypot(green, blue)) * 0.57735027, gamma ); | |
out_lut[3 * i + 0] = roundf(255.f * k * red); | |
out_lut[3 * i + 1] = roundf(255.f * k * green); | |
out_lut[3 * i + 2] = roundf(255.f * k * blue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment