3 Generate an image from a png which can be used by guilib.
5 Copyright (C) 2009 Daniel Mack <daniel@caiaq.de>
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 print "guilib image file generator"
27 print "Usage: %s <image> <outfilename> <imagename>" % (sys
.argv
[0])
28 print "This tool will output a 'static struct guilib_image' to <outfile>"
29 print "containing the pixel information from <imagefile>. The struct will"
30 print "be named <imagename>."
31 print "All paramters are mandatory."
35 imagefile
= sys
.argv
[1]
37 imagename
= sys
.argv
[3]
47 im
= gd
.image(imagefile
)
50 out
= "static struct guilib_image %s = {\n" % (imagename
)
51 out
+= "\t.width = %d,\n" % (w
)
52 out
+= "\t.height = %d,\n" % (h
)
53 out
+= "\t.data = {\n"
56 for n
in range (0, w
* h
):
57 pixel
= im
.getPixel((n
% w
, n
/ w
))
60 (r
, g
, b
) = im
.colorComponents(pixel
)
61 color
= (r
+ g
+ b
) / 3
64 outbyte |
= 1 << (7 - bit
);
67 out
+= "0x%02x, " % outbyte
79 out
+= struct
.pack("B", outbyte
)
84 print "unable to open bitmap file >%s<" % (imagefile
)
87 f
= open(outfile
, 'w')