-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbimage.py
30 lines (24 loc) · 884 Bytes
/
fbimage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
import os
def main():
if len(sys.argv) != 2:
usage()
return 2
with open(sys.argv[1], 'rb') as fd:
pbm_format = fd.readline().strip()
if pbm_format != b'P4':
print("ERROR: input file must be binary PBM (type P4)",
file = sys.stderr)
return 1
pbm_dims = [int(d) for d in fd.readline().strip().split()]
pbm_data = fd.read()
fbbase = "fb_{0}".format(os.path.basename(sys.argv[1]))
fbname = os.path.splitext(fbbase)[0]
with sys.stdout as fd:
f = "{0} = framebuf.FrameBuffer(bytearray({1}), {2}, {3}, framebuf.MONO_HLSB)\n"
fd.write(f.format(fbname, str(pbm_data), pbm_dims[0], pbm_dims[1]))
def usage():
print("""usage: {0} PBM_FILE""".format(os.path.basename(sys.argv[0])),
file = sys.stderr)
if __name__ == '__main__':
main()