From b17657884a8b3c6e19ab562966110efe5d249089 Mon Sep 17 00:00:00 2001 From: raphael Date: Wed, 27 Nov 2024 13:56:31 +0100 Subject: [PATCH] chore: move coin and hand to statics and modify c compilation --- build.sh | 4 ++-- png2c.c | 20 ++++++++++++++++---- coin.png => static/assets/coin.png | Bin hand.png => static/assets/hand.png | Bin 4 files changed, 18 insertions(+), 6 deletions(-) rename coin.png => static/assets/coin.png (100%) rename hand.png => static/assets/hand.png (100%) diff --git a/build.sh b/build.sh index d525fd8..0183252 100755 --- a/build.sh +++ b/build.sh @@ -51,8 +51,8 @@ echo -e "$pengers_html" > pengers_image.html.temp sed -e '//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 diff --git a/png2c.c b/png2c.c index fa9dbdb..4ed4f19 100644 --- a/png2c.c +++ b/png2c.c @@ -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(" "); diff --git a/coin.png b/static/assets/coin.png similarity index 100% rename from coin.png rename to static/assets/coin.png diff --git a/hand.png b/static/assets/hand.png similarity index 100% rename from hand.png rename to static/assets/hand.png