diff --git a/tools/image.pbm b/tools/image.pbm new file mode 100644 index 0000000000000000000000000000000000000000..b4003000b3a981536cfe6fb70949ad69cb3d5ef0 Binary files /dev/null and b/tools/image.pbm differ diff --git a/tools/pbm.py b/tools/pbm.py new file mode 100755 index 0000000000000000000000000000000000000000..7fefdcffd85c8b5b42417a6e19c593a9fb8bcbfe --- /dev/null +++ b/tools/pbm.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +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() \ No newline at end of file