42_KFS/tools/icon_converter.py

37 lines
753 B
Python
Raw Normal View History

2024-12-10 10:26:00 -05:00
from PIL import Image
import sys
import os
if (len(sys.argv) < 2):
print("Error: usage python icon_maker.py {img}")
image = Image.open(sys.argv[1])
width, height = image.size
pixels = list(image.getdata())
pixels = [r << 16 | g << 8 | b for r, g, b in pixels]
string = str(pixels).replace("(", "{").replace(")", "}").replace("[", "{").replace("]", "}")
filename: str = os.path.basename(sys.argv[1]).split(".")[0]
string = f"""\
#pragma once
#include <stdint.h>
#include "icon.h"
uint32_t {filename}_color_map[{width} * {height}] = {string};
struct icon {filename}_icon = {{
.height = {height},
.width = {width},
.pixels = {filename}_color_map
}};
"""
with open(f"./headers/icons/{filename}.h", "w") as f:
f.write(string)