The script I used to format ds9's SLS color table
[zanmar/loader_fits] / formatsls.py
1 #!/usr/bin/python2
2
3 # format the sls file so it is compact in C
4
5 f = open( 'sls.lut', 'r' )
6 line = f.readlines()
7 f.close()
8
9 r = []
10 g = []
11 b = []
12
13 for i in line:
14     val = i.split()
15     r.append( float( val[ 0 ] ) )
16     g.append( float( val[ 1 ] ) )
17     b.append( float( val[ 2 ] ) )
18
19 print "const float slsR[] ={",
20 for x in r:
21     #x =  x * 255 )
22     if( x == 0 ):
23         print "0,",
24     elif( x == 1.0 ):
25         print "1,",
26     else:
27         print "%8.6f," %( x ),
28
29 print
30
31 print "const float slsG[] ={",
32 for x in g:
33     #x =  x * 255 )
34     if( x == 0 ):
35         print "0,",
36     elif( x == 1.0 ):
37         print "1,",
38     else:
39         print "%8.6f," %( x ),
40
41 print
42 print "const float slsB[] ={",
43 for x in b:
44     #x =  x * 255 )
45     if( x == 0 ):
46         print "0,",
47     elif( x == 1.0 ):
48         print "1,",
49     else:
50         print "%8.6f," %( x ),
51
52 print
53