From 2fbcb88858f9b3585885a6fa3fb4dd344ec934b6 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 8 Jul 2021 17:58:16 +0200 Subject: [PATCH] Convertisseur de Bmp --- BmpToHConvertor.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 BmpToHConvertor.py diff --git a/BmpToHConvertor.py b/BmpToHConvertor.py new file mode 100644 index 0000000..986e6a5 --- /dev/null +++ b/BmpToHConvertor.py @@ -0,0 +1,31 @@ +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument("INPUT_FILE") +parser.add_argument("OUTPUT_FILE") +args = parser.parse_args() + +input_file = open(args.INPUT_FILE, "rb") +output_file = open(args.OUTPUT_FILE, "w") + +output_file.write("""#include "stdlib" +const uint8_t mon_image[] = { +""") + +bytes_array = [] +while input_file.peek(1) != b'' : + bytes_array.append("\\0x" + input_file.read(1).hex()) + +print("Il y a {} octets dans le fichier".format(len(bytes_array))) + +data = "" +for n, repr in enumerate(bytes_array): + data += repr +', ' + if n%8 == 7: + data+= "\n" +output_file.write(data) +output_file.write(""" +};""") + +input_file.close() +output_file.close() \ No newline at end of file