From 1d4b1d4e352a0c445d08e2e0a0df7060ffd88e83 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 10 May 2026 06:25:27 +0900 Subject: [PATCH] rewrite in c --- tools/Makefile | 7 +++++-- tools/icon-converter.c | 36 ++++++++++++++++++++++++++++++++++++ tools/icon-converter.sh | 15 --------------- 3 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 tools/icon-converter.c delete mode 100755 tools/icon-converter.sh diff --git a/tools/Makefile b/tools/Makefile index 3bac0e6..036e365 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -6,7 +6,7 @@ LIBS = `pkg-config --libs freetype2` .PHONY: all clean .SUFFIXES: .c .o -all: fuzzer font +all: fuzzer font icon-converter icon-converter fuzzer: fuzzer.o $(CC) -g -L../src/ -Wl,-R../src -o $@ fuzzer.o -lMw @@ -14,8 +14,11 @@ fuzzer: fuzzer.o font: font.o $(CC) $(LDFLAGS) -o $@ font.o $(LIBS) +icon-converter: icon-converter.o + $(CC) -o $@ icon-converter.o -lm + .c.o: $(CC) $(CFLAGS) -c -o $@ $< clean: - rm -f *.o font fuzzer + rm -f *.o font fuzzer icon-converter diff --git a/tools/icon-converter.c b/tools/icon-converter.c new file mode 100644 index 0000000..0a3ece8 --- /dev/null +++ b/tools/icon-converter.c @@ -0,0 +1,36 @@ +#define STB_IMAGE_IMPLEMENTATION +#include "../external/stb_image.h" + +#include + +int main(int argc, char** argv){ + unsigned char* rgba; + int width, height, bpp; + int i; + + if(argc != 3){ + printf("Usage: %s input name\n", argv[0]); + return 1; + } + + rgba = stbi_load(argv[1], &width, &height, &bpp, 4); + + printf("MwU32 %s[] = {\n", argv[2]); + printf(" (%d << 16) | %d,\n", width, height); + for(i = 0; i < width * height; i++){ + unsigned char* px = &rgba[i * 4]; + unsigned int p = 0; + int j; + + for(j = 0; j < 4; j++){ + p = p << 8; + p = p | px[j]; + } + + printf(" 0x%x,\n", p); + } + printf(" 0\n"); + printf("};\n"); + + free(rgba); +} diff --git a/tools/icon-converter.sh b/tools/icon-converter.sh deleted file mode 100755 index 9d96846..0000000 --- a/tools/icon-converter.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -if [ "x$1" = "x" -o "x$2" = "x" ]; then - echo "Usage: $0 input name" - exit 1 -fi - -GEO=`convert $1 json:- 2>/dev/null | jq -r '(.[0].image.geometry.width | tostring) + "x" + (.[0].image.geometry.height | tostring)'` -WIDTH=`echo $GEO | cut -dx -f1` -HEIGHT=`echo $GEO | cut -dx -f2` - -echo "MwU32 $2[] = {" -echo " ($WIDTH << 16) | $HEIGHT," -convert $1 txt:- 2>/dev/null | grep -oE '#[0-9a-fA-F]{8}' | sed 's/^#/ 0x/' | sed -E 's/$/,/' -echo " 0" -echo "};"