~ubuntu-branches/ubuntu/karmic/sdl-image1.2/karmic

« back to all changes in this revision

Viewing changes to IMG_gif.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-06-09 07:21:47 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060609072147-31buc05gjjhttun0
Tags: 1.2.5-1
* New upstream release
* Updated Build-Depends and Depends to SDL 1.2.10
* Updated minimum shlibs version to 1.2.5
* Updated Standards-Version to 3.7.2
* Simplified watch file
* Fixed address of FSF in debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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
4
4
 
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.
9
9
 
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.
14
14
 
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
18
18
 
19
19
    Sam Lantinga
20
20
    slouken@libsdl.org
21
21
*/
22
22
 
23
 
/* $Id: IMG_gif.c,v 1.6 2004/01/04 17:33:01 slouken Exp $ */
24
 
 
25
23
/* This is a GIF image file loading framework */
26
24
 
27
25
#include <stdio.h>
34
32
/* See if an image is contained in a data source */
35
33
int IMG_isGIF(SDL_RWops *src)
36
34
{
 
35
        int start;
37
36
        int is_GIF;
38
37
        char magic[6];
39
38
 
 
39
        start = SDL_RWtell(src);
40
40
        is_GIF = 0;
41
 
        if ( SDL_RWread(src, magic, 6, 1) ) {
 
41
        if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
42
42
                if ( (strncmp(magic, "GIF", 3) == 0) &&
43
43
                     ((memcmp(magic + 3, "87a", 3) == 0) ||
44
44
                      (memcmp(magic + 3, "89a", 3) == 0)) ) {
45
45
                        is_GIF = 1;
46
46
                }
47
47
        }
 
48
        SDL_RWseek(src, start, SEEK_SET);
48
49
        return(is_GIF);
49
50
}
50
51
 
148
149
Image *
149
150
IMG_LoadGIF_RW(SDL_RWops *src)
150
151
{
 
152
    int start;
151
153
    unsigned char buf[16];
152
154
    unsigned char c;
153
155
    unsigned char localColorMap[3][MAXCOLORMAPSIZE];
160
162
    Image *image = NULL;
161
163
 
162
164
    if ( src == NULL ) {
163
 
        goto done;
 
165
        return NULL;
164
166
    }
 
167
    start = SDL_RWtell(src);
 
168
 
165
169
    if (!ReadOK(src, buf, 6)) {
166
170
        RWSetMsg("error reading magic number");
167
171
        goto done;
259
263
#endif
260
264
 
261
265
done:
 
266
    if ( image == NULL ) {
 
267
        SDL_RWseek(src, start, SEEK_SET);
 
268
    }
262
269
    return image;
263
270
}
264
271
 
310
317
        break;
311
318
    case 0xfe:                  /* Comment Extension */
312
319
        str = "Comment Extension";
313
 
        while (GetDataBlock(src, (unsigned char *) buf) != 0);
 
320
        while (GetDataBlock(src, (unsigned char *) buf) != 0)
 
321
            ;
314
322
        return FALSE;
315
323
    case 0xf9:                  /* Graphic Control Extension */
316
324
        str = "Graphic Control Extension";
321
329
        if ((buf[0] & 0x1) != 0)
322
330
            Gif89.transparent = buf[3];
323
331
 
324
 
        while (GetDataBlock(src, (unsigned char *) buf) != 0);
 
332
        while (GetDataBlock(src, (unsigned char *) buf) != 0)
 
333
            ;
325
334
        return FALSE;
326
335
    default:
327
336
        str = (char *)buf;
329
338
        break;
330
339
    }
331
340
 
332
 
    while (GetDataBlock(src, (unsigned char *) buf) != 0);
 
341
    while (GetDataBlock(src, (unsigned char *) buf) != 0)
 
342
        ;
333
343
 
334
344
    return FALSE;
335
345
}
459
469
            if (ZeroDataBlock)
460
470
                return -2;
461
471
 
462
 
            while ((count = GetDataBlock(src, buf)) > 0);
 
472
            while ((count = GetDataBlock(src, buf)) > 0)
 
473
                ;
463
474
 
464
475
            if (count != 0) {
465
476
                /*
526
537
    **  If this is an "uninteresting picture" ignore it.
527
538
     */
528
539
    if (ignore) {
529
 
        while (LWZReadByte(src, FALSE, c) >= 0);
 
540
        while (LWZReadByte(src, FALSE, c) >= 0)
 
541
            ;
530
542
        return NULL;
531
543
    }
532
544
    image = ImageNewCmap(len, height, cmapSize);