This commit is contained in:
parent
e659037335
commit
314508a159
1 changed files with 26 additions and 17 deletions
43
src/util.c
43
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue