|
@@ -4567,6 +4567,37 @@ void tnsRGB2HCY(real *rgb, real *hcy){
|
|
|
lrgb[2]=_srgb_transfer_function_inv(rgb[2]);
|
|
|
tnsRGB2HCYLinear(lrgb,hcy);
|
|
|
}
|
|
|
+static float hue2rgb(float p, float q, float t) {
|
|
|
+ if (t < 0) t += 1; if (t > 1) t -= 1;
|
|
|
+ if (t < 1./6) return p + (q - p) * 6 * t;
|
|
|
+ if (t < 1./2) return q;
|
|
|
+ if (t < 2./3) return p + (q - p) * (2./3 - t) * 6;
|
|
|
+ return p;
|
|
|
+}
|
|
|
+void tnsRGB2HSL(real *rgb, real *hsl) {
|
|
|
+ float max = TNS_MAX3(rgb[0],rgb[1],rgb[2]);
|
|
|
+ float min = TNS_MIN3(rgb[0],rgb[1],rgb[2]);
|
|
|
+ hsl[0]=hsl[1]=hsl[2]=(max+min) / 2;
|
|
|
+ if (max == min) { hsl[0]=hsl[1]=0; }
|
|
|
+ else {
|
|
|
+ float d = max - min;
|
|
|
+ hsl[1] = (hsl[2] > 0.5) ? d / (2 - max - min) : d / (max + min);
|
|
|
+ if (max == rgb[0]) { hsl[0] = (rgb[1] - rgb[2]) / d + (rgb[1] < rgb[2] ? 6 : 0); }
|
|
|
+ else if (max == rgb[1]) { hsl[0] = (rgb[2] - rgb[0]) / d + 2; }
|
|
|
+ else if (max == rgb[2]) { hsl[0] = (rgb[0] - rgb[1]) / d + 4; }
|
|
|
+ hsl[0] /= 6;
|
|
|
+ }
|
|
|
+}
|
|
|
+void tnsHSL2RGB(real *hsl, real *rgb) {
|
|
|
+ if(hsl[1]==0) {rgb[0]=rgb[1]=rgb[2]=hsl[2];}
|
|
|
+ else {
|
|
|
+ float q = hsl[2] < 0.5 ? hsl[2] * (1 + hsl[1]) : hsl[2] + hsl[1] - hsl[2] * hsl[1];
|
|
|
+ float p = 2 * hsl[2] - q;
|
|
|
+ rgb[0] = hue2rgb(p, q, hsl[0] + 1./3);
|
|
|
+ rgb[1] = hue2rgb(p, q, hsl[0]);
|
|
|
+ rgb[2] = hue2rgb(p, q, hsl[0] - 1./3);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
void tnsClearAll(){
|
|
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
|