2
2
SDL_image: An example image loading library for use with SDL
3
Copyright (C) 1999-2004 Sam Lantinga
3
Copyright (C) 1997-2006 Sam Lantinga
5
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
6
modify it under the terms of the GNU Lesser General Public
7
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
8
version 2.1 of the License, or (at your option) any later version.
10
10
This library is distributed in the hope that it will be useful,
11
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
13
Lesser General Public License for more details.
15
You should have received a copy of the GNU Library General Public
16
License along with this library; if not, write to the Free
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
/* $Id: IMG_pnm.c,v 1.5 2004/01/04 22:04:38 slouken Exp $ */
26
24
* PNM (portable anymap) image loader:
42
40
/* See if an image is contained in a data source */
43
41
int IMG_isPNM(SDL_RWops *src)
48
* PNM magic signatures:
49
* P1 PBM, ascii format
50
* P2 PGM, ascii format
51
* P3 PPM, ascii format
52
* P4 PBM, binary format
53
* P5 PGM, binary format
54
* P6 PPM, binary format
56
return (SDL_RWread(src, magic, 2, 1)
57
&& magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6');
47
start = SDL_RWtell(src);
49
if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
51
* PNM magic signatures:
52
* P1 PBM, ascii format
53
* P2 PGM, ascii format
54
* P3 PPM, ascii format
55
* P4 PBM, binary format
56
* P5 PGM, binary format
57
* P6 PPM, binary format
58
* P7 PAM, a general wrapper for PNM data
60
if ( magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6' ) {
64
SDL_RWseek(src, start, SEEK_SET);
60
68
/* read a non-negative integer from the source. return -1 upon error */
104
113
char *error = NULL;
107
enum { PBM, PGM, PPM } kind;
116
enum { PBM, PGM, PPM, PAM } kind;
109
118
#define ERROR(s) do { error = (s); goto done; } while(0)