Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / resources / conv_to_ewm_prop.py
1 #!/usr/bin/python
2
3 # Copyright 2011 Anthony Tong <atong@trustedcs.com>
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """
18 tool to preconvert an icon file to a x11 property as expected
19 by ewm hints spec:
20 width, length, [argb pixels]
21 """
22
23 import PIL
24 import PIL.Image
25
26 import os
27 import sys
28
29 def usage():
30         print "convert_to_ewm_prop <infile> <outfile>"
31         return 1
32
33 def main(argv):
34         if len(argv) != 3:
35                 return usage()
36
37         im = PIL.Image.open(argv[1])
38         fp = open(argv[2], 'w')
39
40         var_name = os.path.basename(argv[2])
41         if var_name.endswith('.h'):
42                 var_name = var_name[:-2]
43
44         fp.write("static unsigned long %s_prop [] = {\n" % var_name)
45         fp.write(" %d, %d\n" % im.size)
46
47         i = 0
48         for pixel in im.getdata():
49                 r,g,b,a = pixel
50                 pixel = b 
51                 pixel |= g << 8
52                 pixel |= r << 16
53                 pixel |= a << 24
54                 fp.write(" , %du" % pixel)
55
56                 i += 1
57                 if i % 8 == 0:
58                         fp.write("\n")
59
60         fp.write("};\n")
61
62 if __name__ == '__main__':
63         sys.exit(main(sys.argv))
64