Changeset 2202 for trunk/src/lol/image
 Timestamp:
 Jan 5, 2013, 6:56:32 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/image/color.h
r2200 r2202 215 215 * input should be in CIE L*a*b*. 216 216 */ 217 static float DistanceCIEDE2000(vec3 lab1, vec3 lab2) 218 { 219 float const deg2rad = 6.28318530718f / 360.f; 220 float const rad2deg = 360.f / 6.28318530718f; 221 222 float C1 = length(lab1.yz); 223 float C2 = length(lab2.yz); 224 float C_ = 0.5f * (C1 + C2); 225 226 float L1 = lab1.x; 227 float L2 = lab2.x; 228 float dLp = L2  L1; 229 float L_ = 0.5f * (L1 + L2); 230 231 float tmp1 = pow(C_, 7.f); 232 float tmp2 = 1.5f  0.5f * sqrt(tmp1 / (tmp1 + pow(25.f, 7.f))); 233 float ap1 = lab1.y * tmp2; 234 float ap2 = lab2.y * tmp2; 235 float Cp1 = sqrt(ap1 * ap1 + lab1.z * lab1.z); 236 float Cp2 = sqrt(ap2 * ap2 + lab2.z * lab2.z); 237 float dCp = Cp2  Cp1; 238 float Cp_ = 0.5f * (Cp1 + Cp2); 239 240 float hp1 = fmod(atan2(lab1.z, ap1) * rad2deg, 360.f); 241 if (hp1 < 0.f) 242 hp1 += 360.f; 243 float hp2 = fmod(atan2(lab2.z, ap2) * rad2deg, 360.f); 244 if (hp2 < 0.f) 245 hp2 += 360.f; 246 float dhp; 247 if (abs(hp1  hp2) <= 180.f) 248 dhp = hp2  hp1; 249 else if (hp2 <= hp1) 250 dhp = hp2  hp1 + 360.f; 251 else 252 dhp = hp2  hp1  360.f; 253 float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(dhp / 2.f * deg2rad); 254 float Hp_; 255 if (abs(hp1  hp2) > 180.f) 256 Hp_ = 0.5f * (hp1 + hp2 + 360.f); 257 else 258 Hp_ = 0.5f * (hp1 + hp2); 259 260 float T = 1.f  0.17f * cos((Hp_  30.f) * deg2rad) 261 + 0.24f * cos(2 * Hp_ * deg2rad) 262 + 0.32f * cos((3.f * Hp_ + 6.f) * deg2rad) 263  0.20f * cos((4.f * Hp_  63.f) * deg2rad); 264 float SL = 1.f + 0.015f * (L_  50) * (L_  50) 265 / sqrt(20.f + (L_  50) * (L_  50)); 266 float SC = 1.f + 0.045f * Cp_; 267 float SH = 1.f + 0.015f * Cp_ * T; 268 float RT = 2.f * sqrt(pow(Cp_, 7.f) / (pow(Cp_, 7.f) + pow(25.f, 7.f))) 269 * sin(60.f * deg2rad * exp(pow((Hp_  275.f) / 25.f, 2.f))); 270 271 dLp /= SL; 272 dCp /= SC; 273 dHp /= SH; 274 275 return sqrt(dLp * dLp + dCp * dCp + dHp * dHp + RT * dCp * dHp); 276 } 277 278 /* Convert a wavelength to an xyY fully saturated colour */ 217 static float DistanceCIEDE2000(vec3 lab1, vec3 lab2); 218 219 /* 220 * Convert a wavelength into an xyY fully saturated colour. 221 */ 279 222 static vec3 WavelengthToCIExyY(float nm); 280 223 };
Note: See TracChangeset
for help on using the changeset viewer.