From 314508a159c6ee1309b577f55fd0e2d2129d3a82 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Mon, 9 Mar 2026 01:01:47 +0900 Subject: [PATCH] add gif --- src/util.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/util.c b/src/util.c index 60caa44..04570c8 100644 --- a/src/util.c +++ b/src/util.c @@ -43,6 +43,9 @@ char* u_http_path(const char* top, const char* path) { return u_strvacat(top, "build/", path, NULL); /* otherwise, concat */ } +/* reason why this exists, is because IE6 has bugs with PNG transparency + * and script i wrote, needs image size or it (sometimes) breaaks how it's shown. + */ int u_image_size(const char* top, const char* path, char* (*path_func)(const char* top, const char* path), int* w, int* h) { char* p; int ch; @@ -59,24 +62,12 @@ int u_image_size(const char* top, const char* path, char* (*path_func)(const cha if((f = fopen(p, "rb")) != NULL) { unsigned char buffer[512]; unsigned char png_sig[16] = { - 0x89, - 0x50, - 0x4e, - 0x47, - 0x0d, - 0x0a, - 0x1a, - 0x0a, - /**/ - 0x00, - 0x00, - 0x00, - 0x0d, - 0x49, - 0x48, - 0x44, - 0x52}; + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, + 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52}; + unsigned char gif_sig[6] = { + 0x47, 0x49, 0x46, 0x38, 0x39, 0x61}; /* GIF89a */ + fseek(f, 0, SEEK_SET); if(fread(buffer, 1, 16, f) == 16 && memcmp(buffer, png_sig, 16) == 0 && fread(buffer, 1, 13, f) == 13) { int i; @@ -94,6 +85,24 @@ int u_image_size(const char* top, const char* path, char* (*path_func)(const cha st = 1; } + fseek(f, 0, SEEK_SET); + if(fread(buffer, 1, 6, f) == 6 && memcmp(buffer, gif_sig, 6) == 0 && fread(buffer, 1, 4, f) == 4) { + int i; + + *w = 0; + *h = 0; + + for(i = 0; i < 2; i++) { + *w = (*w) << 8; + *w |= buffer[1 - i + 0]; + + *h = (*h) << 8; + *h |= buffer[1 - i + 2]; + } + + st = 1; + } + fclose(f); }