27 // However, the following notice accompanied the original version of this |
27 // However, the following notice accompanied the original version of this |
28 // file: |
28 // file: |
29 // |
29 // |
30 // |
30 // |
31 // Little cms |
31 // Little cms |
32 // Copyright (C) 1998-2006 Marti Maria |
32 // Copyright (C) 1998-2007 Marti Maria |
33 // |
33 // |
34 // Permission is hereby granted, free of charge, to any person obtaining |
34 // Permission is hereby granted, free of charge, to any person obtaining |
35 // a copy of this software and associated documentation files (the "Software"), |
35 // a copy of this software and associated documentation files (the "Software"), |
36 // to deal in the Software without restriction, including without limitation |
36 // to deal in the Software without restriction, including without limitation |
37 // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
37 // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
64 (1.10 - Actually ICC did it, so this should be checked for full ICC 4.0 support) |
64 (1.10 - Actually ICC did it, so this should be checked for full ICC 4.0 support) |
65 |
65 |
66 */ |
66 */ |
67 |
67 |
68 |
68 |
69 BOOL _cmsEndPointsBySpace(icColorSpaceSignature Space, WORD **White, WORD **Black, |
69 LCMSBOOL _cmsEndPointsBySpace(icColorSpaceSignature Space, WORD **White, WORD **Black, |
70 int *nOutputs) |
70 int *nOutputs) |
71 { |
71 { |
72 // Only most common spaces |
72 // Only most common spaces |
73 |
73 |
74 static WORD RGBblack[4] = { 0, 0, 0 }; |
74 static WORD RGBblack[4] = { 0, 0, 0 }; |
374 double Ls = Lab2 ->L; |
374 double Ls = Lab2 ->L; |
375 double as = Lab2 ->a; |
375 double as = Lab2 ->a; |
376 double bs = Lab2 ->b; |
376 double bs = Lab2 ->b; |
377 double Cs = sqrt( Sqr(as) + Sqr(bs) ); |
377 double Cs = sqrt( Sqr(as) + Sqr(bs) ); |
378 |
378 |
379 |
|
380 double G = 0.5 * ( 1 - sqrt(pow((C + Cs) / 2 , 7.0) / (pow((C + Cs) / 2, 7.0) + pow(25.0, 7.0) ) )); |
379 double G = 0.5 * ( 1 - sqrt(pow((C + Cs) / 2 , 7.0) / (pow((C + Cs) / 2, 7.0) + pow(25.0, 7.0) ) )); |
381 |
380 |
382 double a_p = (1 + G ) * a1; |
381 double a_p = (1 + G ) * a1; |
383 double b_p = b1; |
382 double b_p = b1; |
384 double C_p = sqrt( Sqr(a_p) + Sqr(b_p)); |
383 double C_p = sqrt( Sqr(a_p) + Sqr(b_p)); |
388 double a_ps = (1 + G) * as; |
387 double a_ps = (1 + G) * as; |
389 double b_ps = bs; |
388 double b_ps = bs; |
390 double C_ps = sqrt(Sqr(a_ps) + Sqr(b_ps)); |
389 double C_ps = sqrt(Sqr(a_ps) + Sqr(b_ps)); |
391 double h_ps = atan2deg(a_ps, b_ps); |
390 double h_ps = atan2deg(a_ps, b_ps); |
392 |
391 |
393 |
|
394 |
|
395 double meanC_p =(C_p + C_ps) / 2; |
392 double meanC_p =(C_p + C_ps) / 2; |
396 |
393 |
397 double meanh_p = fabs(h_ps-h_p) <= 180 ? (h_ps + h_p)/2 : (h_ps+h_p-360)/2; |
394 double hps_plus_hp = h_ps + h_p; |
398 |
395 double hps_minus_hp = h_ps - h_p; |
399 double delta_h = fabs(h_p - h_ps) <= 180 ? fabs(h_p - h_ps) : 360 - fabs(h_p - h_ps); |
396 |
400 double delta_L = fabs(L1 - Ls); |
397 double meanh_p = fabs(hps_minus_hp) <= 180.000001 ? (hps_plus_hp)/2 : |
401 double delta_C = fabs(C_p - C_ps); |
398 (hps_plus_hp) < 360 ? (hps_plus_hp + 360)/2 : |
|
399 (hps_plus_hp - 360)/2; |
|
400 |
|
401 double delta_h = (hps_minus_hp) <= -180.000001 ? (hps_minus_hp + 360) : |
|
402 (hps_minus_hp) > 180 ? (hps_minus_hp - 360) : |
|
403 (hps_minus_hp); |
|
404 double delta_L = (Ls - L1); |
|
405 double delta_C = (C_ps - C_p ); |
|
406 |
402 |
407 |
403 double delta_H =2 * sqrt(C_ps*C_p) * sin(RADIANES(delta_h) / 2); |
408 double delta_H =2 * sqrt(C_ps*C_p) * sin(RADIANES(delta_h) / 2); |
404 |
409 |
405 double T = 1 - 0.17 * cos(RADIANES(meanh_p-30)) |
410 double T = 1 - 0.17 * cos(RADIANES(meanh_p-30)) |
406 + 0.24 * cos(RADIANES(2*meanh_p)) |
411 + 0.24 * cos(RADIANES(2*meanh_p)) |
1107 { |
1112 { |
1108 LPGAMMATABLE Trans[MAXCHANNELS]; |
1113 LPGAMMATABLE Trans[MAXCHANNELS]; |
1109 unsigned int t, i, v; |
1114 unsigned int t, i, v; |
1110 int j; |
1115 int j; |
1111 WORD In[MAXCHANNELS], Out[MAXCHANNELS]; |
1116 WORD In[MAXCHANNELS], Out[MAXCHANNELS]; |
1112 BOOL lIsSuitable; |
1117 LCMSBOOL lIsSuitable; |
1113 _LPcmsTRANSFORM InputXForm = (_LPcmsTRANSFORM) h[0]; |
1118 _LPcmsTRANSFORM InputXForm = (_LPcmsTRANSFORM) h[0]; |
1114 _LPcmsTRANSFORM OutputXForm = (_LPcmsTRANSFORM) h[nTransforms-1]; |
1119 _LPcmsTRANSFORM OutputXForm = (_LPcmsTRANSFORM) h[nTransforms-1]; |
1115 |
1120 |
1116 |
1121 |
1117 // First space is *Lab, use our specialized curves for v2 Lab |
1122 // First space is *Lab, use our specialized curves for v2 Lab |
1124 cmsFreeGammaTriple(Trans); |
1129 cmsFreeGammaTriple(Trans); |
1125 return; |
1130 return; |
1126 } |
1131 } |
1127 |
1132 |
1128 |
1133 |
1129 // Do nothing on all but RGB to RGB transforms |
1134 // Do nothing on all but Gray/RGB to Gray/RGB transforms |
1130 |
1135 |
1131 if ((InputXForm ->EntryColorSpace != icSigRgbData) || |
1136 if (((InputXForm ->EntryColorSpace != icSigRgbData) && (InputXForm ->EntryColorSpace != icSigGrayData)) || |
1132 (OutputXForm->ExitColorSpace != icSigRgbData)) return; |
1137 ((OutputXForm->ExitColorSpace != icSigRgbData) && (OutputXForm->ExitColorSpace != icSigGrayData))) return; |
1133 |
1138 |
1134 |
1139 |
1135 for (t = 0; t < Grid -> InputChan; t++) |
1140 for (t = 0; t < Grid -> InputChan; t++) |
1136 Trans[t] = cmsAllocGamma(PRELINEARIZATION_POINTS); |
1141 Trans[t] = cmsAllocGamma(PRELINEARIZATION_POINTS); |
1137 |
1142 |
1167 |
1172 |
1168 // Exclude if weird endpoints |
1173 // Exclude if weird endpoints |
1169 if (!HasProperEndpoints(Trans[t])) |
1174 if (!HasProperEndpoints(Trans[t])) |
1170 lIsSuitable = FALSE; |
1175 lIsSuitable = FALSE; |
1171 |
1176 |
|
1177 /* |
1172 // Exclude if transfer function is not smooth enough |
1178 // Exclude if transfer function is not smooth enough |
1173 // to be modelled as a gamma function, or the gamma is reversed |
1179 // to be modelled as a gamma function, or the gamma is reversed |
|
1180 |
1174 if (cmsEstimateGamma(Trans[t]) < 1.0) |
1181 if (cmsEstimateGamma(Trans[t]) < 1.0) |
1175 lIsSuitable = FALSE; |
1182 lIsSuitable = FALSE; |
|
1183 */ |
1176 |
1184 |
1177 } |
1185 } |
1178 |
1186 |
1179 if (lIsSuitable) { |
1187 if (lIsSuitable) { |
1180 |
1188 |