IMG_png.c
changeset 117 e613cf987897
parent 100 3feaaa4104f6
child 118 c5e736a47ad2
equal deleted inserted replaced
116:df32aeaf0b10 117:e613cf987897
    74 #define PNG_BYTES_TO_CHECK 4
    74 #define PNG_BYTES_TO_CHECK 4
    75 
    75 
    76 /* See if an image is contained in a data source */
    76 /* See if an image is contained in a data source */
    77 int IMG_isPNG(SDL_RWops *src)
    77 int IMG_isPNG(SDL_RWops *src)
    78 {
    78 {
    79    unsigned char buf[PNG_BYTES_TO_CHECK];
    79 	int start;
    80 
    80 	int is_PNG;
    81    /* Read in the signature bytes */
    81 	unsigned char buf[PNG_BYTES_TO_CHECK];
    82    if (SDL_RWread(src, buf, 1, PNG_BYTES_TO_CHECK) != PNG_BYTES_TO_CHECK)
    82 
    83       return 0;
    83 	start = SDL_RWtell(src);
    84 
    84 	is_PNG = 0;
    85    /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature. */
    85 	if ( SDL_RWread(src, buf, 1, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK ) {
    86    return( !png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
    86 		is_PNG = (png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK) == 0);
       
    87 	}
       
    88 	SDL_RWseek(src, start, SEEK_SET);
       
    89 	return(is_PNG);
    87 }
    90 }
    88 
    91 
    89 /* Load a PNG type image from an SDL datasource */
    92 /* Load a PNG type image from an SDL datasource */
    90 static void png_read_data(png_structp ctx, png_bytep area, png_size_t size)
    93 static void png_read_data(png_structp ctx, png_bytep area, png_size_t size)
    91 {
    94 {