Public Function cieDe2000(p1 As colorProps, p2 As colorProps) As Double

' calculates the distance between 2 colors using CIEDE200

' see http://www.ece.rochester.edu/~gsharma/cieDe2000/cieDe2000noteCRNA.pdf

Dim c1 As Double, c2 As Double, _

c As Double, g As Double, a1 As Double, b1 As Double, _

a2 As Double, b2 As Double, c1Tick As Double, c2Tick As Double, _

h1 As Double, h2 As Double, dh As Double, dl As Double, dc As Double, _

lTickAvg As Double, cTickAvg As Double, hTickAvg As Double, l50 As Double, sl As Double, _

sc As Double, t As Double, sh As Double, dTheta As Double, kp As Double, _

rc As Double, kl As Double, kc As Double, kh As Double, dlk As Double, _

dck As Double, dhk As Double, rt As Double, dBigH As Double

kp = 25 ^ 7

kl = 1

kc = 1

kh = 1

' calculate c &amp;amp; g values

c1 = Sqr(p1.aStar ^ 2 + p1.bStar ^ 2)

c2 = Sqr(p2.aStar ^ 2 + p2.bStar ^ 2)

c = (c1 + c2) / 2

g = 0.5 * (1 - Sqr(c ^ 7 / (c ^ 7 + kp)))

' adjusted ab*

a1 = (1 + g) * p1.aStar

a2 = (1 + g) * p2.aStar

' adjusted cs

c1Tick = Sqr(a1 ^ 2 + p1.bStar ^ 2)

c2Tick = Sqr(a2 ^ 2 + p2.bStar ^ 2)

' adjusted h

h1 = computeH(a1, p1.bStar)

h2 = computeH(a2, p2.bStar)

' deltas

If (h2 - h1 &amp;gt; 180) Then '1

dh = h2 - h1 - 360

ElseIf (h2 - h1 &amp;lt; -180) Then ' 2

dh = h2 - h1 + 360

Else '0

dh = h2 - h1

End If

dl = p2.LStar - p1.LStar

dc = c2Tick - c1Tick

dBigH = (2 * Sqr(c1Tick * c2Tick) * sIn(toRadians(dh / 2)))

' averages

lTickAvg = (p1.LStar + p2.LStar) / 2

cTickAvg = (c1Tick + c2Tick) / 2

If (c1Tick * c2Tick = 0) Then '3

hTickAvg = h1 + h2

ElseIf (Abs(h2 - h1) &amp;lt;= 180) Then '0

hTickAvg = (h1 + h2) / 2

ElseIf (h2 + h1 &amp;lt; 360) Then '1

hTickAvg = (h1 + h2) / 2 + 180

Else '2

hTickAvg = (h1 + h2) / 2 - 180

End If

l50 = (lTickAvg - 50) ^ 2

sl = 1 + (0.015 * l50 / Sqr(20 + l50))

sc = 1 + 0.045 * cTickAvg

t = 1 - 0.17 * Cos(toRadians(hTickAvg - 30)) + 0.24 * _

Cos(toRadians(2 * hTickAvg)) + 0.32 * _

Cos(toRadians(3 * hTickAvg + 6)) - 0.2 * _

Cos(toRadians(4 * hTickAvg - 63))

sh = 1 + 0.015 * cTickAvg * t

dTheta = 30 * Exp(-1 * ((hTickAvg - 275) / 25) ^ 2)

rc = 2 * Sqr(cTickAvg ^ 7 / (cTickAvg ^ 7 + kp))

rt = -sIn(toRadians(2 * dTheta)) * rc

dlk = dl / sl / kl

dck = dc / sc / kc

dhk = dBigH / sh / kh

cieDe2000 = Sqr(dlk ^ 2 + dck ^ 2 + dhk ^ 2 + rt * dck * dhk)

End Function