-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin.py
More file actions
37 lines (27 loc) · 1.12 KB
/
Copy pathbin.py
File metadata and controls
37 lines (27 loc) · 1.12 KB
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
31
32
33
34
35
36
37
import re
import os
# Path to your bitmaps.h file
HEADER_PATH = "bitmaps.h"
OUTPUT_DIR = "output_bins"
# Create output folder
os.makedirs(OUTPUT_DIR, exist_ok=True)
# Read header file
with open(HEADER_PATH, "r") as file:
content = file.read()
# Match all image arrays: image0, image1, ..., image111
pattern = r'const\s+uint8_t\s+(image\d+)\[\]\s+PROGMEM\s*=\s*\{([^}]*)\};'
matches = re.findall(pattern, content, re.DOTALL)
print(f"Found {len(matches)} image arrays...")
# Write each image to a .bin file
for idx, (name, data) in enumerate(matches):
# Extract byte values
bytes_clean = data.replace("\n", " ").replace("\r", " ").strip()
byte_list = [int(b.strip(), 16) for b in bytes_clean.split(",") if b.strip()]
# Format filename with leading zeros
filename = f"img{idx:03}.bin" # Pads the index with leading zeros
out_path = os.path.join(OUTPUT_DIR, filename)
# Write to binary file
with open(out_path, "wb") as bin_file:
bin_file.write(bytearray(byte_list))
print(f"Saved {out_path} ({len(byte_list)} bytes)")
print("✅ Done converting header images to .bin files!")