add gif
All checks were successful
pyrite-dev/taiga/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-03-09 01:01:47 +09:00
commit 314508a159
Signed by: nishi
GPG key ID: 27EF69B208EB9343

View file

@ -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);
}