IMG.c
changeset 117 e613cf987897
parent 110 23d7437faa1b
child 119 336c49447e0d
equal deleted inserted replaced
116:df32aeaf0b10 117:e613cf987897
    94 }
    94 }
    95 
    95 
    96 /* Load an image from an SDL datasource, optionally specifying the type */
    96 /* Load an image from an SDL datasource, optionally specifying the type */
    97 SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type)
    97 SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type)
    98 {
    98 {
    99 	int i, start;
    99 	int i;
   100 	SDL_Surface *image;
   100 	SDL_Surface *image;
   101 
   101 
   102 	/* Make sure there is something to do.. */
   102 	/* Make sure there is something to do.. */
   103 	if ( src == NULL ) {
   103 	if ( src == NULL ) {
   104 		IMG_SetError("Passed a NULL data source");
   104 		IMG_SetError("Passed a NULL data source");
   112 			SDL_RWclose(src);
   112 			SDL_RWclose(src);
   113 		return(NULL);
   113 		return(NULL);
   114 	}
   114 	}
   115 
   115 
   116 	/* Detect the type of image being loaded */
   116 	/* Detect the type of image being loaded */
   117 	start = SDL_RWtell(src);
       
   118 	image = NULL;
   117 	image = NULL;
   119 	for ( i=0; i < ARRAYSIZE(supported); ++i ) {
   118 	for ( i=0; i < ARRAYSIZE(supported); ++i ) {
   120 		if(supported[i].is) {
   119 		if(supported[i].is) {
   121 			SDL_RWseek(src, start, SEEK_SET);
       
   122 			if(!supported[i].is(src))
   120 			if(!supported[i].is(src))
   123 				continue;
   121 				continue;
   124 		} else {
   122 		} else {
   125 			/* magicless format */
   123 			/* magicless format */
   126 			if(!type
   124 			if(!type
   129 		}
   127 		}
   130 #ifdef DEBUG_IMGLIB
   128 #ifdef DEBUG_IMGLIB
   131 		fprintf(stderr, "IMGLIB: Loading image as %s\n",
   129 		fprintf(stderr, "IMGLIB: Loading image as %s\n",
   132 			supported[i].type);
   130 			supported[i].type);
   133 #endif
   131 #endif
   134 		SDL_RWseek(src, start, SEEK_SET);
       
   135 		image = supported[i].load(src);
   132 		image = supported[i].load(src);
   136 		if(freesrc)
   133 		if(freesrc)
   137 			SDL_RWclose(src);
   134 			SDL_RWclose(src);
   138 		return image;
   135 		return image;
   139 	}
   136 	}