tconvert-hex-to-rgb.py - cross-stitch - interactively turn images into patterns for cross stitching
 (HTM) git clone git://src.adamsgaard.dk/cross-stitch
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tconvert-hex-to-rgb.py (587B)
       ---
            1 #!/usr/bin/env python
            2 import numpy
            3 
            4 _NUMERALS = '0123456789abcdefABCDEF'
            5 _HEXDEC = {v: int(v, 16) for v in (x+y for x in _NUMERALS for y in
            6     _NUMERALS)}
            7 LOWERCASE, UPPERCASE = 'x', 'X'
            8 
            9 def rgb(triplet):
           10         return (_HEXDEC[triplet[0:2]], _HEXDEC[triplet[2:4]],
           11                 _HEXDEC[triplet[4:6]])
           12 
           13 #hexlist = numpy.loadtxt('./256-color.dat')
           14 rgblist = numpy.empty((256,3))
           15 fin = open('./256-color.dat')
           16 i = 0
           17 for line in fin:
           18     #print line,
           19     rgbval = rgb(line)
           20     #print rgbval
           21     rgblist[i,:] = rgbval
           22     i += 1
           23 
           24 numpy.savetxt('256-color-rgb.dat', rgblist, fmt='%d')