chore: move coin and hand to statics and modify c compilation

This commit is contained in:
raphael 2024-11-27 13:56:31 +01:00
parent d6ab4e4022
commit b17657884a
4 changed files with 18 additions and 6 deletions

View File

@ -51,8 +51,8 @@ echo -e "$pengers_html" > pengers_image.html.temp
sed -e '/<!-- penger images src -->/rpengers_image.html.temp' index.html.template > index.html
rm pengers_image.html.temp
./png2c "hand.png" > hand.c
./png2c "coin.png" > coin.c
./out/png2c "static/assets/hand.png" > out/hand.c
./out/png2c "static/assets/coin.png" > out/coin.c
clang -O3 --target=wasm32 -fno-builtin -nostdlib --no-standard-libraries -Wl,--no-entry $export_cmd -Wl,--allow-undefined -o $f.wasm $a

20
png2c.c
View File

@ -20,11 +20,23 @@ int main(int argc, const char *argv[])
}
if (argc < 3) { // no id provided
int file_name_len = strlen(img_path) - strlen(".png");
char *last_slash = strrchr(img_path, '/');
char extracted[50];
printf("int %.*s_height = %d;\n", file_name_len, img_path, height);
printf("int %.*s_width = %d;\n", file_name_len, img_path, width);
printf("unsigned int %.*s_img[%d][%d] = {\n", file_name_len, img_path, height, width);
if (last_slash != NULL) {
// Extract the part after the last '/'
strcpy(extracted, last_slash + 1);
// Remove the '.png' extension
char *dot = strrchr(extracted, '.');
if (dot != NULL) {
*dot = '\0'; // Null-terminate the string at the '.'
}
}
printf("int %s_height = %d;\n", extracted, height);
printf("int %s_width = %d;\n", extracted, width);
printf("unsigned int %s_img[%d][%d] = {\n", extracted, height, width);
for (int y = 0; y < height; y++) {
printf(" ");

View File

Before

Width:  |  Height:  |  Size: 474 B

After

Width:  |  Height:  |  Size: 474 B

View File

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB