Skip to content

Commit

Permalink
Allow detection of PNG images without necessarily being able to dynam…
Browse files Browse the repository at this point in the history
…ically load the PNG library.
  • Loading branch information
slouken committed Jul 18, 2007
1 parent 3be31d5 commit 0592c6c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions IMG_png.c
Expand Up @@ -270,18 +270,19 @@ int IMG_isPNG(SDL_RWops *src)
int is_PNG;
unsigned char buf[PNG_BYTES_TO_CHECK];

if ( IMG_InitPNG() < 0 ) {
return 0;
}
if ( !src )
return 0;
start = SDL_RWtell(src);
is_PNG = 0;
if ( SDL_RWread(src, buf, 1, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK ) {
is_PNG = (lib.png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK) == 0);
if ( buf[0] == 0x89 &&
buf[1] == 'P' &&
buf[2] == 'N' &&
buf[3] == 'G' ) {
is_PNG = 1;
}
}
SDL_RWseek(src, start, SEEK_SET);
IMG_QuitPNG();
return(is_PNG);
}

Expand Down

0 comments on commit 0592c6c

Please sign in to comment.