--- /dev/null
+#colors.py\r
+#A part of NonVisual Desktop Access (NVDA)\r
+#Copyright (C) 2006-2008 NVDA Contributors <http://www.nvda-project.org/>\r
+#This file is covered by the GNU General Public License.\r
+#See the file COPYING for more details.\r
+\r
+from collections import namedtuple\r
+import math\r
+\r
+RGB=namedtuple('RGB',('red','green','blue'))\r
+\r
+RGBToNames={\r
+ RGB(0x00,0x00,0x00):_('black'),\r
+ RGB(0x00,0x80,0x00):_('green'),\r
+ RGB(0xc0,0xc0,0xc0):_('light grey'),\r
+ RGB(0x00,0xff,0x00):_('lime'),\r
+ RGB(0x80,0x80,0x80):_('grey'),\r
+ RGB(0x80,0x80,0x00):_('olive'),\r
+ RGB(0xff,0xff,0xff):_('white'),\r
+ RGB(0xff,0xff,0x00):_('yellow'),\r
+ RGB(0x80,0x00,0x00):_('dark red'),\r
+ RGB(0x00,0x00,0xa0):_('navy blue'),\r
+ RGB(0xff,0x00,0x00):_('red'),\r
+ RGB(0x00,0x00,0xff):_('blue'),\r
+ RGB(0x80,0x00,0x80):_('purple'),\r
+ RGB(0x00,0x80,0x80):_('teal'),\r
+ RGB(0xff,0x00,0xff):_('fuchsia'),\r
+ RGB(0x00,0xff,0xff):_('aqua'),\r
+}\r
+\r
+def findColorName(rgb):\r
+ foundName=RGBToNames.get(rgb,None)\r
+ if not foundName:\r
+ closestRGB=sorted(RGBToNames.iterkeys(),key=lambda x: math.sqrt((abs(rgb.red-x.red)*0.3)**2+(abs(rgb.green-x.green)*0.59)**2+(abs(rgb.blue-x.blue)*0.11)**2))[0]\r
+ foundName=RGBToNames[closestRGB]\r
+ RGBToNames[rgb]=foundName\r
+ return foundName\r
+\r
+\r