IMG_xcf.c
changeset 118 c5e736a47ad2
parent 117 e613cf987897
child 121 1bf9c0c87374
     1.1 --- a/IMG_xcf.c	Sat Feb 04 20:37:17 2006 +0000
     1.2 +++ b/IMG_xcf.c	Sat Feb 04 22:26:04 2006 +0000
     1.3 @@ -671,12 +671,15 @@
     1.4    return 0;
     1.5  }
     1.6  
     1.7 -SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src) {
     1.8 +SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src)
     1.9 +{
    1.10 +  int start;
    1.11 +  const char *error = NULL;
    1.12    SDL_Surface *surface, *lays;
    1.13    xcf_header * head;
    1.14    xcf_layer  * layer;
    1.15    xcf_channel ** channel;
    1.16 -  int read_error, chnls, i, offsets;
    1.17 +  int chnls, i, offsets;
    1.18    Uint32 offset, fp;
    1.19  
    1.20    unsigned char * (* load_tile) (SDL_RWops *, Uint32, int, int, int);
    1.21 @@ -685,10 +688,10 @@
    1.22      /* The error message has been set in SDL_RWFromFile */
    1.23      return NULL;
    1.24    }
    1.25 +  start = SDL_RWtell(src);
    1.26  
    1.27    /* Initialize the data we will clean up when we're done */
    1.28    surface = NULL;
    1.29 -  read_error = 0;
    1.30  
    1.31    head = read_xcf_header (src);
    1.32  
    1.33 @@ -710,7 +713,7 @@
    1.34  			     0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
    1.35  
    1.36    if ( surface == NULL ) {
    1.37 -    IMG_SetError("Out of memory");
    1.38 +    error = "Out of memory";
    1.39      goto done;
    1.40    }
    1.41  
    1.42 @@ -728,7 +731,7 @@
    1.43  			  0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
    1.44  
    1.45    if ( lays == NULL ) {
    1.46 -    IMG_SetError("Out of memory");
    1.47 +    error = "Out of memory";
    1.48      goto done;
    1.49    }
    1.50  
    1.51 @@ -775,7 +778,7 @@
    1.52  			   0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
    1.53  
    1.54      if (chs == NULL) {
    1.55 -      IMG_SetError("Out of memory");
    1.56 +      error = "Out of memory";
    1.57        goto done;
    1.58      }
    1.59      for (i = 0; i < chnls; i++) {
    1.60 @@ -790,12 +793,15 @@
    1.61      SDL_FreeSurface (chs);
    1.62    }
    1.63  
    1.64 - done:
    1.65 +done:
    1.66    free_xcf_header (head);
    1.67 -  if ( read_error ) {
    1.68 -    SDL_FreeSurface(surface);
    1.69 -    IMG_SetError("Error reading XCF data");
    1.70 -    surface = NULL;
    1.71 +  if ( error ) {
    1.72 +    SDL_RWseek(src, start, SEEK_SET);
    1.73 +    if ( surface ) {
    1.74 +      SDL_FreeSurface(surface);
    1.75 +      surface = NULL;
    1.76 +    }
    1.77 +    IMG_SetError(error);
    1.78    }
    1.79  
    1.80    return(surface);