IMG_pnm.c
changeset 117 e613cf987897
parent 98 9f94c4674cc9
child 118 c5e736a47ad2
equal deleted inserted replaced
116:df32aeaf0b10 117:e613cf987897
    40 #ifdef LOAD_PNM
    40 #ifdef LOAD_PNM
    41 
    41 
    42 /* See if an image is contained in a data source */
    42 /* See if an image is contained in a data source */
    43 int IMG_isPNM(SDL_RWops *src)
    43 int IMG_isPNM(SDL_RWops *src)
    44 {
    44 {
       
    45 	int start;
       
    46 	int is_PNM;
    45 	char magic[2];
    47 	char magic[2];
    46 
    48 
    47 	/*
    49 	start = SDL_RWtell(src);
    48 	 * PNM magic signatures:
    50 	is_PNM = 0;
    49 	 * P1	PBM, ascii format
    51 	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    50 	 * P2	PGM, ascii format
    52 		/*
    51 	 * P3	PPM, ascii format
    53 		 * PNM magic signatures:
    52 	 * P4	PBM, binary format
    54 		 * P1	PBM, ascii format
    53 	 * P5	PGM, binary format
    55 		 * P2	PGM, ascii format
    54 	 * P6	PPM, binary format
    56 		 * P3	PPM, ascii format
    55 	 */
    57 		 * P4	PBM, binary format
    56 	return (SDL_RWread(src, magic, 2, 1)
    58 		 * P5	PGM, binary format
    57 		&& magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6');
    59 		 * P6	PPM, binary format
       
    60 		 */
       
    61 		if ( magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6' ) {
       
    62 			is_PNM = 1;
       
    63 		}
       
    64 	}
       
    65 	SDL_RWseek(src, start, SEEK_SET);
       
    66 	return(is_PNM);
    58 }
    67 }
    59 
    68 
    60 /* read a non-negative integer from the source. return -1 upon error */
    69 /* read a non-negative integer from the source. return -1 upon error */
    61 static int ReadNumber(SDL_RWops *src)
    70 static int ReadNumber(SDL_RWops *src)
    62 {
    71 {