dos3d
diff src/texture.c @ 19:c10f62b2bd56
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 30 Nov 2011 07:17:09 +0200 |
parents | c8ffdbc6139e |
children |
line diff
1.1 --- a/src/texture.c Wed Nov 30 00:06:28 2011 +0200 1.2 +++ b/src/texture.c Wed Nov 30 07:17:09 2011 +0200 1.3 @@ -24,7 +24,7 @@ 1.4 1.5 struct texture *load_texture(const char *fname) 1.6 { 1.7 - int i, num_pixels; 1.8 + int i, num_pixels, hdrline = 0; 1.9 struct texture *tex; 1.10 long fpos; 1.11 1.12 @@ -38,10 +38,45 @@ 1.13 free_texture(tex); 1.14 return 0; 1.15 } 1.16 - if(fscanf(tex->file, "P6 %d %d 255 ", &tex->width, &tex->height) != 2) { 1.17 - fprintf(stderr, "invalid pixmap: %s\n", fname); 1.18 - free_texture(tex); 1.19 - return 0; 1.20 + 1.21 + while(hdrline < 3) { 1.22 + char buf[64]; 1.23 + if(!fgets(buf, sizeof buf, tex->file)) { 1.24 + fprintf(stderr, "invalid pixmap: %s\n", fname); 1.25 + free_texture(tex); 1.26 + return 0; 1.27 + } 1.28 + 1.29 + if(buf[0] == '#') { 1.30 + continue; 1.31 + } 1.32 + 1.33 + switch(hdrline) { 1.34 + case 0: 1.35 + if(buf[0] != 'P' || buf[1] != '6') { 1.36 + fprintf(stderr, "invalid pixmap: %s\n", fname); 1.37 + free_texture(tex); 1.38 + return 0; 1.39 + } 1.40 + break; 1.41 + 1.42 + case 1: 1.43 + if(sscanf(buf, "%d %d", &tex->width, &tex->height) != 2) { 1.44 + fprintf(stderr, "invalid pixmap: %s\n", fname); 1.45 + free_texture(tex); 1.46 + return 0; 1.47 + } 1.48 + break; 1.49 + 1.50 + case 2: 1.51 + if(atoi(buf) != 255) { 1.52 + fprintf(stderr, "invalid pixmap: %s\n", fname); 1.53 + free_texture(tex); 1.54 + return 0; 1.55 + } 1.56 + break; 1.57 + } 1.58 + hdrline++; 1.59 } 1.60 fpos = ftell(tex->file); 1.61