// Compare the difference of two RGB values, weigh by CCIR 601 luminosity: ColorCompare(r1,g1,b1, r2,g2,b2) l1 = (r1*299 + g1*587 + b1*114) / 255000 l2 = (r2*299 + g2*587 + b2*114) / 255000 dL = l1-l2 dR = (r1-r2)/255, dG = (g1-g2)/255, dB = (b1-b2)/255 return (dR*dR*0.299 + dG*dG*0.587 + dB*dB*0.114)*0.75 + dL*dL