refactoring

This commit is contained in:
Devaev Maxim
2020-12-08 17:17:10 +03:00
parent 8fc11ac056
commit 9039aa8ac5
24 changed files with 947 additions and 900 deletions

View File

@@ -22,6 +22,7 @@
import sys
import os
import io
import struct
@@ -62,7 +63,8 @@ def _get_jpeg_size(data: bytes) -> Tuple[int, int]:
def main() -> None:
assert len(sys.argv) == 4, f"{sys.argv[0]} <file.jpeg> <file.h> <name>"
jpeg_path = sys.argv[1]
header_path = sys.argv[2]
c_path = sys.argv[2]
h_path = os.path.basename(c_path[:-2]) + ".h"
name = sys.argv[3]
with open(jpeg_path, "rb") as jpeg_file:
@@ -78,13 +80,15 @@ def main() -> None:
for index in range(0, len(jpeg_data), 20)
) + ",\n}"
text = f"{common.C_PREPEND}\n\n"
text = f"{common.C_PREPEND}\n"
text += f"#include \"{h_path}\"\n\n\n"
text += f"const unsigned {name}_JPEG_WIDTH = {width};\n"
text += f"const unsigned {name}_JPEG_HEIGHT = {height};\n\n"
text += f"const size_t {name}_JPEG_DATA_SIZE = {len(jpeg_data)};\n"
text += f"const unsigned char {name}_JPEG_DATA[] = {jpeg_data_text};\n"
with open(header_path, "w") as header_file:
header_file.write(text)
with open(c_path, "w") as c_file:
c_file.write(text)
# =====