3 # Author: Brendan Le Foll <brendan.le.foll@intel.com>
4 # Copyright (c) 2014 Intel Corporation.
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
25 from __future__ import print_function
30 # Pixels are arranged in one byte for 8 vertical pixels and not addressed individually
31 # We convert the image to greysacle and end up making it monochrome where we
32 # consider that every pixel that is '40' is black.
37 if len(sys.argv) != 2:
38 print('Please specify an image to use as the only argument')
41 im = Image.open(sys.argv[1])
42 im = im.convert('L').resize((width, height))
44 data = list(im.getdata())
46 byteblock = [0 for i in range(width)]
47 widthblock = [list(byteblock) for i in range(int(height/8))]
52 # we split the list by width * 8, to create data chunks of 8rows
53 datachunks=[data[x:x+(width*8)] for x in range(0, len(data), (width*8))]
55 # grab every pixel of image (or datachunk)
56 while i < len(widthblock):
58 for y in datachunks[i]:
59 xcoor = pixcount % width
60 ycoor = int(pixcount/width)
61 blknum = xcoor % len(widthblock)
64 # 40 is what we consider 'black'
66 widthblock[i][xcoor] |= (1 << blkycoor)
71 flatlist = [y for x in widthblock for y in x]
73 carray = 'static uint8_t image[] = {\n' + ', '.join(str(x) for x in flatlist)
74 print(carray + '\n};')