Add missing color.h

This commit is contained in:
BeaR 2014-08-10 20:25:05 +02:00 committed by oy
parent 551b21162f
commit bfb245c2bb

59
src/base/color.h Normal file
View file

@ -0,0 +1,59 @@
#ifndef BASE_COLOR_H
#define BASE_COLOR_H
#include "vmath.h"
/*
Title: Color handling
*/
/*
Function: HueToRgb
Converts Hue to RGB
*/
inline float HueToRgb(float v1, float v2, float h)
{
if(h < 0.0f) h += 1;
if(h > 1.0f) h -= 1;
if((6.0f * h) < 1.0f) return v1 + (v2 - v1) * 6.0f * h;
if((2.0f * h) < 1.0f) return v2;
if((3.0f * h) < 2.0f) return v1 + (v2 - v1) * ((2.0f/3.0f) - h) * 6.0f;
return v1;
}
/*
Function: HslToRgb
Converts HSL to RGB
*/
inline vec3 HslToRgb(vec3 HSL)
{
if(HSL.s == 0.0f)
return vec3(HSL.l, HSL.l, HSL.l);
else
{
float v2 = HSL.l < 0.5f ? HSL.l * (1.0f + HSL.s) : (HSL.l+HSL.s) - (HSL.s*HSL.l);
float v1 = 2.0f * HSL.l - v2;
return vec3(HueToRgb(v1, v2, HSL.h + (1.0f/3.0f)), HueToRgb(v1, v2, HSL.h), HueToRgb(v1, v2, HSL.h - (1.0f/3.0f)));
}
}
/*
Function: HexToRgba
Converts Hex to Rgba
Remarks: Hex should be RGBA8
*/
inline vec4 HexToRgba(int hex)
{
vec4 c;
c.r = ((hex >> 24) & 0xFF) / 255.0f;
c.g = ((hex >> 16) & 0xFF) / 255.0f;
c.b = ((hex >> 8) & 0xFF) / 255.0f;
c.a = (hex & 0xFF) / 255.0f;
return c;
}
#endif