IMG_pnm.c
changeset 117 e613cf987897
parent 98 9f94c4674cc9
child 118 c5e736a47ad2
     1.1 --- a/IMG_pnm.c	Sat Feb 04 04:53:36 2006 +0000
     1.2 +++ b/IMG_pnm.c	Sat Feb 04 20:37:17 2006 +0000
     1.3 @@ -42,19 +42,28 @@
     1.4  /* See if an image is contained in a data source */
     1.5  int IMG_isPNM(SDL_RWops *src)
     1.6  {
     1.7 +	int start;
     1.8 +	int is_PNM;
     1.9  	char magic[2];
    1.10  
    1.11 -	/*
    1.12 -	 * PNM magic signatures:
    1.13 -	 * P1	PBM, ascii format
    1.14 -	 * P2	PGM, ascii format
    1.15 -	 * P3	PPM, ascii format
    1.16 -	 * P4	PBM, binary format
    1.17 -	 * P5	PGM, binary format
    1.18 -	 * P6	PPM, binary format
    1.19 -	 */
    1.20 -	return (SDL_RWread(src, magic, 2, 1)
    1.21 -		&& magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6');
    1.22 +	start = SDL_RWtell(src);
    1.23 +	is_PNM = 0;
    1.24 +	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    1.25 +		/*
    1.26 +		 * PNM magic signatures:
    1.27 +		 * P1	PBM, ascii format
    1.28 +		 * P2	PGM, ascii format
    1.29 +		 * P3	PPM, ascii format
    1.30 +		 * P4	PBM, binary format
    1.31 +		 * P5	PGM, binary format
    1.32 +		 * P6	PPM, binary format
    1.33 +		 */
    1.34 +		if ( magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6' ) {
    1.35 +			is_PNM = 1;
    1.36 +		}
    1.37 +	}
    1.38 +	SDL_RWseek(src, start, SEEK_SET);
    1.39 +	return(is_PNM);
    1.40  }
    1.41  
    1.42  /* read a non-negative integer from the source. return -1 upon error */