| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
#include <math.h> |
| 6 |
#include "icc.h" |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#define NTESTS 34 |
| 12 |
|
| 13 |
|
| 14 |
struct { |
| 15 |
double Lab1[3]; |
| 16 |
double Lab2[3]; |
| 17 |
double de; |
| 18 |
} ref[NTESTS] = { |
| 19 |
{ 50.0000, 2.6772, -79.7751, 50.0000, 0.0000, -82.7485, 2.0425 }, |
| 20 |
{ 50.0000, 3.1571, -77.2803, 50.0000, 0.0000, -82.7485, 2.8615 }, |
| 21 |
{ 50.0000, 2.8361, -74.0200, 50.0000, 0.0000, -82.7485, 3.4412 }, |
| 22 |
{ 50.0000, -1.3802, -84.2814, 50.0000, 0.0000, -82.7485, 1.0000 }, |
| 23 |
{ 50.0000, -1.1848, -84.8006, 50.0000, 0.0000, -82.7485, 1.0000 }, |
| 24 |
{ 50.0000, -0.9009, -85.5211, 50.0000, 0.0000, -82.7485, 1.0000 }, |
| 25 |
{ 50.0000, 0.0000, 0.0000, 50.0000, -1.0000, 2.0000, 2.3669 }, |
| 26 |
{ 50.0000, -1.0000, 2.0000, 50.0000, 0.0000, 0.0000, 2.3669 }, |
| 27 |
{ 50.0000, 2.4900, -0.0010, 50.0000, -2.4900, 0.0009, 7.1792 }, |
| 28 |
{ 50.0000, 2.4900, -0.0010, 50.0000, -2.4900, 0.0010, 7.1792 }, |
| 29 |
{ 50.0000, 2.4900, -0.0010, 50.0000, -2.4900, 0.0011, 7.2195 }, |
| 30 |
{ 50.0000, 2.4900, -0.0010, 50.0000, -2.4900, 0.0012, 7.2195 }, |
| 31 |
{ 50.0000, -0.0010, 2.4900, 50.0000, 0.0009, -2.4900, 4.8045 }, |
| 32 |
{ 50.0000, -0.0010, 2.4900, 50.0000, 0.0010, -2.4900, 4.8045 }, |
| 33 |
{ 50.0000, -0.0010, 2.4900, 50.0000, 0.0011, -2.4900, 4.7461 }, |
| 34 |
{ 50.0000, 2.5000, 0.0000, 50.0000, 0.0000, -2.5000, 4.3065 }, |
| 35 |
{ 50.0000, 2.5000, 0.0000, 73.0000, 25.0000, -18.0000, 27.1492 }, |
| 36 |
{ 50.0000, 2.5000, 0.0000, 61.0000, -5.0000, 29.0000, 22.8977 }, |
| 37 |
{ 50.0000, 2.5000, 0.0000, 56.0000, -27.0000, -3.0000, 31.9030 }, |
| 38 |
{ 50.0000, 2.5000, 0.0000, 58.0000, 24.0000, 15.0000, 19.4535 }, |
| 39 |
{ 50.0000, 2.5000, 0.0000, 50.0000, 3.1736, 0.5854, 1.0000 }, |
| 40 |
{ 50.0000, 2.5000, 0.0000, 50.0000, 3.2972, 0.0000, 1.0000 }, |
| 41 |
{ 50.0000, 2.5000, 0.0000, 50.0000, 1.8634, 0.5757, 1.0000 }, |
| 42 |
{ 50.0000, 2.5000, 0.0000, 50.0000, 3.2592, 0.3350, 1.0000 }, |
| 43 |
{ 60.2574, -34.0099, 36.2677, 60.4626, -34.1751, 39.4387, 1.2644 }, |
| 44 |
{ 63.0109, -31.0961, -5.8663, 62.8187, -29.7946, -4.0864, 1.2630 }, |
| 45 |
{ 61.2901, 3.7196, -5.3901, 61.4292, 2.2480, -4.9620, 1.8731 }, |
| 46 |
{ 35.0831, -44.1164, 3.7933, 35.0232, -40.0716, 1.5901, 1.8645 }, |
| 47 |
{ 22.7233, 20.0904, -46.6940, 23.0331, 14.9730, -42.5619, 2.0373 }, |
| 48 |
{ 36.4612, 47.8580, 18.3852, 36.2715, 50.5065, 21.2231, 1.4146 }, |
| 49 |
{ 90.8027, -2.0831, 1.4410, 91.1528, -1.6435, 0.0447, 1.4441 }, |
| 50 |
{ 90.9257, -0.5406, -0.9208, 88.6381, -0.8985, -0.7239, 1.5381 }, |
| 51 |
{ 6.7747, -0.2908, -2.4247, 5.8714, -0.0985, -2.2286, 0.6377 }, |
| 52 |
{ 2.0776, 0.0795, -1.1350, 0.9033, -0.0636, -0.5514, 0.9082 } |
| 53 |
}; |
| 54 |
|
| 55 |
double icmCIE2K(double *Lab1, double *Lab2); |
| 56 |
|
| 57 |
int main(void) { |
| 58 |
int rv = 0; |
| 59 |
int i; |
| 60 |
|
| 61 |
printf("Starting Test:\n"); |
| 62 |
|
| 63 |
#ifdef NEVER |
| 64 |
for (i = 0; i < NTESTS; i++) { |
| 65 |
printf("Lab1 = %f %f %f\n", ref[i].Lab1[0], ref[i].Lab1[1], ref[i].Lab1[2]); |
| 66 |
printf("Lab2 = %f %f %f\n", ref[i].Lab2[0], ref[i].Lab2[1], ref[i].Lab2[2]); |
| 67 |
printf("de = %f\n",ref[i].de); |
| 68 |
} |
| 69 |
#endif |
| 70 |
|
| 71 |
|
| 72 |
for (i = 0; i < NTESTS; i++) { |
| 73 |
double de; |
| 74 |
|
| 75 |
de = icmCIE2K(ref[i].Lab1, ref[i].Lab2); |
| 76 |
if (fabs(de - ref[i].de) > 0.0001) { |
| 77 |
printf("Error at index %d:\n",i); |
| 78 |
printf("Lab1 = %f %f %f\n", ref[i].Lab1[0], ref[i].Lab1[1], ref[i].Lab1[2]); |
| 79 |
printf("Lab2 = %f %f %f\n", ref[i].Lab2[0], ref[i].Lab2[1], ref[i].Lab2[2]); |
| 80 |
printf("DeltaE is %f, should be %f\n\n",de,ref[i].de); |
| 81 |
rv = 1; |
| 82 |
} |
| 83 |
de = icmCIE2K(ref[i].Lab2, ref[i].Lab1); |
| 84 |
if (fabs(de - ref[i].de) > 0.0001) { |
| 85 |
printf("Error at index %d:\n",i); |
| 86 |
printf("Lab1 = %f %f %f\n", ref[i].Lab2[0], ref[i].Lab2[1], ref[i].Lab2[2]); |
| 87 |
printf("Lab2 = %f %f %f\n", ref[i].Lab1[0], ref[i].Lab1[1], ref[i].Lab1[2]); |
| 88 |
printf("DeltaE is %f, should be %f\n\n",de,ref[i].de); |
| 89 |
rv = 1; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
printf("Test Finished\n"); |
| 94 |
return rv; |
| 95 |
} |
| 96 |
|
| 97 |
#ifdef NEVER |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
double icmCIE2Ksq(double *Lab0, double *Lab1) { |
| 106 |
double C1, C2; |
| 107 |
double h1, h2; |
| 108 |
double dL, dC, dH; |
| 109 |
double dsq; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
#define RAD2DEG(xx) (180.0/3.14159265358979 * (xx)) |
| 116 |
#define DEG2RAD(xx) (3.14159265358979/180.0 * (xx)) |
| 117 |
|
| 118 |
|
| 119 |
{ |
| 120 |
double C1ab, C2ab; |
| 121 |
double Cab, Cab7, G; |
| 122 |
double a1, a2; |
| 123 |
|
| 124 |
C1ab = sqrt(Lab0[1] * Lab0[1] + Lab0[2] * Lab0[2]); |
| 125 |
C2ab = sqrt(Lab1[1] * Lab1[1] + Lab1[2] * Lab1[2]); |
| 126 |
Cab = 0.5 * (C1ab + C2ab); |
| 127 |
Cab7 = pow(Cab,7.0); |
| 128 |
G = 0.5 * (1.0 - sqrt(Cab7/(Cab7 + 6103515625.0))); |
| 129 |
a1 = (1.0 + G) * Lab0[1]; |
| 130 |
a2 = (1.0 + G) * Lab1[1]; |
| 131 |
C1 = sqrt(a1 * a1 + Lab0[2] * Lab0[2]); |
| 132 |
C2 = sqrt(a2 * a2 + Lab1[2] * Lab1[2]); |
| 133 |
|
| 134 |
if (C1 < 1e-9) |
| 135 |
h1 = 0.0; |
| 136 |
else { |
| 137 |
h1 = RAD2DEG(atan2(Lab0[2], a1)); |
| 138 |
if (h1 < 0.0) |
| 139 |
h1 += 360.0; |
| 140 |
} |
| 141 |
|
| 142 |
if (C2 < 1e-9) |
| 143 |
h2 = 0.0; |
| 144 |
else { |
| 145 |
h2 = RAD2DEG(atan2(Lab1[2], a2)); |
| 146 |
if (h2 < 0.0) |
| 147 |
h2 += 360.0; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
{ |
| 153 |
double dh; |
| 154 |
|
| 155 |
dL = Lab1[0] - Lab0[0]; |
| 156 |
dC = C2 - C1; |
| 157 |
if (C1 < 1e-9 || C2 < 1e-9) { |
| 158 |
dh = 0.0; |
| 159 |
} else { |
| 160 |
dh = h2 - h1; |
| 161 |
if (dh > 180.0) |
| 162 |
dh -= 360.0; |
| 163 |
else if (dh < -180.0) |
| 164 |
dh += 360.0; |
| 165 |
} |
| 166 |
|
| 167 |
dH = 2.0 * sqrt(C1 * C2) * sin(DEG2RAD(0.5 * dh)); |
| 168 |
} |
| 169 |
|
| 170 |
{ |
| 171 |
double L, C, h, T; |
| 172 |
double hh, ddeg; |
| 173 |
double C7, RC, L50sq, SL, SC, SH, RT; |
| 174 |
double dLsq, dCsq, dHsq, RCH; |
| 175 |
|
| 176 |
L = 0.5 * (Lab0[0] + Lab1[0]); |
| 177 |
C = 0.5 * (C1 + C2); |
| 178 |
if (C1 < 1e-9 || C2 < 1e-9) { |
| 179 |
h = h1 + h2; |
| 180 |
} else { |
| 181 |
h = h1 + h2; |
| 182 |
if (fabs(h1 - h2) > 180.0) { |
| 183 |
if (h < 360.0) |
| 184 |
h += 360.0; |
| 185 |
else if (h >= 360.0) |
| 186 |
h -= 360.0; |
| 187 |
} |
| 188 |
h *= 0.5; |
| 189 |
} |
| 190 |
T = 1.0 - 0.17 * cos(DEG2RAD(h-30.0)) + 0.24 * cos(DEG2RAD(2.0 * h)) |
| 191 |
+ 0.32 * cos(DEG2RAD(3.0 * h + 6.0)) - 0.2 * cos(DEG2RAD(4.0 * h - 63.0)); |
| 192 |
hh = (h - 275.0)/25.0; |
| 193 |
ddeg = 30.0 * exp(-hh * hh); |
| 194 |
C7 = pow(C,7.0); |
| 195 |
RC = 2.0 * sqrt(C7/(C7 + 6103515625.0)); |
| 196 |
L50sq = (L - 50.0) * (L - 50.0); |
| 197 |
SL = 1.0 + (0.015 * L50sq)/sqrt(20.0 + L50sq); |
| 198 |
SC = 1.0 + 0.045 * C; |
| 199 |
SH = 1.0 + 0.015 * C * T; |
| 200 |
RT = -sin(DEG2RAD(2 * ddeg)) * RC; |
| 201 |
|
| 202 |
dLsq = dL/SL; |
| 203 |
dCsq = dC/SC; |
| 204 |
dHsq = dH/SH; |
| 205 |
|
| 206 |
RCH = RT * dCsq * dHsq; |
| 207 |
|
| 208 |
dLsq *= dLsq; |
| 209 |
dCsq *= dCsq; |
| 210 |
dHsq *= dHsq; |
| 211 |
|
| 212 |
dsq = dLsq + dCsq + dHsq + RCH; |
| 213 |
} |
| 214 |
|
| 215 |
return dsq; |
| 216 |
|
| 217 |
#undef RAD2DEG |
| 218 |
#undef DEG2RAD |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
double icmCIE2K(double *Lab0, double *Lab1) { |
| 223 |
return sqrt(icmCIE2Ksq(Lab0, Lab1)); |
| 224 |
} |
| 225 |
|
| 226 |
#endif |