4 #ifdef __cplusplus //libs if c++ is used 10 #else //libs if pure c is used 18 float m[3][3] = {{3.2406f, -1.5372f, -0.4986f}, {-0.9689f, 1.8758f, 0.0415f}, {0.0557f, -0.2040f, 1.0570f}};
19 float m_inv[3][3] = {{0.4124f, 0.3576f, 0.1805f}, {0.2126f, 0.7152f, 0.0722f}, {0.0193f, 0.1192f, 0.9505f}};
46 float round_(
float num,
int places);
56 void HUSLtoRGB(
float *r,
float *g,
float *
b,
float h,
float s,
float l )
71 void RGBtoHUSL(
float *h,
float *s,
float *l,
float r,
float g,
float b )
93 float C, bottom, cosH, hrad, lbottom, m1, m2, m3, rbottom, result, sinH, sub1, sub2, t, top;
94 int _i, _j, _len, _len1;
96 float _ref[2] = {0.0f, 1.0f};
99 hrad = (float) ((H / 360.0
f) * 2 * M_PI);
100 sinH = (float) (sin(hrad));
101 cosH = (float) (cos(hrad));
102 sub1 = (float) (pow(L + 16, 3) / 1560896.0);
103 sub2 = sub1 > 0.008856 ? sub1 : (float) (L / 903.3);
105 for (_i = 0, _len = 3; _i < _len; ++_i) {
107 m1 = row[0], m2 = row[1], m3 = row[2];
108 top = (float) ((0.99915 * m1 + 1.05122 * m2 + 1.14460 * m3) * sub2);
109 rbottom = (float) (0.86330 * m3 - 0.17266 * m2);
110 lbottom = (float) (0.12949 * m3 - 0.38848 * m1);
111 bottom = (rbottom * sinH + lbottom * cosH) * sub2;
113 for (_j = 0, _len1 = 2; _j < _len1; ++_j) {
115 C = (float) (L * (top - 1.05122 * t) / (bottom + 0.17266 * sinH * t));
116 if ((C > 0 && C < result)) {
128 for (i = _i = 0, _ref = len - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
138 n = (float) (pow(10.0
f, places));
139 return (
float) (floor(num * n) / n);
145 return (
float) (pow(t, 1.0
f / 3.0
f));
147 return (
float) (7.787 * t + 16 / 116.0);
153 if (pow(t, 3) >
lab_e) {
154 return (
float) (pow(t, 3));
156 return (116 * t - 16) /
lab_k;
162 if (c <= 0.0031308) {
165 return (
float) (1.055 * pow(c, 1 / 2.4
f) - 0.055);
174 return (
float) (pow((c + a) / (1 + a), 2.4
f));
176 return (
float) (c / 12.92);
184 for(i = 0; i < 3; ++i){
185 tuple[i] =
round_(tuple[i], 3);
187 if (tuple[i] < 0 || tuple[i] > 1) {
195 tuple[i] =
round_(tuple[i]*255, 0);
217 float B, G, R, X, Y, Z;
241 float L, U, V, X, Y, Z, varU, varV;
247 varU = (4 * X) / (X + (15.0
f * Y) + (3 * Z));
248 varV = (9 * Y) / (X + (15.0
f * Y) + (3 * Z));
249 L = 116 *
f(Y /
refY) - 16;
250 U = 13 * L * (varU -
refU);
251 V = 13 * L * (varV -
refV);
262 float L, U, V, X, Y, Z, varU, varV, varY;
269 tuple[2] = tuple[1] = tuple[0] = 0.0f;
273 varY =
f_inv((L + 16) / 116.0
f);
274 varU = U / (13.0f * L) +
refU;
275 varV = V / (13.0f * L) +
refV;
277 X = 0 - (9 * Y * varU) / ((varU - 4.0
f) * varV - varU * varV);
278 Z = (9 * Y - (15 * varV * Y) - (varV * X)) / (3.0
f * varV);
289 float C, H, Hrad, L, U, V;
295 C = (float) (pow(pow(U, 2) + pow(V, 2), (1 / 2.0
f)));
296 Hrad = (float) (atan2(V, U));
297 H = (float) (Hrad * 360.0
f / 2.0
f / M_PI);
311 float C, H, Hrad, L, U, V;
317 Hrad = (float) (H / 360.0 * 2.0 * M_PI);
318 U = (float) (cos(Hrad) * C);
319 V = (float) (sin(Hrad) * C);
330 float C, H, L, S, max;
337 C = max / 100.0f * S;
348 float C, H, L, S, max;
float maxChroma(float L, float H)
float dotProduct(float *a, float *b, int len)
float * LCH_LUV(float *tuple)
float * LCH_HUSL(float *tuple)
float * HUSL_LCH(float *tuple)
void HUSLtoRGB(float *r, float *g, float *b, float h, float s, float l)
float * LUV_XYZ(float *tuple)
float * XYZ_LUV(float *tuple)
float * rgbPrepare(float *tuple)
void RGBtoHUSL(float *h, float *s, float *l, float r, float g, float b)
float * RGB_XYZ(float *tuple)
float round_(float num, int places)
float * LUV_LCH(float *tuple)
float fromLinear(float c)
float * XYZ_RGB(float *tuple)