mirror of
https://github.com/radex/radmatrix.git
synced 2024-10-04 03:37:46 +00:00
firmware: png decode demo
This commit is contained in:
parent
d7a40b2123
commit
e76fd8a0ad
3 changed files with 55 additions and 3 deletions
1
firmware/.gitignore
vendored
1
firmware/.gitignore
vendored
|
@ -3,3 +3,4 @@
|
||||||
.vscode/c_cpp_properties.json
|
.vscode/c_cpp_properties.json
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.vscode/ipch
|
.vscode/ipch
|
||||||
|
src/gfx_png.h
|
||||||
|
|
|
@ -22,8 +22,6 @@ def to_code(name, path):
|
||||||
img = Image.open(path)
|
img = Image.open(path)
|
||||||
img = img.convert("1", dither=Image.Dither.FLOYDSTEINBERG)
|
img = img.convert("1", dither=Image.Dither.FLOYDSTEINBERG)
|
||||||
w, h = img.size
|
w, h = img.size
|
||||||
colors = img.getcolors()
|
|
||||||
print(colors)
|
|
||||||
|
|
||||||
code = f"uint32_t gfx_{name}[{h}] = {'{'}\n"
|
code = f"uint32_t gfx_{name}[{h}] = {'{'}\n"
|
||||||
|
|
||||||
|
@ -37,7 +35,7 @@ def to_code(name, path):
|
||||||
code += "};\n\n"
|
code += "};\n\n"
|
||||||
return code
|
return code
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def generate_gfx():
|
||||||
gfx = get_all_gfx()
|
gfx = get_all_gfx()
|
||||||
gfx_code = ''.join(to_code(name, path) for name, path in gfx)
|
gfx_code = ''.join(to_code(name, path) for name, path in gfx)
|
||||||
|
|
||||||
|
@ -55,3 +53,38 @@ if __name__ == "__main__":
|
||||||
f.write(index)
|
f.write(index)
|
||||||
|
|
||||||
print("gfx.h generated!")
|
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 <Arduino.h>\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()
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
#include "gfx_png.h"
|
||||||
|
#include "lodepng.h"
|
||||||
|
|
||||||
#define COL_SER 0
|
#define COL_SER 0
|
||||||
#define COL_OE 26
|
#define COL_OE 26
|
||||||
|
@ -102,6 +104,22 @@ void setup() {
|
||||||
// clear frames
|
// clear frames
|
||||||
frameIndex = 0;
|
frameIndex = 0;
|
||||||
frameLastChangedAt = millis();
|
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() {
|
void loop() {
|
||||||
|
|
Loading…
Reference in a new issue