IMG.c
changeset 368 8a61842d00ce
parent 347 ad5034cad524
child 393 e94321a2e752
     1.1 --- a/IMG.c	Thu Apr 25 00:22:51 2013 -0700
     1.2 +++ b/IMG.c	Tue May 21 21:24:32 2013 -0700
     1.3 @@ -31,33 +31,33 @@
     1.4  
     1.5  /* Table of image detection and loading functions */
     1.6  static struct {
     1.7 -	char *type;
     1.8 -	int (SDLCALL *is)(SDL_RWops *src);
     1.9 -	SDL_Surface *(SDLCALL *load)(SDL_RWops *src);
    1.10 +    char *type;
    1.11 +    int (SDLCALL *is)(SDL_RWops *src);
    1.12 +    SDL_Surface *(SDLCALL *load)(SDL_RWops *src);
    1.13  } supported[] = {
    1.14 -	/* keep magicless formats first */
    1.15 -	{ "TGA", NULL,      IMG_LoadTGA_RW },
    1.16 -	{ "CUR", IMG_isCUR, IMG_LoadCUR_RW },
    1.17 -	{ "ICO", IMG_isICO, IMG_LoadICO_RW },
    1.18 -	{ "BMP", IMG_isBMP, IMG_LoadBMP_RW },
    1.19 -	{ "GIF", IMG_isGIF, IMG_LoadGIF_RW },
    1.20 -	{ "JPG", IMG_isJPG, IMG_LoadJPG_RW },
    1.21 -	{ "LBM", IMG_isLBM, IMG_LoadLBM_RW },
    1.22 -	{ "PCX", IMG_isPCX, IMG_LoadPCX_RW },
    1.23 -	{ "PNG", IMG_isPNG, IMG_LoadPNG_RW },
    1.24 -	{ "PNM", IMG_isPNM, IMG_LoadPNM_RW }, /* P[BGP]M share code */
    1.25 -	{ "TIF", IMG_isTIF, IMG_LoadTIF_RW },
    1.26 -	{ "XCF", IMG_isXCF, IMG_LoadXCF_RW },
    1.27 -	{ "XPM", IMG_isXPM, IMG_LoadXPM_RW },
    1.28 -	{ "XV",  IMG_isXV,  IMG_LoadXV_RW  },
    1.29 -	{ "WEBP", IMG_isWEBP, IMG_LoadWEBP_RW },
    1.30 +    /* keep magicless formats first */
    1.31 +    { "TGA", NULL,      IMG_LoadTGA_RW },
    1.32 +    { "CUR", IMG_isCUR, IMG_LoadCUR_RW },
    1.33 +    { "ICO", IMG_isICO, IMG_LoadICO_RW },
    1.34 +    { "BMP", IMG_isBMP, IMG_LoadBMP_RW },
    1.35 +    { "GIF", IMG_isGIF, IMG_LoadGIF_RW },
    1.36 +    { "JPG", IMG_isJPG, IMG_LoadJPG_RW },
    1.37 +    { "LBM", IMG_isLBM, IMG_LoadLBM_RW },
    1.38 +    { "PCX", IMG_isPCX, IMG_LoadPCX_RW },
    1.39 +    { "PNG", IMG_isPNG, IMG_LoadPNG_RW },
    1.40 +    { "PNM", IMG_isPNM, IMG_LoadPNM_RW }, /* P[BGP]M share code */
    1.41 +    { "TIF", IMG_isTIF, IMG_LoadTIF_RW },
    1.42 +    { "XCF", IMG_isXCF, IMG_LoadXCF_RW },
    1.43 +    { "XPM", IMG_isXPM, IMG_LoadXPM_RW },
    1.44 +    { "XV",  IMG_isXV,  IMG_LoadXV_RW  },
    1.45 +    { "WEBP", IMG_isWEBP, IMG_LoadWEBP_RW },
    1.46  };
    1.47  
    1.48  const SDL_version *IMG_Linked_Version(void)
    1.49  {
    1.50 -	static SDL_version linked_version;
    1.51 -	SDL_IMAGE_VERSION(&linked_version);
    1.52 -	return(&linked_version);
    1.53 +    static SDL_version linked_version;
    1.54 +    SDL_IMAGE_VERSION(&linked_version);
    1.55 +    return(&linked_version);
    1.56  }
    1.57  
    1.58  extern int IMG_InitJPG();
    1.59 @@ -74,48 +74,48 @@
    1.60  
    1.61  int IMG_Init(int flags)
    1.62  {
    1.63 -	int result = 0;
    1.64 +    int result = 0;
    1.65  
    1.66 -	if (flags & IMG_INIT_JPG) {
    1.67 -		if ((initialized & IMG_INIT_JPG) || IMG_InitJPG() == 0) {
    1.68 -			result |= IMG_INIT_JPG;
    1.69 -		}
    1.70 -	}
    1.71 -	if (flags & IMG_INIT_PNG) {
    1.72 -		if ((initialized & IMG_INIT_PNG) || IMG_InitPNG() == 0) {
    1.73 -			result |= IMG_INIT_PNG;
    1.74 -		}
    1.75 -	}
    1.76 -	if (flags & IMG_INIT_TIF) {
    1.77 -		if ((initialized & IMG_INIT_TIF) || IMG_InitTIF() == 0) {
    1.78 -			result |= IMG_INIT_TIF;
    1.79 -		}
    1.80 -	}
    1.81 -	if (flags & IMG_INIT_WEBP) {
    1.82 -		if ((initialized & IMG_INIT_WEBP) || IMG_InitWEBP() == 0) {
    1.83 -			result |= IMG_INIT_WEBP;
    1.84 -		}
    1.85 -	}
    1.86 -	initialized |= result;
    1.87 +    if (flags & IMG_INIT_JPG) {
    1.88 +        if ((initialized & IMG_INIT_JPG) || IMG_InitJPG() == 0) {
    1.89 +            result |= IMG_INIT_JPG;
    1.90 +        }
    1.91 +    }
    1.92 +    if (flags & IMG_INIT_PNG) {
    1.93 +        if ((initialized & IMG_INIT_PNG) || IMG_InitPNG() == 0) {
    1.94 +            result |= IMG_INIT_PNG;
    1.95 +        }
    1.96 +    }
    1.97 +    if (flags & IMG_INIT_TIF) {
    1.98 +        if ((initialized & IMG_INIT_TIF) || IMG_InitTIF() == 0) {
    1.99 +            result |= IMG_INIT_TIF;
   1.100 +        }
   1.101 +    }
   1.102 +    if (flags & IMG_INIT_WEBP) {
   1.103 +        if ((initialized & IMG_INIT_WEBP) || IMG_InitWEBP() == 0) {
   1.104 +            result |= IMG_INIT_WEBP;
   1.105 +        }
   1.106 +    }
   1.107 +    initialized |= result;
   1.108  
   1.109 -	return (initialized);
   1.110 +    return (initialized);
   1.111  }
   1.112  
   1.113  void IMG_Quit()
   1.114  {
   1.115 -	if (initialized & IMG_INIT_JPG) {
   1.116 -		IMG_QuitJPG();
   1.117 -	}
   1.118 -	if (initialized & IMG_INIT_PNG) {
   1.119 -		IMG_QuitPNG();
   1.120 -	}
   1.121 -	if (initialized & IMG_INIT_TIF) {
   1.122 -		IMG_QuitTIF();
   1.123 -	}
   1.124 -	if (initialized & IMG_INIT_WEBP) {
   1.125 -		IMG_QuitWEBP();
   1.126 -	}
   1.127 -	initialized = 0;
   1.128 +    if (initialized & IMG_INIT_JPG) {
   1.129 +        IMG_QuitJPG();
   1.130 +    }
   1.131 +    if (initialized & IMG_INIT_PNG) {
   1.132 +        IMG_QuitPNG();
   1.133 +    }
   1.134 +    if (initialized & IMG_INIT_TIF) {
   1.135 +        IMG_QuitTIF();
   1.136 +    }
   1.137 +    if (initialized & IMG_INIT_WEBP) {
   1.138 +        IMG_QuitWEBP();
   1.139 +    }
   1.140 +    initialized = 0;
   1.141  }
   1.142  
   1.143  #if !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND)
   1.144 @@ -144,63 +144,63 @@
   1.145  /* Portable case-insensitive string compare function */
   1.146  static int IMG_string_equals(const char *str1, const char *str2)
   1.147  {
   1.148 -	while ( *str1 && *str2 ) {
   1.149 -		if ( toupper((unsigned char)*str1) !=
   1.150 -		     toupper((unsigned char)*str2) )
   1.151 -			break;
   1.152 -		++str1;
   1.153 -		++str2;
   1.154 -	}
   1.155 -	return (!*str1 && !*str2);
   1.156 +    while ( *str1 && *str2 ) {
   1.157 +        if ( toupper((unsigned char)*str1) !=
   1.158 +             toupper((unsigned char)*str2) )
   1.159 +            break;
   1.160 +        ++str1;
   1.161 +        ++str2;
   1.162 +    }
   1.163 +    return (!*str1 && !*str2);
   1.164  }
   1.165  
   1.166  /* Load an image from an SDL datasource, optionally specifying the type */
   1.167  SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type)
   1.168  {
   1.169 -	int i;
   1.170 -	SDL_Surface *image;
   1.171 +    int i;
   1.172 +    SDL_Surface *image;
   1.173  
   1.174 -	/* Make sure there is something to do.. */
   1.175 -	if ( src == NULL ) {
   1.176 -		IMG_SetError("Passed a NULL data source");
   1.177 -		return(NULL);
   1.178 -	}
   1.179 +    /* Make sure there is something to do.. */
   1.180 +    if ( src == NULL ) {
   1.181 +        IMG_SetError("Passed a NULL data source");
   1.182 +        return(NULL);
   1.183 +    }
   1.184  
   1.185 -	/* See whether or not this data source can handle seeking */
   1.186 -	if ( SDL_RWseek(src, 0, RW_SEEK_CUR) < 0 ) {
   1.187 -		IMG_SetError("Can't seek in this data source");
   1.188 -		if(freesrc)
   1.189 -			SDL_RWclose(src);
   1.190 -		return(NULL);
   1.191 -	}
   1.192 +    /* See whether or not this data source can handle seeking */
   1.193 +    if ( SDL_RWseek(src, 0, RW_SEEK_CUR) < 0 ) {
   1.194 +        IMG_SetError("Can't seek in this data source");
   1.195 +        if(freesrc)
   1.196 +            SDL_RWclose(src);
   1.197 +        return(NULL);
   1.198 +    }
   1.199  
   1.200 -	/* Detect the type of image being loaded */
   1.201 -	image = NULL;
   1.202 -	for ( i=0; i < ARRAYSIZE(supported); ++i ) {
   1.203 -		if(supported[i].is) {
   1.204 -			if(!supported[i].is(src))
   1.205 -				continue;
   1.206 -		} else {
   1.207 -			/* magicless format */
   1.208 -			if(!type
   1.209 -			   || !IMG_string_equals(type, supported[i].type))
   1.210 -				continue;
   1.211 -		}
   1.212 +    /* Detect the type of image being loaded */
   1.213 +    image = NULL;
   1.214 +    for ( i=0; i < ARRAYSIZE(supported); ++i ) {
   1.215 +        if(supported[i].is) {
   1.216 +            if(!supported[i].is(src))
   1.217 +                continue;
   1.218 +        } else {
   1.219 +            /* magicless format */
   1.220 +            if(!type
   1.221 +               || !IMG_string_equals(type, supported[i].type))
   1.222 +                continue;
   1.223 +        }
   1.224  #ifdef DEBUG_IMGLIB
   1.225 -		fprintf(stderr, "IMGLIB: Loading image as %s\n",
   1.226 -			supported[i].type);
   1.227 +        fprintf(stderr, "IMGLIB: Loading image as %s\n",
   1.228 +            supported[i].type);
   1.229  #endif
   1.230 -		image = supported[i].load(src);
   1.231 -		if(freesrc)
   1.232 -			SDL_RWclose(src);
   1.233 -		return image;
   1.234 -	}
   1.235 +        image = supported[i].load(src);
   1.236 +        if(freesrc)
   1.237 +            SDL_RWclose(src);
   1.238 +        return image;
   1.239 +    }
   1.240  
   1.241 -	if ( freesrc ) {
   1.242 -		SDL_RWclose(src);
   1.243 -	}
   1.244 -	IMG_SetError("Unsupported image format");
   1.245 -	return NULL;
   1.246 +    if ( freesrc ) {
   1.247 +        SDL_RWclose(src);
   1.248 +    }
   1.249 +    IMG_SetError("Unsupported image format");
   1.250 +    return NULL;
   1.251  }
   1.252  
   1.253  SDL_Texture *IMG_LoadTexture(SDL_Renderer *renderer, const char *file)