diff --git a/firmware/.gitignore b/firmware/.gitignore index 89cc49c..9ec2224 100644 --- a/firmware/.gitignore +++ b/firmware/.gitignore @@ -3,3 +3,4 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +src/gfx_png.h diff --git a/firmware/scripts/gfx_convert.py b/firmware/scripts/gfx_convert.py index 274ac0b..30ec29b 100644 --- a/firmware/scripts/gfx_convert.py +++ b/firmware/scripts/gfx_convert.py @@ -22,8 +22,6 @@ def to_code(name, path): img = Image.open(path) img = img.convert("1", dither=Image.Dither.FLOYDSTEINBERG) w, h = img.size - colors = img.getcolors() - print(colors) code = f"uint32_t gfx_{name}[{h}] = {'{'}\n" @@ -37,7 +35,7 @@ def to_code(name, path): code += "};\n\n" return code -if __name__ == "__main__": +def generate_gfx(): gfx = get_all_gfx() gfx_code = ''.join(to_code(name, path) for name, path in gfx) @@ -55,3 +53,38 @@ if __name__ == "__main__": f.write(index) print("gfx.h generated!") + +def png_to_code(name, path): + file = open(path, "rb") + data = file.read() + size = len(data) + + code = f"uint8_t png_{name}[{size}] = {'{'}" + for i in range(size): + code += f"0x{data[i]:02x}," + code += "};\n\n" + return code + +def generate_png_gfx(): + gfx = get_all_gfx() + gfx_code = ''.join(png_to_code(name, path) for name, path in gfx) + + header = f"#pragma once\n#include \n\n/* DO NOT MODIFY - AUTOGENERATED! */\n\n" + + index = f"uint8_t* png_frames[{len(gfx)}] = {'{'}\n" + for name, _ in gfx: + index += f" png_{name},\n" + index += "};\n" + + with open("src/gfx_png.h", "w") as f: + f.write(header) + f.write("#define PNG_COUNT " + str(len(gfx)) + "\n\n") + f.write(gfx_code) + f.write(index) + + print("gfx_png.h generated!") + + +if __name__ == "__main__": + generate_gfx() + generate_png_gfx() diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index b9ab010..7a32432 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -1,5 +1,7 @@ #include #include "gfx.h" +#include "gfx_png.h" +#include "lodepng.h" #define COL_SER 0 #define COL_OE 26 @@ -102,6 +104,22 @@ void setup() { // clear frames frameIndex = 0; frameLastChangedAt = millis(); + + delay(1500); + + Serial.println("Decoding PNG..."); + + auto b4 = millis(); + unsigned char *buffer = 0; + unsigned width, height; + lodepng_decode_memory(&buffer, &width, &height, png_badapple_001, sizeof(png_badapple_001), LCT_GREY, 8); + + Serial.print("Decoded in "); + Serial.print(millis() - b4); + Serial.println("ms"); + + Serial.println(width); + Serial.println(height); } void loop() {