Cleaned up whitespace for the 2.0.0 release
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 May 2013 21:24:32 -0700
changeset 3688a61842d00ce
parent 367 b2aa197f6774
child 369 35beff028453
Cleaned up whitespace for the 2.0.0 release
IMG.c
IMG_ImageIO.m
IMG_UIImage.m
IMG_bmp.c
IMG_gif.c
IMG_jpg.c
IMG_lbm.c
IMG_pcx.c
IMG_png.c
IMG_pnm.c
IMG_tga.c
IMG_tif.c
IMG_webp.c
IMG_xcf.c
IMG_xpm.c
IMG_xv.c
IMG_xxx.c
SDL_image.h
VisualC/resource.h
VisualCE/resource.h
Xcode/showimage/SDLMain.m
showimage.c
     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)
     2.1 --- a/IMG_ImageIO.m	Thu Apr 25 00:22:51 2013 -0700
     2.2 +++ b/IMG_ImageIO.m	Tue May 21 21:24:32 2013 -0700
     2.3 @@ -45,7 +45,7 @@
     2.4  // so you can clean up any resources.
     2.5  static void MyProviderReleaseInfoCallback(void* rwops_userdata)
     2.6  {
     2.7 -    // What should I put here? 
     2.8 +    // What should I put here?
     2.9      // I think the user and SDL_RWops controls closing, so I don't do anything.
    2.10  }
    2.11  
    2.12 @@ -60,7 +60,7 @@
    2.13      off_t start_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
    2.14      SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
    2.15      off_t end_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
    2.16 -    return (end_position - start_position);	
    2.17 +    return (end_position - start_position);
    2.18  }
    2.19  #else // CGDataProviderCreate was deprecated in 10.5
    2.20  static void MyProviderSkipBytesCallback(void* rwops_userdata, size_t the_count)
    2.21 @@ -78,9 +78,9 @@
    2.22  static CGImageSourceRef CreateCGImageSourceFromRWops(SDL_RWops* rw_ops, CFDictionaryRef hints_and_options)
    2.23  {
    2.24      CGImageSourceRef source_ref;
    2.25 -    
    2.26 +
    2.27      // Similar to SDL_RWops, Apple has their own callbacks for dealing with data streams.
    2.28 -    
    2.29 +
    2.30  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
    2.31      CGDataProviderSequentialCallbacks provider_callbacks =
    2.32      {
    2.33 @@ -90,12 +90,12 @@
    2.34          MyProviderRewindCallback,
    2.35          MyProviderReleaseInfoCallback
    2.36      };
    2.37 -    
    2.38 +
    2.39      CGDataProviderRef data_provider = CGDataProviderCreateSequential(rw_ops, &provider_callbacks);
    2.40 -    
    2.41 -    
    2.42 +
    2.43 +
    2.44  #else // CGDataProviderCreate was deprecated in 10.5
    2.45 -    
    2.46 +
    2.47      CGDataProviderCallbacks provider_callbacks =
    2.48      {
    2.49          MyProviderGetBytesCallback,
    2.50 @@ -103,7 +103,7 @@
    2.51          MyProviderRewindCallback,
    2.52          MyProviderReleaseInfoCallback
    2.53      };
    2.54 -    
    2.55 +
    2.56      CGDataProviderRef data_provider = CGDataProviderCreate(rw_ops, &provider_callbacks);
    2.57  #endif
    2.58      // Get the CGImageSourceRef.
    2.59 @@ -120,41 +120,41 @@
    2.60      CFURLRef the_url = NULL;
    2.61      CGImageSourceRef source_ref = NULL;
    2.62      CFStringRef cf_string = NULL;
    2.63 -    
    2.64 +
    2.65      /* Create a CFString from a C string */
    2.66      cf_string = CFStringCreateWithCString(NULL, the_path, kCFStringEncodingUTF8);
    2.67      if (!cf_string) {
    2.68          return NULL;
    2.69      }
    2.70 -    
    2.71 +
    2.72      /* Create a CFURL from a CFString */
    2.73      the_url = CFURLCreateWithFileSystemPath(NULL, cf_string, kCFURLPOSIXPathStyle, false);
    2.74 -    
    2.75 +
    2.76      /* Don't need the CFString any more (error or not) */
    2.77      CFRelease(cf_string);
    2.78 -    
    2.79 +
    2.80      if(!the_url)
    2.81      {
    2.82          return NULL;
    2.83      }
    2.84 -    
    2.85 -    
    2.86 +
    2.87 +
    2.88      source_ref = CGImageSourceCreateWithURL(the_url, NULL);
    2.89      /* Don't need the URL any more (error or not) */
    2.90      CFRelease(the_url);
    2.91 -    
    2.92 +
    2.93      return source_ref;
    2.94  }
    2.95  
    2.96  static CGImageRef CreateCGImageFromCGImageSource(CGImageSourceRef image_source)
    2.97  {
    2.98      CGImageRef image_ref = NULL;
    2.99 -    
   2.100 +
   2.101      if(NULL == image_source)
   2.102      {
   2.103          return NULL;
   2.104      }
   2.105 -    
   2.106 +
   2.107      // Get the first item in the image source (some image formats may
   2.108      // contain multiple items).
   2.109      image_ref = CGImageSourceCreateImageAtIndex(image_source, 0, NULL);
   2.110 @@ -168,16 +168,16 @@
   2.111  static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
   2.112  {
   2.113      CFDictionaryRef hint_dictionary = NULL;
   2.114 -    
   2.115 +
   2.116      if(uti_string_hint != NULL)
   2.117      {
   2.118          // Do a bunch of work to setup a CFDictionary containing the jpeg compression properties.
   2.119          CFStringRef the_keys[1];
   2.120          CFStringRef the_values[1];
   2.121 -        
   2.122 +
   2.123          the_keys[0] = kCGImageSourceTypeIdentifierHint;
   2.124          the_values[0] = uti_string_hint;
   2.125 -        
   2.126 +
   2.127          // kCFTypeDictionaryKeyCallBacks or kCFCopyStringDictionaryKeyCallBacks?
   2.128          hint_dictionary = CFDictionaryCreate(NULL, (const void**)&the_keys, (const void**)&the_values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
   2.129      }
   2.130 @@ -194,42 +194,42 @@
   2.131       * non-RGBA image formats so I'm making the rest up.
   2.132       * All this code should be scrutinized.
   2.133       */
   2.134 -    
   2.135 +
   2.136      size_t w = CGImageGetWidth(image_ref);
   2.137      size_t h = CGImageGetHeight(image_ref);
   2.138      CGRect rect = {{0, 0}, {w, h}};
   2.139 -    
   2.140 +
   2.141      CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref);
   2.142      //size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
   2.143      size_t bits_per_component = 8;
   2.144 -    
   2.145 +
   2.146      SDL_Surface* surface;
   2.147      Uint32 Amask;
   2.148      Uint32 Rmask;
   2.149      Uint32 Gmask;
   2.150      Uint32 Bmask;
   2.151 -    
   2.152 +
   2.153      CGContextRef bitmap_context;
   2.154      CGBitmapInfo bitmap_info;
   2.155  
   2.156 -	/* This sets up a color space that results in identical values
   2.157 -	 * as the image data itself, which is the same as the standalone
   2.158 -	 * libpng loader.
   2.159 -	 * Thanks to Allegro. :)
   2.160 -	 */
   2.161 -	CGFloat whitePoint[3] = { 0.950, 1.000, 1.089 };
   2.162 -	CGFloat blackPoint[3] = { 0.000, 0.000, 0.000 };
   2.163 -	CGFloat gamma[3] = { 2.2, 2.2, 2.2 };
   2.164 -	CGFloat matrix[9] = {
   2.165 -		0.412, 0.213, 0.019,
   2.166 -		0.358, 0.715, 0.119,
   2.167 -		0.180, 0.072, 0.950
   2.168 -	};
   2.169 -	CGColorSpaceRef color_space =
   2.170 -		CGColorSpaceCreateCalibratedRGB(
   2.171 -									whitePoint, blackPoint, gamma, matrix
   2.172 -									);   
   2.173 -	
   2.174 +    /* This sets up a color space that results in identical values
   2.175 +     * as the image data itself, which is the same as the standalone
   2.176 +     * libpng loader.
   2.177 +     * Thanks to Allegro. :)
   2.178 +     */
   2.179 +    CGFloat whitePoint[3] = { 0.950, 1.000, 1.089 };
   2.180 +    CGFloat blackPoint[3] = { 0.000, 0.000, 0.000 };
   2.181 +    CGFloat gamma[3] = { 2.2, 2.2, 2.2 };
   2.182 +    CGFloat matrix[9] = {
   2.183 +        0.412, 0.213, 0.019,
   2.184 +        0.358, 0.715, 0.119,
   2.185 +        0.180, 0.072, 0.950
   2.186 +    };
   2.187 +    CGColorSpaceRef color_space =
   2.188 +        CGColorSpaceCreateCalibratedRGB(
   2.189 +                                    whitePoint, blackPoint, gamma, matrix
   2.190 +                                    );
   2.191 +
   2.192      if (alpha == kCGImageAlphaNone ||
   2.193          alpha == kCGImageAlphaNoneSkipFirst ||
   2.194          alpha == kCGImageAlphaNoneSkipLast) {
   2.195 @@ -241,11 +241,11 @@
   2.196          bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */
   2.197          Amask = 0xFF000000;
   2.198      }
   2.199 -    
   2.200 +
   2.201      Rmask = 0x00FF0000;
   2.202      Gmask = 0x0000FF00;
   2.203      Bmask = 0x000000FF;
   2.204 -    
   2.205 +
   2.206      surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask);
   2.207      if (surface)
   2.208      {
   2.209 @@ -259,12 +259,12 @@
   2.210                                                 color_space,
   2.211                                                 bitmap_info
   2.212                                                 );
   2.213 -        
   2.214 +
   2.215          // Draws the image into the context's image_data
   2.216          CGContextDrawImage(bitmap_context, rect, image_ref);
   2.217 -        
   2.218 +
   2.219          CGContextRelease(bitmap_context);
   2.220 -        
   2.221 +
   2.222          // FIXME: Reverse the premultiplied alpha
   2.223          if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) {
   2.224              int i, j;
   2.225 @@ -289,12 +289,12 @@
   2.226              }
   2.227          }
   2.228      }
   2.229 -    
   2.230 +
   2.231      if (color_space)
   2.232      {
   2.233 -        CGColorSpaceRelease(color_space);			
   2.234 +        CGColorSpaceRelease(color_space);
   2.235      }
   2.236 -    
   2.237 +
   2.238      return surface;
   2.239  }
   2.240  static SDL_Surface* Create_SDL_Surface_From_CGImage_Index(CGImageRef image_ref)
   2.241 @@ -306,7 +306,7 @@
   2.242  
   2.243      SDL_Surface* surface;
   2.244      SDL_Palette* palette;
   2.245 -	CGColorSpaceRef color_space = CGImageGetColorSpace(image_ref);
   2.246 +    CGColorSpaceRef color_space = CGImageGetColorSpace(image_ref);
   2.247      CGColorSpaceRef base_color_space = CGColorSpaceGetBaseColorSpace(color_space);
   2.248      size_t num_components = CGColorSpaceGetNumberOfComponents(base_color_space);
   2.249      size_t num_entries = CGColorSpaceGetColorTableCount(color_space);
   2.250 @@ -350,7 +350,7 @@
   2.251  }
   2.252  static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)
   2.253  {
   2.254 -	CGColorSpaceRef color_space = CGImageGetColorSpace(image_ref);
   2.255 +    CGColorSpaceRef color_space = CGImageGetColorSpace(image_ref);
   2.256      if (CGColorSpaceGetModel(color_space) == kCGColorSpaceModelIndexed) {
   2.257          return Create_SDL_Surface_From_CGImage_Index(image_ref);
   2.258      } else {
   2.259 @@ -404,26 +404,26 @@
   2.260  static int Internal_isType_UIImage (SDL_RWops *rw_ops, CFStringRef uti_string_to_test)
   2.261  {
   2.262      int is_type = 0;
   2.263 -    
   2.264 +
   2.265  #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
   2.266      int start = SDL_RWtell(rw_ops);
   2.267      if ((0 == CFStringCompare(uti_string_to_test, kUTTypeICO, 0)) ||
   2.268          (0 == CFStringCompare(uti_string_to_test, CFSTR("com.microsoft.cur"), 0))) {
   2.269 -        
   2.270 +
   2.271          // The Win32 ICO file header (14 bytes)
   2.272          Uint16 bfReserved;
   2.273          Uint16 bfType;
   2.274          Uint16 bfCount;
   2.275          int type = (0 == CFStringCompare(uti_string_to_test, kUTTypeICO, 0)) ? 1 : 2;
   2.276 -        
   2.277 +
   2.278          bfReserved = SDL_ReadLE16(rw_ops);
   2.279          bfType = SDL_ReadLE16(rw_ops);
   2.280          bfCount = SDL_ReadLE16(rw_ops);
   2.281 -        if ((bfReserved == 0) && (bfType == type) && (bfCount != 0)) 
   2.282 +        if ((bfReserved == 0) && (bfType == type) && (bfCount != 0))
   2.283              is_type = 1;
   2.284      } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeBMP, 0)) {
   2.285          char magic[2];
   2.286 -        
   2.287 +
   2.288          if ( SDL_RWread(rw_ops, magic, sizeof(magic), 1) ) {
   2.289              if ( strncmp(magic, "BM", 2) == 0 ) {
   2.290                  is_type = 1;
   2.291 @@ -431,7 +431,7 @@
   2.292          }
   2.293      } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeGIF, 0)) {
   2.294          char magic[6];
   2.295 -        
   2.296 +
   2.297          if ( SDL_RWread(rw_ops, magic, sizeof(magic), 1) ) {
   2.298              if ( (strncmp(magic, "GIF", 3) == 0) &&
   2.299                  ((memcmp(magic + 3, "87a", 3) == 0) ||
   2.300 @@ -442,11 +442,11 @@
   2.301      } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeJPEG, 0)) {
   2.302          int in_scan = 0;
   2.303          Uint8 magic[4];
   2.304 -        
   2.305 +
   2.306          // This detection code is by Steaphan Greene <stea@cs.binghamton.edu>
   2.307          // Blame me, not Sam, if this doesn't work right. */
   2.308          // And don't forget to report the problem to the the sdl list too! */
   2.309 -        
   2.310 +
   2.311          if ( SDL_RWread(rw_ops, magic, 2, 1) ) {
   2.312              if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
   2.313                  is_type = 1;
   2.314 @@ -479,7 +479,7 @@
   2.315                          if ( end != start + size - 2 ) is_type = 0;
   2.316                          if ( magic[1] == 0xDA ) {
   2.317                              /* Now comes the actual JPEG meat */
   2.318 -#ifdef	FAST_IS_JPEG
   2.319 +#ifdef  FAST_IS_JPEG
   2.320                              /* Ok, I'm convinced.  It is a JPEG. */
   2.321                              break;
   2.322  #else
   2.323 @@ -493,7 +493,7 @@
   2.324          }
   2.325      } else if (0 == CFStringCompare(uti_string_to_test, kUTTypePNG, 0)) {
   2.326          Uint8 magic[4];
   2.327 -        
   2.328 +
   2.329          if ( SDL_RWread(rw_ops, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   2.330              if ( magic[0] == 0x89 &&
   2.331                  magic[1] == 'P' &&
   2.332 @@ -506,7 +506,7 @@
   2.333          //TODO: fill me!
   2.334      } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeTIFF, 0)) {
   2.335          Uint8 magic[4];
   2.336 -        
   2.337 +
   2.338          if ( SDL_RWread(rw_ops, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   2.339              if ( (magic[0] == 'I' &&
   2.340                    magic[1] == 'I' &&
   2.341 @@ -520,7 +520,7 @@
   2.342                  }
   2.343          }
   2.344      }
   2.345 -    
   2.346 +
   2.347      // reset the file descption pointer
   2.348      SDL_RWseek(rw_ops, start, SEEK_SET);
   2.349  
   2.350 @@ -531,29 +531,29 @@
   2.351  static int Internal_isType_ImageIO (SDL_RWops *rw_ops, CFStringRef uti_string_to_test)
   2.352  {
   2.353      int is_type = 0;
   2.354 -    
   2.355 -    CFDictionaryRef hint_dictionary = CreateHintDictionary(uti_string_to_test);	
   2.356 +
   2.357 +    CFDictionaryRef hint_dictionary = CreateHintDictionary(uti_string_to_test);
   2.358      CGImageSourceRef image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
   2.359 -    
   2.360 +
   2.361      if (hint_dictionary != NULL) {
   2.362 -        CFRelease(hint_dictionary);		
   2.363 +        CFRelease(hint_dictionary);
   2.364      }
   2.365 -    
   2.366 +
   2.367      if (NULL == image_source) {
   2.368          return 0;
   2.369      }
   2.370 -    
   2.371 +
   2.372      // This will get the UTI of the container, not the image itself.
   2.373      // Under most cases, this won't be a problem.
   2.374      // But if a person passes an icon file which contains a bmp,
   2.375      // the format will be of the icon file.
   2.376 -    // But I think the main SDL_image codebase has this same problem so I'm not going to worry about it.	
   2.377 +    // But I think the main SDL_image codebase has this same problem so I'm not going to worry about it.
   2.378      CFStringRef uti_type = CGImageSourceGetType(image_source);
   2.379 -    //	CFShow(uti_type);
   2.380 -    
   2.381 +    //  CFShow(uti_type);
   2.382 +
   2.383      // Unsure if we really want conformance or equality
   2.384      is_type = (int)UTTypeConformsTo(uti_string_to_test, uti_type);
   2.385 -    
   2.386 +
   2.387      CFRelease(image_source);
   2.388      return is_type;
   2.389  }
   2.390 @@ -562,7 +562,7 @@
   2.391  {
   2.392      if (rw_ops == NULL)
   2.393          return 0;
   2.394 -    
   2.395 +
   2.396  #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
   2.397      if (USE_UIIMAGE_BACKEND())
   2.398          return Internal_isType_UIImage(rw_ops, uti_string_to_test);
   2.399 @@ -628,22 +628,22 @@
   2.400      NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   2.401      UIImage *ui_image;
   2.402      int bytes_read = 0;
   2.403 -    // I don't know what a good size is. 
   2.404 +    // I don't know what a good size is.
   2.405      // Max recommended texture size is 1024x1024 on iPhone so maybe base it on that?
   2.406      const int block_size = 1024*4;
   2.407      char temp_buffer[block_size];
   2.408 -    
   2.409 +
   2.410      NSMutableData* ns_data = [[NSMutableData alloc] initWithCapacity:1024*1024*4];
   2.411      do {
   2.412          bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
   2.413          [ns_data appendBytes:temp_buffer length:bytes_read];
   2.414      } while (bytes_read > 0);
   2.415 -    
   2.416 +
   2.417      ui_image = [[UIImage alloc] initWithData:ns_data];
   2.418      if (ui_image != nil)
   2.419          sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
   2.420      [ui_image release];
   2.421 -    [ns_data release];          
   2.422 +    [ns_data release];
   2.423      [autorelease_pool drain];
   2.424  
   2.425  #endif  /* #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)) */
   2.426 @@ -656,11 +656,11 @@
   2.427      CGImageSourceRef image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
   2.428  
   2.429      if (hint_dictionary != NULL)
   2.430 -        CFRelease(hint_dictionary);		
   2.431 +        CFRelease(hint_dictionary);
   2.432  
   2.433      if (NULL == image_source)
   2.434          return NULL;
   2.435 -    
   2.436 +
   2.437      CGImageRef image_ref = CreateCGImageFromCGImageSource(image_source);
   2.438      CFRelease(image_source);
   2.439  
   2.440 @@ -675,7 +675,7 @@
   2.441  static SDL_Surface *LoadImageFromRWops (SDL_RWops *rw_ops, CFStringRef uti_string_hint)
   2.442  {
   2.443  #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
   2.444 -    if (USE_UIIMAGE_BACKEND()) 
   2.445 +    if (USE_UIIMAGE_BACKEND())
   2.446          return LoadImageFromRWops_UIImage(rw_ops, uti_string_hint);
   2.447      else
   2.448  #endif
   2.449 @@ -697,7 +697,7 @@
   2.450      [autorelease_pool drain];
   2.451  
   2.452  #endif  /* #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)) */
   2.453 -    return sdl_surface;	
   2.454 +    return sdl_surface;
   2.455  }
   2.456  
   2.457  static SDL_Surface* LoadImageFromFile_ImageIO (const char *file)
   2.458 @@ -708,7 +708,7 @@
   2.459  
   2.460      if(NULL == image_source)
   2.461          return NULL;
   2.462 -    
   2.463 +
   2.464      CGImageRef image_ref = CreateCGImageFromCGImageSource(image_source);
   2.465      CFRelease(image_source);
   2.466  
   2.467 @@ -716,7 +716,7 @@
   2.468          return NULL;
   2.469      SDL_Surface *sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
   2.470      CFRelease(image_ref);
   2.471 -    return sdl_surface;	
   2.472 +    return sdl_surface;
   2.473  }
   2.474  
   2.475  static SDL_Surface* LoadImageFromFile (const char *file)
   2.476 @@ -780,7 +780,7 @@
   2.477  SDL_Surface* IMG_Load (const char *file)
   2.478  {
   2.479      SDL_Surface* sdl_surface = NULL;
   2.480 -    
   2.481 +
   2.482      sdl_surface = LoadImageFromFile(file);
   2.483      if(NULL == sdl_surface)
   2.484      {
     3.1 --- a/IMG_UIImage.m	Thu Apr 25 00:22:51 2013 -0700
     3.2 +++ b/IMG_UIImage.m	Tue May 21 21:24:32 2013 -0700
     3.3 @@ -14,185 +14,185 @@
     3.4  // (Copied straight from the ImageIO backend.)
     3.5  static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)
     3.6  {
     3.7 -	/* This code is adapted from Apple's Documentation found here:
     3.8 -	 * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html
     3.9 -	 * Listing 9-4††Using a Quartz image as a texture source.
    3.10 -	 * Unfortunately, this guide doesn't show what to do about
    3.11 -	 * non-RGBA image formats so I'm making the rest up.
    3.12 -	 * All this code should be scrutinized.
    3.13 -	 */
    3.14 +    /* This code is adapted from Apple's Documentation found here:
    3.15 +     * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html
    3.16 +     * Listing 9-4††Using a Quartz image as a texture source.
    3.17 +     * Unfortunately, this guide doesn't show what to do about
    3.18 +     * non-RGBA image formats so I'm making the rest up.
    3.19 +     * All this code should be scrutinized.
    3.20 +     */
    3.21  
    3.22 -	size_t w = CGImageGetWidth(image_ref);
    3.23 -	size_t h = CGImageGetHeight(image_ref);
    3.24 -	CGRect rect = {{0, 0}, {w, h}};
    3.25 +    size_t w = CGImageGetWidth(image_ref);
    3.26 +    size_t h = CGImageGetHeight(image_ref);
    3.27 +    CGRect rect = {{0, 0}, {w, h}};
    3.28  
    3.29 -	CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref);
    3.30 -	//size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
    3.31 -	size_t bits_per_component = 8;
    3.32 +    CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref);
    3.33 +    //size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
    3.34 +    size_t bits_per_component = 8;
    3.35  
    3.36 -	SDL_Surface* surface;
    3.37 -	Uint32 Amask;
    3.38 -	Uint32 Rmask;
    3.39 -	Uint32 Gmask;
    3.40 -	Uint32 Bmask;
    3.41 +    SDL_Surface* surface;
    3.42 +    Uint32 Amask;
    3.43 +    Uint32 Rmask;
    3.44 +    Uint32 Gmask;
    3.45 +    Uint32 Bmask;
    3.46  
    3.47 -	CGContextRef bitmap_context;
    3.48 -	CGBitmapInfo bitmap_info;
    3.49 -	CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
    3.50 +    CGContextRef bitmap_context;
    3.51 +    CGBitmapInfo bitmap_info;
    3.52 +    CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
    3.53  
    3.54 -	if (alpha == kCGImageAlphaNone ||
    3.55 -	    alpha == kCGImageAlphaNoneSkipFirst ||
    3.56 -	    alpha == kCGImageAlphaNoneSkipLast) {
    3.57 -		bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; /* XRGB */
    3.58 -		Amask = 0x00000000;
    3.59 -	} else {
    3.60 -		/* kCGImageAlphaFirst isn't supported */
    3.61 -		//bitmap_info = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; /* ARGB */
    3.62 -		bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */
    3.63 -		Amask = 0xFF000000;
    3.64 -	}
    3.65 +    if (alpha == kCGImageAlphaNone ||
    3.66 +        alpha == kCGImageAlphaNoneSkipFirst ||
    3.67 +        alpha == kCGImageAlphaNoneSkipLast) {
    3.68 +        bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; /* XRGB */
    3.69 +        Amask = 0x00000000;
    3.70 +    } else {
    3.71 +        /* kCGImageAlphaFirst isn't supported */
    3.72 +        //bitmap_info = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; /* ARGB */
    3.73 +        bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */
    3.74 +        Amask = 0xFF000000;
    3.75 +    }
    3.76  
    3.77 -	Rmask = 0x00FF0000;
    3.78 -	Gmask = 0x0000FF00;
    3.79 -	Bmask = 0x000000FF;
    3.80 +    Rmask = 0x00FF0000;
    3.81 +    Gmask = 0x0000FF00;
    3.82 +    Bmask = 0x000000FF;
    3.83  
    3.84 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask);
    3.85 -	if (surface)
    3.86 -	{
    3.87 -		// Sets up a context to be drawn to with surface->pixels as the area to be drawn to
    3.88 -		bitmap_context = CGBitmapContextCreate(
    3.89 -															surface->pixels,
    3.90 -															surface->w,
    3.91 -															surface->h,
    3.92 -															bits_per_component,
    3.93 -															surface->pitch,
    3.94 -															color_space,
    3.95 -															bitmap_info
    3.96 -															);
    3.97 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask);
    3.98 +    if (surface)
    3.99 +    {
   3.100 +        // Sets up a context to be drawn to with surface->pixels as the area to be drawn to
   3.101 +        bitmap_context = CGBitmapContextCreate(
   3.102 +                                                            surface->pixels,
   3.103 +                                                            surface->w,
   3.104 +                                                            surface->h,
   3.105 +                                                            bits_per_component,
   3.106 +                                                            surface->pitch,
   3.107 +                                                            color_space,
   3.108 +                                                            bitmap_info
   3.109 +                                                            );
   3.110  
   3.111 -		// Draws the image into the context's image_data
   3.112 -		CGContextDrawImage(bitmap_context, rect, image_ref);
   3.113 +        // Draws the image into the context's image_data
   3.114 +        CGContextDrawImage(bitmap_context, rect, image_ref);
   3.115  
   3.116 -		CGContextRelease(bitmap_context);
   3.117 +        CGContextRelease(bitmap_context);
   3.118  
   3.119 -		// FIXME: Reverse the premultiplied alpha
   3.120 -		if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) {
   3.121 -			int i, j;
   3.122 -			Uint8 *p = (Uint8 *)surface->pixels;
   3.123 -			for (i = surface->h * surface->pitch/4; i--; ) {
   3.124 +        // FIXME: Reverse the premultiplied alpha
   3.125 +        if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) {
   3.126 +            int i, j;
   3.127 +            Uint8 *p = (Uint8 *)surface->pixels;
   3.128 +            for (i = surface->h * surface->pitch/4; i--; ) {
   3.129  #if __LITTLE_ENDIAN__
   3.130 -				Uint8 A = p[3];
   3.131 -				if (A) {
   3.132 -					for (j = 0; j < 3; ++j) {
   3.133 -						p[j] = (p[j] * 255) / A;
   3.134 -					}
   3.135 -				}
   3.136 +                Uint8 A = p[3];
   3.137 +                if (A) {
   3.138 +                    for (j = 0; j < 3; ++j) {
   3.139 +                        p[j] = (p[j] * 255) / A;
   3.140 +                    }
   3.141 +                }
   3.142  #else
   3.143 -				Uint8 A = p[0];
   3.144 -				if (A) {
   3.145 -					for (j = 1; j < 4; ++j) {
   3.146 -						p[j] = (p[j] * 255) / A;
   3.147 -					}
   3.148 -				}
   3.149 +                Uint8 A = p[0];
   3.150 +                if (A) {
   3.151 +                    for (j = 1; j < 4; ++j) {
   3.152 +                        p[j] = (p[j] * 255) / A;
   3.153 +                    }
   3.154 +                }
   3.155  #endif /* ENDIAN */
   3.156 -				p += 4;
   3.157 -			}
   3.158 -		}
   3.159 -	}
   3.160 +                p += 4;
   3.161 +            }
   3.162 +        }
   3.163 +    }
   3.164  
   3.165 -	if (color_space)
   3.166 -	{
   3.167 -		CGColorSpaceRelease(color_space);			
   3.168 -	}
   3.169 +    if (color_space)
   3.170 +    {
   3.171 +        CGColorSpaceRelease(color_space);
   3.172 +    }
   3.173  
   3.174 -	return surface;
   3.175 +    return surface;
   3.176  }
   3.177  
   3.178  static SDL_Surface* LoadImageFromRWops(SDL_RWops* rw_ops, CFStringRef uti_string_hint)
   3.179  {
   3.180 -	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   3.181 -	SDL_Surface* sdl_surface;
   3.182 -	UIImage* ui_image;
   3.183 +    NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   3.184 +    SDL_Surface* sdl_surface;
   3.185 +    UIImage* ui_image;
   3.186  
   3.187 -	int bytes_read = 0;
   3.188 -	// I don't know what a good size is. 
   3.189 -	// Max recommended texture size is 1024x1024 on iPhone so maybe base it on that?
   3.190 -	const int block_size = 1024*4;
   3.191 -	char temp_buffer[block_size];
   3.192 -	
   3.193 -	NSMutableData* ns_data = [[NSMutableData alloc] initWithCapacity:1024*1024*4];
   3.194 +    int bytes_read = 0;
   3.195 +    // I don't know what a good size is.
   3.196 +    // Max recommended texture size is 1024x1024 on iPhone so maybe base it on that?
   3.197 +    const int block_size = 1024*4;
   3.198 +    char temp_buffer[block_size];
   3.199  
   3.200 -	
   3.201 -	do
   3.202 -	{
   3.203 -		bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
   3.204 -		[ns_data appendBytes:temp_buffer length:bytes_read];
   3.205 -	} while(bytes_read > 0);
   3.206 +    NSMutableData* ns_data = [[NSMutableData alloc] initWithCapacity:1024*1024*4];
   3.207  
   3.208 -	ui_image = [[UIImage alloc] initWithData:ns_data];
   3.209 -	
   3.210 -	sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
   3.211  
   3.212 -	[ui_image release];
   3.213 -	[ns_data release];
   3.214 +    do
   3.215 +    {
   3.216 +        bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
   3.217 +        [ns_data appendBytes:temp_buffer length:bytes_read];
   3.218 +    } while(bytes_read > 0);
   3.219  
   3.220 -	[autorelease_pool drain];
   3.221 +    ui_image = [[UIImage alloc] initWithData:ns_data];
   3.222  
   3.223 -	return sdl_surface;
   3.224 +    sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
   3.225 +
   3.226 +    [ui_image release];
   3.227 +    [ns_data release];
   3.228 +
   3.229 +    [autorelease_pool drain];
   3.230 +
   3.231 +    return sdl_surface;
   3.232  }
   3.233  
   3.234  static SDL_Surface* LoadImageFromFile(const char *file)
   3.235  {
   3.236 -	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   3.237 -	SDL_Surface* sdl_surface = NULL;
   3.238 -	UIImage* ui_image;
   3.239 -	NSString* ns_string;
   3.240 -	
   3.241 -	ns_string = [[NSString alloc] initWithUTF8String:file];
   3.242 -	ui_image = [[UIImage alloc] initWithContentsOfFile:ns_string];
   3.243 -	if(ui_image != NULL)
   3.244 -	{
   3.245 -		sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
   3.246 -	}
   3.247 -	
   3.248 -	[ui_image release];
   3.249 -	[ns_string release];
   3.250 -	
   3.251 -	[autorelease_pool drain];
   3.252 -	
   3.253 -	return sdl_surface;
   3.254 +    NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   3.255 +    SDL_Surface* sdl_surface = NULL;
   3.256 +    UIImage* ui_image;
   3.257 +    NSString* ns_string;
   3.258 +
   3.259 +    ns_string = [[NSString alloc] initWithUTF8String:file];
   3.260 +    ui_image = [[UIImage alloc] initWithContentsOfFile:ns_string];
   3.261 +    if(ui_image != NULL)
   3.262 +    {
   3.263 +        sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
   3.264 +    }
   3.265 +
   3.266 +    [ui_image release];
   3.267 +    [ns_string release];
   3.268 +
   3.269 +    [autorelease_pool drain];
   3.270 +
   3.271 +    return sdl_surface;
   3.272  }
   3.273  
   3.274  
   3.275  /* Since UIImage doesn't really support streams well, we should optimize for the file case. */
   3.276  SDL_Surface *IMG_Load(const char *file)
   3.277  {
   3.278 -	SDL_Surface* sdl_surface = NULL;
   3.279 +    SDL_Surface* sdl_surface = NULL;
   3.280  
   3.281 -	sdl_surface = LoadImageFromFile(file);
   3.282 -	if(NULL == sdl_surface)
   3.283 -	{
   3.284 -		// Either the file doesn't exist or ImageIO doesn't understand the format.
   3.285 -		// For the latter case, fallback to the native SDL_image handlers.
   3.286 +    sdl_surface = LoadImageFromFile(file);
   3.287 +    if(NULL == sdl_surface)
   3.288 +    {
   3.289 +        // Either the file doesn't exist or ImageIO doesn't understand the format.
   3.290 +        // For the latter case, fallback to the native SDL_image handlers.
   3.291  
   3.292 -		SDL_RWops *src = SDL_RWFromFile(file, "rb");
   3.293 -		char *ext = strrchr(file, '.');
   3.294 -		if(ext) {
   3.295 -			ext++;
   3.296 -		}
   3.297 -		if(!src) {
   3.298 -			/* The error message has been set in SDL_RWFromFile */
   3.299 -			return NULL;
   3.300 -		}
   3.301 -		sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
   3.302 -	}
   3.303 -	return sdl_surface;
   3.304 +        SDL_RWops *src = SDL_RWFromFile(file, "rb");
   3.305 +        char *ext = strrchr(file, '.');
   3.306 +        if(ext) {
   3.307 +            ext++;
   3.308 +        }
   3.309 +        if(!src) {
   3.310 +            /* The error message has been set in SDL_RWFromFile */
   3.311 +            return NULL;
   3.312 +        }
   3.313 +        sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
   3.314 +    }
   3.315 +    return sdl_surface;
   3.316  }
   3.317  
   3.318  
   3.319  int IMG_InitJPG()
   3.320  {
   3.321 -	return 0;
   3.322 +    return 0;
   3.323  }
   3.324  
   3.325  void IMG_QuitJPG()
   3.326 @@ -201,7 +201,7 @@
   3.327  
   3.328  int IMG_InitPNG()
   3.329  {
   3.330 -	return 0;
   3.331 +    return 0;
   3.332  }
   3.333  
   3.334  void IMG_QuitPNG()
   3.335 @@ -210,7 +210,7 @@
   3.336  
   3.337  int IMG_InitTIF()
   3.338  {
   3.339 -	return 0;
   3.340 +    return 0;
   3.341  }
   3.342  
   3.343  void IMG_QuitTIF()
   3.344 @@ -220,221 +220,221 @@
   3.345  /* Copied straight from other files so I don't have to alter them. */
   3.346  static int IMG_isICOCUR(SDL_RWops *src, int type)
   3.347  {
   3.348 -	int start;
   3.349 -	int is_ICOCUR;
   3.350 +    int start;
   3.351 +    int is_ICOCUR;
   3.352  
   3.353 -	/* The Win32 ICO file header (14 bytes) */
   3.354 +    /* The Win32 ICO file header (14 bytes) */
   3.355      Uint16 bfReserved;
   3.356      Uint16 bfType;
   3.357      Uint16 bfCount;
   3.358  
   3.359 -	if ( !src )
   3.360 -		return 0;
   3.361 -	start = SDL_RWtell(src);
   3.362 -	is_ICOCUR = 0;
   3.363 +    if ( !src )
   3.364 +        return 0;
   3.365 +    start = SDL_RWtell(src);
   3.366 +    is_ICOCUR = 0;
   3.367      bfReserved = SDL_ReadLE16(src);
   3.368      bfType = SDL_ReadLE16(src);
   3.369      bfCount = SDL_ReadLE16(src);
   3.370 -    if ((bfReserved == 0) && (bfType == type) && (bfCount != 0)) 
   3.371 -    	is_ICOCUR = 1;
   3.372 -	SDL_RWseek(src, start, SEEK_SET);
   3.373 +    if ((bfReserved == 0) && (bfType == type) && (bfCount != 0))
   3.374 +        is_ICOCUR = 1;
   3.375 +    SDL_RWseek(src, start, SEEK_SET);
   3.376  
   3.377 -	return (is_ICOCUR);
   3.378 +    return (is_ICOCUR);
   3.379  }
   3.380  
   3.381  int IMG_isICO(SDL_RWops *src)
   3.382  {
   3.383 -	return IMG_isICOCUR(src, 1);
   3.384 +    return IMG_isICOCUR(src, 1);
   3.385  }
   3.386  
   3.387  int IMG_isCUR(SDL_RWops *src)
   3.388  {
   3.389 -	return IMG_isICOCUR(src, 2);
   3.390 +    return IMG_isICOCUR(src, 2);
   3.391  }
   3.392  
   3.393  int IMG_isBMP(SDL_RWops *src)
   3.394  {
   3.395 -	int start;
   3.396 -	int is_BMP;
   3.397 -	char magic[2];
   3.398 -	
   3.399 -	if ( !src )
   3.400 -		return 0;
   3.401 -	start = SDL_RWtell(src);
   3.402 -	is_BMP = 0;
   3.403 -	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   3.404 -		if ( strncmp(magic, "BM", 2) == 0 ) {
   3.405 -			is_BMP = 1;
   3.406 -		}
   3.407 -	}
   3.408 -	SDL_RWseek(src, start, SEEK_SET);
   3.409 -	return(is_BMP);
   3.410 +    int start;
   3.411 +    int is_BMP;
   3.412 +    char magic[2];
   3.413 +
   3.414 +    if ( !src )
   3.415 +        return 0;
   3.416 +    start = SDL_RWtell(src);
   3.417 +    is_BMP = 0;
   3.418 +    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   3.419 +        if ( strncmp(magic, "BM", 2) == 0 ) {
   3.420 +            is_BMP = 1;
   3.421 +        }
   3.422 +    }
   3.423 +    SDL_RWseek(src, start, SEEK_SET);
   3.424 +    return(is_BMP);
   3.425  }
   3.426  
   3.427  int IMG_isGIF(SDL_RWops *src)
   3.428  {
   3.429 -	int start;
   3.430 -	int is_GIF;
   3.431 -	char magic[6];
   3.432 -	
   3.433 -	if ( !src )
   3.434 -		return 0;
   3.435 -	start = SDL_RWtell(src);
   3.436 -	is_GIF = 0;
   3.437 -	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   3.438 -		if ( (strncmp(magic, "GIF", 3) == 0) &&
   3.439 -			((memcmp(magic + 3, "87a", 3) == 0) ||
   3.440 -			 (memcmp(magic + 3, "89a", 3) == 0)) ) {
   3.441 -			is_GIF = 1;
   3.442 -		}
   3.443 -	}
   3.444 -	SDL_RWseek(src, start, SEEK_SET);
   3.445 -	return(is_GIF);
   3.446 +    int start;
   3.447 +    int is_GIF;
   3.448 +    char magic[6];
   3.449 +
   3.450 +    if ( !src )
   3.451 +        return 0;
   3.452 +    start = SDL_RWtell(src);
   3.453 +    is_GIF = 0;
   3.454 +    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   3.455 +        if ( (strncmp(magic, "GIF", 3) == 0) &&
   3.456 +            ((memcmp(magic + 3, "87a", 3) == 0) ||
   3.457 +             (memcmp(magic + 3, "89a", 3) == 0)) ) {
   3.458 +            is_GIF = 1;
   3.459 +        }
   3.460 +    }
   3.461 +    SDL_RWseek(src, start, SEEK_SET);
   3.462 +    return(is_GIF);
   3.463  }
   3.464  
   3.465  int IMG_isJPG(SDL_RWops *src)
   3.466  {
   3.467 -	int start;
   3.468 -	int is_JPG;
   3.469 -	int in_scan;
   3.470 -	Uint8 magic[4];
   3.471 -	
   3.472 -	/* This detection code is by Steaphan Greene <stea@cs.binghamton.edu> */
   3.473 -	/* Blame me, not Sam, if this doesn't work right. */
   3.474 -	/* And don't forget to report the problem to the the sdl list too! */
   3.475 -	
   3.476 -	if ( !src )
   3.477 -		return 0;
   3.478 -	start = SDL_RWtell(src);
   3.479 -	is_JPG = 0;
   3.480 -	in_scan = 0;
   3.481 -	if ( SDL_RWread(src, magic, 2, 1) ) {
   3.482 -		if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
   3.483 -			is_JPG = 1;
   3.484 -			while (is_JPG == 1) {
   3.485 -				if(SDL_RWread(src, magic, 1, 2) != 2) {
   3.486 -					is_JPG = 0;
   3.487 -				} else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
   3.488 -					is_JPG = 0;
   3.489 -				} else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
   3.490 -					/* Extra padding in JPEG (legal) */
   3.491 -					/* or this is data and we are scanning */
   3.492 -					SDL_RWseek(src, -1, SEEK_CUR);
   3.493 -				} else if(magic[1] == 0xD9) {
   3.494 -					/* Got to end of good JPEG */
   3.495 -					break;
   3.496 -				} else if( (in_scan == 1) && (magic[1] == 0x00) ) {
   3.497 -					/* This is an encoded 0xFF within the data */
   3.498 -				} else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
   3.499 -					/* These have nothing else */
   3.500 -				} else if(SDL_RWread(src, magic+2, 1, 2) != 2) {
   3.501 -					is_JPG = 0;
   3.502 -				} else {
   3.503 -					/* Yes, it's big-endian */
   3.504 -					Uint32 start;
   3.505 -					Uint32 size;
   3.506 -					Uint32 end;
   3.507 -					start = SDL_RWtell(src);
   3.508 -					size = (magic[2] << 8) + magic[3];
   3.509 -					end = SDL_RWseek(src, size-2, SEEK_CUR);
   3.510 -					if ( end != start + size - 2 ) is_JPG = 0;
   3.511 -					if ( magic[1] == 0xDA ) {
   3.512 -						/* Now comes the actual JPEG meat */
   3.513 -#ifdef	FAST_IS_JPEG
   3.514 -						/* Ok, I'm convinced.  It is a JPEG. */
   3.515 -						break;
   3.516 +    int start;
   3.517 +    int is_JPG;
   3.518 +    int in_scan;
   3.519 +    Uint8 magic[4];
   3.520 +
   3.521 +    /* This detection code is by Steaphan Greene <stea@cs.binghamton.edu> */
   3.522 +    /* Blame me, not Sam, if this doesn't work right. */
   3.523 +    /* And don't forget to report the problem to the the sdl list too! */
   3.524 +
   3.525 +    if ( !src )
   3.526 +        return 0;
   3.527 +    start = SDL_RWtell(src);
   3.528 +    is_JPG = 0;
   3.529 +    in_scan = 0;
   3.530 +    if ( SDL_RWread(src, magic, 2, 1) ) {
   3.531 +        if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
   3.532 +            is_JPG = 1;
   3.533 +            while (is_JPG == 1) {
   3.534 +                if(SDL_RWread(src, magic, 1, 2) != 2) {
   3.535 +                    is_JPG = 0;
   3.536 +                } else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
   3.537 +                    is_JPG = 0;
   3.538 +                } else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
   3.539 +                    /* Extra padding in JPEG (legal) */
   3.540 +                    /* or this is data and we are scanning */
   3.541 +                    SDL_RWseek(src, -1, SEEK_CUR);
   3.542 +                } else if(magic[1] == 0xD9) {
   3.543 +                    /* Got to end of good JPEG */
   3.544 +                    break;
   3.545 +                } else if( (in_scan == 1) && (magic[1] == 0x00) ) {
   3.546 +                    /* This is an encoded 0xFF within the data */
   3.547 +                } else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
   3.548 +                    /* These have nothing else */
   3.549 +                } else if(SDL_RWread(src, magic+2, 1, 2) != 2) {
   3.550 +                    is_JPG = 0;
   3.551 +                } else {
   3.552 +                    /* Yes, it's big-endian */
   3.553 +                    Uint32 start;
   3.554 +                    Uint32 size;
   3.555 +                    Uint32 end;
   3.556 +                    start = SDL_RWtell(src);
   3.557 +                    size = (magic[2] << 8) + magic[3];
   3.558 +                    end = SDL_RWseek(src, size-2, SEEK_CUR);
   3.559 +                    if ( end != start + size - 2 ) is_JPG = 0;
   3.560 +                    if ( magic[1] == 0xDA ) {
   3.561 +                        /* Now comes the actual JPEG meat */
   3.562 +#ifdef  FAST_IS_JPEG
   3.563 +                        /* Ok, I'm convinced.  It is a JPEG. */
   3.564 +                        break;
   3.565  #else
   3.566 -						/* I'm not convinced.  Prove it! */
   3.567 -						in_scan = 1;
   3.568 +                        /* I'm not convinced.  Prove it! */
   3.569 +                        in_scan = 1;
   3.570  #endif
   3.571 -					}
   3.572 -				}
   3.573 -			}
   3.574 -		}
   3.575 -	}
   3.576 -	SDL_RWseek(src, start, SEEK_SET);
   3.577 -	return(is_JPG);
   3.578 +                    }
   3.579 +                }
   3.580 +            }
   3.581 +        }
   3.582 +    }
   3.583 +    SDL_RWseek(src, start, SEEK_SET);
   3.584 +    return(is_JPG);
   3.585  }
   3.586  
   3.587  int IMG_isPNG(SDL_RWops *src)
   3.588  {
   3.589 -	int start;
   3.590 -	int is_PNG;
   3.591 -	Uint8 magic[4];
   3.592 -	
   3.593 -	if ( !src )
   3.594 -		return 0;
   3.595 -	start = SDL_RWtell(src);
   3.596 -	is_PNG = 0;
   3.597 -	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   3.598 -		if ( magic[0] == 0x89 &&
   3.599 -			magic[1] == 'P' &&
   3.600 -			magic[2] == 'N' &&
   3.601 -			magic[3] == 'G' ) {
   3.602 -			is_PNG = 1;
   3.603 -		}
   3.604 -	}
   3.605 -	SDL_RWseek(src, start, SEEK_SET);
   3.606 -	return(is_PNG);
   3.607 +    int start;
   3.608 +    int is_PNG;
   3.609 +    Uint8 magic[4];
   3.610 +
   3.611 +    if ( !src )
   3.612 +        return 0;
   3.613 +    start = SDL_RWtell(src);
   3.614 +    is_PNG = 0;
   3.615 +    if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   3.616 +        if ( magic[0] == 0x89 &&
   3.617 +            magic[1] == 'P' &&
   3.618 +            magic[2] == 'N' &&
   3.619 +            magic[3] == 'G' ) {
   3.620 +            is_PNG = 1;
   3.621 +        }
   3.622 +    }
   3.623 +    SDL_RWseek(src, start, SEEK_SET);
   3.624 +    return(is_PNG);
   3.625  }
   3.626  
   3.627  int IMG_isTIF(SDL_RWops* src)
   3.628  {
   3.629 -	int start;
   3.630 -	int is_TIF;
   3.631 -	Uint8 magic[4];
   3.632 -	
   3.633 -	if ( !src )
   3.634 -		return 0;
   3.635 -	start = SDL_RWtell(src);
   3.636 -	is_TIF = 0;
   3.637 -	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   3.638 -		if ( (magic[0] == 'I' &&
   3.639 -			  magic[1] == 'I' &&
   3.640 -		      magic[2] == 0x2a &&
   3.641 -			  magic[3] == 0x00) ||
   3.642 -			(magic[0] == 'M' &&
   3.643 -			 magic[1] == 'M' &&
   3.644 -			 magic[2] == 0x00 &&
   3.645 -			 magic[3] == 0x2a) ) {
   3.646 -			is_TIF = 1;
   3.647 -		}
   3.648 -	}
   3.649 -	SDL_RWseek(src, start, SEEK_SET);
   3.650 -	return(is_TIF);
   3.651 +    int start;
   3.652 +    int is_TIF;
   3.653 +    Uint8 magic[4];
   3.654 +
   3.655 +    if ( !src )
   3.656 +        return 0;
   3.657 +    start = SDL_RWtell(src);
   3.658 +    is_TIF = 0;
   3.659 +    if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   3.660 +        if ( (magic[0] == 'I' &&
   3.661 +              magic[1] == 'I' &&
   3.662 +              magic[2] == 0x2a &&
   3.663 +              magic[3] == 0x00) ||
   3.664 +            (magic[0] == 'M' &&
   3.665 +             magic[1] == 'M' &&
   3.666 +             magic[2] == 0x00 &&
   3.667 +             magic[3] == 0x2a) ) {
   3.668 +            is_TIF = 1;
   3.669 +        }
   3.670 +    }
   3.671 +    SDL_RWseek(src, start, SEEK_SET);
   3.672 +    return(is_TIF);
   3.673  }
   3.674  
   3.675  SDL_Surface* IMG_LoadCUR_RW(SDL_RWops *src)
   3.676  {
   3.677 -	/* FIXME: Is this a supported type? */
   3.678 -	return LoadImageFromRWops(src, CFSTR("com.microsoft.cur"));
   3.679 +    /* FIXME: Is this a supported type? */
   3.680 +    return LoadImageFromRWops(src, CFSTR("com.microsoft.cur"));
   3.681  }
   3.682  SDL_Surface* IMG_LoadICO_RW(SDL_RWops *src)
   3.683  {
   3.684 -	return LoadImageFromRWops(src, kUTTypeICO);
   3.685 +    return LoadImageFromRWops(src, kUTTypeICO);
   3.686  }
   3.687  SDL_Surface* IMG_LoadBMP_RW(SDL_RWops *src)
   3.688  {
   3.689 -	return LoadImageFromRWops(src, kUTTypeBMP);
   3.690 +    return LoadImageFromRWops(src, kUTTypeBMP);
   3.691  }
   3.692  SDL_Surface* IMG_LoadGIF_RW(SDL_RWops *src)
   3.693  {
   3.694 -	return LoadImageFromRWops(src, kUTTypeGIF);
   3.695 +    return LoadImageFromRWops(src, kUTTypeGIF);
   3.696  }
   3.697  SDL_Surface* IMG_LoadJPG_RW(SDL_RWops *src)
   3.698  {
   3.699 -	return LoadImageFromRWops(src, kUTTypeJPEG);
   3.700 +    return LoadImageFromRWops(src, kUTTypeJPEG);
   3.701  }
   3.702  SDL_Surface* IMG_LoadPNG_RW(SDL_RWops *src)
   3.703  {
   3.704 -	return LoadImageFromRWops(src, kUTTypePNG);
   3.705 +    return LoadImageFromRWops(src, kUTTypePNG);
   3.706  }
   3.707  SDL_Surface* IMG_LoadTGA_RW(SDL_RWops *src)
   3.708  {
   3.709 -	return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image"));
   3.710 +    return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image"));
   3.711  }
   3.712  SDL_Surface* IMG_LoadTIF_RW(SDL_RWops *src)
   3.713  {
   3.714 -	return LoadImageFromRWops(src, kUTTypeTIFF);
   3.715 +    return LoadImageFromRWops(src, kUTTypeTIFF);
   3.716  }
   3.717  
     4.1 --- a/IMG_bmp.c	Thu Apr 25 00:22:51 2013 -0700
     4.2 +++ b/IMG_bmp.c	Tue May 21 21:24:32 2013 -0700
     4.3 @@ -35,55 +35,55 @@
     4.4  /* See if an image is contained in a data source */
     4.5  int IMG_isBMP(SDL_RWops *src)
     4.6  {
     4.7 -	Sint64 start;
     4.8 -	int is_BMP;
     4.9 -	char magic[2];
    4.10 +    Sint64 start;
    4.11 +    int is_BMP;
    4.12 +    char magic[2];
    4.13  
    4.14 -	if ( !src )
    4.15 -		return 0;
    4.16 -	start = SDL_RWtell(src);
    4.17 -	is_BMP = 0;
    4.18 -	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    4.19 -		if ( SDL_strncmp(magic, "BM", 2) == 0 ) {
    4.20 -			is_BMP = 1;
    4.21 -		}
    4.22 -	}
    4.23 -	SDL_RWseek(src, start, RW_SEEK_SET);
    4.24 -	return(is_BMP);
    4.25 +    if ( !src )
    4.26 +        return 0;
    4.27 +    start = SDL_RWtell(src);
    4.28 +    is_BMP = 0;
    4.29 +    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    4.30 +        if ( SDL_strncmp(magic, "BM", 2) == 0 ) {
    4.31 +            is_BMP = 1;
    4.32 +        }
    4.33 +    }
    4.34 +    SDL_RWseek(src, start, RW_SEEK_SET);
    4.35 +    return(is_BMP);
    4.36  }
    4.37  
    4.38  static int IMG_isICOCUR(SDL_RWops *src, int type)
    4.39  {
    4.40 -	Sint64 start;
    4.41 -	int is_ICOCUR;
    4.42 +    Sint64 start;
    4.43 +    int is_ICOCUR;
    4.44  
    4.45 -	/* The Win32 ICO file header (14 bytes) */
    4.46 +    /* The Win32 ICO file header (14 bytes) */
    4.47      Uint16 bfReserved;
    4.48      Uint16 bfType;
    4.49      Uint16 bfCount;
    4.50  
    4.51 -	if ( !src )
    4.52 -		return 0;
    4.53 -	start = SDL_RWtell(src);
    4.54 -	is_ICOCUR = 0;
    4.55 +    if ( !src )
    4.56 +        return 0;
    4.57 +    start = SDL_RWtell(src);
    4.58 +    is_ICOCUR = 0;
    4.59      bfReserved = SDL_ReadLE16(src);
    4.60      bfType = SDL_ReadLE16(src);
    4.61      bfCount = SDL_ReadLE16(src);
    4.62 -    if ((bfReserved == 0) && (bfType == type) && (bfCount != 0)) 
    4.63 -    	is_ICOCUR = 1;
    4.64 -	SDL_RWseek(src, start, RW_SEEK_SET);
    4.65 +    if ((bfReserved == 0) && (bfType == type) && (bfCount != 0))
    4.66 +        is_ICOCUR = 1;
    4.67 +    SDL_RWseek(src, start, RW_SEEK_SET);
    4.68  
    4.69 -	return (is_ICOCUR);
    4.70 +    return (is_ICOCUR);
    4.71  }
    4.72  
    4.73  int IMG_isICO(SDL_RWops *src)
    4.74  {
    4.75 -	return IMG_isICOCUR(src, 1);
    4.76 +    return IMG_isICOCUR(src, 1);
    4.77  }
    4.78  
    4.79  int IMG_isCUR(SDL_RWops *src)
    4.80  {
    4.81 -	return IMG_isICOCUR(src, 2);
    4.82 +    return IMG_isICOCUR(src, 2);
    4.83  }
    4.84  
    4.85  #include "SDL_error.h"
    4.86 @@ -92,425 +92,425 @@
    4.87  
    4.88  /* Compression encodings for BMP files */
    4.89  #ifndef BI_RGB
    4.90 -#define BI_RGB		0
    4.91 -#define BI_RLE8		1
    4.92 -#define BI_RLE4		2
    4.93 -#define BI_BITFIELDS	3
    4.94 +#define BI_RGB      0
    4.95 +#define BI_RLE8     1
    4.96 +#define BI_RLE4     2
    4.97 +#define BI_BITFIELDS    3
    4.98  #endif
    4.99  
   4.100  static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
   4.101  {
   4.102 -	/*
   4.103 -	| Sets the surface pixels from src.  A bmp image is upside down.
   4.104 -	*/
   4.105 -	int pitch = surface->pitch;
   4.106 -	int height = surface->h;
   4.107 -	Uint8 *start = (Uint8 *)surface->pixels;
   4.108 -	Uint8 *end = start + (height*pitch);
   4.109 -	Uint8 *bits = end-pitch, *spot;
   4.110 -	int ofs = 0;
   4.111 -	Uint8 ch;
   4.112 -	Uint8 needsPad;
   4.113 +    /*
   4.114 +    | Sets the surface pixels from src.  A bmp image is upside down.
   4.115 +    */
   4.116 +    int pitch = surface->pitch;
   4.117 +    int height = surface->h;
   4.118 +    Uint8 *start = (Uint8 *)surface->pixels;
   4.119 +    Uint8 *end = start + (height*pitch);
   4.120 +    Uint8 *bits = end-pitch, *spot;
   4.121 +    int ofs = 0;
   4.122 +    Uint8 ch;
   4.123 +    Uint8 needsPad;
   4.124  
   4.125 -#define COPY_PIXEL(x)	spot = &bits[ofs++]; if(spot >= start && spot < end) *spot = (x)
   4.126 +#define COPY_PIXEL(x)   spot = &bits[ofs++]; if(spot >= start && spot < end) *spot = (x)
   4.127  
   4.128 -	for (;;) {
   4.129 -		if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.130 -		/*
   4.131 -		| encoded mode starts with a run length, and then a byte
   4.132 -		| with two colour indexes to alternate between for the run
   4.133 -		*/
   4.134 -		if ( ch ) {
   4.135 -			Uint8 pixel;
   4.136 -			if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
   4.137 -			if ( isRle8 ) {                 /* 256-color bitmap, compressed */
   4.138 -				do {
   4.139 -					COPY_PIXEL(pixel);
   4.140 -				} while (--ch);
   4.141 -			} else {                         /* 16-color bitmap, compressed */
   4.142 -				Uint8 pixel0 = pixel >> 4;
   4.143 -				Uint8 pixel1 = pixel & 0x0F;
   4.144 -				for (;;) {
   4.145 -					COPY_PIXEL(pixel0);	/* even count, high nibble */
   4.146 -					if (!--ch) break;
   4.147 -					COPY_PIXEL(pixel1);	/* odd count, low nibble */
   4.148 -					if (!--ch) break;
   4.149 -				}
   4.150 -			}
   4.151 -		} else {
   4.152 -			/*
   4.153 -			| A leading zero is an escape; it may signal the end of the bitmap,
   4.154 -			| a cursor move, or some absolute data.
   4.155 -			| zero tag may be absolute mode or an escape
   4.156 -			*/
   4.157 -			if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.158 -			switch (ch) {
   4.159 -			case 0:                         /* end of line */
   4.160 -				ofs = 0;
   4.161 -				bits -= pitch;               /* go to previous */
   4.162 -				break;
   4.163 -			case 1:                         /* end of bitmap */
   4.164 -				return 0;                    /* success! */
   4.165 -			case 2:                         /* delta */
   4.166 -				if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.167 -				ofs += ch;
   4.168 -				if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.169 -				bits -= (ch * pitch);
   4.170 -				break;
   4.171 -			default:                        /* no compression */
   4.172 -				if (isRle8) {
   4.173 -					needsPad = ( ch & 1 );
   4.174 -					do {
   4.175 -						Uint8 pixel;
   4.176 -						if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
   4.177 -						COPY_PIXEL(pixel);
   4.178 -					} while (--ch);
   4.179 -				} else {
   4.180 -					needsPad = ( ((ch+1)>>1) & 1 ); /* (ch+1)>>1: bytes size */
   4.181 -					for (;;) {
   4.182 -						Uint8 pixel;
   4.183 -						if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
   4.184 -						COPY_PIXEL(pixel >> 4);
   4.185 -						if (!--ch) break;
   4.186 -						COPY_PIXEL(pixel & 0x0F);
   4.187 -						if (!--ch) break;
   4.188 -					}
   4.189 -				}
   4.190 -				/* pad at even boundary */
   4.191 -				if ( needsPad && !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.192 -				break;
   4.193 -			}
   4.194 -		}
   4.195 -	}
   4.196 +    for (;;) {
   4.197 +        if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.198 +        /*
   4.199 +        | encoded mode starts with a run length, and then a byte
   4.200 +        | with two colour indexes to alternate between for the run
   4.201 +        */
   4.202 +        if ( ch ) {
   4.203 +            Uint8 pixel;
   4.204 +            if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
   4.205 +            if ( isRle8 ) {                 /* 256-color bitmap, compressed */
   4.206 +                do {
   4.207 +                    COPY_PIXEL(pixel);
   4.208 +                } while (--ch);
   4.209 +            } else {                         /* 16-color bitmap, compressed */
   4.210 +                Uint8 pixel0 = pixel >> 4;
   4.211 +                Uint8 pixel1 = pixel & 0x0F;
   4.212 +                for (;;) {
   4.213 +                    COPY_PIXEL(pixel0); /* even count, high nibble */
   4.214 +                    if (!--ch) break;
   4.215 +                    COPY_PIXEL(pixel1); /* odd count, low nibble */
   4.216 +                    if (!--ch) break;
   4.217 +                }
   4.218 +            }
   4.219 +        } else {
   4.220 +            /*
   4.221 +            | A leading zero is an escape; it may signal the end of the bitmap,
   4.222 +            | a cursor move, or some absolute data.
   4.223 +            | zero tag may be absolute mode or an escape
   4.224 +            */
   4.225 +            if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.226 +            switch (ch) {
   4.227 +            case 0:                         /* end of line */
   4.228 +                ofs = 0;
   4.229 +                bits -= pitch;               /* go to previous */
   4.230 +                break;
   4.231 +            case 1:                         /* end of bitmap */
   4.232 +                return 0;                    /* success! */
   4.233 +            case 2:                         /* delta */
   4.234 +                if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.235 +                ofs += ch;
   4.236 +                if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.237 +                bits -= (ch * pitch);
   4.238 +                break;
   4.239 +            default:                        /* no compression */
   4.240 +                if (isRle8) {
   4.241 +                    needsPad = ( ch & 1 );
   4.242 +                    do {
   4.243 +                        Uint8 pixel;
   4.244 +                        if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
   4.245 +                        COPY_PIXEL(pixel);
   4.246 +                    } while (--ch);
   4.247 +                } else {
   4.248 +                    needsPad = ( ((ch+1)>>1) & 1 ); /* (ch+1)>>1: bytes size */
   4.249 +                    for (;;) {
   4.250 +                        Uint8 pixel;
   4.251 +                        if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
   4.252 +                        COPY_PIXEL(pixel >> 4);
   4.253 +                        if (!--ch) break;
   4.254 +                        COPY_PIXEL(pixel & 0x0F);
   4.255 +                        if (!--ch) break;
   4.256 +                    }
   4.257 +                }
   4.258 +                /* pad at even boundary */
   4.259 +                if ( needsPad && !SDL_RWread(src, &ch, 1, 1) ) return 1;
   4.260 +                break;
   4.261 +            }
   4.262 +        }
   4.263 +    }
   4.264  }
   4.265  
   4.266  static SDL_Surface *LoadBMP_RW (SDL_RWops *src, int freesrc)
   4.267  {
   4.268 -	SDL_bool was_error;
   4.269 -	Sint64 fp_offset;
   4.270 -	int bmpPitch;
   4.271 -	int i, pad;
   4.272 -	SDL_Surface *surface;
   4.273 -	Uint32 Rmask;
   4.274 -	Uint32 Gmask;
   4.275 -	Uint32 Bmask;
   4.276 -	Uint32 Amask;
   4.277 -	SDL_Palette *palette;
   4.278 -	Uint8 *bits;
   4.279 -	Uint8 *top, *end;
   4.280 -	SDL_bool topDown;
   4.281 -	int ExpandBMP;
   4.282 +    SDL_bool was_error;
   4.283 +    Sint64 fp_offset;
   4.284 +    int bmpPitch;
   4.285 +    int i, pad;
   4.286 +    SDL_Surface *surface;
   4.287 +    Uint32 Rmask;
   4.288 +    Uint32 Gmask;
   4.289 +    Uint32 Bmask;
   4.290 +    Uint32 Amask;
   4.291 +    SDL_Palette *palette;
   4.292 +    Uint8 *bits;
   4.293 +    Uint8 *top, *end;
   4.294 +    SDL_bool topDown;
   4.295 +    int ExpandBMP;
   4.296  
   4.297 -	/* The Win32 BMP file header (14 bytes) */
   4.298 -	char   magic[2];
   4.299 -	Uint32 bfSize;
   4.300 -	Uint16 bfReserved1;
   4.301 -	Uint16 bfReserved2;
   4.302 -	Uint32 bfOffBits;
   4.303 +    /* The Win32 BMP file header (14 bytes) */
   4.304 +    char   magic[2];
   4.305 +    Uint32 bfSize;
   4.306 +    Uint16 bfReserved1;
   4.307 +    Uint16 bfReserved2;
   4.308 +    Uint32 bfOffBits;
   4.309  
   4.310 -	/* The Win32 BITMAPINFOHEADER struct (40 bytes) */
   4.311 -	Uint32 biSize;
   4.312 -	Sint32 biWidth;
   4.313 -	Sint32 biHeight;
   4.314 -	Uint16 biPlanes;
   4.315 -	Uint16 biBitCount;
   4.316 -	Uint32 biCompression;
   4.317 -	Uint32 biSizeImage;
   4.318 -	Sint32 biXPelsPerMeter;
   4.319 -	Sint32 biYPelsPerMeter;
   4.320 -	Uint32 biClrUsed;
   4.321 -	Uint32 biClrImportant;
   4.322 +    /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
   4.323 +    Uint32 biSize;
   4.324 +    Sint32 biWidth;
   4.325 +    Sint32 biHeight;
   4.326 +    Uint16 biPlanes;
   4.327 +    Uint16 biBitCount;
   4.328 +    Uint32 biCompression;
   4.329 +    Uint32 biSizeImage;
   4.330 +    Sint32 biXPelsPerMeter;
   4.331 +    Sint32 biYPelsPerMeter;
   4.332 +    Uint32 biClrUsed;
   4.333 +    Uint32 biClrImportant;
   4.334  
   4.335 -	/* Make sure we are passed a valid data source */
   4.336 -	surface = NULL;
   4.337 -	was_error = SDL_FALSE;
   4.338 -	if ( src == NULL ) {
   4.339 -		was_error = SDL_TRUE;
   4.340 -		goto done;
   4.341 -	}
   4.342 +    /* Make sure we are passed a valid data source */
   4.343 +    surface = NULL;
   4.344 +    was_error = SDL_FALSE;
   4.345 +    if ( src == NULL ) {
   4.346 +        was_error = SDL_TRUE;
   4.347 +        goto done;
   4.348 +    }
   4.349  
   4.350 -	/* Read in the BMP file header */
   4.351 -	fp_offset = SDL_RWtell(src);
   4.352 -	SDL_ClearError();
   4.353 -	if ( SDL_RWread(src, magic, 1, 2) != 2 ) {
   4.354 -		SDL_Error(SDL_EFREAD);
   4.355 -		was_error = SDL_TRUE;
   4.356 -		goto done;
   4.357 -	}
   4.358 -	if ( SDL_strncmp(magic, "BM", 2) != 0 ) {
   4.359 -		IMG_SetError("File is not a Windows BMP file");
   4.360 -		was_error = SDL_TRUE;
   4.361 -		goto done;
   4.362 -	}
   4.363 -	bfSize		= SDL_ReadLE32(src);
   4.364 -	bfReserved1	= SDL_ReadLE16(src);
   4.365 -	bfReserved2	= SDL_ReadLE16(src);
   4.366 -	bfOffBits	= SDL_ReadLE32(src);
   4.367 +    /* Read in the BMP file header */
   4.368 +    fp_offset = SDL_RWtell(src);
   4.369 +    SDL_ClearError();
   4.370 +    if ( SDL_RWread(src, magic, 1, 2) != 2 ) {
   4.371 +        SDL_Error(SDL_EFREAD);
   4.372 +        was_error = SDL_TRUE;
   4.373 +        goto done;
   4.374 +    }
   4.375 +    if ( SDL_strncmp(magic, "BM", 2) != 0 ) {
   4.376 +        IMG_SetError("File is not a Windows BMP file");
   4.377 +        was_error = SDL_TRUE;
   4.378 +        goto done;
   4.379 +    }
   4.380 +    bfSize      = SDL_ReadLE32(src);
   4.381 +    bfReserved1 = SDL_ReadLE16(src);
   4.382 +    bfReserved2 = SDL_ReadLE16(src);
   4.383 +    bfOffBits   = SDL_ReadLE32(src);
   4.384  
   4.385 -	/* Read the Win32 BITMAPINFOHEADER */
   4.386 -	biSize		= SDL_ReadLE32(src);
   4.387 -	if ( biSize == 12 ) {
   4.388 -		biWidth		= (Uint32)SDL_ReadLE16(src);
   4.389 -		biHeight	= (Uint32)SDL_ReadLE16(src);
   4.390 -		biPlanes	= SDL_ReadLE16(src);
   4.391 -		biBitCount	= SDL_ReadLE16(src);
   4.392 -		biCompression	= BI_RGB;
   4.393 -		biSizeImage	= 0;
   4.394 -		biXPelsPerMeter	= 0;
   4.395 -		biYPelsPerMeter	= 0;
   4.396 -		biClrUsed	= 0;
   4.397 -		biClrImportant	= 0;
   4.398 -	} else {
   4.399 -		biWidth		= SDL_ReadLE32(src);
   4.400 -		biHeight	= SDL_ReadLE32(src);
   4.401 -		biPlanes	= SDL_ReadLE16(src);
   4.402 -		biBitCount	= SDL_ReadLE16(src);
   4.403 -		biCompression	= SDL_ReadLE32(src);
   4.404 -		biSizeImage	= SDL_ReadLE32(src);
   4.405 -		biXPelsPerMeter	= SDL_ReadLE32(src);
   4.406 -		biYPelsPerMeter	= SDL_ReadLE32(src);
   4.407 -		biClrUsed	= SDL_ReadLE32(src);
   4.408 -		biClrImportant	= SDL_ReadLE32(src);
   4.409 -	}
   4.410 -	if (biHeight < 0) {
   4.411 -		topDown = SDL_TRUE;
   4.412 -		biHeight = -biHeight;
   4.413 -	} else {
   4.414 -		topDown = SDL_FALSE;
   4.415 -	}
   4.416 +    /* Read the Win32 BITMAPINFOHEADER */
   4.417 +    biSize      = SDL_ReadLE32(src);
   4.418 +    if ( biSize == 12 ) {
   4.419 +        biWidth     = (Uint32)SDL_ReadLE16(src);
   4.420 +        biHeight    = (Uint32)SDL_ReadLE16(src);
   4.421 +        biPlanes    = SDL_ReadLE16(src);
   4.422 +        biBitCount  = SDL_ReadLE16(src);
   4.423 +        biCompression   = BI_RGB;
   4.424 +        biSizeImage = 0;
   4.425 +        biXPelsPerMeter = 0;
   4.426 +        biYPelsPerMeter = 0;
   4.427 +        biClrUsed   = 0;
   4.428 +        biClrImportant  = 0;
   4.429 +    } else {
   4.430 +        biWidth     = SDL_ReadLE32(src);
   4.431 +        biHeight    = SDL_ReadLE32(src);
   4.432 +        biPlanes    = SDL_ReadLE16(src);
   4.433 +        biBitCount  = SDL_ReadLE16(src);
   4.434 +        biCompression   = SDL_ReadLE32(src);
   4.435 +        biSizeImage = SDL_ReadLE32(src);
   4.436 +        biXPelsPerMeter = SDL_ReadLE32(src);
   4.437 +        biYPelsPerMeter = SDL_ReadLE32(src);
   4.438 +        biClrUsed   = SDL_ReadLE32(src);
   4.439 +        biClrImportant  = SDL_ReadLE32(src);
   4.440 +    }
   4.441 +    if (biHeight < 0) {
   4.442 +        topDown = SDL_TRUE;
   4.443 +        biHeight = -biHeight;
   4.444 +    } else {
   4.445 +        topDown = SDL_FALSE;
   4.446 +    }
   4.447  
   4.448 -	/* Check for read error */
   4.449 -	if ( strcmp(SDL_GetError(), "") != 0 ) {
   4.450 -		was_error = SDL_TRUE;
   4.451 -		goto done;
   4.452 -	}
   4.453 +    /* Check for read error */
   4.454 +    if ( strcmp(SDL_GetError(), "") != 0 ) {
   4.455 +        was_error = SDL_TRUE;
   4.456 +        goto done;
   4.457 +    }
   4.458  
   4.459 -	/* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
   4.460 -	switch (biBitCount) {
   4.461 -		case 1:
   4.462 -		case 4:
   4.463 -			ExpandBMP = biBitCount;
   4.464 -			biBitCount = 8;
   4.465 -			break;
   4.466 -		default:
   4.467 -			ExpandBMP = 0;
   4.468 -			break;
   4.469 -	}
   4.470 +    /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
   4.471 +    switch (biBitCount) {
   4.472 +        case 1:
   4.473 +        case 4:
   4.474 +            ExpandBMP = biBitCount;
   4.475 +            biBitCount = 8;
   4.476 +            break;
   4.477 +        default:
   4.478 +            ExpandBMP = 0;
   4.479 +            break;
   4.480 +    }
   4.481  
   4.482 -	/* RLE4 and RLE8 BMP compression is supported */
   4.483 -	Rmask = Gmask = Bmask = Amask = 0;
   4.484 -	switch (biCompression) {
   4.485 -		case BI_RGB:
   4.486 -			/* If there are no masks, use the defaults */
   4.487 -			if ( bfOffBits == (14+biSize) ) {
   4.488 -				/* Default values for the BMP format */
   4.489 -				switch (biBitCount) {
   4.490 -					case 15:
   4.491 -					case 16:
   4.492 -						Rmask = 0x7C00;
   4.493 -						Gmask = 0x03E0;
   4.494 -						Bmask = 0x001F;
   4.495 -						break;
   4.496 -					case 24:
   4.497 +    /* RLE4 and RLE8 BMP compression is supported */
   4.498 +    Rmask = Gmask = Bmask = Amask = 0;
   4.499 +    switch (biCompression) {
   4.500 +        case BI_RGB:
   4.501 +            /* If there are no masks, use the defaults */
   4.502 +            if ( bfOffBits == (14+biSize) ) {
   4.503 +                /* Default values for the BMP format */
   4.504 +                switch (biBitCount) {
   4.505 +                    case 15:
   4.506 +                    case 16:
   4.507 +                        Rmask = 0x7C00;
   4.508 +                        Gmask = 0x03E0;
   4.509 +                        Bmask = 0x001F;
   4.510 +                        break;
   4.511 +                    case 24:
   4.512  #if SDL_BYTEORDER == SDL_BIG_ENDIAN
   4.513 -					        Rmask = 0x000000FF;
   4.514 -					        Gmask = 0x0000FF00;
   4.515 -					        Bmask = 0x00FF0000;
   4.516 +                            Rmask = 0x000000FF;
   4.517 +                            Gmask = 0x0000FF00;
   4.518 +                            Bmask = 0x00FF0000;
   4.519  #else
   4.520 -						Rmask = 0x00FF0000;
   4.521 -						Gmask = 0x0000FF00;
   4.522 -						Bmask = 0x000000FF;
   4.523 +                        Rmask = 0x00FF0000;
   4.524 +                        Gmask = 0x0000FF00;
   4.525 +                        Bmask = 0x000000FF;
   4.526  #endif
   4.527 -						break;
   4.528 -					case 32:
   4.529 -						Amask = 0xFF000000;
   4.530 -						Rmask = 0x00FF0000;
   4.531 -						Gmask = 0x0000FF00;
   4.532 -						Bmask = 0x000000FF;
   4.533 -						break;
   4.534 -					default:
   4.535 -						break;
   4.536 -				}
   4.537 -				break;
   4.538 -			}
   4.539 -			/* Fall through -- read the RGB masks */
   4.540 +                        break;
   4.541 +                    case 32:
   4.542 +                        Amask = 0xFF000000;
   4.543 +                        Rmask = 0x00FF0000;
   4.544 +                        Gmask = 0x0000FF00;
   4.545 +                        Bmask = 0x000000FF;
   4.546 +                        break;
   4.547 +                    default:
   4.548 +                        break;
   4.549 +                }
   4.550 +                break;
   4.551 +            }
   4.552 +            /* Fall through -- read the RGB masks */
   4.553  
   4.554 -		default:
   4.555 -			switch (biBitCount) {
   4.556 -				case 15:
   4.557 -				case 16:
   4.558 -					Rmask = SDL_ReadLE32(src);
   4.559 -					Gmask = SDL_ReadLE32(src);
   4.560 -					Bmask = SDL_ReadLE32(src);
   4.561 -					break;
   4.562 -				case 32:
   4.563 -					Rmask = SDL_ReadLE32(src);
   4.564 -					Gmask = SDL_ReadLE32(src);
   4.565 -					Bmask = SDL_ReadLE32(src);
   4.566 -					Amask = SDL_ReadLE32(src);
   4.567 -					break;
   4.568 -				default:
   4.569 -					break;
   4.570 -			}
   4.571 -			break;
   4.572 -	}
   4.573 +        default:
   4.574 +            switch (biBitCount) {
   4.575 +                case 15:
   4.576 +                case 16:
   4.577 +                    Rmask = SDL_ReadLE32(src);
   4.578 +                    Gmask = SDL_ReadLE32(src);
   4.579 +                    Bmask = SDL_ReadLE32(src);
   4.580 +                    break;
   4.581 +                case 32:
   4.582 +                    Rmask = SDL_ReadLE32(src);
   4.583 +                    Gmask = SDL_ReadLE32(src);
   4.584 +                    Bmask = SDL_ReadLE32(src);
   4.585 +                    Amask = SDL_ReadLE32(src);
   4.586 +                    break;
   4.587 +                default:
   4.588 +                    break;
   4.589 +            }
   4.590 +            break;
   4.591 +    }
   4.592  
   4.593 -	/* Create a compatible surface, note that the colors are RGB ordered */
   4.594 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   4.595 -			biWidth, biHeight, biBitCount, Rmask, Gmask, Bmask, Amask);
   4.596 -	if ( surface == NULL ) {
   4.597 -		was_error = SDL_TRUE;
   4.598 -		goto done;
   4.599 -	}
   4.600 +    /* Create a compatible surface, note that the colors are RGB ordered */
   4.601 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   4.602 +            biWidth, biHeight, biBitCount, Rmask, Gmask, Bmask, Amask);
   4.603 +    if ( surface == NULL ) {
   4.604 +        was_error = SDL_TRUE;
   4.605 +        goto done;
   4.606 +    }
   4.607  
   4.608 -	/* Load the palette, if any */
   4.609 -	palette = (surface->format)->palette;
   4.610 -	if ( palette ) {
   4.611 -		if ( SDL_RWseek(src, fp_offset+14+biSize, RW_SEEK_SET) < 0 ) {
   4.612 -			SDL_Error(SDL_EFSEEK);
   4.613 -			was_error = SDL_TRUE;
   4.614 -			goto done;
   4.615 -		}
   4.616 +    /* Load the palette, if any */
   4.617 +    palette = (surface->format)->palette;
   4.618 +    if ( palette ) {
   4.619 +        if ( SDL_RWseek(src, fp_offset+14+biSize, RW_SEEK_SET) < 0 ) {
   4.620 +            SDL_Error(SDL_EFSEEK);
   4.621 +            was_error = SDL_TRUE;
   4.622 +            goto done;
   4.623 +        }
   4.624  
   4.625 -		/*
   4.626 -		| guich: always use 1<<bpp b/c some bitmaps can bring wrong information
   4.627 -		| for colorsUsed
   4.628 -		*/
   4.629 -		/* if ( biClrUsed == 0 ) {  */
   4.630 -		biClrUsed = 1 << biBitCount;
   4.631 -		/* } */
   4.632 -		if ( biSize == 12 ) {
   4.633 -			for ( i = 0; i < (int)biClrUsed; ++i ) {
   4.634 -				SDL_RWread(src, &palette->colors[i].b, 1, 1);
   4.635 -				SDL_RWread(src, &palette->colors[i].g, 1, 1);
   4.636 -				SDL_RWread(src, &palette->colors[i].r, 1, 1);
   4.637 -				palette->colors[i].a = SDL_ALPHA_OPAQUE;
   4.638 -			}	
   4.639 -		} else {
   4.640 -			for ( i = 0; i < (int)biClrUsed; ++i ) {
   4.641 -				SDL_RWread(src, &palette->colors[i].b, 1, 1);
   4.642 -				SDL_RWread(src, &palette->colors[i].g, 1, 1);
   4.643 -				SDL_RWread(src, &palette->colors[i].r, 1, 1);
   4.644 -				SDL_RWread(src, &palette->colors[i].a, 1, 1);
   4.645 +        /*
   4.646 +        | guich: always use 1<<bpp b/c some bitmaps can bring wrong information
   4.647 +        | for colorsUsed
   4.648 +        */
   4.649 +        /* if ( biClrUsed == 0 ) {  */
   4.650 +        biClrUsed = 1 << biBitCount;
   4.651 +        /* } */
   4.652 +        if ( biSize == 12 ) {
   4.653 +            for ( i = 0; i < (int)biClrUsed; ++i ) {
   4.654 +                SDL_RWread(src, &palette->colors[i].b, 1, 1);
   4.655 +                SDL_RWread(src, &palette->colors[i].g, 1, 1);
   4.656 +                SDL_RWread(src, &palette->colors[i].r, 1, 1);
   4.657 +                palette->colors[i].a = SDL_ALPHA_OPAQUE;
   4.658 +            }
   4.659 +        } else {
   4.660 +            for ( i = 0; i < (int)biClrUsed; ++i ) {
   4.661 +                SDL_RWread(src, &palette->colors[i].b, 1, 1);
   4.662 +                SDL_RWread(src, &palette->colors[i].g, 1, 1);
   4.663 +                SDL_RWread(src, &palette->colors[i].r, 1, 1);
   4.664 +                SDL_RWread(src, &palette->colors[i].a, 1, 1);
   4.665  
   4.666 -				/* According to Microsoft documentation, the fourth element
   4.667 -				   is reserved and must be zero, so we shouldn't treat it as
   4.668 -				   alpha.
   4.669 -				*/
   4.670 -				palette->colors[i].a = SDL_ALPHA_OPAQUE;
   4.671 -			}	
   4.672 -		}
   4.673 -		palette->ncolors = biClrUsed;
   4.674 -	}
   4.675 +                /* According to Microsoft documentation, the fourth element
   4.676 +                   is reserved and must be zero, so we shouldn't treat it as
   4.677 +                   alpha.
   4.678 +                */
   4.679 +                palette->colors[i].a = SDL_ALPHA_OPAQUE;
   4.680 +            }
   4.681 +        }
   4.682 +        palette->ncolors = biClrUsed;
   4.683 +    }
   4.684  
   4.685 -	/* Read the surface pixels.  Note that the bmp image is upside down */
   4.686 -	if ( SDL_RWseek(src, fp_offset+bfOffBits, RW_SEEK_SET) < 0 ) {
   4.687 -		SDL_Error(SDL_EFSEEK);
   4.688 -		was_error = SDL_TRUE;
   4.689 -		goto done;
   4.690 -	}
   4.691 -	if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) {
   4.692 -		was_error = (SDL_bool)readRlePixels(surface, src, biCompression == BI_RLE8);
   4.693 -		if (was_error) IMG_SetError("Error reading from BMP");
   4.694 -		goto done;
   4.695 -	}
   4.696 -	top = (Uint8 *)surface->pixels;
   4.697 -	end = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
   4.698 -	switch (ExpandBMP) {
   4.699 -		case 1:
   4.700 -			bmpPitch = (biWidth + 7) >> 3;
   4.701 -			pad  = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
   4.702 -			break;
   4.703 -		case 4:
   4.704 -			bmpPitch = (biWidth + 1) >> 1;
   4.705 -			pad  = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
   4.706 -			break;
   4.707 -		default:
   4.708 -			pad  = ((surface->pitch%4) ?
   4.709 -					(4-(surface->pitch%4)) : 0);
   4.710 -			break;
   4.711 -	}
   4.712 -	if ( topDown ) {
   4.713 -		bits = top;
   4.714 -	} else {
   4.715 -		bits = end - surface->pitch;
   4.716 -	}
   4.717 -	while ( bits >= top && bits < end ) {
   4.718 -		switch (ExpandBMP) {
   4.719 -			case 1:
   4.720 -			case 4: {
   4.721 -			Uint8 pixel = 0;
   4.722 -			int   shift = (8-ExpandBMP);
   4.723 -			for ( i=0; i<surface->w; ++i ) {
   4.724 -				if ( i%(8/ExpandBMP) == 0 ) {
   4.725 -					if ( !SDL_RWread(src, &pixel, 1, 1) ) {
   4.726 -						IMG_SetError(
   4.727 -					"Error reading from BMP");
   4.728 -						was_error = SDL_TRUE;
   4.729 -						goto done;
   4.730 -					}
   4.731 -				}
   4.732 -				*(bits+i) = (pixel>>shift);
   4.733 -				pixel <<= ExpandBMP;
   4.734 -			} }
   4.735 -			break;
   4.736 +    /* Read the surface pixels.  Note that the bmp image is upside down */
   4.737 +    if ( SDL_RWseek(src, fp_offset+bfOffBits, RW_SEEK_SET) < 0 ) {
   4.738 +        SDL_Error(SDL_EFSEEK);
   4.739 +        was_error = SDL_TRUE;
   4.740 +        goto done;
   4.741 +    }
   4.742 +    if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) {
   4.743 +        was_error = (SDL_bool)readRlePixels(surface, src, biCompression == BI_RLE8);
   4.744 +        if (was_error) IMG_SetError("Error reading from BMP");
   4.745 +        goto done;
   4.746 +    }
   4.747 +    top = (Uint8 *)surface->pixels;
   4.748 +    end = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
   4.749 +    switch (ExpandBMP) {
   4.750 +        case 1:
   4.751 +            bmpPitch = (biWidth + 7) >> 3;
   4.752 +            pad  = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
   4.753 +            break;
   4.754 +        case 4:
   4.755 +            bmpPitch = (biWidth + 1) >> 1;
   4.756 +            pad  = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
   4.757 +            break;
   4.758 +        default:
   4.759 +            pad  = ((surface->pitch%4) ?
   4.760 +                    (4-(surface->pitch%4)) : 0);
   4.761 +            break;
   4.762 +    }
   4.763 +    if ( topDown ) {
   4.764 +        bits = top;
   4.765 +    } else {
   4.766 +        bits = end - surface->pitch;
   4.767 +    }
   4.768 +    while ( bits >= top && bits < end ) {
   4.769 +        switch (ExpandBMP) {
   4.770 +            case 1:
   4.771 +            case 4: {
   4.772 +            Uint8 pixel = 0;
   4.773 +            int   shift = (8-ExpandBMP);
   4.774 +            for ( i=0; i<surface->w; ++i ) {
   4.775 +                if ( i%(8/ExpandBMP) == 0 ) {
   4.776 +                    if ( !SDL_RWread(src, &pixel, 1, 1) ) {
   4.777 +                        IMG_SetError(
   4.778 +                    "Error reading from BMP");
   4.779 +                        was_error = SDL_TRUE;
   4.780 +                        goto done;
   4.781 +                    }
   4.782 +                }
   4.783 +                *(bits+i) = (pixel>>shift);
   4.784 +                pixel <<= ExpandBMP;
   4.785 +            } }
   4.786 +            break;
   4.787  
   4.788 -			default:
   4.789 -			if ( SDL_RWread(src, bits, 1, surface->pitch)
   4.790 -							 != surface->pitch ) {
   4.791 -				SDL_Error(SDL_EFREAD);
   4.792 -				was_error = SDL_TRUE;
   4.793 -				goto done;
   4.794 -			}
   4.795 +            default:
   4.796 +            if ( SDL_RWread(src, bits, 1, surface->pitch)
   4.797 +                             != surface->pitch ) {
   4.798 +                SDL_Error(SDL_EFREAD);
   4.799 +                was_error = SDL_TRUE;
   4.800 +                goto done;
   4.801 +            }
   4.802  #if SDL_BYTEORDER == SDL_BIG_ENDIAN
   4.803 -			/* Byte-swap the pixels if needed. Note that the 24bpp
   4.804 -			   case has already been taken care of above. */
   4.805 -			switch(biBitCount) {
   4.806 -				case 15:
   4.807 -				case 16: {
   4.808 -				        Uint16 *pix = (Uint16 *)bits;
   4.809 -					for(i = 0; i < surface->w; i++)
   4.810 -					        pix[i] = SDL_Swap16(pix[i]);
   4.811 -					break;
   4.812 -				}
   4.813 +            /* Byte-swap the pixels if needed. Note that the 24bpp
   4.814 +               case has already been taken care of above. */
   4.815 +            switch(biBitCount) {
   4.816 +                case 15:
   4.817 +                case 16: {
   4.818 +                        Uint16 *pix = (Uint16 *)bits;
   4.819 +                    for(i = 0; i < surface->w; i++)
   4.820 +                            pix[i] = SDL_Swap16(pix[i]);
   4.821 +                    break;
   4.822 +                }
   4.823  
   4.824 -				case 32: {
   4.825 -				        Uint32 *pix = (Uint32 *)bits;
   4.826 -					for(i = 0; i < surface->w; i++)
   4.827 -					        pix[i] = SDL_Swap32(pix[i]);
   4.828 -					break;
   4.829 -				}
   4.830 -			}
   4.831 +                case 32: {
   4.832 +                        Uint32 *pix = (Uint32 *)bits;
   4.833 +                    for(i = 0; i < surface->w; i++)
   4.834 +                            pix[i] = SDL_Swap32(pix[i]);
   4.835 +                    break;
   4.836 +                }
   4.837 +            }
   4.838  #endif
   4.839 -			break;
   4.840 -		}
   4.841 -		/* Skip padding bytes, ugh */
   4.842 -		if ( pad ) {
   4.843 -			Uint8 padbyte;
   4.844 -			for ( i=0; i<pad; ++i ) {
   4.845 -				SDL_RWread(src, &padbyte, 1, 1);
   4.846 -			}
   4.847 -		}
   4.848 -		if ( topDown ) {
   4.849 -			bits += surface->pitch;
   4.850 -		} else {
   4.851 -			bits -= surface->pitch;
   4.852 -		}
   4.853 -	}
   4.854 +            break;
   4.855 +        }
   4.856 +        /* Skip padding bytes, ugh */
   4.857 +        if ( pad ) {
   4.858 +            Uint8 padbyte;
   4.859 +            for ( i=0; i<pad; ++i ) {
   4.860 +                SDL_RWread(src, &padbyte, 1, 1);
   4.861 +            }
   4.862 +        }
   4.863 +        if ( topDown ) {
   4.864 +            bits += surface->pitch;
   4.865 +        } else {
   4.866 +            bits -= surface->pitch;
   4.867 +        }
   4.868 +    }
   4.869  done:
   4.870 -	if ( was_error ) {
   4.871 -		if ( src ) {
   4.872 -			SDL_RWseek(src, fp_offset, RW_SEEK_SET);
   4.873 -		}
   4.874 -		if ( surface ) {
   4.875 -			SDL_FreeSurface(surface);
   4.876 -		}
   4.877 -		surface = NULL;
   4.878 -	}
   4.879 -	if ( freesrc && src ) {
   4.880 -		SDL_RWclose(src);
   4.881 -	}
   4.882 -	return(surface);
   4.883 +    if ( was_error ) {
   4.884 +        if ( src ) {
   4.885 +            SDL_RWseek(src, fp_offset, RW_SEEK_SET);
   4.886 +        }
   4.887 +        if ( surface ) {
   4.888 +            SDL_FreeSurface(surface);
   4.889 +        }
   4.890 +        surface = NULL;
   4.891 +    }
   4.892 +    if ( freesrc && src ) {
   4.893 +        SDL_RWclose(src);
   4.894 +    }
   4.895 +    return(surface);
   4.896  }
   4.897  
   4.898  static Uint8
   4.899 @@ -798,19 +798,19 @@
   4.900  /* Load a BMP type image from an SDL datasource */
   4.901  SDL_Surface *IMG_LoadBMP_RW(SDL_RWops *src)
   4.902  {
   4.903 -	return(LoadBMP_RW(src, 0));
   4.904 +    return(LoadBMP_RW(src, 0));
   4.905  }
   4.906  
   4.907  /* Load a ICO type image from an SDL datasource */
   4.908  SDL_Surface *IMG_LoadICO_RW(SDL_RWops *src)
   4.909  {
   4.910 -	return(LoadICOCUR_RW(src, 1, 0));
   4.911 +    return(LoadICOCUR_RW(src, 1, 0));
   4.912  }
   4.913  
   4.914  /* Load a CUR type image from an SDL datasource */
   4.915  SDL_Surface *IMG_LoadCUR_RW(SDL_RWops *src)
   4.916  {
   4.917 -	return(LoadICOCUR_RW(src, 2, 0));
   4.918 +    return(LoadICOCUR_RW(src, 2, 0));
   4.919  }
   4.920  
   4.921  #else
   4.922 @@ -818,35 +818,35 @@
   4.923  /* See if an image is contained in a data source */
   4.924  int IMG_isBMP(SDL_RWops *src)
   4.925  {
   4.926 -	return(0);
   4.927 +    return(0);
   4.928  }
   4.929  
   4.930  int IMG_isICO(SDL_RWops *src)
   4.931  {
   4.932 -	return(0);
   4.933 +    return(0);
   4.934  }
   4.935  
   4.936  int IMG_isCUR(SDL_RWops *src)
   4.937  {
   4.938 -	return(0);
   4.939 +    return(0);
   4.940  }
   4.941  
   4.942  /* Load a BMP type image from an SDL datasource */
   4.943  SDL_Surface *IMG_LoadBMP_RW(SDL_RWops *src)
   4.944  {
   4.945 -	return(NULL);
   4.946 +    return(NULL);
   4.947  }
   4.948  
   4.949  /* Load a BMP type image from an SDL datasource */
   4.950  SDL_Surface *IMG_LoadCUR_RW(SDL_RWops *src)
   4.951  {
   4.952 -	return(NULL);
   4.953 +    return(NULL);
   4.954  }
   4.955  
   4.956  /* Load a BMP type image from an SDL datasource */
   4.957  SDL_Surface *IMG_LoadICO_RW(SDL_RWops *src)
   4.958  {
   4.959 -	return(NULL);
   4.960 +    return(NULL);
   4.961  }
   4.962  
   4.963  #endif /* LOAD_BMP */
     5.1 --- a/IMG_gif.c	Thu Apr 25 00:22:51 2013 -0700
     5.2 +++ b/IMG_gif.c	Tue May 21 21:24:32 2013 -0700
     5.3 @@ -33,35 +33,35 @@
     5.4  /* See if an image is contained in a data source */
     5.5  int IMG_isGIF(SDL_RWops *src)
     5.6  {
     5.7 -	Sint64 start;
     5.8 -	int is_GIF;
     5.9 -	char magic[6];
    5.10 +    Sint64 start;
    5.11 +    int is_GIF;
    5.12 +    char magic[6];
    5.13  
    5.14 -	if ( !src )
    5.15 -		return 0;
    5.16 -	start = SDL_RWtell(src);
    5.17 -	is_GIF = 0;
    5.18 -	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    5.19 -		if ( (SDL_strncmp(magic, "GIF", 3) == 0) &&
    5.20 -		     ((SDL_memcmp(magic + 3, "87a", 3) == 0) ||
    5.21 -		      (SDL_memcmp(magic + 3, "89a", 3) == 0)) ) {
    5.22 -			is_GIF = 1;
    5.23 -		}
    5.24 -	}
    5.25 -	SDL_RWseek(src, start, RW_SEEK_SET);
    5.26 -	return(is_GIF);
    5.27 +    if ( !src )
    5.28 +        return 0;
    5.29 +    start = SDL_RWtell(src);
    5.30 +    is_GIF = 0;
    5.31 +    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    5.32 +        if ( (SDL_strncmp(magic, "GIF", 3) == 0) &&
    5.33 +             ((SDL_memcmp(magic + 3, "87a", 3) == 0) ||
    5.34 +              (SDL_memcmp(magic + 3, "89a", 3) == 0)) ) {
    5.35 +            is_GIF = 1;
    5.36 +        }
    5.37 +    }
    5.38 +    SDL_RWseek(src, start, RW_SEEK_SET);
    5.39 +    return(is_GIF);
    5.40  }
    5.41  
    5.42  /* Code from here to end of file has been adapted from XPaint:           */
    5.43  /* +-------------------------------------------------------------------+ */
    5.44 -/* | Copyright 1990, 1991, 1993 David Koblas.			       | */
    5.45 -/* | Copyright 1996 Torsten Martinsen.				       | */
    5.46 +/* | Copyright 1990, 1991, 1993 David Koblas.                  | */
    5.47 +/* | Copyright 1996 Torsten Martinsen.                     | */
    5.48  /* |   Permission to use, copy, modify, and distribute this software   | */
    5.49  /* |   and its documentation for any purpose and without fee is hereby | */
    5.50  /* |   granted, provided that the above copyright notice appear in all | */
    5.51  /* |   copies and that both that copyright notice and this permission  | */
    5.52  /* |   notice appear in supporting documentation.  This software is    | */
    5.53 -/* |   provided "as is" without express or implied warranty.	       | */
    5.54 +/* |   provided "as is" without express or implied warranty.           | */
    5.55  /* +-------------------------------------------------------------------+ */
    5.56  
    5.57  /* Adapted for use in SDL by Sam Lantinga -- 7/20/98 */
    5.58 @@ -79,14 +79,14 @@
    5.59  */
    5.60  #include "SDL.h"
    5.61  
    5.62 -#define Image			SDL_Surface
    5.63 -#define RWSetMsg		IMG_SetError
    5.64 -#define ImageNewCmap(w, h, s)	SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,8,0,0,0,0)
    5.65 +#define Image           SDL_Surface
    5.66 +#define RWSetMsg        IMG_SetError
    5.67 +#define ImageNewCmap(w, h, s)   SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,8,0,0,0,0)
    5.68  #define ImageSetCmap(s, i, R, G, B) do { \
    5.69 -				s->format->palette->colors[i].r = R; \
    5.70 -				s->format->palette->colors[i].g = G; \
    5.71 -				s->format->palette->colors[i].b = B; \
    5.72 -			} while (0)
    5.73 +                s->format->palette->colors[i].r = R; \
    5.74 +                s->format->palette->colors[i].g = G; \
    5.75 +                s->format->palette->colors[i].b = B; \
    5.76 +            } while (0)
    5.77  /* * * * * */
    5.78  
    5.79  #else
    5.80 @@ -96,30 +96,30 @@
    5.81  #include "image.h"
    5.82  #include "rwTable.h"
    5.83  
    5.84 -#define SDL_RWops	FILE
    5.85 -#define SDL_RWclose	fclose
    5.86 +#define SDL_RWops   FILE
    5.87 +#define SDL_RWclose fclose
    5.88  
    5.89  #endif /* USED_BY_SDL */
    5.90  
    5.91  
    5.92 -#define	MAXCOLORMAPSIZE		256
    5.93 +#define MAXCOLORMAPSIZE     256
    5.94  
    5.95 -#define	TRUE	1
    5.96 -#define	FALSE	0
    5.97 +#define TRUE    1
    5.98 +#define FALSE   0
    5.99  
   5.100 -#define CM_RED		0
   5.101 -#define CM_GREEN	1
   5.102 -#define CM_BLUE		2
   5.103 +#define CM_RED      0
   5.104 +#define CM_GREEN    1
   5.105 +#define CM_BLUE     2
   5.106  
   5.107 -#define	MAX_LWZ_BITS		12
   5.108 +#define MAX_LWZ_BITS        12
   5.109  
   5.110 -#define INTERLACE		0x40
   5.111 -#define LOCALCOLORMAP	0x80
   5.112 -#define BitSet(byte, bit)	(((byte) & (bit)) == (bit))
   5.113 +#define INTERLACE       0x40
   5.114 +#define LOCALCOLORMAP   0x80
   5.115 +#define BitSet(byte, bit)   (((byte) & (bit)) == (bit))
   5.116  
   5.117 -#define	ReadOK(file,buffer,len)	SDL_RWread(file, buffer, len, 1)
   5.118 +#define ReadOK(file,buffer,len) SDL_RWread(file, buffer, len, 1)
   5.119  
   5.120 -#define LM_to_uint(a,b)			(((b)<<8)|(a))
   5.121 +#define LM_to_uint(a,b)         (((b)<<8)|(a))
   5.122  
   5.123  static struct {
   5.124      unsigned int Width;
   5.125 @@ -140,14 +140,14 @@
   5.126  } Gif89;
   5.127  
   5.128  static int ReadColorMap(SDL_RWops * src, int number,
   5.129 -			unsigned char buffer[3][MAXCOLORMAPSIZE], int *flag);
   5.130 +            unsigned char buffer[3][MAXCOLORMAPSIZE], int *flag);
   5.131  static int DoExtension(SDL_RWops * src, int label);
   5.132  static int GetDataBlock(SDL_RWops * src, unsigned char *buf);
   5.133  static int GetCode(SDL_RWops * src, int code_size, int flag);
   5.134  static int LWZReadByte(SDL_RWops * src, int flag, int input_code_size);
   5.135  static Image *ReadImage(SDL_RWops * src, int len, int height, int,
   5.136 -			unsigned char cmap[3][MAXCOLORMAPSIZE],
   5.137 -			int gray, int interlace, int ignore);
   5.138 +            unsigned char cmap[3][MAXCOLORMAPSIZE],
   5.139 +            int gray, int interlace, int ignore);
   5.140  
   5.141  Image *
   5.142  IMG_LoadGIF_RW(SDL_RWops *src)
   5.143 @@ -165,23 +165,23 @@
   5.144      Image *image = NULL;
   5.145  
   5.146      if ( src == NULL ) {
   5.147 -	return NULL;
   5.148 +    return NULL;
   5.149      }
   5.150      start = SDL_RWtell(src);
   5.151  
   5.152      if (!ReadOK(src, buf, 6)) {
   5.153 -	RWSetMsg("error reading magic number");
   5.154 +    RWSetMsg("error reading magic number");
   5.155          goto done;
   5.156      }
   5.157      if (SDL_strncmp((char *) buf, "GIF", 3) != 0) {
   5.158 -	RWSetMsg("not a GIF file");
   5.159 +    RWSetMsg("not a GIF file");
   5.160          goto done;
   5.161      }
   5.162      SDL_memcpy(version, (char *) buf + 3, 3);
   5.163      version[3] = '\0';
   5.164  
   5.165      if ((SDL_strcmp(version, "87a") != 0) && (SDL_strcmp(version, "89a") != 0)) {
   5.166 -	RWSetMsg("bad version number, not '87a' or '89a'");
   5.167 +    RWSetMsg("bad version number, not '87a' or '89a'");
   5.168          goto done;
   5.169      }
   5.170      Gif89.transparent = -1;
   5.171 @@ -190,7 +190,7 @@
   5.172      Gif89.disposal = 0;
   5.173  
   5.174      if (!ReadOK(src, buf, 7)) {
   5.175 -	RWSetMsg("failed to read screen descriptor");
   5.176 +    RWSetMsg("failed to read screen descriptor");
   5.177          goto done;
   5.178      }
   5.179      GifScreen.Width = LM_to_uint(buf[0], buf[1]);
   5.180 @@ -200,63 +200,63 @@
   5.181      GifScreen.Background = buf[5];
   5.182      GifScreen.AspectRatio = buf[6];
   5.183  
   5.184 -    if (BitSet(buf[4], LOCALCOLORMAP)) {	/* Global Colormap */
   5.185 -	if (ReadColorMap(src, GifScreen.BitPixel, GifScreen.ColorMap,
   5.186 -			 &GifScreen.GrayScale)) {
   5.187 -	    RWSetMsg("error reading global colormap");
   5.188 +    if (BitSet(buf[4], LOCALCOLORMAP)) {    /* Global Colormap */
   5.189 +    if (ReadColorMap(src, GifScreen.BitPixel, GifScreen.ColorMap,
   5.190 +             &GifScreen.GrayScale)) {
   5.191 +        RWSetMsg("error reading global colormap");
   5.192              goto done;
   5.193 -	}
   5.194 +    }
   5.195      }
   5.196      do {
   5.197 -	if (!ReadOK(src, &c, 1)) {
   5.198 -	    RWSetMsg("EOF / read error on image data");
   5.199 +    if (!ReadOK(src, &c, 1)) {
   5.200 +        RWSetMsg("EOF / read error on image data");
   5.201              goto done;
   5.202 -	}
   5.203 -	if (c == ';') {		/* GIF terminator */
   5.204 -	    if (imageCount < imageNumber) {
   5.205 -		RWSetMsg("only %d image%s found in file",
   5.206 -			 imageCount, imageCount > 1 ? "s" : "");
   5.207 +    }
   5.208 +    if (c == ';') {     /* GIF terminator */
   5.209 +        if (imageCount < imageNumber) {
   5.210 +        RWSetMsg("only %d image%s found in file",
   5.211 +             imageCount, imageCount > 1 ? "s" : "");
   5.212                  goto done;
   5.213 -	    }
   5.214 -	}
   5.215 -	if (c == '!') {		/* Extension */
   5.216 -	    if (!ReadOK(src, &c, 1)) {
   5.217 -		RWSetMsg("EOF / read error on extention function code");
   5.218 +        }
   5.219 +    }
   5.220 +    if (c == '!') {     /* Extension */
   5.221 +        if (!ReadOK(src, &c, 1)) {
   5.222 +        RWSetMsg("EOF / read error on extention function code");
   5.223                  goto done;
   5.224 -	    }
   5.225 -	    DoExtension(src, c);
   5.226 -	    continue;
   5.227 -	}
   5.228 -	if (c != ',') {		/* Not a valid start character */
   5.229 -	    continue;
   5.230 -	}
   5.231 -	++imageCount;
   5.232 +        }
   5.233 +        DoExtension(src, c);
   5.234 +        continue;
   5.235 +    }
   5.236 +    if (c != ',') {     /* Not a valid start character */
   5.237 +        continue;
   5.238 +    }
   5.239 +    ++imageCount;
   5.240  
   5.241 -	if (!ReadOK(src, buf, 9)) {
   5.242 -	    RWSetMsg("couldn't read left/top/width/height");
   5.243 +    if (!ReadOK(src, buf, 9)) {
   5.244 +        RWSetMsg("couldn't read left/top/width/height");
   5.245              goto done;
   5.246 -	}
   5.247 -	useGlobalColormap = !BitSet(buf[8], LOCALCOLORMAP);
   5.248 +    }
   5.249 +    useGlobalColormap = !BitSet(buf[8], LOCALCOLORMAP);
   5.250  
   5.251 -	bitPixel = 1 << ((buf[8] & 0x07) + 1);
   5.252 +    bitPixel = 1 << ((buf[8] & 0x07) + 1);
   5.253  
   5.254 -	if (!useGlobalColormap) {
   5.255 -	    if (ReadColorMap(src, bitPixel, localColorMap, &grayScale)) {
   5.256 -		RWSetMsg("error reading local colormap");
   5.257 +    if (!useGlobalColormap) {
   5.258 +        if (ReadColorMap(src, bitPixel, localColorMap, &grayScale)) {
   5.259 +        RWSetMsg("error reading local colormap");
   5.260                  goto done;
   5.261 -	    }
   5.262 -	    image = ReadImage(src, LM_to_uint(buf[4], buf[5]),
   5.263 -			      LM_to_uint(buf[6], buf[7]),
   5.264 -			      bitPixel, localColorMap, grayScale,
   5.265 -			      BitSet(buf[8], INTERLACE),
   5.266 -			      imageCount != imageNumber);
   5.267 -	} else {
   5.268 -	    image = ReadImage(src, LM_to_uint(buf[4], buf[5]),
   5.269 -			      LM_to_uint(buf[6], buf[7]),
   5.270 -			      GifScreen.BitPixel, GifScreen.ColorMap,
   5.271 -			      GifScreen.GrayScale, BitSet(buf[8], INTERLACE),
   5.272 -			      imageCount != imageNumber);
   5.273 -	}
   5.274 +        }
   5.275 +        image = ReadImage(src, LM_to_uint(buf[4], buf[5]),
   5.276 +                  LM_to_uint(buf[6], buf[7]),
   5.277 +                  bitPixel, localColorMap, grayScale,
   5.278 +                  BitSet(buf[8], INTERLACE),
   5.279 +                  imageCount != imageNumber);
   5.280 +    } else {
   5.281 +        image = ReadImage(src, LM_to_uint(buf[4], buf[5]),
   5.282 +                  LM_to_uint(buf[6], buf[7]),
   5.283 +                  GifScreen.BitPixel, GifScreen.ColorMap,
   5.284 +                  GifScreen.GrayScale, BitSet(buf[8], INTERLACE),
   5.285 +                  imageCount != imageNumber);
   5.286 +    }
   5.287      } while (image == NULL);
   5.288  
   5.289  #ifdef USED_BY_SDL
   5.290 @@ -283,21 +283,21 @@
   5.291      flag = TRUE;
   5.292  
   5.293      for (i = 0; i < number; ++i) {
   5.294 -	if (!ReadOK(src, rgb, sizeof(rgb))) {
   5.295 -	    RWSetMsg("bad colormap");
   5.296 -	    return 1;
   5.297 -	}
   5.298 -	buffer[CM_RED][i] = rgb[0];
   5.299 -	buffer[CM_GREEN][i] = rgb[1];
   5.300 -	buffer[CM_BLUE][i] = rgb[2];
   5.301 -	flag &= (rgb[0] == rgb[1] && rgb[1] == rgb[2]);
   5.302 +    if (!ReadOK(src, rgb, sizeof(rgb))) {
   5.303 +        RWSetMsg("bad colormap");
   5.304 +        return 1;
   5.305 +    }
   5.306 +    buffer[CM_RED][i] = rgb[0];
   5.307 +    buffer[CM_GREEN][i] = rgb[1];
   5.308 +    buffer[CM_BLUE][i] = rgb[2];
   5.309 +    flag &= (rgb[0] == rgb[1] && rgb[1] == rgb[2]);
   5.310      }
   5.311  
   5.312  #if 0
   5.313      if (flag)
   5.314 -	*gray = (number == 2) ? PBM_TYPE : PGM_TYPE;
   5.315 +    *gray = (number == 2) ? PBM_TYPE : PGM_TYPE;
   5.316      else
   5.317 -	*gray = PPM_TYPE;
   5.318 +    *gray = PPM_TYPE;
   5.319  #else
   5.320      *gray = 0;
   5.321  #endif
   5.322 @@ -312,37 +312,37 @@
   5.323      char *str;
   5.324  
   5.325      switch (label) {
   5.326 -    case 0x01:			/* Plain Text Extension */
   5.327 -	str = "Plain Text Extension";
   5.328 -	break;
   5.329 -    case 0xff:			/* Application Extension */
   5.330 -	str = "Application Extension";
   5.331 -	break;
   5.332 -    case 0xfe:			/* Comment Extension */
   5.333 -	str = "Comment Extension";
   5.334 -	while (GetDataBlock(src, (unsigned char *) buf) != 0)
   5.335 -	    ;
   5.336 -	return FALSE;
   5.337 -    case 0xf9:			/* Graphic Control Extension */
   5.338 -	str = "Graphic Control Extension";
   5.339 -	(void) GetDataBlock(src, (unsigned char *) buf);
   5.340 -	Gif89.disposal = (buf[0] >> 2) & 0x7;
   5.341 -	Gif89.inputFlag = (buf[0] >> 1) & 0x1;
   5.342 -	Gif89.delayTime = LM_to_uint(buf[1], buf[2]);
   5.343 -	if ((buf[0] & 0x1) != 0)
   5.344 -	    Gif89.transparent = buf[3];
   5.345 +    case 0x01:          /* Plain Text Extension */
   5.346 +    str = "Plain Text Extension";
   5.347 +    break;
   5.348 +    case 0xff:          /* Application Extension */
   5.349 +    str = "Application Extension";
   5.350 +    break;
   5.351 +    case 0xfe:          /* Comment Extension */
   5.352 +    str = "Comment Extension";
   5.353 +    while (GetDataBlock(src, (unsigned char *) buf) != 0)
   5.354 +        ;
   5.355 +    return FALSE;
   5.356 +    case 0xf9:          /* Graphic Control Extension */
   5.357 +    str = "Graphic Control Extension";
   5.358 +    (void) GetDataBlock(src, (unsigned char *) buf);
   5.359 +    Gif89.disposal = (buf[0] >> 2) & 0x7;
   5.360 +    Gif89.inputFlag = (buf[0] >> 1) & 0x1;
   5.361 +    Gif89.delayTime = LM_to_uint(buf[1], buf[2]);
   5.362 +    if ((buf[0] & 0x1) != 0)
   5.363 +        Gif89.transparent = buf[3];
   5.364  
   5.365 -	while (GetDataBlock(src, (unsigned char *) buf) != 0)
   5.366 -	    ;
   5.367 -	return FALSE;
   5.368 +    while (GetDataBlock(src, (unsigned char *) buf) != 0)
   5.369 +        ;
   5.370 +    return FALSE;
   5.371      default:
   5.372 -	str = (char *)buf;
   5.373 -	SDL_snprintf(str, 256, "UNKNOWN (0x%02x)", label);
   5.374 -	break;
   5.375 +    str = (char *)buf;
   5.376 +    SDL_snprintf(str, 256, "UNKNOWN (0x%02x)", label);
   5.377 +    break;
   5.378      }
   5.379  
   5.380      while (GetDataBlock(src, (unsigned char *) buf) != 0)
   5.381 -	;
   5.382 +    ;
   5.383  
   5.384      return FALSE;
   5.385  }
   5.386 @@ -355,14 +355,14 @@
   5.387      unsigned char count;
   5.388  
   5.389      if (!ReadOK(src, &count, 1)) {
   5.390 -	/* pm_message("error in getting DataBlock size" ); */
   5.391 -	return -1;
   5.392 +    /* pm_message("error in getting DataBlock size" ); */
   5.393 +    return -1;
   5.394      }
   5.395      ZeroDataBlock = count == 0;
   5.396  
   5.397      if ((count != 0) && (!ReadOK(src, buf, count))) {
   5.398 -	/* pm_message("error in reading DataBlock" ); */
   5.399 -	return -1;
   5.400 +    /* pm_message("error in reading DataBlock" ); */
   5.401 +    return -1;
   5.402      }
   5.403      return count;
   5.404  }
   5.405 @@ -376,30 +376,30 @@
   5.406      unsigned char count;
   5.407  
   5.408      if (flag) {
   5.409 -	curbit = 0;
   5.410 -	lastbit = 0;
   5.411 -	done = FALSE;
   5.412 -	return 0;
   5.413 +    curbit = 0;
   5.414 +    lastbit = 0;
   5.415 +    done = FALSE;
   5.416 +    return 0;
   5.417      }
   5.418      if ((curbit + code_size) >= lastbit) {
   5.419 -	if (done) {
   5.420 -	    if (curbit >= lastbit)
   5.421 -		RWSetMsg("ran off the end of my bits");
   5.422 -	    return -1;
   5.423 -	}
   5.424 -	buf[0] = buf[last_byte - 2];
   5.425 -	buf[1] = buf[last_byte - 1];
   5.426 +    if (done) {
   5.427 +        if (curbit >= lastbit)
   5.428 +        RWSetMsg("ran off the end of my bits");
   5.429 +        return -1;
   5.430 +    }
   5.431 +    buf[0] = buf[last_byte - 2];
   5.432 +    buf[1] = buf[last_byte - 1];
   5.433  
   5.434 -	if ((count = GetDataBlock(src, &buf[2])) == 0)
   5.435 -	    done = TRUE;
   5.436 +    if ((count = GetDataBlock(src, &buf[2])) == 0)
   5.437 +        done = TRUE;
   5.438  
   5.439 -	last_byte = 2 + count;
   5.440 -	curbit = (curbit - lastbit) + 16;
   5.441 -	lastbit = (2 + count) * 8;
   5.442 +    last_byte = 2 + count;
   5.443 +    curbit = (curbit - lastbit) + 16;
   5.444 +    lastbit = (2 + count) * 8;
   5.445      }
   5.446      ret = 0;
   5.447      for (i = curbit, j = 0; j < code_size; ++i, ++j)
   5.448 -	ret |= ((buf[i / 8] & (1 << (i % 8))) != 0) << j;
   5.449 +    ret |= ((buf[i / 8] & (1 << (i % 8))) != 0) << j;
   5.450  
   5.451      curbit += code_size;
   5.452  
   5.453 @@ -424,116 +424,116 @@
   5.454          return -1;
   5.455  
   5.456      if (flag) {
   5.457 -	set_code_size = input_code_size;
   5.458 -	code_size = set_code_size + 1;
   5.459 -	clear_code = 1 << set_code_size;
   5.460 -	end_code = clear_code + 1;
   5.461 -	max_code_size = 2 * clear_code;
   5.462 -	max_code = clear_code + 2;
   5.463 +    set_code_size = input_code_size;
   5.464 +    code_size = set_code_size + 1;
   5.465 +    clear_code = 1 << set_code_size;
   5.466 +    end_code = clear_code + 1;
   5.467 +    max_code_size = 2 * clear_code;
   5.468 +    max_code = clear_code + 2;
   5.469  
   5.470 -	GetCode(src, 0, TRUE);
   5.471 +    GetCode(src, 0, TRUE);
   5.472  
   5.473 -	fresh = TRUE;
   5.474 +    fresh = TRUE;
   5.475  
   5.476 -	for (i = 0; i < clear_code; ++i) {
   5.477 -	    table[0][i] = 0;
   5.478 -	    table[1][i] = i;
   5.479 -	}
   5.480 -	table[1][0] = 0;
   5.481 -	for (; i < (1 << MAX_LWZ_BITS); ++i)
   5.482 -	    table[0][i] = 0;
   5.483 +    for (i = 0; i < clear_code; ++i) {
   5.484 +        table[0][i] = 0;
   5.485 +        table[1][i] = i;
   5.486 +    }
   5.487 +    table[1][0] = 0;
   5.488 +    for (; i < (1 << MAX_LWZ_BITS); ++i)
   5.489 +        table[0][i] = 0;
   5.490  
   5.491 -	sp = stack;
   5.492 +    sp = stack;
   5.493  
   5.494 -	return 0;
   5.495 +    return 0;
   5.496      } else if (fresh) {
   5.497 -	fresh = FALSE;
   5.498 -	do {
   5.499 -	    firstcode = oldcode = GetCode(src, code_size, FALSE);
   5.500 -	} while (firstcode == clear_code);
   5.501 -	return firstcode;
   5.502 +    fresh = FALSE;
   5.503 +    do {
   5.504 +        firstcode = oldcode = GetCode(src, code_size, FALSE);
   5.505 +    } while (firstcode == clear_code);
   5.506 +    return firstcode;
   5.507      }
   5.508      if (sp > stack)
   5.509 -	return *--sp;
   5.510 +    return *--sp;
   5.511  
   5.512      while ((code = GetCode(src, code_size, FALSE)) >= 0) {
   5.513 -	if (code == clear_code) {
   5.514 -	    for (i = 0; i < clear_code; ++i) {
   5.515 -		table[0][i] = 0;
   5.516 -		table[1][i] = i;
   5.517 -	    }
   5.518 -	    for (; i < (1 << MAX_LWZ_BITS); ++i)
   5.519 -		table[0][i] = table[1][i] = 0;
   5.520 -	    code_size = set_code_size + 1;
   5.521 -	    max_code_size = 2 * clear_code;
   5.522 -	    max_code = clear_code + 2;
   5.523 -	    sp = stack;
   5.524 -	    firstcode = oldcode = GetCode(src, code_size, FALSE);
   5.525 -	    return firstcode;
   5.526 -	} else if (code == end_code) {
   5.527 -	    int count;
   5.528 -	    unsigned char buf[260];
   5.529 +    if (code == clear_code) {
   5.530 +        for (i = 0; i < clear_code; ++i) {
   5.531 +        table[0][i] = 0;
   5.532 +        table[1][i] = i;
   5.533 +        }
   5.534 +        for (; i < (1 << MAX_LWZ_BITS); ++i)
   5.535 +        table[0][i] = table[1][i] = 0;
   5.536 +        code_size = set_code_size + 1;
   5.537 +        max_code_size = 2 * clear_code;
   5.538 +        max_code = clear_code + 2;
   5.539 +        sp = stack;
   5.540 +        firstcode = oldcode = GetCode(src, code_size, FALSE);
   5.541 +        return firstcode;
   5.542 +    } else if (code == end_code) {
   5.543 +        int count;
   5.544 +        unsigned char buf[260];
   5.545  
   5.546 -	    if (ZeroDataBlock)
   5.547 -		return -2;
   5.548 +        if (ZeroDataBlock)
   5.549 +        return -2;
   5.550  
   5.551 -	    while ((count = GetDataBlock(src, buf)) > 0)
   5.552 -		;
   5.553 +        while ((count = GetDataBlock(src, buf)) > 0)
   5.554 +        ;
   5.555  
   5.556 -	    if (count != 0) {
   5.557 -		/*
   5.558 -		 * pm_message("missing EOD in data stream (common occurence)");
   5.559 -		 */
   5.560 -	    }
   5.561 -	    return -2;
   5.562 -	}
   5.563 -	incode = code;
   5.564 +        if (count != 0) {
   5.565 +        /*
   5.566 +         * pm_message("missing EOD in data stream (common occurence)");
   5.567 +         */
   5.568 +        }
   5.569 +        return -2;
   5.570 +    }
   5.571 +    incode = code;
   5.572  
   5.573 -	if (code >= max_code) {
   5.574 -	    *sp++ = firstcode;
   5.575 -	    code = oldcode;
   5.576 -	}
   5.577 -	while (code >= clear_code) {
   5.578 -		/* Guard against buffer overruns */
   5.579 -		if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
   5.580 -			RWSetMsg("invalid LWZ data");
   5.581 -			return -3;
   5.582 -		}
   5.583 -	    *sp++ = table[1][code];
   5.584 -	    if (code == table[0][code])
   5.585 -		RWSetMsg("circular table entry BIG ERROR");
   5.586 -	    code = table[0][code];
   5.587 -	}
   5.588 +    if (code >= max_code) {
   5.589 +        *sp++ = firstcode;
   5.590 +        code = oldcode;
   5.591 +    }
   5.592 +    while (code >= clear_code) {
   5.593 +        /* Guard against buffer overruns */
   5.594 +        if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
   5.595 +            RWSetMsg("invalid LWZ data");
   5.596 +            return -3;
   5.597 +        }
   5.598 +        *sp++ = table[1][code];
   5.599 +        if (code == table[0][code])
   5.600 +        RWSetMsg("circular table entry BIG ERROR");
   5.601 +        code = table[0][code];
   5.602 +    }
   5.603  
   5.604 -	/* Guard against buffer overruns */
   5.605 -	if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
   5.606 -		RWSetMsg("invalid LWZ data");
   5.607 -		return -4;
   5.608 -	}
   5.609 -	*sp++ = firstcode = table[1][code];
   5.610 +    /* Guard against buffer overruns */
   5.611 +    if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
   5.612 +        RWSetMsg("invalid LWZ data");
   5.613 +        return -4;
   5.614 +    }
   5.615 +    *sp++ = firstcode = table[1][code];
   5.616  
   5.617 -	if ((code = max_code) < (1 << MAX_LWZ_BITS)) {
   5.618 -	    table[0][code] = oldcode;
   5.619 -	    table[1][code] = firstcode;
   5.620 -	    ++max_code;
   5.621 -	    if ((max_code >= max_code_size) &&
   5.622 -		(max_code_size < (1 << MAX_LWZ_BITS))) {
   5.623 -		max_code_size *= 2;
   5.624 -		++code_size;
   5.625 -	    }
   5.626 -	}
   5.627 -	oldcode = incode;
   5.628 +    if ((code = max_code) < (1 << MAX_LWZ_BITS)) {
   5.629 +        table[0][code] = oldcode;
   5.630 +        table[1][code] = firstcode;
   5.631 +        ++max_code;
   5.632 +        if ((max_code >= max_code_size) &&
   5.633 +        (max_code_size < (1 << MAX_LWZ_BITS))) {
   5.634 +        max_code_size *= 2;
   5.635 +        ++code_size;
   5.636 +        }
   5.637 +    }
   5.638 +    oldcode = incode;
   5.639  
   5.640 -	if (sp > stack)
   5.641 -	    return *--sp;
   5.642 +    if (sp > stack)
   5.643 +        return *--sp;
   5.644      }
   5.645      return code;
   5.646  }
   5.647  
   5.648  static Image *
   5.649  ReadImage(SDL_RWops * src, int len, int height, int cmapSize,
   5.650 -	  unsigned char cmap[3][MAXCOLORMAPSIZE],
   5.651 -	  int gray, int interlace, int ignore)
   5.652 +      unsigned char cmap[3][MAXCOLORMAPSIZE],
   5.653 +      int gray, int interlace, int ignore)
   5.654  {
   5.655      Image *image;
   5.656      unsigned char c;
   5.657 @@ -541,75 +541,75 @@
   5.658      int xpos = 0, ypos = 0, pass = 0;
   5.659  
   5.660      /*
   5.661 -    **	Initialize the compression routines
   5.662 +    **  Initialize the compression routines
   5.663       */
   5.664      if (!ReadOK(src, &c, 1)) {
   5.665 -	RWSetMsg("EOF / read error on image data");
   5.666 -	return NULL;
   5.667 +    RWSetMsg("EOF / read error on image data");
   5.668 +    return NULL;
   5.669      }
   5.670      if (LWZReadByte(src, TRUE, c) < 0) {
   5.671 -	RWSetMsg("error reading image");
   5.672 -	return NULL;
   5.673 +    RWSetMsg("error reading image");
   5.674 +    return NULL;
   5.675      }
   5.676      /*
   5.677 -    **	If this is an "uninteresting picture" ignore it.
   5.678 +    **  If this is an "uninteresting picture" ignore it.
   5.679       */
   5.680      if (ignore) {
   5.681 -	while (LWZReadByte(src, FALSE, c) >= 0)
   5.682 -	    ;
   5.683 -	return NULL;
   5.684 +    while (LWZReadByte(src, FALSE, c) >= 0)
   5.685 +        ;
   5.686 +    return NULL;
   5.687      }
   5.688      image = ImageNewCmap(len, height, cmapSize);
   5.689  
   5.690      for (i = 0; i < cmapSize; i++)
   5.691 -	ImageSetCmap(image, i, cmap[CM_RED][i],
   5.692 -		     cmap[CM_GREEN][i], cmap[CM_BLUE][i]);
   5.693 +    ImageSetCmap(image, i, cmap[CM_RED][i],
   5.694 +             cmap[CM_GREEN][i], cmap[CM_BLUE][i]);
   5.695  
   5.696      while ((v = LWZReadByte(src, FALSE, c)) >= 0) {
   5.697  #ifdef USED_BY_SDL
   5.698 -	((Uint8 *)image->pixels)[xpos + ypos * image->pitch] = v;
   5.699 +    ((Uint8 *)image->pixels)[xpos + ypos * image->pitch] = v;
   5.700  #else
   5.701 -	image->data[xpos + ypos * len] = v;
   5.702 +    image->data[xpos + ypos * len] = v;
   5.703  #endif
   5.704 -	++xpos;
   5.705 -	if (xpos == len) {
   5.706 -	    xpos = 0;
   5.707 -	    if (interlace) {
   5.708 -		switch (pass) {
   5.709 -		case 0:
   5.710 -		case 1:
   5.711 -		    ypos += 8;
   5.712 -		    break;
   5.713 -		case 2:
   5.714 -		    ypos += 4;
   5.715 -		    break;
   5.716 -		case 3:
   5.717 -		    ypos += 2;
   5.718 -		    break;
   5.719 -		}
   5.720 +    ++xpos;
   5.721 +    if (xpos == len) {
   5.722 +        xpos = 0;
   5.723 +        if (interlace) {
   5.724 +        switch (pass) {
   5.725 +        case 0:
   5.726 +        case 1:
   5.727 +            ypos += 8;
   5.728 +            break;
   5.729 +        case 2:
   5.730 +            ypos += 4;
   5.731 +            break;
   5.732 +        case 3:
   5.733 +            ypos += 2;
   5.734 +            break;
   5.735 +        }
   5.736  
   5.737 -		if (ypos >= height) {
   5.738 -		    ++pass;
   5.739 -		    switch (pass) {
   5.740 -		    case 1:
   5.741 -			ypos = 4;
   5.742 -			break;
   5.743 -		    case 2:
   5.744 -			ypos = 2;
   5.745 -			break;
   5.746 -		    case 3:
   5.747 -			ypos = 1;
   5.748 -			break;
   5.749 -		    default:
   5.750 -			goto fini;
   5.751 -		    }
   5.752 -		}
   5.753 -	    } else {
   5.754 -		++ypos;
   5.755 -	    }
   5.756 -	}
   5.757 -	if (ypos >= height)
   5.758 -	    break;
   5.759 +        if (ypos >= height) {
   5.760 +            ++pass;
   5.761 +            switch (pass) {
   5.762 +            case 1:
   5.763 +            ypos = 4;
   5.764 +            break;
   5.765 +            case 2:
   5.766 +            ypos = 2;
   5.767 +            break;
   5.768 +            case 3:
   5.769 +            ypos = 1;
   5.770 +            break;
   5.771 +            default:
   5.772 +            goto fini;
   5.773 +            }
   5.774 +        }
   5.775 +        } else {
   5.776 +        ++ypos;
   5.777 +        }
   5.778 +    }
   5.779 +    if (ypos >= height)
   5.780 +        break;
   5.781      }
   5.782  
   5.783    fini:
   5.784 @@ -622,13 +622,13 @@
   5.785  /* See if an image is contained in a data source */
   5.786  int IMG_isGIF(SDL_RWops *src)
   5.787  {
   5.788 -	return(0);
   5.789 +    return(0);
   5.790  }
   5.791  
   5.792  /* Load a GIF type image from an SDL datasource */
   5.793  SDL_Surface *IMG_LoadGIF_RW(SDL_RWops *src)
   5.794  {
   5.795 -	return(NULL);
   5.796 +    return(NULL);
   5.797  }
   5.798  
   5.799  #endif /* LOAD_GIF */
     6.1 --- a/IMG_jpg.c	Thu Apr 25 00:22:51 2013 -0700
     6.2 +++ b/IMG_jpg.c	Tue May 21 21:24:32 2013 -0700
     6.3 @@ -34,9 +34,9 @@
     6.4  #include <jpeglib.h>
     6.5  
     6.6  #ifdef JPEG_TRUE  /* MinGW version of jpeg-8.x renamed TRUE to JPEG_TRUE etc. */
     6.7 -	typedef JPEG_boolean boolean;
     6.8 -	#define TRUE JPEG_TRUE
     6.9 -	#define FALSE JPEG_FALSE
    6.10 +    typedef JPEG_boolean boolean;
    6.11 +    #define TRUE JPEG_TRUE
    6.12 +    #define FALSE JPEG_FALSE
    6.13  #endif
    6.14  
    6.15  /* Define this for fast loading and not as good image quality */
    6.16 @@ -46,205 +46,205 @@
    6.17  #define FAST_IS_JPEG
    6.18  
    6.19  static struct {
    6.20 -	int loaded;
    6.21 -	void *handle;
    6.22 -	void (*jpeg_calc_output_dimensions) (j_decompress_ptr cinfo);
    6.23 -	void (*jpeg_CreateDecompress) (j_decompress_ptr cinfo, int version, size_t structsize);
    6.24 -	void (*jpeg_destroy_decompress) (j_decompress_ptr cinfo);
    6.25 -	boolean (*jpeg_finish_decompress) (j_decompress_ptr cinfo);
    6.26 -	int (*jpeg_read_header) (j_decompress_ptr cinfo, boolean require_image);
    6.27 -	JDIMENSION (*jpeg_read_scanlines) (j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines);
    6.28 -	boolean (*jpeg_resync_to_restart) (j_decompress_ptr cinfo, int desired);
    6.29 -	boolean (*jpeg_start_decompress) (j_decompress_ptr cinfo);
    6.30 -	struct jpeg_error_mgr * (*jpeg_std_error) (struct jpeg_error_mgr * err);
    6.31 +    int loaded;
    6.32 +    void *handle;
    6.33 +    void (*jpeg_calc_output_dimensions) (j_decompress_ptr cinfo);
    6.34 +    void (*jpeg_CreateDecompress) (j_decompress_ptr cinfo, int version, size_t structsize);
    6.35 +    void (*jpeg_destroy_decompress) (j_decompress_ptr cinfo);
    6.36 +    boolean (*jpeg_finish_decompress) (j_decompress_ptr cinfo);
    6.37 +    int (*jpeg_read_header) (j_decompress_ptr cinfo, boolean require_image);
    6.38 +    JDIMENSION (*jpeg_read_scanlines) (j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines);
    6.39 +    boolean (*jpeg_resync_to_restart) (j_decompress_ptr cinfo, int desired);
    6.40 +    boolean (*jpeg_start_decompress) (j_decompress_ptr cinfo);
    6.41 +    struct jpeg_error_mgr * (*jpeg_std_error) (struct jpeg_error_mgr * err);
    6.42  } lib;
    6.43  
    6.44  #ifdef LOAD_JPG_DYNAMIC
    6.45  int IMG_InitJPG()
    6.46  {
    6.47 -	if ( lib.loaded == 0 ) {
    6.48 -		lib.handle = SDL_LoadObject(LOAD_JPG_DYNAMIC);
    6.49 -		if ( lib.handle == NULL ) {
    6.50 -			return -1;
    6.51 -		}
    6.52 -		lib.jpeg_calc_output_dimensions =
    6.53 -			(void (*) (j_decompress_ptr))
    6.54 -			SDL_LoadFunction(lib.handle, "jpeg_calc_output_dimensions");
    6.55 -		if ( lib.jpeg_calc_output_dimensions == NULL ) {
    6.56 -			SDL_UnloadObject(lib.handle);
    6.57 -			return -1;
    6.58 -		}
    6.59 -		lib.jpeg_CreateDecompress = 
    6.60 -			(void (*) (j_decompress_ptr, int, size_t))
    6.61 -			SDL_LoadFunction(lib.handle, "jpeg_CreateDecompress");
    6.62 -		if ( lib.jpeg_CreateDecompress == NULL ) {
    6.63 -			SDL_UnloadObject(lib.handle);
    6.64 -			return -1;
    6.65 -		}
    6.66 -		lib.jpeg_destroy_decompress = 
    6.67 -			(void (*) (j_decompress_ptr))
    6.68 -			SDL_LoadFunction(lib.handle, "jpeg_destroy_decompress");
    6.69 -		if ( lib.jpeg_destroy_decompress == NULL ) {
    6.70 -			SDL_UnloadObject(lib.handle);
    6.71 -			return -1;
    6.72 -		}
    6.73 -		lib.jpeg_finish_decompress = 
    6.74 -			(boolean (*) (j_decompress_ptr))
    6.75 -			SDL_LoadFunction(lib.handle, "jpeg_finish_decompress");
    6.76 -		if ( lib.jpeg_finish_decompress == NULL ) {
    6.77 -			SDL_UnloadObject(lib.handle);
    6.78 -			return -1;
    6.79 -		}
    6.80 -		lib.jpeg_read_header = 
    6.81 -			(int (*) (j_decompress_ptr, boolean))
    6.82 -			SDL_LoadFunction(lib.handle, "jpeg_read_header");
    6.83 -		if ( lib.jpeg_read_header == NULL ) {
    6.84 -			SDL_UnloadObject(lib.handle);
    6.85 -			return -1;
    6.86 -		}
    6.87 -		lib.jpeg_read_scanlines = 
    6.88 -			(JDIMENSION (*) (j_decompress_ptr, JSAMPARRAY, JDIMENSION))
    6.89 -			SDL_LoadFunction(lib.handle, "jpeg_read_scanlines");
    6.90 -		if ( lib.jpeg_read_scanlines == NULL ) {
    6.91 -			SDL_UnloadObject(lib.handle);
    6.92 -			return -1;
    6.93 -		}
    6.94 -		lib.jpeg_resync_to_restart = 
    6.95 -			(boolean (*) (j_decompress_ptr, int))
    6.96 -			SDL_LoadFunction(lib.handle, "jpeg_resync_to_restart");
    6.97 -		if ( lib.jpeg_resync_to_restart == NULL ) {
    6.98 -			SDL_UnloadObject(lib.handle);
    6.99 -			return -1;
   6.100 -		}
   6.101 -		lib.jpeg_start_decompress = 
   6.102 -			(boolean (*) (j_decompress_ptr))
   6.103 -			SDL_LoadFunction(lib.handle, "jpeg_start_decompress");
   6.104 -		if ( lib.jpeg_start_decompress == NULL ) {
   6.105 -			SDL_UnloadObject(lib.handle);
   6.106 -			return -1;
   6.107 -		}
   6.108 -		lib.jpeg_std_error = 
   6.109 -			(struct jpeg_error_mgr * (*) (struct jpeg_error_mgr *))
   6.110 -			SDL_LoadFunction(lib.handle, "jpeg_std_error");
   6.111 -		if ( lib.jpeg_std_error == NULL ) {
   6.112 -			SDL_UnloadObject(lib.handle);
   6.113 -			return -1;
   6.114 -		}
   6.115 -	}
   6.116 -	++lib.loaded;
   6.117 +    if ( lib.loaded == 0 ) {
   6.118 +        lib.handle = SDL_LoadObject(LOAD_JPG_DYNAMIC);
   6.119 +        if ( lib.handle == NULL ) {
   6.120 +            return -1;
   6.121 +        }
   6.122 +        lib.jpeg_calc_output_dimensions =
   6.123 +            (void (*) (j_decompress_ptr))
   6.124 +            SDL_LoadFunction(lib.handle, "jpeg_calc_output_dimensions");
   6.125 +        if ( lib.jpeg_calc_output_dimensions == NULL ) {
   6.126 +            SDL_UnloadObject(lib.handle);
   6.127 +            return -1;
   6.128 +        }
   6.129 +        lib.jpeg_CreateDecompress =
   6.130 +            (void (*) (j_decompress_ptr, int, size_t))
   6.131 +            SDL_LoadFunction(lib.handle, "jpeg_CreateDecompress");
   6.132 +        if ( lib.jpeg_CreateDecompress == NULL ) {
   6.133 +            SDL_UnloadObject(lib.handle);
   6.134 +            return -1;
   6.135 +        }
   6.136 +        lib.jpeg_destroy_decompress =
   6.137 +            (void (*) (j_decompress_ptr))
   6.138 +            SDL_LoadFunction(lib.handle, "jpeg_destroy_decompress");
   6.139 +        if ( lib.jpeg_destroy_decompress == NULL ) {
   6.140 +            SDL_UnloadObject(lib.handle);
   6.141 +            return -1;
   6.142 +        }
   6.143 +        lib.jpeg_finish_decompress =
   6.144 +            (boolean (*) (j_decompress_ptr))
   6.145 +            SDL_LoadFunction(lib.handle, "jpeg_finish_decompress");
   6.146 +        if ( lib.jpeg_finish_decompress == NULL ) {
   6.147 +            SDL_UnloadObject(lib.handle);
   6.148 +            return -1;
   6.149 +        }
   6.150 +        lib.jpeg_read_header =
   6.151 +            (int (*) (j_decompress_ptr, boolean))
   6.152 +            SDL_LoadFunction(lib.handle, "jpeg_read_header");
   6.153 +        if ( lib.jpeg_read_header == NULL ) {
   6.154 +            SDL_UnloadObject(lib.handle);
   6.155 +            return -1;
   6.156 +        }
   6.157 +        lib.jpeg_read_scanlines =
   6.158 +            (JDIMENSION (*) (j_decompress_ptr, JSAMPARRAY, JDIMENSION))
   6.159 +            SDL_LoadFunction(lib.handle, "jpeg_read_scanlines");
   6.160 +        if ( lib.jpeg_read_scanlines == NULL ) {
   6.161 +            SDL_UnloadObject(lib.handle);
   6.162 +            return -1;
   6.163 +        }
   6.164 +        lib.jpeg_resync_to_restart =
   6.165 +            (boolean (*) (j_decompress_ptr, int))
   6.166 +            SDL_LoadFunction(lib.handle, "jpeg_resync_to_restart");
   6.167 +        if ( lib.jpeg_resync_to_restart == NULL ) {
   6.168 +            SDL_UnloadObject(lib.handle);
   6.169 +            return -1;
   6.170 +        }
   6.171 +        lib.jpeg_start_decompress =
   6.172 +            (boolean (*) (j_decompress_ptr))
   6.173 +            SDL_LoadFunction(lib.handle, "jpeg_start_decompress");
   6.174 +        if ( lib.jpeg_start_decompress == NULL ) {
   6.175 +            SDL_UnloadObject(lib.handle);
   6.176 +            return -1;
   6.177 +        }
   6.178 +        lib.jpeg_std_error =
   6.179 +            (struct jpeg_error_mgr * (*) (struct jpeg_error_mgr *))
   6.180 +            SDL_LoadFunction(lib.handle, "jpeg_std_error");
   6.181 +        if ( lib.jpeg_std_error == NULL ) {
   6.182 +            SDL_UnloadObject(lib.handle);
   6.183 +            return -1;
   6.184 +        }
   6.185 +    }
   6.186 +    ++lib.loaded;
   6.187  
   6.188 -	return 0;
   6.189 +    return 0;
   6.190  }
   6.191  void IMG_QuitJPG()
   6.192  {
   6.193 -	if ( lib.loaded == 0 ) {
   6.194 -		return;
   6.195 -	}
   6.196 -	if ( lib.loaded == 1 ) {
   6.197 -		SDL_UnloadObject(lib.handle);
   6.198 -	}
   6.199 -	--lib.loaded;
   6.200 +    if ( lib.loaded == 0 ) {
   6.201 +        return;
   6.202 +    }
   6.203 +    if ( lib.loaded == 1 ) {
   6.204 +        SDL_UnloadObject(lib.handle);
   6.205 +    }
   6.206 +    --lib.loaded;
   6.207  }
   6.208  #else
   6.209  int IMG_InitJPG()
   6.210  {
   6.211 -	if ( lib.loaded == 0 ) {
   6.212 -		lib.jpeg_calc_output_dimensions = jpeg_calc_output_dimensions;
   6.213 -		lib.jpeg_CreateDecompress = jpeg_CreateDecompress;
   6.214 -		lib.jpeg_destroy_decompress = jpeg_destroy_decompress;
   6.215 -		lib.jpeg_finish_decompress = jpeg_finish_decompress;
   6.216 -		lib.jpeg_read_header = jpeg_read_header;
   6.217 -		lib.jpeg_read_scanlines = jpeg_read_scanlines;
   6.218 -		lib.jpeg_resync_to_restart = jpeg_resync_to_restart;
   6.219 -		lib.jpeg_start_decompress = jpeg_start_decompress;
   6.220 -		lib.jpeg_std_error = jpeg_std_error;
   6.221 -	}
   6.222 -	++lib.loaded;
   6.223 +    if ( lib.loaded == 0 ) {
   6.224 +        lib.jpeg_calc_output_dimensions = jpeg_calc_output_dimensions;
   6.225 +        lib.jpeg_CreateDecompress = jpeg_CreateDecompress;
   6.226 +        lib.jpeg_destroy_decompress = jpeg_destroy_decompress;
   6.227 +        lib.jpeg_finish_decompress = jpeg_finish_decompress;
   6.228 +        lib.jpeg_read_header = jpeg_read_header;
   6.229 +        lib.jpeg_read_scanlines = jpeg_read_scanlines;
   6.230 +        lib.jpeg_resync_to_restart = jpeg_resync_to_restart;
   6.231 +        lib.jpeg_start_decompress = jpeg_start_decompress;
   6.232 +        lib.jpeg_std_error = jpeg_std_error;
   6.233 +    }
   6.234 +    ++lib.loaded;
   6.235  
   6.236 -	return 0;
   6.237 +    return 0;
   6.238  }
   6.239  void IMG_QuitJPG()
   6.240  {
   6.241 -	if ( lib.loaded == 0 ) {
   6.242 -		return;
   6.243 -	}
   6.244 -	if ( lib.loaded == 1 ) {
   6.245 -	}
   6.246 -	--lib.loaded;
   6.247 +    if ( lib.loaded == 0 ) {
   6.248 +        return;
   6.249 +    }
   6.250 +    if ( lib.loaded == 1 ) {
   6.251 +    }
   6.252 +    --lib.loaded;
   6.253  }
   6.254  #endif /* LOAD_JPG_DYNAMIC */
   6.255  
   6.256  /* See if an image is contained in a data source */
   6.257  int IMG_isJPG(SDL_RWops *src)
   6.258  {
   6.259 -	Sint64 start;
   6.260 -	int is_JPG;
   6.261 -	int in_scan;
   6.262 -	Uint8 magic[4];
   6.263 +    Sint64 start;
   6.264 +    int is_JPG;
   6.265 +    int in_scan;
   6.266 +    Uint8 magic[4];
   6.267  
   6.268 -	/* This detection code is by Steaphan Greene <stea@cs.binghamton.edu> */
   6.269 -	/* Blame me, not Sam, if this doesn't work right. */
   6.270 -	/* And don't forget to report the problem to the the sdl list too! */
   6.271 +    /* This detection code is by Steaphan Greene <stea@cs.binghamton.edu> */
   6.272 +    /* Blame me, not Sam, if this doesn't work right. */
   6.273 +    /* And don't forget to report the problem to the the sdl list too! */
   6.274  
   6.275 -	if ( !src )
   6.276 -		return 0;
   6.277 -	start = SDL_RWtell(src);
   6.278 -	is_JPG = 0;
   6.279 -	in_scan = 0;
   6.280 -	if ( SDL_RWread(src, magic, 2, 1) ) {
   6.281 -		if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
   6.282 -			is_JPG = 1;
   6.283 -			while (is_JPG == 1) {
   6.284 -				if(SDL_RWread(src, magic, 1, 2) != 2) {
   6.285 -					is_JPG = 0;
   6.286 -				} else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
   6.287 -					is_JPG = 0;
   6.288 -				} else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
   6.289 -					/* Extra padding in JPEG (legal) */
   6.290 -					/* or this is data and we are scanning */
   6.291 -					SDL_RWseek(src, -1, RW_SEEK_CUR);
   6.292 -				} else if(magic[1] == 0xD9) {
   6.293 -					/* Got to end of good JPEG */
   6.294 -					break;
   6.295 -				} else if( (in_scan == 1) && (magic[1] == 0x00) ) {
   6.296 -					/* This is an encoded 0xFF within the data */
   6.297 -				} else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
   6.298 -					/* These have nothing else */
   6.299 -				} else if(SDL_RWread(src, magic+2, 1, 2) != 2) {
   6.300 -					is_JPG = 0;
   6.301 -				} else {
   6.302 -					/* Yes, it's big-endian */
   6.303 -					Sint64 innerStart;
   6.304 -					Uint32 size;
   6.305 -					Sint64 end;
   6.306 -					innerStart = SDL_RWtell(src);
   6.307 -					size = (magic[2] << 8) + magic[3];
   6.308 -					end = SDL_RWseek(src, size-2, RW_SEEK_CUR);
   6.309 -					if ( end != innerStart + size - 2 ) is_JPG = 0;
   6.310 -					if ( magic[1] == 0xDA ) {
   6.311 -						/* Now comes the actual JPEG meat */
   6.312 -#ifdef	FAST_IS_JPEG
   6.313 -						/* Ok, I'm convinced.  It is a JPEG. */
   6.314 -						break;
   6.315 +    if ( !src )
   6.316 +        return 0;
   6.317 +    start = SDL_RWtell(src);
   6.318 +    is_JPG = 0;
   6.319 +    in_scan = 0;
   6.320 +    if ( SDL_RWread(src, magic, 2, 1) ) {
   6.321 +        if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
   6.322 +            is_JPG = 1;
   6.323 +            while (is_JPG == 1) {
   6.324 +                if(SDL_RWread(src, magic, 1, 2) != 2) {
   6.325 +                    is_JPG = 0;
   6.326 +                } else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
   6.327 +                    is_JPG = 0;
   6.328 +                } else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
   6.329 +                    /* Extra padding in JPEG (legal) */
   6.330 +                    /* or this is data and we are scanning */
   6.331 +                    SDL_RWseek(src, -1, RW_SEEK_CUR);
   6.332 +                } else if(magic[1] == 0xD9) {
   6.333 +                    /* Got to end of good JPEG */
   6.334 +                    break;
   6.335 +                } else if( (in_scan == 1) && (magic[1] == 0x00) ) {
   6.336 +                    /* This is an encoded 0xFF within the data */
   6.337 +                } else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
   6.338 +                    /* These have nothing else */
   6.339 +                } else if(SDL_RWread(src, magic+2, 1, 2) != 2) {
   6.340 +                    is_JPG = 0;
   6.341 +                } else {
   6.342 +                    /* Yes, it's big-endian */
   6.343 +                    Sint64 innerStart;
   6.344 +                    Uint32 size;
   6.345 +                    Sint64 end;
   6.346 +                    innerStart = SDL_RWtell(src);
   6.347 +                    size = (magic[2] << 8) + magic[3];
   6.348 +                    end = SDL_RWseek(src, size-2, RW_SEEK_CUR);
   6.349 +                    if ( end != innerStart + size - 2 ) is_JPG = 0;
   6.350 +                    if ( magic[1] == 0xDA ) {
   6.351 +                        /* Now comes the actual JPEG meat */
   6.352 +#ifdef  FAST_IS_JPEG
   6.353 +                        /* Ok, I'm convinced.  It is a JPEG. */
   6.354 +                        break;
   6.355  #else
   6.356 -						/* I'm not convinced.  Prove it! */
   6.357 -						in_scan = 1;
   6.358 +                        /* I'm not convinced.  Prove it! */
   6.359 +                        in_scan = 1;
   6.360  #endif
   6.361 -					}
   6.362 -				}
   6.363 -			}
   6.364 -		}
   6.365 -	}
   6.366 -	SDL_RWseek(src, start, RW_SEEK_SET);
   6.367 -	return(is_JPG);
   6.368 +                    }
   6.369 +                }
   6.370 +            }
   6.371 +        }
   6.372 +    }
   6.373 +    SDL_RWseek(src, start, RW_SEEK_SET);
   6.374 +    return(is_JPG);
   6.375  }
   6.376  
   6.377 -#define INPUT_BUFFER_SIZE	4096
   6.378 +#define INPUT_BUFFER_SIZE   4096
   6.379  typedef struct {
   6.380 -	struct jpeg_source_mgr pub;
   6.381 +    struct jpeg_source_mgr pub;
   6.382  
   6.383 -	SDL_RWops *ctx;
   6.384 -	Uint8 buffer[INPUT_BUFFER_SIZE];
   6.385 +    SDL_RWops *ctx;
   6.386 +    Uint8 buffer[INPUT_BUFFER_SIZE];
   6.387  } my_source_mgr;
   6.388  
   6.389  /*
   6.390 @@ -253,8 +253,8 @@
   6.391   */
   6.392  static void init_source (j_decompress_ptr cinfo)
   6.393  {
   6.394 -	/* We don't actually need to do anything */
   6.395 -	return;
   6.396 +    /* We don't actually need to do anything */
   6.397 +    return;
   6.398  }
   6.399  
   6.400  /*
   6.401 @@ -262,20 +262,20 @@
   6.402   */
   6.403  static boolean fill_input_buffer (j_decompress_ptr cinfo)
   6.404  {
   6.405 -	my_source_mgr * src = (my_source_mgr *) cinfo->src;
   6.406 -	int nbytes;
   6.407 +    my_source_mgr * src = (my_source_mgr *) cinfo->src;
   6.408 +    int nbytes;
   6.409  
   6.410 -	nbytes = SDL_RWread(src->ctx, src->buffer, 1, INPUT_BUFFER_SIZE);
   6.411 -	if (nbytes <= 0) {
   6.412 -		/* Insert a fake EOI marker */
   6.413 -		src->buffer[0] = (Uint8) 0xFF;
   6.414 -		src->buffer[1] = (Uint8) JPEG_EOI;
   6.415 -		nbytes = 2;
   6.416 -	}
   6.417 -	src->pub.next_input_byte = src->buffer;
   6.418 -	src->pub.bytes_in_buffer = nbytes;
   6.419 +    nbytes = SDL_RWread(src->ctx, src->buffer, 1, INPUT_BUFFER_SIZE);
   6.420 +    if (nbytes <= 0) {
   6.421 +        /* Insert a fake EOI marker */
   6.422 +        src->buffer[0] = (Uint8) 0xFF;
   6.423 +        src->buffer[1] = (Uint8) JPEG_EOI;
   6.424 +        nbytes = 2;
   6.425 +    }
   6.426 +    src->pub.next_input_byte = src->buffer;
   6.427 +    src->pub.bytes_in_buffer = nbytes;
   6.428  
   6.429 -	return TRUE;
   6.430 +    return TRUE;
   6.431  }
   6.432  
   6.433  
   6.434 @@ -292,23 +292,23 @@
   6.435   */
   6.436  static void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
   6.437  {
   6.438 -	my_source_mgr * src = (my_source_mgr *) cinfo->src;
   6.439 +    my_source_mgr * src = (my_source_mgr *) cinfo->src;
   6.440  
   6.441 -	/* Just a dumb implementation for now.	Could use fseek() except
   6.442 -	 * it doesn't work on pipes.  Not clear that being smart is worth
   6.443 -	 * any trouble anyway --- large skips are infrequent.
   6.444 -	 */
   6.445 -	if (num_bytes > 0) {
   6.446 -		while (num_bytes > (long) src->pub.bytes_in_buffer) {
   6.447 -			num_bytes -= (long) src->pub.bytes_in_buffer;
   6.448 -			(void) src->pub.fill_input_buffer(cinfo);
   6.449 -			/* note we assume that fill_input_buffer will never
   6.450 -			 * return FALSE, so suspension need not be handled.
   6.451 -			 */
   6.452 -		}
   6.453 -		src->pub.next_input_byte += (size_t) num_bytes;
   6.454 -		src->pub.bytes_in_buffer -= (size_t) num_bytes;
   6.455 -	}
   6.456 +    /* Just a dumb implementation for now.  Could use fseek() except
   6.457 +     * it doesn't work on pipes.  Not clear that being smart is worth
   6.458 +     * any trouble anyway --- large skips are infrequent.
   6.459 +     */
   6.460 +    if (num_bytes > 0) {
   6.461 +        while (num_bytes > (long) src->pub.bytes_in_buffer) {
   6.462 +            num_bytes -= (long) src->pub.bytes_in_buffer;
   6.463 +            (void) src->pub.fill_input_buffer(cinfo);
   6.464 +            /* note we assume that fill_input_buffer will never
   6.465 +             * return FALSE, so suspension need not be handled.
   6.466 +             */
   6.467 +        }
   6.468 +        src->pub.next_input_byte += (size_t) num_bytes;
   6.469 +        src->pub.bytes_in_buffer -= (size_t) num_bytes;
   6.470 +    }
   6.471  }
   6.472  
   6.473  /*
   6.474 @@ -317,8 +317,8 @@
   6.475   */
   6.476  static void term_source (j_decompress_ptr cinfo)
   6.477  {
   6.478 -	/* We don't actually need to do anything */
   6.479 -	return;
   6.480 +    /* We don't actually need to do anything */
   6.481 +    return;
   6.482  }
   6.483  
   6.484  /*
   6.485 @@ -337,10 +337,10 @@
   6.486     * This makes it unsafe to use this manager and a different source
   6.487     * manager serially with the same JPEG object.  Caveat programmer.
   6.488     */
   6.489 -  if (cinfo->src == NULL) {	/* first time for this JPEG object? */
   6.490 +  if (cinfo->src == NULL) { /* first time for this JPEG object? */
   6.491      cinfo->src = (struct jpeg_source_mgr *)
   6.492        (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
   6.493 -				  sizeof(my_source_mgr));
   6.494 +                  sizeof(my_source_mgr));
   6.495      src = (my_source_mgr *) cinfo->src;
   6.496    }
   6.497  
   6.498 @@ -356,122 +356,122 @@
   6.499  }
   6.500  
   6.501  struct my_error_mgr {
   6.502 -	struct jpeg_error_mgr errmgr;
   6.503 -	jmp_buf escape;
   6.504 +    struct jpeg_error_mgr errmgr;
   6.505 +    jmp_buf escape;
   6.506  };
   6.507  
   6.508  static void my_error_exit(j_common_ptr cinfo)
   6.509  {
   6.510 -	struct my_error_mgr *err = (struct my_error_mgr *)cinfo->err;
   6.511 -	longjmp(err->escape, 1);
   6.512 +    struct my_error_mgr *err = (struct my_error_mgr *)cinfo->err;
   6.513 +    longjmp(err->escape, 1);
   6.514  }
   6.515  
   6.516  static void output_no_message(j_common_ptr cinfo)
   6.517  {
   6.518 -	/* do nothing */
   6.519 +    /* do nothing */
   6.520  }
   6.521  
   6.522  /* Load a JPEG type image from an SDL datasource */
   6.523  SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
   6.524  {
   6.525 -	Sint64 start;
   6.526 -	struct jpeg_decompress_struct cinfo;
   6.527 -	JSAMPROW rowptr[1];
   6.528 -	SDL_Surface *volatile surface = NULL;
   6.529 -	struct my_error_mgr jerr;
   6.530 +    Sint64 start;
   6.531 +    struct jpeg_decompress_struct cinfo;
   6.532 +    JSAMPROW rowptr[1];
   6.533 +    SDL_Surface *volatile surface = NULL;
   6.534 +    struct my_error_mgr jerr;
   6.535  
   6.536 -	if ( !src ) {
   6.537 -		/* The error message has been set in SDL_RWFromFile */
   6.538 -		return NULL;
   6.539 -	}
   6.540 -	start = SDL_RWtell(src);
   6.541 +    if ( !src ) {
   6.542 +        /* The error message has been set in SDL_RWFromFile */
   6.543 +        return NULL;
   6.544 +    }
   6.545 +    start = SDL_RWtell(src);
   6.546  
   6.547 -	if ( !IMG_Init(IMG_INIT_JPG) ) {
   6.548 -		return NULL;
   6.549 -	}
   6.550 +    if ( !IMG_Init(IMG_INIT_JPG) ) {
   6.551 +        return NULL;
   6.552 +    }
   6.553  
   6.554 -	/* Create a decompression structure and load the JPEG header */
   6.555 -	cinfo.err = lib.jpeg_std_error(&jerr.errmgr);
   6.556 -	jerr.errmgr.error_exit = my_error_exit;
   6.557 -	jerr.errmgr.output_message = output_no_message;
   6.558 -	if(setjmp(jerr.escape)) {
   6.559 -		/* If we get here, libjpeg found an error */
   6.560 -		lib.jpeg_destroy_decompress(&cinfo);
   6.561 -		if ( surface != NULL ) {
   6.562 -			SDL_FreeSurface(surface);
   6.563 -		}
   6.564 -		SDL_RWseek(src, start, RW_SEEK_SET);
   6.565 -		IMG_SetError("JPEG loading error");
   6.566 -		return NULL;
   6.567 -	}
   6.568 +    /* Create a decompression structure and load the JPEG header */
   6.569 +    cinfo.err = lib.jpeg_std_error(&jerr.errmgr);
   6.570 +    jerr.errmgr.error_exit = my_error_exit;
   6.571 +    jerr.errmgr.output_message = output_no_message;
   6.572 +    if(setjmp(jerr.escape)) {
   6.573 +        /* If we get here, libjpeg found an error */
   6.574 +        lib.jpeg_destroy_decompress(&cinfo);
   6.575 +        if ( surface != NULL ) {
   6.576 +            SDL_FreeSurface(surface);
   6.577 +        }
   6.578 +        SDL_RWseek(src, start, RW_SEEK_SET);
   6.579 +        IMG_SetError("JPEG loading error");
   6.580 +        return NULL;
   6.581 +    }
   6.582  
   6.583 -	lib.jpeg_create_decompress(&cinfo);
   6.584 -	jpeg_SDL_RW_src(&cinfo, src);
   6.585 -	lib.jpeg_read_header(&cinfo, TRUE);
   6.586 +    lib.jpeg_create_decompress(&cinfo);
   6.587 +    jpeg_SDL_RW_src(&cinfo, src);
   6.588 +    lib.jpeg_read_header(&cinfo, TRUE);
   6.589  
   6.590 -	if(cinfo.num_components == 4) {
   6.591 -		/* Set 32-bit Raw output */
   6.592 -		cinfo.out_color_space = JCS_CMYK;
   6.593 -		cinfo.quantize_colors = FALSE;
   6.594 -		lib.jpeg_calc_output_dimensions(&cinfo);
   6.595 +    if(cinfo.num_components == 4) {
   6.596 +        /* Set 32-bit Raw output */
   6.597 +        cinfo.out_color_space = JCS_CMYK;
   6.598 +        cinfo.quantize_colors = FALSE;
   6.599 +        lib.jpeg_calc_output_dimensions(&cinfo);
   6.600  
   6.601 -		/* Allocate an output surface to hold the image */
   6.602 -		surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   6.603 -		        cinfo.output_width, cinfo.output_height, 32,
   6.604 +        /* Allocate an output surface to hold the image */
   6.605 +        surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   6.606 +                cinfo.output_width, cinfo.output_height, 32,
   6.607  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   6.608 -		                   0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
   6.609 +                           0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
   6.610  #else
   6.611 -		                   0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF);
   6.612 +                           0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF);
   6.613  #endif
   6.614 -	} else {
   6.615 -		/* Set 24-bit RGB output */
   6.616 -		cinfo.out_color_space = JCS_RGB;
   6.617 -		cinfo.quantize_colors = FALSE;
   6.618 +    } else {
   6.619 +        /* Set 24-bit RGB output */
   6.620 +        cinfo.out_color_space = JCS_RGB;
   6.621 +        cinfo.quantize_colors = FALSE;
   6.622  #ifdef FAST_JPEG
   6.623 -		cinfo.scale_num   = 1;
   6.624 -		cinfo.scale_denom = 1;
   6.625 -		cinfo.dct_method = JDCT_FASTEST;
   6.626 -		cinfo.do_fancy_upsampling = FALSE;
   6.627 +        cinfo.scale_num   = 1;
   6.628 +        cinfo.scale_denom = 1;
   6.629 +        cinfo.dct_method = JDCT_FASTEST;
   6.630 +        cinfo.do_fancy_upsampling = FALSE;
   6.631  #endif
   6.632 -		lib.jpeg_calc_output_dimensions(&cinfo);
   6.633 +        lib.jpeg_calc_output_dimensions(&cinfo);
   6.634  
   6.635 -		/* Allocate an output surface to hold the image */
   6.636 -		surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   6.637 -		        cinfo.output_width, cinfo.output_height, 24,
   6.638 +        /* Allocate an output surface to hold the image */
   6.639 +        surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   6.640 +                cinfo.output_width, cinfo.output_height, 24,
   6.641  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   6.642 -		                   0x0000FF, 0x00FF00, 0xFF0000,
   6.643 +                           0x0000FF, 0x00FF00, 0xFF0000,
   6.644  #else
   6.645 -		                   0xFF0000, 0x00FF00, 0x0000FF,
   6.646 +                           0xFF0000, 0x00FF00, 0x0000FF,
   6.647  #endif
   6.648 -		                   0);
   6.649 -	}
   6.650 +                           0);
   6.651 +    }
   6.652  
   6.653 -	if ( surface == NULL ) {
   6.654 -		lib.jpeg_destroy_decompress(&cinfo);
   6.655 -		SDL_RWseek(src, start, RW_SEEK_SET);
   6.656 -		IMG_SetError("Out of memory");
   6.657 -		return NULL;
   6.658 -	}
   6.659 +    if ( surface == NULL ) {
   6.660 +        lib.jpeg_destroy_decompress(&cinfo);
   6.661 +        SDL_RWseek(src, start, RW_SEEK_SET);
   6.662 +        IMG_SetError("Out of memory");
   6.663 +        return NULL;
   6.664 +    }
   6.665  
   6.666 -	/* Decompress the image */
   6.667 -	lib.jpeg_start_decompress(&cinfo);
   6.668 -	while ( cinfo.output_scanline < cinfo.output_height ) {
   6.669 -		rowptr[0] = (JSAMPROW)(Uint8 *)surface->pixels +
   6.670 -		                    cinfo.output_scanline * surface->pitch;
   6.671 -		lib.jpeg_read_scanlines(&cinfo, rowptr, (JDIMENSION) 1);
   6.672 -	}
   6.673 -	lib.jpeg_finish_decompress(&cinfo);
   6.674 -	lib.jpeg_destroy_decompress(&cinfo);
   6.675 +    /* Decompress the image */
   6.676 +    lib.jpeg_start_decompress(&cinfo);
   6.677 +    while ( cinfo.output_scanline < cinfo.output_height ) {
   6.678 +        rowptr[0] = (JSAMPROW)(Uint8 *)surface->pixels +
   6.679 +                            cinfo.output_scanline * surface->pitch;
   6.680 +        lib.jpeg_read_scanlines(&cinfo, rowptr, (JDIMENSION) 1);
   6.681 +    }
   6.682 +    lib.jpeg_finish_decompress(&cinfo);
   6.683 +    lib.jpeg_destroy_decompress(&cinfo);
   6.684  
   6.685 -	return(surface);
   6.686 +    return(surface);
   6.687  }
   6.688  
   6.689  #else
   6.690  
   6.691  int IMG_InitJPG()
   6.692  {
   6.693 -	IMG_SetError("JPEG images are not supported");
   6.694 -	return(-1);
   6.695 +    IMG_SetError("JPEG images are not supported");
   6.696 +    return(-1);
   6.697  }
   6.698  
   6.699  void IMG_QuitJPG()
   6.700 @@ -481,13 +481,13 @@
   6.701  /* See if an image is contained in a data source */
   6.702  int IMG_isJPG(SDL_RWops *src)
   6.703  {
   6.704 -	return(0);
   6.705 +    return(0);
   6.706  }
   6.707  
   6.708  /* Load a JPEG type image from an SDL datasource */
   6.709  SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
   6.710  {
   6.711 -	return(NULL);
   6.712 +    return(NULL);
   6.713  }
   6.714  
   6.715  #endif /* LOAD_JPG */
     7.1 --- a/IMG_lbm.c	Thu Apr 25 00:22:51 2013 -0700
     7.2 +++ b/IMG_lbm.c	Tue May 21 21:24:32 2013 -0700
     7.3 @@ -46,440 +46,440 @@
     7.4  
     7.5  typedef struct
     7.6  {
     7.7 -    Uint16 w, h;		/* width & height of the bitmap in pixels */
     7.8 -    Sint16 x, y;		/* screen coordinates of the bitmap */
     7.9 -    Uint8 planes;		/* number of planes of the bitmap */
    7.10 -    Uint8 mask;			/* mask type ( 0 => no mask ) */
    7.11 -    Uint8 tcomp;		/* compression type */
    7.12 -    Uint8 pad1;			/* dummy value, for padding */
    7.13 -    Uint16 tcolor;		/* transparent color */
    7.14 -    Uint8 xAspect,		/* pixel aspect ratio */
    7.15 +    Uint16 w, h;        /* width & height of the bitmap in pixels */
    7.16 +    Sint16 x, y;        /* screen coordinates of the bitmap */
    7.17 +    Uint8 planes;       /* number of planes of the bitmap */
    7.18 +    Uint8 mask;         /* mask type ( 0 => no mask ) */
    7.19 +    Uint8 tcomp;        /* compression type */
    7.20 +    Uint8 pad1;         /* dummy value, for padding */
    7.21 +    Uint16 tcolor;      /* transparent color */
    7.22 +    Uint8 xAspect,      /* pixel aspect ratio */
    7.23            yAspect;
    7.24 -    Sint16  Lpage;		/* width of the screen in pixels */
    7.25 -    Sint16  Hpage;		/* height of the screen in pixels */
    7.26 +    Sint16  Lpage;      /* width of the screen in pixels */
    7.27 +    Sint16  Hpage;      /* height of the screen in pixels */
    7.28  } BMHD;
    7.29  
    7.30  int IMG_isLBM( SDL_RWops *src )
    7.31  {
    7.32 -	Sint64 start;
    7.33 -	int   is_LBM;
    7.34 -	Uint8 magic[4+4+4];
    7.35 +    Sint64 start;
    7.36 +    int   is_LBM;
    7.37 +    Uint8 magic[4+4+4];
    7.38  
    7.39 -	if ( !src ) 
    7.40 -		return 0;
    7.41 -	start = SDL_RWtell(src);
    7.42 -	is_LBM = 0;
    7.43 -	if ( SDL_RWread( src, magic, sizeof(magic), 1 ) )
    7.44 -	{
    7.45 -		if ( !SDL_memcmp( magic, "FORM", 4 ) &&
    7.46 -			( !SDL_memcmp( magic + 8, "PBM ", 4 ) ||
    7.47 -			  !SDL_memcmp( magic + 8, "ILBM", 4 ) ) )
    7.48 -		{
    7.49 -			is_LBM = 1;
    7.50 -		}
    7.51 -	}
    7.52 -	SDL_RWseek(src, start, RW_SEEK_SET);
    7.53 -	return( is_LBM );
    7.54 +    if ( !src )
    7.55 +        return 0;
    7.56 +    start = SDL_RWtell(src);
    7.57 +    is_LBM = 0;
    7.58 +    if ( SDL_RWread( src, magic, sizeof(magic), 1 ) )
    7.59 +    {
    7.60 +        if ( !SDL_memcmp( magic, "FORM", 4 ) &&
    7.61 +            ( !SDL_memcmp( magic + 8, "PBM ", 4 ) ||
    7.62 +              !SDL_memcmp( magic + 8, "ILBM", 4 ) ) )
    7.63 +        {
    7.64 +            is_LBM = 1;
    7.65 +        }
    7.66 +    }
    7.67 +    SDL_RWseek(src, start, RW_SEEK_SET);
    7.68 +    return( is_LBM );
    7.69  }
    7.70  
    7.71  SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
    7.72  {
    7.73 -	Sint64 start;
    7.74 -	SDL_Surface *Image;
    7.75 -	Uint8       id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
    7.76 -	Uint32      size, bytesloaded, nbcolors;
    7.77 -	Uint32      i, j, bytesperline, nbplanes, stencil, plane, h;
    7.78 -	Uint32      remainingbytes;
    7.79 -	Uint32      width;
    7.80 -	BMHD	      bmhd;
    7.81 -	char        *error;
    7.82 -	Uint8       flagHAM,flagEHB;
    7.83 +    Sint64 start;
    7.84 +    SDL_Surface *Image;
    7.85 +    Uint8       id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
    7.86 +    Uint32      size, bytesloaded, nbcolors;
    7.87 +    Uint32      i, j, bytesperline, nbplanes, stencil, plane, h;
    7.88 +    Uint32      remainingbytes;
    7.89 +    Uint32      width;
    7.90 +    BMHD          bmhd;
    7.91 +    char        *error;
    7.92 +    Uint8       flagHAM,flagEHB;
    7.93  
    7.94 -	Image   = NULL;
    7.95 -	error   = NULL;
    7.96 -	MiniBuf = NULL;
    7.97 +    Image   = NULL;
    7.98 +    error   = NULL;
    7.99 +    MiniBuf = NULL;
   7.100  
   7.101 -	if ( !src ) {
   7.102 -		/* The error message has been set in SDL_RWFromFile */
   7.103 -		return NULL;
   7.104 -	}
   7.105 -	start = SDL_RWtell(src);
   7.106 +    if ( !src ) {
   7.107 +        /* The error message has been set in SDL_RWFromFile */
   7.108 +        return NULL;
   7.109 +    }
   7.110 +    start = SDL_RWtell(src);
   7.111  
   7.112 -	if ( !SDL_RWread( src, id, 4, 1 ) )
   7.113 -	{
   7.114 -		error="error reading IFF chunk";
   7.115 -		goto done;
   7.116 -	}
   7.117 +    if ( !SDL_RWread( src, id, 4, 1 ) )
   7.118 +    {
   7.119 +        error="error reading IFF chunk";
   7.120 +        goto done;
   7.121 +    }
   7.122  
   7.123 -	/* Should be the size of the file minus 4+4 ( 'FORM'+size ) */
   7.124 -	if ( !SDL_RWread( src, &size, 4, 1 ) )
   7.125 -	{
   7.126 -		error="error reading IFF chunk size";
   7.127 -		goto done;
   7.128 -	}
   7.129 +    /* Should be the size of the file minus 4+4 ( 'FORM'+size ) */
   7.130 +    if ( !SDL_RWread( src, &size, 4, 1 ) )
   7.131 +    {
   7.132 +        error="error reading IFF chunk size";
   7.133 +        goto done;
   7.134 +    }
   7.135  
   7.136 -	/* As size is not used here, no need to swap it */
   7.137 +    /* As size is not used here, no need to swap it */
   7.138  
   7.139 -	if ( memcmp( id, "FORM", 4 ) != 0 )
   7.140 -	{
   7.141 -		error="not a IFF file";
   7.142 -		goto done;
   7.143 -	}
   7.144 +    if ( memcmp( id, "FORM", 4 ) != 0 )
   7.145 +    {
   7.146 +        error="not a IFF file";
   7.147 +        goto done;
   7.148 +    }
   7.149  
   7.150 -	if ( !SDL_RWread( src, id, 4, 1 ) )
   7.151 -	{
   7.152 -		error="error reading IFF chunk";
   7.153 -		goto done;
   7.154 -	}
   7.155 +    if ( !SDL_RWread( src, id, 4, 1 ) )
   7.156 +    {
   7.157 +        error="error reading IFF chunk";
   7.158 +        goto done;
   7.159 +    }
   7.160  
   7.161 -	pbm = 0;
   7.162 +    pbm = 0;
   7.163  
   7.164 -	/* File format : PBM=Packed Bitmap, ILBM=Interleaved Bitmap */
   7.165 -	if ( !SDL_memcmp( id, "PBM ", 4 ) ) pbm = 1;
   7.166 -	else if ( SDL_memcmp( id, "ILBM", 4 ) )
   7.167 -	{
   7.168 -		error="not a IFF picture";
   7.169 -		goto done;
   7.170 -	}
   7.171 +    /* File format : PBM=Packed Bitmap, ILBM=Interleaved Bitmap */
   7.172 +    if ( !SDL_memcmp( id, "PBM ", 4 ) ) pbm = 1;
   7.173 +    else if ( SDL_memcmp( id, "ILBM", 4 ) )
   7.174 +    {
   7.175 +        error="not a IFF picture";
   7.176 +        goto done;
   7.177 +    }
   7.178  
   7.179 -	nbcolors = 0;
   7.180 +    nbcolors = 0;
   7.181  
   7.182 -	SDL_memset( &bmhd, 0, sizeof( BMHD ) );
   7.183 -	flagHAM = 0;
   7.184 -	flagEHB = 0;
   7.185 +    SDL_memset( &bmhd, 0, sizeof( BMHD ) );
   7.186 +    flagHAM = 0;
   7.187 +    flagEHB = 0;
   7.188  
   7.189 -	while ( SDL_memcmp( id, "BODY", 4 ) != 0 )
   7.190 -	{
   7.191 -		if ( !SDL_RWread( src, id, 4, 1 ) ) 
   7.192 -		{
   7.193 -			error="error reading IFF chunk";
   7.194 -			goto done;
   7.195 -		}
   7.196 +    while ( SDL_memcmp( id, "BODY", 4 ) != 0 )
   7.197 +    {
   7.198 +        if ( !SDL_RWread( src, id, 4, 1 ) )
   7.199 +        {
   7.200 +            error="error reading IFF chunk";
   7.201 +            goto done;
   7.202 +        }
   7.203  
   7.204 -		if ( !SDL_RWread( src, &size, 4, 1 ) )
   7.205 -		{
   7.206 -			error="error reading IFF chunk size";
   7.207 -			goto done;
   7.208 -		}
   7.209 +        if ( !SDL_RWread( src, &size, 4, 1 ) )
   7.210 +        {
   7.211 +            error="error reading IFF chunk size";
   7.212 +            goto done;
   7.213 +        }
   7.214  
   7.215 -		bytesloaded = 0;
   7.216 +        bytesloaded = 0;
   7.217  
   7.218 -		size = SDL_SwapBE32( size );
   7.219 +        size = SDL_SwapBE32( size );
   7.220  
   7.221 -		if ( !SDL_memcmp( id, "BMHD", 4 ) ) /* Bitmap header */
   7.222 -		{
   7.223 -			if ( !SDL_RWread( src, &bmhd, sizeof( BMHD ), 1 ) )
   7.224 -			{
   7.225 -				error="error reading BMHD chunk";
   7.226 -				goto done;
   7.227 -			}
   7.228 +        if ( !SDL_memcmp( id, "BMHD", 4 ) ) /* Bitmap header */
   7.229 +        {
   7.230 +            if ( !SDL_RWread( src, &bmhd, sizeof( BMHD ), 1 ) )
   7.231 +            {
   7.232 +                error="error reading BMHD chunk";
   7.233 +                goto done;
   7.234 +            }
   7.235  
   7.236 -			bytesloaded = sizeof( BMHD );
   7.237 +            bytesloaded = sizeof( BMHD );
   7.238  
   7.239 -			bmhd.w 		= SDL_SwapBE16( bmhd.w );
   7.240 -			bmhd.h 		= SDL_SwapBE16( bmhd.h );
   7.241 -			bmhd.x 		= SDL_SwapBE16( bmhd.x );
   7.242 -			bmhd.y 		= SDL_SwapBE16( bmhd.y );
   7.243 -			bmhd.tcolor = SDL_SwapBE16( bmhd.tcolor );
   7.244 -			bmhd.Lpage 	= SDL_SwapBE16( bmhd.Lpage );
   7.245 -			bmhd.Hpage 	= SDL_SwapBE16( bmhd.Hpage );
   7.246 -		}
   7.247 +            bmhd.w      = SDL_SwapBE16( bmhd.w );
   7.248 +            bmhd.h      = SDL_SwapBE16( bmhd.h );
   7.249 +            bmhd.x      = SDL_SwapBE16( bmhd.x );
   7.250 +            bmhd.y      = SDL_SwapBE16( bmhd.y );
   7.251 +            bmhd.tcolor = SDL_SwapBE16( bmhd.tcolor );
   7.252 +            bmhd.Lpage  = SDL_SwapBE16( bmhd.Lpage );
   7.253 +            bmhd.Hpage  = SDL_SwapBE16( bmhd.Hpage );
   7.254 +        }
   7.255  
   7.256 -		if ( !SDL_memcmp( id, "CMAP", 4 ) ) /* palette ( Color Map ) */
   7.257 -		{
   7.258 -			if ( !SDL_RWread( src, &colormap, size, 1 ) )
   7.259 -			{
   7.260 -				error="error reading CMAP chunk";
   7.261 -				goto done;
   7.262 -			}
   7.263 +        if ( !SDL_memcmp( id, "CMAP", 4 ) ) /* palette ( Color Map ) */
   7.264 +        {
   7.265 +            if ( !SDL_RWread( src, &colormap, size, 1 ) )
   7.266 +            {
   7.267 +                error="error reading CMAP chunk";
   7.268 +                goto done;
   7.269 +            }
   7.270  
   7.271 -			bytesloaded = size;
   7.272 -			nbcolors = size / 3;
   7.273 -		}
   7.274 +            bytesloaded = size;
   7.275 +            nbcolors = size / 3;
   7.276 +        }
   7.277  
   7.278 -		if ( !memcmp( id, "CAMG", 4 ) ) /* Amiga ViewMode  */
   7.279 -		{
   7.280 -			Uint32 viewmodes;
   7.281 -			if ( !SDL_RWread( src, &viewmodes, sizeof(viewmodes), 1 ) )
   7.282 -			{
   7.283 -				error="error reading CAMG chunk";
   7.284 -				goto done;
   7.285 -			}
   7.286 +        if ( !memcmp( id, "CAMG", 4 ) ) /* Amiga ViewMode  */
   7.287 +        {
   7.288 +            Uint32 viewmodes;
   7.289 +            if ( !SDL_RWread( src, &viewmodes, sizeof(viewmodes), 1 ) )
   7.290 +            {
   7.291 +                error="error reading CAMG chunk";
   7.292 +                goto done;
   7.293 +            }
   7.294  
   7.295 -			bytesloaded = size;
   7.296 -			viewmodes = SDL_SwapBE32( viewmodes );
   7.297 -			if ( viewmodes & 0x0800 )
   7.298 -				flagHAM = 1;
   7.299 -			if ( viewmodes & 0x0080 )
   7.300 -				flagEHB = 1;
   7.301 -		}
   7.302 +            bytesloaded = size;
   7.303 +            viewmodes = SDL_SwapBE32( viewmodes );
   7.304 +            if ( viewmodes & 0x0800 )
   7.305 +                flagHAM = 1;
   7.306 +            if ( viewmodes & 0x0080 )
   7.307 +                flagEHB = 1;
   7.308 +        }
   7.309  
   7.310 -		if ( SDL_memcmp( id, "BODY", 4 ) )
   7.311 -		{
   7.312 -			if ( size & 1 )	++size;  	/* padding ! */
   7.313 -			size -= bytesloaded;
   7.314 -			/* skip the remaining bytes of this chunk */
   7.315 -			if ( size )	SDL_RWseek( src, size, RW_SEEK_CUR );
   7.316 -		}
   7.317 -	}
   7.318 +        if ( SDL_memcmp( id, "BODY", 4 ) )
   7.319 +        {
   7.320 +            if ( size & 1 ) ++size;     /* padding ! */
   7.321 +            size -= bytesloaded;
   7.322 +            /* skip the remaining bytes of this chunk */
   7.323 +            if ( size ) SDL_RWseek( src, size, RW_SEEK_CUR );
   7.324 +        }
   7.325 +    }
   7.326  
   7.327 -	/* compute some usefull values, based on the bitmap header */
   7.328 +    /* compute some usefull values, based on the bitmap header */
   7.329  
   7.330 -	width = ( bmhd.w + 15 ) & 0xFFFFFFF0;  /* Width in pixels modulo 16 */
   7.331 +    width = ( bmhd.w + 15 ) & 0xFFFFFFF0;  /* Width in pixels modulo 16 */
   7.332  
   7.333 -	bytesperline = ( ( bmhd.w + 15 ) / 16 ) * 2;
   7.334 +    bytesperline = ( ( bmhd.w + 15 ) / 16 ) * 2;
   7.335  
   7.336 -	nbplanes = bmhd.planes;
   7.337 +    nbplanes = bmhd.planes;
   7.338  
   7.339 -	if ( pbm )                         /* File format : 'Packed Bitmap' */
   7.340 -	{
   7.341 -		bytesperline *= 8;
   7.342 -		nbplanes = 1;
   7.343 -	}
   7.344 +    if ( pbm )                         /* File format : 'Packed Bitmap' */
   7.345 +    {
   7.346 +        bytesperline *= 8;
   7.347 +        nbplanes = 1;
   7.348 +    }
   7.349  
   7.350 -	stencil = (bmhd.mask & 1);   /* There is a mask ( 'stencil' ) */
   7.351 +    stencil = (bmhd.mask & 1);   /* There is a mask ( 'stencil' ) */
   7.352  
   7.353 -	/* Allocate memory for a temporary buffer ( used for
   7.354 +    /* Allocate memory for a temporary buffer ( used for
   7.355             decompression/deinterleaving ) */
   7.356  
   7.357 -	MiniBuf = (Uint8 *)SDL_malloc( bytesperline * (nbplanes + stencil) );
   7.358 -	if ( MiniBuf == NULL )
   7.359 -	{
   7.360 -		error="no enough memory for temporary buffer";
   7.361 -		goto done;
   7.362 -	}
   7.363 +    MiniBuf = (Uint8 *)SDL_malloc( bytesperline * (nbplanes + stencil) );
   7.364 +    if ( MiniBuf == NULL )
   7.365 +    {
   7.366 +        error="no enough memory for temporary buffer";
   7.367 +        goto done;
   7.368 +    }
   7.369  
   7.370 -	if ( ( Image = SDL_CreateRGBSurface( SDL_SWSURFACE, width, bmhd.h, (bmhd.planes==24 || flagHAM==1)?24:8, 0, 0, 0, 0 ) ) == NULL )
   7.371 -	   goto done;
   7.372 +    if ( ( Image = SDL_CreateRGBSurface( SDL_SWSURFACE, width, bmhd.h, (bmhd.planes==24 || flagHAM==1)?24:8, 0, 0, 0, 0 ) ) == NULL )
   7.373 +       goto done;
   7.374  
   7.375 -	if ( bmhd.mask & 2 )               /* There is a transparent color */
   7.376 -		SDL_SetColorKey( Image, SDL_TRUE, bmhd.tcolor );
   7.377 +    if ( bmhd.mask & 2 )               /* There is a transparent color */
   7.378 +        SDL_SetColorKey( Image, SDL_TRUE, bmhd.tcolor );
   7.379  
   7.380 -	/* Update palette informations */
   7.381 +    /* Update palette informations */
   7.382  
   7.383 -	/* There is no palette in 24 bits ILBM file */
   7.384 -	if ( nbcolors>0 && flagHAM==0 )
   7.385 -	{
   7.386 -		/* FIXME: Should this include the stencil? See comment below */
   7.387 -		int nbrcolorsfinal = 1 << (nbplanes + stencil);
   7.388 -		ptr = &colormap[0];
   7.389 +    /* There is no palette in 24 bits ILBM file */
   7.390 +    if ( nbcolors>0 && flagHAM==0 )
   7.391 +    {
   7.392 +        /* FIXME: Should this include the stencil? See comment below */
   7.393 +        int nbrcolorsfinal = 1 << (nbplanes + stencil);
   7.394 +        ptr = &colormap[0];
   7.395  
   7.396 -		for ( i=0; i<nbcolors; i++ )
   7.397 -		{
   7.398 -			Image->format->palette->colors[i].r = *ptr++;
   7.399 -			Image->format->palette->colors[i].g = *ptr++;
   7.400 -			Image->format->palette->colors[i].b = *ptr++;
   7.401 -		}
   7.402 +        for ( i=0; i<nbcolors; i++ )
   7.403 +        {
   7.404 +            Image->format->palette->colors[i].r = *ptr++;
   7.405 +            Image->format->palette->colors[i].g = *ptr++;
   7.406 +            Image->format->palette->colors[i].b = *ptr++;
   7.407 +        }
   7.408  
   7.409 -		/* Amiga EHB mode (Extra-Half-Bright) */
   7.410 -		/* 6 bitplanes mode with a 32 colors palette */
   7.411 -		/* The 32 last colors are the same but divided by 2 */
   7.412 -		/* Some Amiga pictures save 64 colors with 32 last wrong colors, */
   7.413 -		/* they shouldn't !, and here we overwrite these 32 bad colors. */
   7.414 -		if ( (nbcolors==32 || flagEHB ) && (1<<bmhd.planes)==64 )
   7.415 -		{
   7.416 -			nbcolors = 64;
   7.417 -			ptr = &colormap[0];
   7.418 -			for ( i=32; i<64; i++ )
   7.419 -			{
   7.420 -				Image->format->palette->colors[i].r = (*ptr++)/2;
   7.421 -				Image->format->palette->colors[i].g = (*ptr++)/2;
   7.422 -				Image->format->palette->colors[i].b = (*ptr++)/2;
   7.423 -			}
   7.424 -		}
   7.425 +        /* Amiga EHB mode (Extra-Half-Bright) */
   7.426 +        /* 6 bitplanes mode with a 32 colors palette */
   7.427 +        /* The 32 last colors are the same but divided by 2 */
   7.428 +        /* Some Amiga pictures save 64 colors with 32 last wrong colors, */
   7.429 +        /* they shouldn't !, and here we overwrite these 32 bad colors. */
   7.430 +        if ( (nbcolors==32 || flagEHB ) && (1<<bmhd.planes)==64 )
   7.431 +        {
   7.432 +            nbcolors = 64;
   7.433 +            ptr = &colormap[0];
   7.434 +            for ( i=32; i<64; i++ )
   7.435 +            {
   7.436 +                Image->format->palette->colors[i].r = (*ptr++)/2;
   7.437 +                Image->format->palette->colors[i].g = (*ptr++)/2;
   7.438 +                Image->format->palette->colors[i].b = (*ptr++)/2;
   7.439 +            }
   7.440 +        }
   7.441  
   7.442 -		/* If nbcolors < 2^nbplanes, repeat the colormap */
   7.443 -		/* This happens when pictures have a stencil mask */
   7.444 -		if ( nbrcolorsfinal > (1<<bmhd.planes) ) {
   7.445 -			nbrcolorsfinal = (1<<bmhd.planes);
   7.446 -		}
   7.447 -		for ( i=nbcolors; i < (Uint32)nbrcolorsfinal; i++ )
   7.448 -		{
   7.449 -			Image->format->palette->colors[i].r = Image->format->palette->colors[i%nbcolors].r;
   7.450 -			Image->format->palette->colors[i].g = Image->format->palette->colors[i%nbcolors].g;
   7.451 -			Image->format->palette->colors[i].b = Image->format->palette->colors[i%nbcolors].b;
   7.452 -		}
   7.453 -		if ( !pbm )
   7.454 -			Image->format->palette->ncolors = nbrcolorsfinal;
   7.455 -	}
   7.456 +        /* If nbcolors < 2^nbplanes, repeat the colormap */
   7.457 +        /* This happens when pictures have a stencil mask */
   7.458 +        if ( nbrcolorsfinal > (1<<bmhd.planes) ) {
   7.459 +            nbrcolorsfinal = (1<<bmhd.planes);
   7.460 +        }
   7.461 +        for ( i=nbcolors; i < (Uint32)nbrcolorsfinal; i++ )
   7.462 +        {
   7.463 +            Image->format->palette->colors[i].r = Image->format->palette->colors[i%nbcolors].r;
   7.464 +            Image->format->palette->colors[i].g = Image->format->palette->colors[i%nbcolors].g;
   7.465 +            Image->format->palette->colors[i].b = Image->format->palette->colors[i%nbcolors].b;
   7.466 +        }
   7.467 +        if ( !pbm )
   7.468 +            Image->format->palette->ncolors = nbrcolorsfinal;
   7.469 +    }
   7.470  
   7.471 -	/* Get the bitmap */
   7.472 +    /* Get the bitmap */
   7.473  
   7.474 -	for ( h=0; h < bmhd.h; h++ )
   7.475 -	{
   7.476 -		/* uncompress the datas of each planes */
   7.477 +    for ( h=0; h < bmhd.h; h++ )
   7.478 +    {
   7.479 +        /* uncompress the datas of each planes */
   7.480  
   7.481 -		for ( plane=0; plane < (nbplanes+stencil); plane++ )
   7.482 -		{
   7.483 -			ptr = MiniBuf + ( plane * bytesperline );
   7.484 +        for ( plane=0; plane < (nbplanes+stencil); plane++ )
   7.485 +        {
   7.486 +            ptr = MiniBuf + ( plane * bytesperline );
   7.487  
   7.488 -			remainingbytes = bytesperline;
   7.489 +            remainingbytes = bytesperline;
   7.490  
   7.491 -			if ( bmhd.tcomp == 1 )	    /* Datas are compressed */
   7.492 -			{
   7.493 -				do
   7.494 -				{
   7.495 -					if ( !SDL_RWread( src, &count, 1, 1 ) )
   7.496 -					{
   7.497 -						error="error reading BODY chunk";
   7.498 -						goto done;
   7.499 -					}
   7.500 +            if ( bmhd.tcomp == 1 )      /* Datas are compressed */
   7.501 +            {
   7.502 +                do
   7.503 +                {
   7.504 +                    if ( !SDL_RWread( src, &count, 1, 1 ) )
   7.505 +                    {
   7.506 +                        error="error reading BODY chunk";
   7.507 +                        goto done;
   7.508 +                    }
   7.509  
   7.510 -					if ( count & 0x80 )
   7.511 -					{
   7.512 -						count ^= 0xFF;
   7.513 -						count += 2; /* now it */
   7.514 +                    if ( count & 0x80 )
   7.515 +                    {
   7.516 +                        count ^= 0xFF;
   7.517 +                        count += 2; /* now it */
   7.518  
   7.519 -						if ( ( count > remainingbytes ) || !SDL_RWread( src, &color, 1, 1 ) )
   7.520 -						{
   7.521 -							error="error reading BODY chunk";
   7.522 -							goto done;
   7.523 -						}
   7.524 -						SDL_memset( ptr, color, count );
   7.525 -					}
   7.526 -					else
   7.527 -					{
   7.528 -						++count;
   7.529 +                        if ( ( count > remainingbytes ) || !SDL_RWread( src, &color, 1, 1 ) )
   7.530 +                        {
   7.531 +                            error="error reading BODY chunk";
   7.532 +                            goto done;
   7.533 +                        }
   7.534 +                        SDL_memset( ptr, color, count );
   7.535 +                    }
   7.536 +                    else
   7.537 +                    {
   7.538 +                        ++count;
   7.539  
   7.540 -						if ( ( count > remainingbytes ) || !SDL_RWread( src, ptr, count, 1 ) )
   7.541 -						{
   7.542 -						   error="error reading BODY chunk";
   7.543 -							goto done;
   7.544 -						}
   7.545 -					}
   7.546 +                        if ( ( count > remainingbytes ) || !SDL_RWread( src, ptr, count, 1 ) )
   7.547 +                        {
   7.548 +                           error="error reading BODY chunk";
   7.549 +                            goto done;
   7.550 +                        }
   7.551 +                    }
   7.552  
   7.553 -					ptr += count;
   7.554 -					remainingbytes -= count;
   7.555 +                    ptr += count;
   7.556 +                    remainingbytes -= count;
   7.557  
   7.558 -				} while ( remainingbytes > 0 );
   7.559 -			}
   7.560 -			else
   7.561 -			{
   7.562 -				if ( !SDL_RWread( src, ptr, bytesperline, 1 ) )
   7.563 -				{
   7.564 -					error="error reading BODY chunk";
   7.565 -					goto done;
   7.566 -				}
   7.567 -			}
   7.568 -		}
   7.569 +                } while ( remainingbytes > 0 );
   7.570 +            }
   7.571 +            else
   7.572 +            {
   7.573 +                if ( !SDL_RWread( src, ptr, bytesperline, 1 ) )
   7.574 +                {
   7.575 +                    error="error reading BODY chunk";
   7.576 +                    goto done;
   7.577 +                }
   7.578 +            }
   7.579 +        }
   7.580  
   7.581 -		/* One line has been read, store it ! */
   7.582 +        /* One line has been read, store it ! */
   7.583  
   7.584 -		ptr = (Uint8 *)Image->pixels;
   7.585 -		if ( nbplanes==24 || flagHAM==1 )
   7.586 -			ptr += h * width * 3;
   7.587 -		else
   7.588 -			ptr += h * width;
   7.589 +        ptr = (Uint8 *)Image->pixels;
   7.590 +        if ( nbplanes==24 || flagHAM==1 )
   7.591 +            ptr += h * width * 3;
   7.592 +        else
   7.593 +            ptr += h * width;
   7.594  
   7.595 -		if ( pbm )                 /* File format : 'Packed Bitmap' */
   7.596 -		{
   7.597 -		   memcpy( ptr, MiniBuf, width );
   7.598 -		}
   7.599 -		else		/* We have to un-interlace the bits ! */
   7.600 -		{
   7.601 -			if ( nbplanes!=24 && flagHAM==0 )
   7.602 -			{
   7.603 -				size = ( width + 7 ) / 8;
   7.604 +        if ( pbm )                 /* File format : 'Packed Bitmap' */
   7.605 +        {
   7.606 +           memcpy( ptr, MiniBuf, width );
   7.607 +        }
   7.608 +        else        /* We have to un-interlace the bits ! */
   7.609 +        {
   7.610 +            if ( nbplanes!=24 && flagHAM==0 )
   7.611 +            {
   7.612 +                size = ( width + 7 ) / 8;
   7.613  
   7.614 -				for ( i=0; i < size; i++ )
   7.615 -				{
   7.616 -					memset( ptr, 0, 8 );
   7.617 +                for ( i=0; i < size; i++ )
   7.618 +                {
   7.619 +                    memset( ptr, 0, 8 );
   7.620  
   7.621 -					for ( plane=0; plane < (nbplanes + stencil); plane++ )
   7.622 -					{
   7.623 -						color = *( MiniBuf + i + ( plane * bytesperline ) );
   7.624 -						msk = 0x80;
   7.625 +                    for ( plane=0; plane < (nbplanes + stencil); plane++ )
   7.626 +                    {
   7.627 +                        color = *( MiniBuf + i + ( plane * bytesperline ) );
   7.628 +                        msk = 0x80;
   7.629  
   7.630 -						for ( j=0; j<8; j++ )
   7.631 -						{
   7.632 -							if ( ( plane + j ) <= 7 ) ptr[j] |= (Uint8)( color & msk ) >> ( 7 - plane - j );
   7.633 -							else 	                    ptr[j] |= (Uint8)( color & msk ) << ( plane + j - 7 );
   7.634 +                        for ( j=0; j<8; j++ )
   7.635 +                        {
   7.636 +                            if ( ( plane + j ) <= 7 ) ptr[j] |= (Uint8)( color & msk ) >> ( 7 - plane - j );
   7.637 +                            else                        ptr[j] |= (Uint8)( color & msk ) << ( plane + j - 7 );
   7.638  
   7.639 -							msk >>= 1;
   7.640 -						}
   7.641 -					}
   7.642 -					ptr += 8;
   7.643 -				}
   7.644 -			}
   7.645 -			else
   7.646 -			{
   7.647 -				Uint32 finalcolor = 0;
   7.648 -				size = ( width + 7 ) / 8;
   7.649 -				/* 24 bitplanes ILBM : R0...R7,G0...G7,B0...B7 */
   7.650 -				/* or HAM (6 bitplanes) or HAM8 (8 bitplanes) modes */
   7.651 -				for ( i=0; i<width; i=i+8 )
   7.652 -				{
   7.653 -					Uint8 maskBit = 0x80;
   7.654 -					for ( j=0; j<8; j++ )
   7.655 -					{
   7.656 -						Uint32 pixelcolor = 0;
   7.657 -						Uint32 maskColor = 1;
   7.658 -						Uint8 dataBody;
   7.659 -						for ( plane=0; plane < nbplanes; plane++ )
   7.660 -						{
   7.661 -							dataBody = MiniBuf[ plane*size+i/8 ];
   7.662 -							if ( dataBody&maskBit )
   7.663 -								pixelcolor = pixelcolor | maskColor;
   7.664 -							maskColor = maskColor<<1;
   7.665 -						}
   7.666 -						/* HAM : 12 bits RGB image (4 bits per color component) */
   7.667 -						/* HAM8 : 18 bits RGB image (6 bits per color component) */
   7.668 -						if ( flagHAM )
   7.669 -						{
   7.670 -							switch( pixelcolor>>(nbplanes-2) )
   7.671 -							{
   7.672 -								case 0: /* take direct color from palette */
   7.673 -									finalcolor = colormap[ pixelcolor*3 ] + (colormap[ pixelcolor*3+1 ]<<8) + (colormap[ pixelcolor*3+2 ]<<16);
   7.674 -									break;
   7.675 -								case 1: /* modify only blue component */
   7.676 -									finalcolor = finalcolor&0x00FFFF;
   7.677 -									finalcolor = finalcolor | (pixelcolor<<(16+(10-nbplanes)));
   7.678 -									break;
   7.679 -								case 2: /* modify only red component */
   7.680 -									finalcolor = finalcolor&0xFFFF00;
   7.681 -									finalcolor = finalcolor | pixelcolor<<(10-nbplanes);
   7.682 -									break;
   7.683 -								case 3: /* modify only green component */
   7.684 -									finalcolor = finalcolor&0xFF00FF;
   7.685 -									finalcolor = finalcolor | (pixelcolor<<(8+(10-nbplanes)));
   7.686 -									break;
   7.687 -							}
   7.688 -						}
   7.689 -						else
   7.690 -						{
   7.691 -							finalcolor = pixelcolor;
   7.692 -						}
   7.693 +                            msk >>= 1;
   7.694 +                        }
   7.695 +                    }
   7.696 +                    ptr += 8;
   7.697 +                }
   7.698 +            }
   7.699 +            else
   7.700 +            {
   7.701 +                Uint32 finalcolor = 0;
   7.702 +                size = ( width + 7 ) / 8;
   7.703 +                /* 24 bitplanes ILBM : R0...R7,G0...G7,B0...B7 */
   7.704 +                /* or HAM (6 bitplanes) or HAM8 (8 bitplanes) modes */
   7.705 +                for ( i=0; i<width; i=i+8 )
   7.706 +                {
   7.707 +                    Uint8 maskBit = 0x80;
   7.708 +                    for ( j=0; j<8; j++ )
   7.709 +                    {
   7.710 +                        Uint32 pixelcolor = 0;
   7.711 +                        Uint32 maskColor = 1;
   7.712 +                        Uint8 dataBody;
   7.713 +                        for ( plane=0; plane < nbplanes; plane++ )
   7.714 +                        {
   7.715 +                            dataBody = MiniBuf[ plane*size+i/8 ];
   7.716 +                            if ( dataBody&maskBit )
   7.717 +                                pixelcolor = pixelcolor | maskColor;
   7.718 +                            maskColor = maskColor<<1;
   7.719 +                        }
   7.720 +                        /* HAM : 12 bits RGB image (4 bits per color component) */
   7.721 +                        /* HAM8 : 18 bits RGB image (6 bits per color component) */
   7.722 +                        if ( flagHAM )
   7.723 +                        {
   7.724 +                            switch( pixelcolor>>(nbplanes-2) )
   7.725 +                            {
   7.726 +                                case 0: /* take direct color from palette */
   7.727 +                                    finalcolor = colormap[ pixelcolor*3 ] + (colormap[ pixelcolor*3+1 ]<<8) + (colormap[ pixelcolor*3+2 ]<<16);
   7.728 +                                    break;
   7.729 +                                case 1: /* modify only blue component */
   7.730 +                                    finalcolor = finalcolor&0x00FFFF;
   7.731 +                                    finalcolor = finalcolor | (pixelcolor<<(16+(10-nbplanes)));
   7.732 +                                    break;
   7.733 +                                case 2: /* modify only red component */
   7.734 +                                    finalcolor = finalcolor&0xFFFF00;
   7.735 +                                    finalcolor = finalcolor | pixelcolor<<(10-nbplanes);
   7.736 +                                    break;
   7.737 +                                case 3: /* modify only green component */
   7.738 +                                    finalcolor = finalcolor&0xFF00FF;
   7.739 +                                    finalcolor = finalcolor | (pixelcolor<<(8+(10-nbplanes)));
   7.740 +                                    break;
   7.741 +                            }
   7.742 +                        }
   7.743 +                        else
   7.744 +                        {
   7.745 +                            finalcolor = pixelcolor;
   7.746 +                        }
   7.747  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   7.748 -							*ptr++ = (Uint8)(finalcolor>>16);
   7.749 -							*ptr++ = (Uint8)(finalcolor>>8);
   7.750 -							*ptr++ = (Uint8)(finalcolor);
   7.751 +                            *ptr++ = (Uint8)(finalcolor>>16);
   7.752 +                            *ptr++ = (Uint8)(finalcolor>>8);
   7.753 +                            *ptr++ = (Uint8)(finalcolor);
   7.754  #else
   7.755 -						    *ptr++ = (Uint8)(finalcolor);
   7.756 -							*ptr++ = (Uint8)(finalcolor>>8);
   7.757 -							*ptr++ = (Uint8)(finalcolor>>16);
   7.758 +                            *ptr++ = (Uint8)(finalcolor);
   7.759 +                            *ptr++ = (Uint8)(finalcolor>>8);
   7.760 +                            *ptr++ = (Uint8)(finalcolor>>16);
   7.761  #endif
   7.762 -						maskBit = maskBit>>1;
   7.763 -					}
   7.764 -				}
   7.765 -			}
   7.766 -		}
   7.767 -	}
   7.768 +                        maskBit = maskBit>>1;
   7.769 +                    }
   7.770 +                }
   7.771 +            }
   7.772 +        }
   7.773 +    }
   7.774  
   7.775  done:
   7.776  
   7.777 -	if ( MiniBuf ) SDL_free( MiniBuf );
   7.778 +    if ( MiniBuf ) SDL_free( MiniBuf );
   7.779  
   7.780 -	if ( error )
   7.781 -	{
   7.782 -		SDL_RWseek(src, start, RW_SEEK_SET);
   7.783 -		if ( Image ) {
   7.784 -			SDL_FreeSurface( Image );
   7.785 -			Image = NULL;
   7.786 -		}
   7.787 -		IMG_SetError( error );
   7.788 -	}
   7.789 +    if ( error )
   7.790 +    {
   7.791 +        SDL_RWseek(src, start, RW_SEEK_SET);
   7.792 +        if ( Image ) {
   7.793 +            SDL_FreeSurface( Image );
   7.794 +            Image = NULL;
   7.795 +        }
   7.796 +        IMG_SetError( error );
   7.797 +    }
   7.798  
   7.799 -	return( Image );
   7.800 +    return( Image );
   7.801  }
   7.802  
   7.803  #else /* LOAD_LBM */
   7.804 @@ -487,13 +487,13 @@
   7.805  /* See if an image is contained in a data source */
   7.806  int IMG_isLBM(SDL_RWops *src)
   7.807  {
   7.808 -	return(0);
   7.809 +    return(0);
   7.810  }
   7.811  
   7.812  /* Load an IFF type image from an SDL datasource */
   7.813  SDL_Surface *IMG_LoadLBM_RW(SDL_RWops *src)
   7.814  {
   7.815 -	return(NULL);
   7.816 +    return(NULL);
   7.817  }
   7.818  
   7.819  #endif /* LOAD_LBM */
     8.1 --- a/IMG_pcx.c	Thu Apr 25 00:22:51 2013 -0700
     8.2 +++ b/IMG_pcx.c	Tue May 21 21:24:32 2013 -0700
     8.3 @@ -42,221 +42,221 @@
     8.4  #ifdef LOAD_PCX
     8.5  
     8.6  struct PCXheader {
     8.7 -	Uint8 Manufacturer;
     8.8 -	Uint8 Version;
     8.9 -	Uint8 Encoding;
    8.10 -	Uint8 BitsPerPixel;
    8.11 -	Sint16 Xmin, Ymin, Xmax, Ymax;
    8.12 -	Sint16 HDpi, VDpi;
    8.13 -	Uint8 Colormap[48];
    8.14 -	Uint8 Reserved;
    8.15 -	Uint8 NPlanes;
    8.16 -	Sint16 BytesPerLine;
    8.17 -	Sint16 PaletteInfo;
    8.18 -	Sint16 HscreenSize;
    8.19 -	Sint16 VscreenSize;
    8.20 -	Uint8 Filler[54];
    8.21 +    Uint8 Manufacturer;
    8.22 +    Uint8 Version;
    8.23 +    Uint8 Encoding;
    8.24 +    Uint8 BitsPerPixel;
    8.25 +    Sint16 Xmin, Ymin, Xmax, Ymax;
    8.26 +    Sint16 HDpi, VDpi;
    8.27 +    Uint8 Colormap[48];
    8.28 +    Uint8 Reserved;
    8.29 +    Uint8 NPlanes;
    8.30 +    Sint16 BytesPerLine;
    8.31 +    Sint16 PaletteInfo;
    8.32 +    Sint16 HscreenSize;
    8.33 +    Sint16 VscreenSize;
    8.34 +    Uint8 Filler[54];
    8.35  };
    8.36  
    8.37  /* See if an image is contained in a data source */
    8.38  int IMG_isPCX(SDL_RWops *src)
    8.39  {
    8.40 -	Sint64 start;
    8.41 -	int is_PCX;
    8.42 -	const int ZSoft_Manufacturer = 10;
    8.43 -	const int PC_Paintbrush_Version = 5;
    8.44 -	const int PCX_Uncompressed_Encoding = 0;
    8.45 -	const int PCX_RunLength_Encoding = 1;
    8.46 -	struct PCXheader pcxh;
    8.47 +    Sint64 start;
    8.48 +    int is_PCX;
    8.49 +    const int ZSoft_Manufacturer = 10;
    8.50 +    const int PC_Paintbrush_Version = 5;
    8.51 +    const int PCX_Uncompressed_Encoding = 0;
    8.52 +    const int PCX_RunLength_Encoding = 1;
    8.53 +    struct PCXheader pcxh;
    8.54  
    8.55 -	if ( !src )
    8.56 -		return 0;
    8.57 -	start = SDL_RWtell(src);
    8.58 -	is_PCX = 0;
    8.59 -	if ( SDL_RWread(src, &pcxh, sizeof(pcxh), 1) == 1 ) {
    8.60 -		if ( (pcxh.Manufacturer == ZSoft_Manufacturer) &&
    8.61 -		     (pcxh.Version == PC_Paintbrush_Version) &&
    8.62 -		     (pcxh.Encoding == PCX_RunLength_Encoding ||
    8.63 -		      pcxh.Encoding == PCX_Uncompressed_Encoding) ) {
    8.64 -			is_PCX = 1;
    8.65 -		}
    8.66 -	}
    8.67 -	SDL_RWseek(src, start, RW_SEEK_SET);
    8.68 -	return(is_PCX);
    8.69 +    if ( !src )
    8.70 +        return 0;
    8.71 +    start = SDL_RWtell(src);
    8.72 +    is_PCX = 0;
    8.73 +    if ( SDL_RWread(src, &pcxh, sizeof(pcxh), 1) == 1 ) {
    8.74 +        if ( (pcxh.Manufacturer == ZSoft_Manufacturer) &&
    8.75 +             (pcxh.Version == PC_Paintbrush_Version) &&
    8.76 +             (pcxh.Encoding == PCX_RunLength_Encoding ||
    8.77 +              pcxh.Encoding == PCX_Uncompressed_Encoding) ) {
    8.78 +            is_PCX = 1;
    8.79 +        }
    8.80 +    }
    8.81 +    SDL_RWseek(src, start, RW_SEEK_SET);
    8.82 +    return(is_PCX);
    8.83  }
    8.84  
    8.85  /* Load a PCX type image from an SDL datasource */
    8.86  SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src)
    8.87  {
    8.88 -	Sint64 start;
    8.89 -	struct PCXheader pcxh;
    8.90 -	Uint32 Rmask;
    8.91 -	Uint32 Gmask;
    8.92 -	Uint32 Bmask;
    8.93 -	Uint32 Amask;
    8.94 -	SDL_Surface *surface = NULL;
    8.95 -	int width, height;
    8.96 -	int y, bpl;
    8.97 -	Uint8 *row, *buf = NULL;
    8.98 -	char *error = NULL;
    8.99 -	int bits, src_bits;
   8.100 +    Sint64 start;
   8.101 +    struct PCXheader pcxh;
   8.102 +    Uint32 Rmask;
   8.103 +    Uint32 Gmask;
   8.104 +    Uint32 Bmask;
   8.105 +    Uint32 Amask;
   8.106 +    SDL_Surface *surface = NULL;
   8.107 +    int width, height;
   8.108 +    int y, bpl;
   8.109 +    Uint8 *row, *buf = NULL;
   8.110 +    char *error = NULL;
   8.111 +    int bits, src_bits;
   8.112  
   8.113 -	if ( !src ) {
   8.114 -		/* The error message has been set in SDL_RWFromFile */
   8.115 -		return NULL;
   8.116 -	}
   8.117 -	start = SDL_RWtell(src);
   8.118 +    if ( !src ) {
   8.119 +        /* The error message has been set in SDL_RWFromFile */
   8.120 +        return NULL;
   8.121 +    }
   8.122 +    start = SDL_RWtell(src);
   8.123  
   8.124 -	if ( ! SDL_RWread(src, &pcxh, sizeof(pcxh), 1) ) {
   8.125 -		error = "file truncated";
   8.126 -		goto done;
   8.127 -	}
   8.128 -	pcxh.Xmin = SDL_SwapLE16(pcxh.Xmin);
   8.129 -	pcxh.Ymin = SDL_SwapLE16(pcxh.Ymin);
   8.130 -	pcxh.Xmax = SDL_SwapLE16(pcxh.Xmax);
   8.131 -	pcxh.Ymax = SDL_SwapLE16(pcxh.Ymax);
   8.132 -	pcxh.BytesPerLine = SDL_SwapLE16(pcxh.BytesPerLine);
   8.133 +    if ( ! SDL_RWread(src, &pcxh, sizeof(pcxh), 1) ) {
   8.134 +        error = "file truncated";
   8.135 +        goto done;
   8.136 +    }
   8.137 +    pcxh.Xmin = SDL_SwapLE16(pcxh.Xmin);
   8.138 +    pcxh.Ymin = SDL_SwapLE16(pcxh.Ymin);
   8.139 +    pcxh.Xmax = SDL_SwapLE16(pcxh.Xmax);
   8.140 +    pcxh.Ymax = SDL_SwapLE16(pcxh.Ymax);
   8.141 +    pcxh.BytesPerLine = SDL_SwapLE16(pcxh.BytesPerLine);
   8.142  
   8.143 -	/* Create the surface of the appropriate type */
   8.144 -	width = (pcxh.Xmax - pcxh.Xmin) + 1;
   8.145 -	height = (pcxh.Ymax - pcxh.Ymin) + 1;
   8.146 -	Rmask = Gmask = Bmask = Amask = 0;
   8.147 -	src_bits = pcxh.BitsPerPixel * pcxh.NPlanes;
   8.148 -	if((pcxh.BitsPerPixel == 1 && pcxh.NPlanes >= 1 && pcxh.NPlanes <= 4)
   8.149 -	   || (pcxh.BitsPerPixel == 8 && pcxh.NPlanes == 1)) {
   8.150 -		bits = 8;
   8.151 -	} else if(pcxh.BitsPerPixel == 8 && pcxh.NPlanes == 3) {
   8.152 -		bits = 24;
   8.153 +    /* Create the surface of the appropriate type */
   8.154 +    width = (pcxh.Xmax - pcxh.Xmin) + 1;
   8.155 +    height = (pcxh.Ymax - pcxh.Ymin) + 1;
   8.156 +    Rmask = Gmask = Bmask = Amask = 0;
   8.157 +    src_bits = pcxh.BitsPerPixel * pcxh.NPlanes;
   8.158 +    if((pcxh.BitsPerPixel == 1 && pcxh.NPlanes >= 1 && pcxh.NPlanes <= 4)
   8.159 +       || (pcxh.BitsPerPixel == 8 && pcxh.NPlanes == 1)) {
   8.160 +        bits = 8;
   8.161 +    } else if(pcxh.BitsPerPixel == 8 && pcxh.NPlanes == 3) {
   8.162 +        bits = 24;
   8.163  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   8.164 -			Rmask = 0x000000FF;
   8.165 -			Gmask = 0x0000FF00;
   8.166 -			Bmask = 0x00FF0000;
   8.167 +            Rmask = 0x000000FF;
   8.168 +            Gmask = 0x0000FF00;
   8.169 +            Bmask = 0x00FF0000;
   8.170  #else
   8.171 -			Rmask = 0xFF0000;
   8.172 -			Gmask = 0x00FF00;
   8.173 -			Bmask = 0x0000FF;
   8.174 +            Rmask = 0xFF0000;
   8.175 +            Gmask = 0x00FF00;
   8.176 +            Bmask = 0x0000FF;
   8.177  #endif
   8.178 -	} else {
   8.179 -		error = "unsupported PCX format";
   8.180 -		goto done;
   8.181 -	}
   8.182 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
   8.183 -				   bits, Rmask, Gmask, Bmask, Amask);
   8.184 -	if ( surface == NULL )
   8.185 -		goto done;
   8.186 +    } else {
   8.187 +        error = "unsupported PCX format";
   8.188 +        goto done;
   8.189 +    }
   8.190 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
   8.191 +                   bits, Rmask, Gmask, Bmask, Amask);
   8.192 +    if ( surface == NULL )
   8.193 +        goto done;
   8.194  
   8.195 -	bpl = pcxh.NPlanes * pcxh.BytesPerLine;
   8.196 -	if (bpl > surface->pitch) {
   8.197 -		error = "bytes per line is too large (corrupt?)";
   8.198 -	}
   8.199 -	buf = (Uint8 *)SDL_malloc(bpl);
   8.200 -	row = (Uint8 *)surface->pixels;
   8.201 -	for ( y=0; y<surface->h; ++y ) {
   8.202 -		/* decode a scan line to a temporary buffer first */
   8.203 -		int i, count = 0;
   8.204 -		Uint8 ch;
   8.205 -		Uint8 *dst = (src_bits == 8) ? row : buf;
   8.206 -		if ( pcxh.Encoding == 0 ) {
   8.207 -			if(!SDL_RWread(src, dst, bpl, 1)) {
   8.208 -				error = "file truncated";
   8.209 -				goto done;
   8.210 -			}
   8.211 -		} else {
   8.212 -			for(i = 0; i < bpl; i++) {
   8.213 -				if(!count) {
   8.214 -					if(!SDL_RWread(src, &ch, 1, 1)) {
   8.215 -						error = "file truncated";
   8.216 -						goto done;
   8.217 -					}
   8.218 -					if( (ch & 0xc0) == 0xc0) {
   8.219 -						count = ch & 0x3f;
   8.220 -						if(!SDL_RWread(src, &ch, 1, 1)) {
   8.221 -							error = "file truncated";
   8.222 -							goto done;
   8.223 -						}
   8.224 -					} else
   8.225 -						count = 1;
   8.226 -				}
   8.227 -				dst[i] = ch;
   8.228 -				count--;
   8.229 -			}
   8.230 -		}
   8.231 +    bpl = pcxh.NPlanes * pcxh.BytesPerLine;
   8.232 +    if (bpl > surface->pitch) {
   8.233 +        error = "bytes per line is too large (corrupt?)";
   8.234 +    }
   8.235 +    buf = (Uint8 *)SDL_malloc(bpl);
   8.236 +    row = (Uint8 *)surface->pixels;
   8.237 +    for ( y=0; y<surface->h; ++y ) {
   8.238 +        /* decode a scan line to a temporary buffer first */
   8.239 +        int i, count = 0;
   8.240 +        Uint8 ch;
   8.241 +        Uint8 *dst = (src_bits == 8) ? row : buf;
   8.242 +        if ( pcxh.Encoding == 0 ) {
   8.243 +            if(!SDL_RWread(src, dst, bpl, 1)) {
   8.244 +                error = "file truncated";
   8.245 +                goto done;
   8.246 +            }
   8.247 +        } else {
   8.248 +            for(i = 0; i < bpl; i++) {
   8.249 +                if(!count) {
   8.250 +                    if(!SDL_RWread(src, &ch, 1, 1)) {
   8.251 +                        error = "file truncated";
   8.252 +                        goto done;
   8.253 +                    }
   8.254 +                    if( (ch & 0xc0) == 0xc0) {
   8.255 +                        count = ch & 0x3f;
   8.256 +                        if(!SDL_RWread(src, &ch, 1, 1)) {
   8.257 +                            error = "file truncated";
   8.258 +                            goto done;
   8.259 +                        }
   8.260 +                    } else
   8.261 +                        count = 1;
   8.262 +                }
   8.263 +                dst[i] = ch;
   8.264 +                count--;
   8.265 +            }
   8.266 +        }
   8.267  
   8.268 -		if(src_bits <= 4) {
   8.269 -			/* expand planes to 1 byte/pixel */
   8.270 -			Uint8 *innerSrc = buf;
   8.271 -			int plane;
   8.272 -			for(plane = 0; plane < pcxh.NPlanes; plane++) {
   8.273 -				int j, k, x = 0;
   8.274 -				for(j = 0; j < pcxh.BytesPerLine; j++) {
   8.275 -					Uint8 byte = *innerSrc++;
   8.276 -					for(k = 7; k >= 0; k--) {
   8.277 -						unsigned bit = (byte >> k) & 1;
   8.278 -						/* skip padding bits */
   8.279 -						if (j * 8 + k >= width)
   8.280 -							continue;
   8.281 -						row[x++] |= bit << plane;
   8.282 -					}
   8.283 -				}
   8.284 -			}
   8.285 - 		} else if(src_bits == 24) {
   8.286 -			/* de-interlace planes */
   8.287 -			Uint8 *innerSrc = buf;
   8.288 -			int plane;
   8.289 -			for(plane = 0; plane < pcxh.NPlanes; plane++) {
   8.290 -				int x;
   8.291 -				dst = row + plane;
   8.292 -				for(x = 0; x < width; x++) {
   8.293 -					*dst = *innerSrc++;
   8.294 -					dst += pcxh.NPlanes;
   8.295 -				}
   8.296 -			}
   8.297 -		}
   8.298 +        if(src_bits <= 4) {
   8.299 +            /* expand planes to 1 byte/pixel */
   8.300 +            Uint8 *innerSrc = buf;
   8.301 +            int plane;
   8.302 +            for(plane = 0; plane < pcxh.NPlanes; plane++) {
   8.303 +                int j, k, x = 0;
   8.304 +                for(j = 0; j < pcxh.BytesPerLine; j++) {
   8.305 +                    Uint8 byte = *innerSrc++;
   8.306 +                    for(k = 7; k >= 0; k--) {
   8.307 +                        unsigned bit = (byte >> k) & 1;
   8.308 +                        /* skip padding bits */
   8.309 +                        if (j * 8 + k >= width)
   8.310 +                            continue;
   8.311 +                        row[x++] |= bit << plane;
   8.312 +                    }
   8.313 +                }
   8.314 +            }
   8.315 +        } else if(src_bits == 24) {
   8.316 +            /* de-interlace planes */
   8.317 +            Uint8 *innerSrc = buf;
   8.318 +            int plane;
   8.319 +            for(plane = 0; plane < pcxh.NPlanes; plane++) {
   8.320 +                int x;
   8.321 +                dst = row + plane;
   8.322 +                for(x = 0; x < width; x++) {
   8.323 +                    *dst = *innerSrc++;
   8.324 +                    dst += pcxh.NPlanes;
   8.325 +                }
   8.326 +            }
   8.327 +        }
   8.328  
   8.329 -		row += surface->pitch;
   8.330 -	}
   8.331 +        row += surface->pitch;
   8.332 +    }
   8.333  
   8.334 -	if(bits == 8) {
   8.335 -		SDL_Color *colors = surface->format->palette->colors;
   8.336 -		int nc = 1 << src_bits;
   8.337 -		int i;
   8.338 +    if(bits == 8) {
   8.339 +        SDL_Color *colors = surface->format->palette->colors;
   8.340 +        int nc = 1 << src_bits;
   8.341 +        int i;
   8.342  
   8.343 -		surface->format->palette->ncolors = nc;
   8.344 -		if(src_bits == 8) {
   8.345 -			Uint8 ch;
   8.346 -			/* look for a 256-colour palette */
   8.347 -			do {
   8.348 -				if ( !SDL_RWread(src, &ch, 1, 1)) {
   8.349 -					error = "file truncated";
   8.350 -					goto done;
   8.351 -				}
   8.352 -			} while ( ch != 12 );
   8.353 +        surface->format->palette->ncolors = nc;
   8.354 +        if(src_bits == 8) {
   8.355 +            Uint8 ch;
   8.356 +            /* look for a 256-colour palette */
   8.357 +            do {
   8.358 +                if ( !SDL_RWread(src, &ch, 1, 1)) {
   8.359 +                    error = "file truncated";
   8.360 +                    goto done;
   8.361 +                }
   8.362 +            } while ( ch != 12 );
   8.363  
   8.364 -			for(i = 0; i < 256; i++) {
   8.365 -				SDL_RWread(src, &colors[i].r, 1, 1);
   8.366 -				SDL_RWread(src, &colors[i].g, 1, 1);
   8.367 -				SDL_RWread(src, &colors[i].b, 1, 1);
   8.368 -			}
   8.369 -		} else {
   8.370 -			for(i = 0; i < nc; i++) {
   8.371 -				colors[i].r = pcxh.Colormap[i * 3];
   8.372 -				colors[i].g = pcxh.Colormap[i * 3 + 1];
   8.373 -				colors[i].b = pcxh.Colormap[i * 3 + 2];
   8.374 -			}
   8.375 -		}
   8.376 -	}
   8.377 +            for(i = 0; i < 256; i++) {
   8.378 +                SDL_RWread(src, &colors[i].r, 1, 1);
   8.379 +                SDL_RWread(src, &colors[i].g, 1, 1);
   8.380 +                SDL_RWread(src, &colors[i].b, 1, 1);
   8.381 +            }
   8.382 +        } else {
   8.383 +            for(i = 0; i < nc; i++) {
   8.384 +                colors[i].r = pcxh.Colormap[i * 3];
   8.385 +                colors[i].g = pcxh.Colormap[i * 3 + 1];
   8.386 +                colors[i].b = pcxh.Colormap[i * 3 + 2];
   8.387 +            }
   8.388 +        }
   8.389 +    }
   8.390  
   8.391  done:
   8.392 -	SDL_free(buf);
   8.393 -	if ( error ) {
   8.394 -		SDL_RWseek(src, start, RW_SEEK_SET);
   8.395 -		if ( surface ) {
   8.396 -			SDL_FreeSurface(surface);
   8.397 -			surface = NULL;
   8.398 -		}
   8.399 -		IMG_SetError(error);
   8.400 -	}
   8.401 -	return(surface);
   8.402 +    SDL_free(buf);
   8.403 +    if ( error ) {
   8.404 +        SDL_RWseek(src, start, RW_SEEK_SET);
   8.405 +        if ( surface ) {
   8.406 +            SDL_FreeSurface(surface);
   8.407 +            surface = NULL;
   8.408 +        }
   8.409 +        IMG_SetError(error);
   8.410 +    }
   8.411 +    return(surface);
   8.412  }
   8.413  
   8.414  #else
   8.415 @@ -264,13 +264,13 @@
   8.416  /* See if an image is contained in a data source */
   8.417  int IMG_isPCX(SDL_RWops *src)
   8.418  {
   8.419 -	return(0);
   8.420 +    return(0);
   8.421  }
   8.422  
   8.423  /* Load a PCX type image from an SDL datasource */
   8.424  SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src)
   8.425  {
   8.426 -	return(NULL);
   8.427 +    return(NULL);
   8.428  }
   8.429  
   8.430  #endif /* LOAD_PCX */
     9.1 --- a/IMG_png.c	Thu Apr 25 00:22:51 2013 -0700
     9.2 +++ b/IMG_png.c	Tue May 21 21:24:32 2013 -0700
     9.3 @@ -32,25 +32,25 @@
     9.4  
     9.5  /*=============================================================================
     9.6          File: SDL_png.c
     9.7 -     Purpose: A PNG loader and saver for the SDL library      
     9.8 -    Revision: 
     9.9 +     Purpose: A PNG loader and saver for the SDL library
    9.10 +    Revision:
    9.11    Created by: Philippe Lavoie          (2 November 1998)
    9.12                lavoie@zeus.genie.uottawa.ca
    9.13 - Modified by: 
    9.14 + Modified by:
    9.15  
    9.16   Copyright notice:
    9.17            Copyright (C) 1998 Philippe Lavoie
    9.18 - 
    9.19 +
    9.20            This library is free software; you can redistribute it and/or
    9.21            modify it under the terms of the GNU Library General Public
    9.22            License as published by the Free Software Foundation; either
    9.23            version 2 of the License, or (at your option) any later version.
    9.24 - 
    9.25 +
    9.26            This library is distributed in the hope that it will be useful,
    9.27            but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.28            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.29            Library General Public License for more details.
    9.30 - 
    9.31 +
    9.32            You should have received a copy of the GNU Library General Public
    9.33            License along with this library; if not, write to the Free
    9.34            Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    9.35 @@ -76,488 +76,488 @@
    9.36  #endif
    9.37  
    9.38  static struct {
    9.39 -	int loaded;
    9.40 -	void *handle;
    9.41 -	png_infop (*png_create_info_struct) (png_structp png_ptr);
    9.42 -	png_structp (*png_create_read_struct) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn);
    9.43 -	void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
    9.44 -	png_uint_32 (*png_get_IHDR) (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method);
    9.45 -	png_voidp (*png_get_io_ptr) (png_structp png_ptr);
    9.46 -	png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
    9.47 -	png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
    9.48 -	png_uint_32 (*png_get_tRNS) (png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values);
    9.49 -	png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
    9.50 -	void (*png_read_image) (png_structp png_ptr, png_bytepp image);
    9.51 -	void (*png_read_info) (png_structp png_ptr, png_infop info_ptr);
    9.52 -	void (*png_read_update_info) (png_structp png_ptr, png_infop info_ptr);
    9.53 -	void (*png_set_expand) (png_structp png_ptr);
    9.54 -	void (*png_set_gray_to_rgb) (png_structp png_ptr);
    9.55 -	void (*png_set_packing) (png_structp png_ptr);
    9.56 -	void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
    9.57 -	void (*png_set_strip_16) (png_structp png_ptr);
    9.58 -	int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
    9.59 +    int loaded;
    9.60 +    void *handle;
    9.61 +    png_infop (*png_create_info_struct) (png_structp png_ptr);
    9.62 +    png_structp (*png_create_read_struct) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn);
    9.63 +    void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
    9.64 +    png_uint_32 (*png_get_IHDR) (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method);
    9.65 +    png_voidp (*png_get_io_ptr) (png_structp png_ptr);
    9.66 +    png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
    9.67 +    png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
    9.68 +    png_uint_32 (*png_get_tRNS) (png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values);
    9.69 +    png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
    9.70 +    void (*png_read_image) (png_structp png_ptr, png_bytepp image);
    9.71 +    void (*png_read_info) (png_structp png_ptr, png_infop info_ptr);
    9.72 +    void (*png_read_update_info) (png_structp png_ptr, png_infop info_ptr);
    9.73 +    void (*png_set_expand) (png_structp png_ptr);
    9.74 +    void (*png_set_gray_to_rgb) (png_structp png_ptr);
    9.75 +    void (*png_set_packing) (png_structp png_ptr);
    9.76 +    void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
    9.77 +    void (*png_set_strip_16) (png_structp png_ptr);
    9.78 +    int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
    9.79  #ifndef LIBPNG_VERSION_12
    9.80 -	jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
    9.81 +    jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
    9.82  #endif
    9.83  } lib;
    9.84  
    9.85  #ifdef LOAD_PNG_DYNAMIC
    9.86  int IMG_InitPNG()
    9.87  {
    9.88 -	if ( lib.loaded == 0 ) {
    9.89 -		lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC);
    9.90 -		if ( lib.handle == NULL ) {
    9.91 -			return -1;
    9.92 -		}
    9.93 -		lib.png_create_info_struct =
    9.94 -			(png_infop (*) (png_structp))
    9.95 -			SDL_LoadFunction(lib.handle, "png_create_info_struct");
    9.96 -		if ( lib.png_create_info_struct == NULL ) {
    9.97 -			SDL_UnloadObject(lib.handle);
    9.98 -			return -1;
    9.99 -		}
   9.100 -		lib.png_create_read_struct =
   9.101 -			(png_structp (*) (png_const_charp, png_voidp, png_error_ptr, png_error_ptr))
   9.102 -			SDL_LoadFunction(lib.handle, "png_create_read_struct");
   9.103 -		if ( lib.png_create_read_struct == NULL ) {
   9.104 -			SDL_UnloadObject(lib.handle);
   9.105 -			return -1;
   9.106 -		}
   9.107 -		lib.png_destroy_read_struct =
   9.108 -			(void (*) (png_structpp, png_infopp, png_infopp))
   9.109 -			SDL_LoadFunction(lib.handle, "png_destroy_read_struct");
   9.110 -		if ( lib.png_destroy_read_struct == NULL ) {
   9.111 -			SDL_UnloadObject(lib.handle);
   9.112 -			return -1;
   9.113 -		}
   9.114 -		lib.png_get_IHDR =
   9.115 -			(png_uint_32 (*) (png_structp, png_infop, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *))
   9.116 -			SDL_LoadFunction(lib.handle, "png_get_IHDR");
   9.117 -		if ( lib.png_get_IHDR == NULL ) {
   9.118 -			SDL_UnloadObject(lib.handle);
   9.119 -			return -1;
   9.120 -		}
   9.121 -		lib.png_get_channels =
   9.122 -			(png_byte (*) (png_structp, png_infop))
   9.123 -			SDL_LoadFunction(lib.handle, "png_get_channels");
   9.124 -		if ( lib.png_get_channels == NULL ) {
   9.125 -			SDL_UnloadObject(lib.handle);
   9.126 -			return -1;
   9.127 -		}
   9.128 -		lib.png_get_io_ptr =
   9.129 -			(png_voidp (*) (png_structp))
   9.130 -			SDL_LoadFunction(lib.handle, "png_get_io_ptr");
   9.131 -		if ( lib.png_get_io_ptr == NULL ) {
   9.132 -			SDL_UnloadObject(lib.handle);
   9.133 -			return -1;
   9.134 -		}
   9.135 -		lib.png_get_PLTE =
   9.136 -			(png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
   9.137 -			SDL_LoadFunction(lib.handle, "png_get_PLTE");
   9.138 -		if ( lib.png_get_PLTE == NULL ) {
   9.139 -			SDL_UnloadObject(lib.handle);
   9.140 -			return -1;
   9.141 -		}
   9.142 -		lib.png_get_tRNS =
   9.143 -			(png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
   9.144 -			SDL_LoadFunction(lib.handle, "png_get_tRNS");
   9.145 -		if ( lib.png_get_tRNS == NULL ) {
   9.146 -			SDL_UnloadObject(lib.handle);
   9.147 -			return -1;
   9.148 -		}
   9.149 -		lib.png_get_valid =
   9.150 -			(png_uint_32 (*) (png_structp, png_infop, png_uint_32))
   9.151 -			SDL_LoadFunction(lib.handle, "png_get_valid");
   9.152 -		if ( lib.png_get_valid == NULL ) {
   9.153 -			SDL_UnloadObject(lib.handle);
   9.154 -			return -1;
   9.155 -		}
   9.156 -		lib.png_read_image =
   9.157 -			(void (*) (png_structp, png_bytepp))
   9.158 -			SDL_LoadFunction(lib.handle, "png_read_image");
   9.159 -		if ( lib.png_read_image == NULL ) {
   9.160 -			SDL_UnloadObject(lib.handle);
   9.161 -			return -1;
   9.162 -		}
   9.163 -		lib.png_read_info =
   9.164 -			(void (*) (png_structp, png_infop))
   9.165 -			SDL_LoadFunction(lib.handle, "png_read_info");
   9.166 -		if ( lib.png_read_info == NULL ) {
   9.167 -			SDL_UnloadObject(lib.handle);
   9.168 -			return -1;
   9.169 -		}
   9.170 -		lib.png_read_update_info =
   9.171 -			(void (*) (png_structp, png_infop))
   9.172 -			SDL_LoadFunction(lib.handle, "png_read_update_info");
   9.173 -		if ( lib.png_read_update_info == NULL ) {
   9.174 -			SDL_UnloadObject(lib.handle);
   9.175 -			return -1;
   9.176 -		}
   9.177 -		lib.png_set_expand =
   9.178 -			(void (*) (png_structp))
   9.179 -			SDL_LoadFunction(lib.handle, "png_set_expand");
   9.180 -		if ( lib.png_set_expand == NULL ) {
   9.181 -			SDL_UnloadObject(lib.handle);
   9.182 -			return -1;
   9.183 -		}
   9.184 -		lib.png_set_gray_to_rgb =
   9.185 -			(void (*) (png_structp))
   9.186 -			SDL_LoadFunction(lib.handle, "png_set_gray_to_rgb");
   9.187 -		if ( lib.png_set_gray_to_rgb == NULL ) {
   9.188 -			SDL_UnloadObject(lib.handle);
   9.189 -			return -1;
   9.190 -		}
   9.191 -		lib.png_set_packing =
   9.192 -			(void (*) (png_structp))
   9.193 -			SDL_LoadFunction(lib.handle, "png_set_packing");
   9.194 -		if ( lib.png_set_packing == NULL ) {
   9.195 -			SDL_UnloadObject(lib.handle);
   9.196 -			return -1;
   9.197 -		}
   9.198 -		lib.png_set_read_fn =
   9.199 -			(void (*) (png_structp, png_voidp, png_rw_ptr))
   9.200 -			SDL_LoadFunction(lib.handle, "png_set_read_fn");
   9.201 -		if ( lib.png_set_read_fn == NULL ) {
   9.202 -			SDL_UnloadObject(lib.handle);
   9.203 -			return -1;
   9.204 -		}
   9.205 -		lib.png_set_strip_16 =
   9.206 -			(void (*) (png_structp))
   9.207 -			SDL_LoadFunction(lib.handle, "png_set_strip_16");
   9.208 -		if ( lib.png_set_strip_16 == NULL ) {
   9.209 -			SDL_UnloadObject(lib.handle);
   9.210 -			return -1;
   9.211 -		}
   9.212 -		lib.png_sig_cmp =
   9.213 -			(int (*) (png_bytep, png_size_t, png_size_t))
   9.214 -			SDL_LoadFunction(lib.handle, "png_sig_cmp");
   9.215 -		if ( lib.png_sig_cmp == NULL ) {
   9.216 -			SDL_UnloadObject(lib.handle);
   9.217 -			return -1;
   9.218 -		}
   9.219 +    if ( lib.loaded == 0 ) {
   9.220 +        lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC);
   9.221 +        if ( lib.handle == NULL ) {
   9.222 +            return -1;
   9.223 +        }
   9.224 +        lib.png_create_info_struct =
   9.225 +            (png_infop (*) (png_structp))
   9.226 +            SDL_LoadFunction(lib.handle, "png_create_info_struct");
   9.227 +        if ( lib.png_create_info_struct == NULL ) {
   9.228 +            SDL_UnloadObject(lib.handle);
   9.229 +            return -1;
   9.230 +        }
   9.231 +        lib.png_create_read_struct =
   9.232 +            (png_structp (*) (png_const_charp, png_voidp, png_error_ptr, png_error_ptr))
   9.233 +            SDL_LoadFunction(lib.handle, "png_create_read_struct");
   9.234 +        if ( lib.png_create_read_struct == NULL ) {
   9.235 +            SDL_UnloadObject(lib.handle);
   9.236 +            return -1;
   9.237 +        }
   9.238 +        lib.png_destroy_read_struct =
   9.239 +            (void (*) (png_structpp, png_infopp, png_infopp))
   9.240 +            SDL_LoadFunction(lib.handle, "png_destroy_read_struct");
   9.241 +        if ( lib.png_destroy_read_struct == NULL ) {
   9.242 +            SDL_UnloadObject(lib.handle);
   9.243 +            return -1;
   9.244 +        }
   9.245 +        lib.png_get_IHDR =
   9.246 +            (png_uint_32 (*) (png_structp, png_infop, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *))
   9.247 +            SDL_LoadFunction(lib.handle, "png_get_IHDR");
   9.248 +        if ( lib.png_get_IHDR == NULL ) {
   9.249 +            SDL_UnloadObject(lib.handle);
   9.250 +            return -1;
   9.251 +        }
   9.252 +        lib.png_get_channels =
   9.253 +            (png_byte (*) (png_structp, png_infop))
   9.254 +            SDL_LoadFunction(lib.handle, "png_get_channels");
   9.255 +        if ( lib.png_get_channels == NULL ) {
   9.256 +            SDL_UnloadObject(lib.handle);
   9.257 +            return -1;
   9.258 +        }
   9.259 +        lib.png_get_io_ptr =
   9.260 +            (png_voidp (*) (png_structp))
   9.261 +            SDL_LoadFunction(lib.handle, "png_get_io_ptr");
   9.262 +        if ( lib.png_get_io_ptr == NULL ) {
   9.263 +            SDL_UnloadObject(lib.handle);
   9.264 +            return -1;
   9.265 +        }
   9.266 +        lib.png_get_PLTE =
   9.267 +            (png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
   9.268 +            SDL_LoadFunction(lib.handle, "png_get_PLTE");
   9.269 +        if ( lib.png_get_PLTE == NULL ) {
   9.270 +            SDL_UnloadObject(lib.handle);
   9.271 +            return -1;
   9.272 +        }
   9.273 +        lib.png_get_tRNS =
   9.274 +            (png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
   9.275 +            SDL_LoadFunction(lib.handle, "png_get_tRNS");
   9.276 +        if ( lib.png_get_tRNS == NULL ) {
   9.277 +            SDL_UnloadObject(lib.handle);
   9.278 +            return -1;
   9.279 +        }
   9.280 +        lib.png_get_valid =
   9.281 +            (png_uint_32 (*) (png_structp, png_infop, png_uint_32))
   9.282 +            SDL_LoadFunction(lib.handle, "png_get_valid");
   9.283 +        if ( lib.png_get_valid == NULL ) {
   9.284 +            SDL_UnloadObject(lib.handle);
   9.285 +            return -1;
   9.286 +        }
   9.287 +        lib.png_read_image =
   9.288 +            (void (*) (png_structp, png_bytepp))
   9.289 +            SDL_LoadFunction(lib.handle, "png_read_image");
   9.290 +        if ( lib.png_read_image == NULL ) {
   9.291 +            SDL_UnloadObject(lib.handle);
   9.292 +            return -1;
   9.293 +        }
   9.294 +        lib.png_read_info =
   9.295 +            (void (*) (png_structp, png_infop))
   9.296 +            SDL_LoadFunction(lib.handle, "png_read_info");
   9.297 +        if ( lib.png_read_info == NULL ) {
   9.298 +            SDL_UnloadObject(lib.handle);
   9.299 +            return -1;
   9.300 +        }
   9.301 +        lib.png_read_update_info =
   9.302 +            (void (*) (png_structp, png_infop))
   9.303 +            SDL_LoadFunction(lib.handle, "png_read_update_info");
   9.304 +        if ( lib.png_read_update_info == NULL ) {
   9.305 +            SDL_UnloadObject(lib.handle);
   9.306 +            return -1;
   9.307 +        }
   9.308 +        lib.png_set_expand =
   9.309 +            (void (*) (png_structp))
   9.310 +            SDL_LoadFunction(lib.handle, "png_set_expand");
   9.311 +        if ( lib.png_set_expand == NULL ) {
   9.312 +            SDL_UnloadObject(lib.handle);
   9.313 +            return -1;
   9.314 +        }
   9.315 +        lib.png_set_gray_to_rgb =
   9.316 +            (void (*) (png_structp))
   9.317 +            SDL_LoadFunction(lib.handle, "png_set_gray_to_rgb");
   9.318 +        if ( lib.png_set_gray_to_rgb == NULL ) {
   9.319 +            SDL_UnloadObject(lib.handle);
   9.320 +            return -1;
   9.321 +        }
   9.322 +        lib.png_set_packing =
   9.323 +            (void (*) (png_structp))
   9.324 +            SDL_LoadFunction(lib.handle, "png_set_packing");
   9.325 +        if ( lib.png_set_packing == NULL ) {
   9.326 +            SDL_UnloadObject(lib.handle);
   9.327 +            return -1;
   9.328 +        }
   9.329 +        lib.png_set_read_fn =
   9.330 +            (void (*) (png_structp, png_voidp, png_rw_ptr))
   9.331 +            SDL_LoadFunction(lib.handle, "png_set_read_fn");
   9.332 +        if ( lib.png_set_read_fn == NULL ) {
   9.333 +            SDL_UnloadObject(lib.handle);
   9.334 +            return -1;
   9.335 +        }
   9.336 +        lib.png_set_strip_16 =
   9.337 +            (void (*) (png_structp))
   9.338 +            SDL_LoadFunction(lib.handle, "png_set_strip_16");
   9.339 +        if ( lib.png_set_strip_16 == NULL ) {
   9.340 +            SDL_UnloadObject(lib.handle);
   9.341 +            return -1;
   9.342 +        }
   9.343 +        lib.png_sig_cmp =
   9.344 +            (int (*) (png_bytep, png_size_t, png_size_t))
   9.345 +            SDL_LoadFunction(lib.handle, "png_sig_cmp");
   9.346 +        if ( lib.png_sig_cmp == NULL ) {
   9.347 +            SDL_UnloadObject(lib.handle);
   9.348 +            return -1;
   9.349 +        }
   9.350  #ifndef LIBPNG_VERSION_12
   9.351 -		lib.png_set_longjmp_fn =
   9.352 -			(jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
   9.353 -			SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
   9.354 -		if ( lib.png_set_longjmp_fn == NULL ) {
   9.355 -			SDL_UnloadObject(lib.handle);
   9.356 -			return -1;
   9.357 -		}
   9.358 +        lib.png_set_longjmp_fn =
   9.359 +            (jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
   9.360 +            SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
   9.361 +        if ( lib.png_set_longjmp_fn == NULL ) {
   9.362 +            SDL_UnloadObject(lib.handle);
   9.363 +            return -1;
   9.364 +        }
   9.365  #endif
   9.366 -	}
   9.367 -	++lib.loaded;
   9.368 +    }
   9.369 +    ++lib.loaded;
   9.370  
   9.371 -	return 0;
   9.372 +    return 0;
   9.373  }
   9.374  void IMG_QuitPNG()
   9.375  {
   9.376 -	if ( lib.loaded == 0 ) {
   9.377 -		return;
   9.378 -	}
   9.379 -	if ( lib.loaded == 1 ) {
   9.380 -		SDL_UnloadObject(lib.handle);
   9.381 -	}
   9.382 -	--lib.loaded;
   9.383 +    if ( lib.loaded == 0 ) {
   9.384 +        return;
   9.385 +    }
   9.386 +    if ( lib.loaded == 1 ) {
   9.387 +        SDL_UnloadObject(lib.handle);
   9.388 +    }
   9.389 +    --lib.loaded;
   9.390  }
   9.391  #else
   9.392  int IMG_InitPNG()
   9.393  {
   9.394 -	if ( lib.loaded == 0 ) {
   9.395 -		lib.png_create_info_struct = png_create_info_struct;
   9.396 -		lib.png_create_read_struct = png_create_read_struct;
   9.397 -		lib.png_destroy_read_struct = png_destroy_read_struct;
   9.398 -		lib.png_get_IHDR = png_get_IHDR;
   9.399 -		lib.png_get_channels = png_get_channels;
   9.400 -		lib.png_get_io_ptr = png_get_io_ptr;
   9.401 -		lib.png_get_PLTE = png_get_PLTE;
   9.402 -		lib.png_get_tRNS = png_get_tRNS;
   9.403 -		lib.png_get_valid = png_get_valid;
   9.404 -		lib.png_read_image = png_read_image;
   9.405 -		lib.png_read_info = png_read_info;
   9.406 -		lib.png_read_update_info = png_read_update_info;
   9.407 -		lib.png_set_expand = png_set_expand;
   9.408 -		lib.png_set_gray_to_rgb = png_set_gray_to_rgb;
   9.409 -		lib.png_set_packing = png_set_packing;
   9.410 -		lib.png_set_read_fn = png_set_read_fn;
   9.411 -		lib.png_set_strip_16 = png_set_strip_16;
   9.412 -		lib.png_sig_cmp = png_sig_cmp;
   9.413 +    if ( lib.loaded == 0 ) {
   9.414 +        lib.png_create_info_struct = png_create_info_struct;
   9.415 +        lib.png_create_read_struct = png_create_read_struct;
   9.416 +        lib.png_destroy_read_struct = png_destroy_read_struct;
   9.417 +        lib.png_get_IHDR = png_get_IHDR;
   9.418 +        lib.png_get_channels = png_get_channels;
   9.419 +        lib.png_get_io_ptr = png_get_io_ptr;
   9.420 +        lib.png_get_PLTE = png_get_PLTE;
   9.421 +        lib.png_get_tRNS = png_get_tRNS;
   9.422 +        lib.png_get_valid = png_get_valid;
   9.423 +        lib.png_read_image = png_read_image;
   9.424 +        lib.png_read_info = png_read_info;
   9.425 +        lib.png_read_update_info = png_read_update_info;
   9.426 +        lib.png_set_expand = png_set_expand;
   9.427 +        lib.png_set_gray_to_rgb = png_set_gray_to_rgb;
   9.428 +        lib.png_set_packing = png_set_packing;
   9.429 +        lib.png_set_read_fn = png_set_read_fn;
   9.430 +        lib.png_set_strip_16 = png_set_strip_16;
   9.431 +        lib.png_sig_cmp = png_sig_cmp;
   9.432  #ifndef LIBPNG_VERSION_12
   9.433 -		lib.png_set_longjmp_fn = png_set_longjmp_fn;
   9.434 +        lib.png_set_longjmp_fn = png_set_longjmp_fn;
   9.435  #endif
   9.436 -	}
   9.437 -	++lib.loaded;
   9.438 +    }
   9.439 +    ++lib.loaded;
   9.440  
   9.441 -	return 0;
   9.442 +    return 0;
   9.443  }
   9.444  void IMG_QuitPNG()
   9.445  {
   9.446 -	if ( lib.loaded == 0 ) {
   9.447 -		return;
   9.448 -	}
   9.449 -	if ( lib.loaded == 1 ) {
   9.450 -	}
   9.451 -	--lib.loaded;
   9.452 +    if ( lib.loaded == 0 ) {
   9.453 +        return;
   9.454 +    }
   9.455 +    if ( lib.loaded == 1 ) {
   9.456 +    }
   9.457 +    --lib.loaded;
   9.458  }
   9.459  #endif /* LOAD_PNG_DYNAMIC */
   9.460  
   9.461  /* See if an image is contained in a data source */
   9.462  int IMG_isPNG(SDL_RWops *src)
   9.463  {
   9.464 -	Sint64 start;
   9.465 -	int is_PNG;
   9.466 -	Uint8 magic[4];
   9.467 +    Sint64 start;
   9.468 +    int is_PNG;
   9.469 +    Uint8 magic[4];
   9.470  
   9.471 -	if ( !src )
   9.472 -		return 0;
   9.473 -	start = SDL_RWtell(src);
   9.474 -	is_PNG = 0;
   9.475 -	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   9.476 +    if ( !src )
   9.477 +        return 0;
   9.478 +    start = SDL_RWtell(src);
   9.479 +    is_PNG = 0;
   9.480 +    if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   9.481                  if ( magic[0] == 0x89 &&
   9.482                       magic[1] == 'P' &&
   9.483                       magic[2] == 'N' &&
   9.484                       magic[3] == 'G' ) {
   9.485 -			is_PNG = 1;
   9.486 -		}
   9.487 -	}
   9.488 -	SDL_RWseek(src, start, RW_SEEK_SET);
   9.489 -	return(is_PNG);
   9.490 +            is_PNG = 1;
   9.491 +        }
   9.492 +    }
   9.493 +    SDL_RWseek(src, start, RW_SEEK_SET);
   9.494 +    return(is_PNG);
   9.495  }
   9.496  
   9.497  /* Load a PNG type image from an SDL datasource */
   9.498  static void png_read_data(png_structp ctx, png_bytep area, png_size_t size)
   9.499  {
   9.500 -	SDL_RWops *src;
   9.501 +    SDL_RWops *src;
   9.502  
   9.503 -	src = (SDL_RWops *)lib.png_get_io_ptr(ctx);
   9.504 -	SDL_RWread(src, area, size, 1);
   9.505 +    src = (SDL_RWops *)lib.png_get_io_ptr(ctx);
   9.506 +    SDL_RWread(src, area, size, 1);
   9.507  }
   9.508  SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
   9.509  {
   9.510 -	Sint64 start;
   9.511 -	const char *error;
   9.512 -	SDL_Surface *volatile surface;
   9.513 -	png_structp png_ptr;
   9.514 -	png_infop info_ptr;
   9.515 -	png_uint_32 width, height;
   9.516 -	int bit_depth, color_type, interlace_type, num_channels;
   9.517 -	Uint32 Rmask;
   9.518 -	Uint32 Gmask;
   9.519 -	Uint32 Bmask;
   9.520 -	Uint32 Amask;
   9.521 -	SDL_Palette *palette;
   9.522 -	png_bytep *volatile row_pointers;
   9.523 -	int row, i;
   9.524 -	int ckey = -1;
   9.525 -	png_color_16 *transv;
   9.526 +    Sint64 start;
   9.527 +    const char *error;
   9.528 +    SDL_Surface *volatile surface;
   9.529 +    png_structp png_ptr;
   9.530 +    png_infop info_ptr;
   9.531 +    png_uint_32 width, height;
   9.532 +    int bit_depth, color_type, interlace_type, num_channels;
   9.533 +    Uint32 Rmask;
   9.534 +    Uint32 Gmask;
   9.535 +    Uint32 Bmask;
   9.536 +    Uint32 Amask;
   9.537 +    SDL_Palette *palette;
   9.538 +    png_bytep *volatile row_pointers;
   9.539 +    int row, i;
   9.540 +    int ckey = -1;
   9.541 +    png_color_16 *transv;
   9.542  
   9.543 -	if ( !src ) {
   9.544 -		/* The error message has been set in SDL_RWFromFile */
   9.545 -		return NULL;
   9.546 -	}
   9.547 -	start = SDL_RWtell(src);
   9.548 +    if ( !src ) {
   9.549 +        /* The error message has been set in SDL_RWFromFile */
   9.550 +        return NULL;
   9.551 +    }
   9.552 +    start = SDL_RWtell(src);
   9.553  
   9.554 -	if ( !IMG_Init(IMG_INIT_PNG) ) {
   9.555 -		return NULL;
   9.556 -	}
   9.557 +    if ( !IMG_Init(IMG_INIT_PNG) ) {
   9.558 +        return NULL;
   9.559 +    }
   9.560  
   9.561 -	/* Initialize the data we will clean up when we're done */
   9.562 -	error = NULL;
   9.563 -	png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL;
   9.564 +    /* Initialize the data we will clean up when we're done */
   9.565 +    error = NULL;
   9.566 +    png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL;
   9.567  
   9.568 -	/* Create the PNG loading context structure */
   9.569 -	png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
   9.570 -					  NULL,NULL,NULL);
   9.571 -	if (png_ptr == NULL){
   9.572 -		error = "Couldn't allocate memory for PNG file or incompatible PNG dll";
   9.573 -		goto done;
   9.574 -	}
   9.575 +    /* Create the PNG loading context structure */
   9.576 +    png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
   9.577 +                      NULL,NULL,NULL);
   9.578 +    if (png_ptr == NULL){
   9.579 +        error = "Couldn't allocate memory for PNG file or incompatible PNG dll";
   9.580 +        goto done;
   9.581 +    }
   9.582  
   9.583 -	 /* Allocate/initialize the memory for image information.  REQUIRED. */
   9.584 -	info_ptr = lib.png_create_info_struct(png_ptr);
   9.585 -	if (info_ptr == NULL) {
   9.586 -		error = "Couldn't create image information for PNG file";
   9.587 -		goto done;
   9.588 -	}
   9.589 +     /* Allocate/initialize the memory for image information.  REQUIRED. */
   9.590 +    info_ptr = lib.png_create_info_struct(png_ptr);
   9.591 +    if (info_ptr == NULL) {
   9.592 +        error = "Couldn't create image information for PNG file";
   9.593 +        goto done;
   9.594 +    }
   9.595  
   9.596 -	/* Set error handling if you are using setjmp/longjmp method (this is
   9.597 -	 * the normal method of doing things with libpng).  REQUIRED unless you
   9.598 -	 * set up your own error handlers in png_create_read_struct() earlier.
   9.599 -	 */
   9.600 +    /* Set error handling if you are using setjmp/longjmp method (this is
   9.601 +     * the normal method of doing things with libpng).  REQUIRED unless you
   9.602 +     * set up your own error handlers in png_create_read_struct() earlier.
   9.603 +     */
   9.604  #ifndef LIBPNG_VERSION_12
   9.605 -	if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
   9.606 +    if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
   9.607  #else
   9.608 -	if ( setjmp(png_ptr->jmpbuf) )
   9.609 +    if ( setjmp(png_ptr->jmpbuf) )
   9.610  #endif
   9.611 -	{
   9.612 -		error = "Error reading the PNG file.";
   9.613 -		goto done;
   9.614 -	}
   9.615 +    {
   9.616 +        error = "Error reading the PNG file.";
   9.617 +        goto done;
   9.618 +    }
   9.619  
   9.620 -	/* Set up the input control */
   9.621 -	lib.png_set_read_fn(png_ptr, src, png_read_data);
   9.622 +    /* Set up the input control */
   9.623 +    lib.png_set_read_fn(png_ptr, src, png_read_data);
   9.624  
   9.625 -	/* Read PNG header info */
   9.626 -	lib.png_read_info(png_ptr, info_ptr);
   9.627 -	lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   9.628 -			&color_type, &interlace_type, NULL, NULL);
   9.629 +    /* Read PNG header info */
   9.630 +    lib.png_read_info(png_ptr, info_ptr);
   9.631 +    lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   9.632 +            &color_type, &interlace_type, NULL, NULL);
   9.633  
   9.634 -	/* tell libpng to strip 16 bit/color files down to 8 bits/color */
   9.635 -	lib.png_set_strip_16(png_ptr) ;
   9.636 +    /* tell libpng to strip 16 bit/color files down to 8 bits/color */
   9.637 +    lib.png_set_strip_16(png_ptr) ;
   9.638  
   9.639 -	/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
   9.640 -	 * byte into separate bytes (useful for paletted and grayscale images).
   9.641 -	 */
   9.642 -	lib.png_set_packing(png_ptr);
   9.643 +    /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
   9.644 +     * byte into separate bytes (useful for paletted and grayscale images).
   9.645 +     */
   9.646 +    lib.png_set_packing(png_ptr);
   9.647  
   9.648 -	/* scale greyscale values to the range 0..255 */
   9.649 -	if (color_type == PNG_COLOR_TYPE_GRAY)
   9.650 -		lib.png_set_expand(png_ptr);
   9.651 +    /* scale greyscale values to the range 0..255 */
   9.652 +    if (color_type == PNG_COLOR_TYPE_GRAY)
   9.653 +        lib.png_set_expand(png_ptr);
   9.654  
   9.655 -	/* For images with a single "transparent colour", set colour key;
   9.656 -	   if more than one index has transparency, or if partially transparent
   9.657 -	   entries exist, use full alpha channel */
   9.658 -	if (lib.png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
   9.659 -	        int num_trans;
   9.660 -		Uint8 *trans;
   9.661 -		lib.png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
   9.662 -			     &transv);
   9.663 -		if (color_type == PNG_COLOR_TYPE_PALETTE) {
   9.664 -		    /* Check if all tRNS entries are opaque except one */
   9.665 -		    int j, t = -1;
   9.666 -		    for (j = 0; j < num_trans; j++) {
   9.667 -			if (trans[j] == 0) {
   9.668 -			    if (t >= 0) {
   9.669 -				break;
   9.670 +    /* For images with a single "transparent colour", set colour key;
   9.671 +       if more than one index has transparency, or if partially transparent
   9.672 +       entries exist, use full alpha channel */
   9.673 +    if (lib.png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
   9.674 +            int num_trans;
   9.675 +        Uint8 *trans;
   9.676 +        lib.png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
   9.677 +                 &transv);
   9.678 +        if (color_type == PNG_COLOR_TYPE_PALETTE) {
   9.679 +            /* Check if all tRNS entries are opaque except one */
   9.680 +            int j, t = -1;
   9.681 +            for (j = 0; j < num_trans; j++) {
   9.682 +            if (trans[j] == 0) {
   9.683 +                if (t >= 0) {
   9.684 +                break;
   9.685                              }
   9.686 -			    t = j;
   9.687 -			} else if (trans[j] != 255) {
   9.688 -			    break;
   9.689 +                t = j;
   9.690 +            } else if (trans[j] != 255) {
   9.691 +                break;
   9.692                          }
   9.693                      }
   9.694 -		    if (j == num_trans) {
   9.695 -			/* exactly one transparent index */
   9.696 -			ckey = t;
   9.697 -		    } else {
   9.698 -			/* more than one transparent index, or translucency */
   9.699 -			lib.png_set_expand(png_ptr);
   9.700 -		    }
   9.701 -		} else
   9.702 -		    ckey = 0; /* actual value will be set later */
   9.703 -	}
   9.704 +            if (j == num_trans) {
   9.705 +            /* exactly one transparent index */
   9.706 +            ckey = t;
   9.707 +            } else {
   9.708 +            /* more than one transparent index, or translucency */
   9.709 +            lib.png_set_expand(png_ptr);
   9.710 +            }
   9.711 +        } else
   9.712 +            ckey = 0; /* actual value will be set later */
   9.713 +    }
   9.714  
   9.715 -	if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
   9.716 -		lib.png_set_gray_to_rgb(png_ptr);
   9.717 +    if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
   9.718 +        lib.png_set_gray_to_rgb(png_ptr);
   9.719  
   9.720 -	lib.png_read_update_info(png_ptr, info_ptr);
   9.721 +    lib.png_read_update_info(png_ptr, info_ptr);
   9.722  
   9.723 -	lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   9.724 -			&color_type, &interlace_type, NULL, NULL);
   9.725 +    lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   9.726 +            &color_type, &interlace_type, NULL, NULL);
   9.727  
   9.728 -	/* Allocate the SDL surface to hold the image */
   9.729 -	Rmask = Gmask = Bmask = Amask = 0 ;
   9.730 -	num_channels = lib.png_get_channels(png_ptr, info_ptr);
   9.731 -	if ( num_channels >= 3 ) {
   9.732 +    /* Allocate the SDL surface to hold the image */
   9.733 +    Rmask = Gmask = Bmask = Amask = 0 ;
   9.734 +    num_channels = lib.png_get_channels(png_ptr, info_ptr);
   9.735 +    if ( num_channels >= 3 ) {
   9.736  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   9.737 -			Rmask = 0x000000FF;
   9.738 -			Gmask = 0x0000FF00;
   9.739 -			Bmask = 0x00FF0000;
   9.740 -			Amask = (num_channels == 4) ? 0xFF000000 : 0;
   9.741 +            Rmask = 0x000000FF;
   9.742 +            Gmask = 0x0000FF00;
   9.743 +            Bmask = 0x00FF0000;
   9.744 +            Amask = (num_channels == 4) ? 0xFF000000 : 0;
   9.745  #else
   9.746 -			int s = (num_channels == 4) ? 0 : 8;
   9.747 -			Rmask = 0xFF000000 >> s;
   9.748 -			Gmask = 0x00FF0000 >> s;
   9.749 -			Bmask = 0x0000FF00 >> s;
   9.750 -			Amask = 0x000000FF >> s;
   9.751 +            int s = (num_channels == 4) ? 0 : 8;
   9.752 +            Rmask = 0xFF000000 >> s;
   9.753 +            Gmask = 0x00FF0000 >> s;
   9.754 +            Bmask = 0x0000FF00 >> s;
   9.755 +            Amask = 0x000000FF >> s;
   9.756  #endif
   9.757 -	}
   9.758 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
   9.759 -			bit_depth*num_channels, Rmask,Gmask,Bmask,Amask);
   9.760 -	if ( surface == NULL ) {
   9.761 -		error = SDL_GetError();
   9.762 -		goto done;
   9.763 -	}
   9.764 +    }
   9.765 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
   9.766 +            bit_depth*num_channels, Rmask,Gmask,Bmask,Amask);
   9.767 +    if ( surface == NULL ) {
   9.768 +        error = SDL_GetError();
   9.769 +        goto done;
   9.770 +    }
   9.771  
   9.772 -	if (ckey != -1) {
   9.773 -	        if (color_type != PNG_COLOR_TYPE_PALETTE)
   9.774 -			/* FIXME: Should these be truncated or shifted down? */
   9.775 -		        ckey = SDL_MapRGB(surface->format,
   9.776 -			                 (Uint8)transv->red,
   9.777 -			                 (Uint8)transv->green,
   9.778 -			                 (Uint8)transv->blue);
   9.779 -	        SDL_SetColorKey(surface, SDL_TRUE, ckey);
   9.780 -	}
   9.781 +    if (ckey != -1) {
   9.782 +            if (color_type != PNG_COLOR_TYPE_PALETTE)
   9.783 +            /* FIXME: Should these be truncated or shifted down? */
   9.784 +                ckey = SDL_MapRGB(surface->format,
   9.785 +                             (Uint8)transv->red,
   9.786 +                             (Uint8)transv->green,
   9.787 +                             (Uint8)transv->blue);
   9.788 +            SDL_SetColorKey(surface, SDL_TRUE, ckey);
   9.789 +    }
   9.790  
   9.791 -	/* Create the array of pointers to image data */
   9.792 -	row_pointers = (png_bytep*) SDL_malloc(sizeof(png_bytep)*height);
   9.793 -	if ( (row_pointers == NULL) ) {
   9.794 -		error = "Out of memory";
   9.795 -		goto done;
   9.796 -	}
   9.797 -	for (row = 0; row < (int)height; row++) {
   9.798 -		row_pointers[row] = (png_bytep)
   9.799 -				(Uint8 *)surface->pixels + row*surface->pitch;
   9.800 -	}
   9.801 +    /* Create the array of pointers to image data */
   9.802 +    row_pointers = (png_bytep*) SDL_malloc(sizeof(png_bytep)*height);
   9.803 +    if ( (row_pointers == NULL) ) {
   9.804 +        error = "Out of memory";
   9.805 +        goto done;
   9.806 +    }
   9.807 +    for (row = 0; row < (int)height; row++) {
   9.808 +        row_pointers[row] = (png_bytep)
   9.809 +                (Uint8 *)surface->pixels + row*surface->pitch;
   9.810 +    }
   9.811  
   9.812 -	/* Read the entire image in one go */
   9.813 -	lib.png_read_image(png_ptr, row_pointers);
   9.814 +    /* Read the entire image in one go */
   9.815 +    lib.png_read_image(png_ptr, row_pointers);
   9.816  
   9.817 -	/* and we're done!  (png_read_end() can be omitted if no processing of
   9.818 -	 * post-IDAT text/time/etc. is desired)
   9.819 -	 * In some cases it can't read PNG's created by some popular programs (ACDSEE),
   9.820 -	 * we do not want to process comments, so we omit png_read_end
   9.821 +    /* and we're done!  (png_read_end() can be omitted if no processing of
   9.822 +     * post-IDAT text/time/etc. is desired)
   9.823 +     * In some cases it can't read PNG's created by some popular programs (ACDSEE),
   9.824 +     * we do not want to process comments, so we omit png_read_end
   9.825  
   9.826 -	lib.png_read_end(png_ptr, info_ptr);
   9.827 -	*/
   9.828 +    lib.png_read_end(png_ptr, info_ptr);
   9.829 +    */
   9.830  
   9.831 -	/* Load the palette, if any */
   9.832 -	palette = surface->format->palette;
   9.833 -	if ( palette ) {
   9.834 -	    int png_num_palette;
   9.835 -	    png_colorp png_palette;
   9.836 -	    lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
   9.837 -	    if (color_type == PNG_COLOR_TYPE_GRAY) {
   9.838 -		palette->ncolors = 256;
   9.839 -		for (i = 0; i < 256; i++) {
   9.840 -		    palette->colors[i].r = i;
   9.841 -		    palette->colors[i].g = i;
   9.842 -		    palette->colors[i].b = i;
   9.843 -		}
   9.844 -	    } else if (png_num_palette > 0 ) {
   9.845 -		palette->ncolors = png_num_palette; 
   9.846 -		for ( i=0; i<png_num_palette; ++i ) {
   9.847 -		    palette->colors[i].b = png_palette[i].blue;
   9.848 -		    palette->colors[i].g = png_palette[i].green;
   9.849 -		    palette->colors[i].r = png_palette[i].red;
   9.850 -		}
   9.851 -	    }
   9.852 -	}
   9.853 +    /* Load the palette, if any */
   9.854 +    palette = surface->format->palette;
   9.855 +    if ( palette ) {
   9.856 +        int png_num_palette;
   9.857 +        png_colorp png_palette;
   9.858 +        lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
   9.859 +        if (color_type == PNG_COLOR_TYPE_GRAY) {
   9.860 +        palette->ncolors = 256;
   9.861 +        for (i = 0; i < 256; i++) {
   9.862 +            palette->colors[i].r = i;
   9.863 +            palette->colors[i].g = i;
   9.864 +            palette->colors[i].b = i;
   9.865 +        }
   9.866 +        } else if (png_num_palette > 0 ) {
   9.867 +        palette->ncolors = png_num_palette;
   9.868 +        for ( i=0; i<png_num_palette; ++i ) {
   9.869 +            palette->colors[i].b = png_palette[i].blue;
   9.870 +            palette->colors[i].g = png_palette[i].green;
   9.871 +            palette->colors[i].r = png_palette[i].red;
   9.872 +        }
   9.873 +        }
   9.874 +    }
   9.875  
   9.876 -done:	/* Clean up and return */
   9.877 -	if ( png_ptr ) {
   9.878 -		lib.png_destroy_read_struct(&png_ptr,
   9.879 -		                        info_ptr ? &info_ptr : (png_infopp)0,
   9.880 -								(png_infopp)0);
   9.881 -	}
   9.882 -	if ( row_pointers ) {
   9.883 -		SDL_free(row_pointers);
   9.884 -	}
   9.885 -	if ( error ) {
   9.886 -		SDL_RWseek(src, start, RW_SEEK_SET);
   9.887 -		if ( surface ) {
   9.888 -			SDL_FreeSurface(surface);
   9.889 -			surface = NULL;
   9.890 -		}
   9.891 -		IMG_SetError(error);
   9.892 -	}
   9.893 -	return(surface); 
   9.894 +done:   /* Clean up and return */
   9.895 +    if ( png_ptr ) {
   9.896 +        lib.png_destroy_read_struct(&png_ptr,
   9.897 +                                info_ptr ? &info_ptr : (png_infopp)0,
   9.898 +                                (png_infopp)0);
   9.899 +    }
   9.900 +    if ( row_pointers ) {
   9.901 +        SDL_free(row_pointers);
   9.902 +    }
   9.903 +    if ( error ) {
   9.904 +        SDL_RWseek(src, start, RW_SEEK_SET);
   9.905 +        if ( surface ) {
   9.906 +            SDL_FreeSurface(surface);
   9.907 +            surface = NULL;
   9.908 +        }
   9.909 +        IMG_SetError(error);
   9.910 +    }
   9.911 +    return(surface);
   9.912  }
   9.913  
   9.914  #else
   9.915  
   9.916  int IMG_InitPNG()
   9.917  {
   9.918 -	IMG_SetError("PNG images are not supported");
   9.919 -	return(-1);
   9.920 +    IMG_SetError("PNG images are not supported");
   9.921 +    return(-1);
   9.922  }
   9.923  
   9.924  void IMG_QuitPNG()
   9.925 @@ -567,13 +567,13 @@
   9.926  /* See if an image is contained in a data source */
   9.927  int IMG_isPNG(SDL_RWops *src)
   9.928  {
   9.929 -	return(0);
   9.930 +    return(0);
   9.931  }
   9.932  
   9.933  /* Load a PNG type image from an SDL datasource */
   9.934  SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
   9.935  {
   9.936 -	return(NULL);
   9.937 +    return(NULL);
   9.938  }
   9.939  
   9.940  #endif /* LOAD_PNG */
    10.1 --- a/IMG_pnm.c	Thu Apr 25 00:22:51 2013 -0700
    10.2 +++ b/IMG_pnm.c	Tue May 21 21:24:32 2013 -0700
    10.3 @@ -39,206 +39,206 @@
    10.4  /* See if an image is contained in a data source */
    10.5  int IMG_isPNM(SDL_RWops *src)
    10.6  {
    10.7 -	Sint64 start;
    10.8 -	int is_PNM;
    10.9 -	char magic[2];
   10.10 +    Sint64 start;
   10.11 +    int is_PNM;
   10.12 +    char magic[2];
   10.13  
   10.14 -	if ( !src )
   10.15 -		return 0;
   10.16 -	start = SDL_RWtell(src);
   10.17 -	is_PNM = 0;
   10.18 -	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   10.19 -		/*
   10.20 -		 * PNM magic signatures:
   10.21 -		 * P1	PBM, ascii format
   10.22 -		 * P2	PGM, ascii format
   10.23 -		 * P3	PPM, ascii format
   10.24 -		 * P4	PBM, binary format
   10.25 -		 * P5	PGM, binary format
   10.26 -		 * P6	PPM, binary format
   10.27 -		 * P7	PAM, a general wrapper for PNM data
   10.28 -		 */
   10.29 -		if ( magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6' ) {
   10.30 -			is_PNM = 1;
   10.31 -		}
   10.32 -	}
   10.33 -	SDL_RWseek(src, start, RW_SEEK_SET);
   10.34 -	return(is_PNM);
   10.35 +    if ( !src )
   10.36 +        return 0;
   10.37 +    start = SDL_RWtell(src);
   10.38 +    is_PNM = 0;
   10.39 +    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   10.40 +        /*
   10.41 +         * PNM magic signatures:
   10.42 +         * P1   PBM, ascii format
   10.43 +         * P2   PGM, ascii format
   10.44 +         * P3   PPM, ascii format
   10.45 +         * P4   PBM, binary format
   10.46 +         * P5   PGM, binary format
   10.47 +         * P6   PPM, binary format
   10.48 +         * P7   PAM, a general wrapper for PNM data
   10.49 +         */
   10.50 +        if ( magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6' ) {
   10.51 +            is_PNM = 1;
   10.52 +        }
   10.53 +    }
   10.54 +    SDL_RWseek(src, start, RW_SEEK_SET);
   10.55 +    return(is_PNM);
   10.56  }
   10.57  
   10.58  /* read a non-negative integer from the source. return -1 upon error */
   10.59  static int ReadNumber(SDL_RWops *src)
   10.60  {
   10.61 -	int number;
   10.62 -	unsigned char ch;
   10.63 +    int number;
   10.64 +    unsigned char ch;
   10.65  
   10.66 -	/* Initialize return value */
   10.67 -	number = 0;
   10.68 +    /* Initialize return value */
   10.69 +    number = 0;
   10.70  
   10.71 -	/* Skip leading whitespace */
   10.72 -	do {
   10.73 -		if ( ! SDL_RWread(src, &ch, 1, 1) ) {
   10.74 -			return(0);
   10.75 -		}
   10.76 -		/* Eat comments as whitespace */
   10.77 -		if ( ch == '#' ) {  /* Comment is '#' to end of line */
   10.78 -			do {
   10.79 -				if ( ! SDL_RWread(src, &ch, 1, 1) ) {
   10.80 -					return -1;
   10.81 -				}
   10.82 -			} while ( (ch != '\r') && (ch != '\n') );
   10.83 -		}
   10.84 -	} while ( isspace(ch) );
   10.85 +    /* Skip leading whitespace */
   10.86 +    do {
   10.87 +        if ( ! SDL_RWread(src, &ch, 1, 1) ) {
   10.88 +            return(0);
   10.89 +        }
   10.90 +        /* Eat comments as whitespace */
   10.91 +        if ( ch == '#' ) {  /* Comment is '#' to end of line */
   10.92 +            do {
   10.93 +                if ( ! SDL_RWread(src, &ch, 1, 1) ) {
   10.94 +                    return -1;
   10.95 +                }
   10.96 +            } while ( (ch != '\r') && (ch != '\n') );
   10.97 +        }
   10.98 +    } while ( isspace(ch) );
   10.99  
  10.100 -	/* Add up the number */
  10.101 -	do {
  10.102 -		number *= 10;
  10.103 -		number += ch-'0';
  10.104 +    /* Add up the number */
  10.105 +    do {
  10.106 +        number *= 10;
  10.107 +        number += ch-'0';
  10.108  
  10.109 -		if ( !SDL_RWread(src, &ch, 1, 1) ) {
  10.110 -			return -1;
  10.111 -		}
  10.112 -	} while ( isdigit(ch) );
  10.113 +        if ( !SDL_RWread(src, &ch, 1, 1) ) {
  10.114 +            return -1;
  10.115 +        }
  10.116 +    } while ( isdigit(ch) );
  10.117  
  10.118 -	return(number);
  10.119 +    return(number);
  10.120  }
  10.121  
  10.122  SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src)
  10.123  {
  10.124 -	Sint64 start;
  10.125 -	SDL_Surface *surface = NULL;
  10.126 -	int width, height;
  10.127 -	int maxval, y, bpl;
  10.128 -	Uint8 *row;
  10.129 -	Uint8 *buf = NULL;
  10.130 -	char *error = NULL;
  10.131 -	Uint8 magic[2];
  10.132 -	int ascii;
  10.133 -	enum { PBM, PGM, PPM, PAM } kind;
  10.134 +    Sint64 start;
  10.135 +    SDL_Surface *surface = NULL;
  10.136 +    int width, height;
  10.137 +    int maxval, y, bpl;
  10.138 +    Uint8 *row;
  10.139 +    Uint8 *buf = NULL;
  10.140 +    char *error = NULL;
  10.141 +    Uint8 magic[2];
  10.142 +    int ascii;
  10.143 +    enum { PBM, PGM, PPM, PAM } kind;
  10.144  
  10.145  #define ERROR(s) do { error = (s); goto done; } while(0)
  10.146  
  10.147 -	if ( !src ) {
  10.148 -		/* The error message has been set in SDL_RWFromFile */
  10.149 -		return NULL;
  10.150 -	}
  10.151 -	start = SDL_RWtell(src);
  10.152 +    if ( !src ) {
  10.153 +        /* The error message has been set in SDL_RWFromFile */
  10.154 +        return NULL;
  10.155 +    }
  10.156 +    start = SDL_RWtell(src);
  10.157  
  10.158 -	SDL_RWread(src, magic, 2, 1);
  10.159 -	kind = magic[1] - '1';
  10.160 -	ascii = 1;
  10.161 -	if(kind >= 3) {
  10.162 -		ascii = 0;
  10.163 -		kind -= 3;
  10.164 -	}
  10.165 +    SDL_RWread(src, magic, 2, 1);
  10.166 +    kind = magic[1] - '1';
  10.167 +    ascii = 1;
  10.168 +    if(kind >= 3) {
  10.169 +        ascii = 0;
  10.170 +        kind -= 3;
  10.171 +    }
  10.172  
  10.173 -	width = ReadNumber(src);
  10.174 -	height = ReadNumber(src);
  10.175 -	if(width <= 0 || height <= 0)
  10.176 -		ERROR("Unable to read image width and height");
  10.177 +    width = ReadNumber(src);
  10.178 +    height = ReadNumber(src);
  10.179 +    if(width <= 0 || height <= 0)
  10.180 +        ERROR("Unable to read image width and height");
  10.181  
  10.182 -	if(kind != PBM) {
  10.183 -		maxval = ReadNumber(src);
  10.184 -		if(maxval <= 0 || maxval > 255)
  10.185 -			ERROR("unsupported PNM format");
  10.186 -	} else
  10.187 -		maxval = 255;	/* never scale PBMs */
  10.188 +    if(kind != PBM) {
  10.189 +        maxval = ReadNumber(src);
  10.190 +        if(maxval <= 0 || maxval > 255)
  10.191 +            ERROR("unsupported PNM format");
  10.192 +    } else
  10.193 +        maxval = 255;   /* never scale PBMs */
  10.194  
  10.195 -	/* binary PNM allows just a single character of whitespace after
  10.196 -	   the last parameter, and we've already consumed it */
  10.197 +    /* binary PNM allows just a single character of whitespace after
  10.198 +       the last parameter, and we've already consumed it */
  10.199  
  10.200 -	if(kind == PPM) {
  10.201 -		/* 24-bit surface in R,G,B byte order */
  10.202 -		surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24,
  10.203 +    if(kind == PPM) {
  10.204 +        /* 24-bit surface in R,G,B byte order */
  10.205 +        surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24,
  10.206  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  10.207 -					   0x000000ff, 0x0000ff00, 0x00ff0000,
  10.208 +                       0x000000ff, 0x0000ff00, 0x00ff0000,
  10.209  #else
  10.210 -					   0x00ff0000, 0x0000ff00, 0x000000ff,
  10.211 +                       0x00ff0000, 0x0000ff00, 0x000000ff,
  10.212  #endif
  10.213 -					   0);
  10.214 -	} else {
  10.215 -		/* load PBM/PGM as 8-bit indexed images */
  10.216 -		surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8,
  10.217 -					   0, 0, 0, 0);
  10.218 -	}
  10.219 -	if ( surface == NULL )
  10.220 -		ERROR("Out of memory");
  10.221 -	bpl = width * surface->format->BytesPerPixel;
  10.222 -	if(kind == PGM) {
  10.223 -		SDL_Color *c = surface->format->palette->colors;
  10.224 -		int i;
  10.225 -		for(i = 0; i < 256; i++)
  10.226 -			c[i].r = c[i].g = c[i].b = i;
  10.227 -		surface->format->palette->ncolors = 256;
  10.228 -	} else if(kind == PBM) {
  10.229 -		/* for some reason PBM has 1=black, 0=white */
  10.230 -		SDL_Color *c = surface->format->palette->colors;
  10.231 -		c[0].r = c[0].g = c[0].b = 255;
  10.232 -		c[1].r = c[1].g = c[1].b = 0;
  10.233 -		surface->format->palette->ncolors = 2;
  10.234 -		bpl = (width + 7) >> 3;
  10.235 -		buf = (Uint8 *)SDL_malloc(bpl);
  10.236 -		if(buf == NULL)
  10.237 -			ERROR("Out of memory");
  10.238 -	}
  10.239 +                       0);
  10.240 +    } else {
  10.241 +        /* load PBM/PGM as 8-bit indexed images */
  10.242 +        surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8,
  10.243 +                       0, 0, 0, 0);
  10.244 +    }
  10.245 +    if ( surface == NULL )
  10.246 +        ERROR("Out of memory");
  10.247 +    bpl = width * surface->format->BytesPerPixel;
  10.248 +    if(kind == PGM) {
  10.249 +        SDL_Color *c = surface->format->palette->colors;
  10.250 +        int i;
  10.251 +        for(i = 0; i < 256; i++)
  10.252 +            c[i].r = c[i].g = c[i].b = i;
  10.253 +        surface->format->palette->ncolors = 256;
  10.254 +    } else if(kind == PBM) {
  10.255 +        /* for some reason PBM has 1=black, 0=white */
  10.256 +        SDL_Color *c = surface->format->palette->colors;
  10.257 +        c[0].r = c[0].g = c[0].b = 255;
  10.258 +        c[1].r = c[1].g = c[1].b = 0;
  10.259 +        surface->format->palette->ncolors = 2;
  10.260 +        bpl = (width + 7) >> 3;
  10.261 +        buf = (Uint8 *)SDL_malloc(bpl);
  10.262 +        if(buf == NULL)
  10.263 +            ERROR("Out of memory");
  10.264 +    }
  10.265  
  10.266 -	/* Read the image into the surface */
  10.267 -	row = (Uint8 *)surface->pixels;
  10.268 -	for(y = 0; y < height; y++) {
  10.269 -		if(ascii) {
  10.270 -			int i;
  10.271 -			if(kind == PBM) {
  10.272 -				for(i = 0; i < width; i++) {
  10.273 -					Uint8 ch;
  10.274 -					do {
  10.275 -						if(!SDL_RWread(src, &ch,
  10.276 -							       1, 1))
  10.277 -						       ERROR("file truncated");
  10.278 -						ch -= '0';
  10.279 -					} while(ch > 1);
  10.280 -					row[i] = ch;
  10.281 -				}
  10.282 -			} else {
  10.283 -				for(i = 0; i < bpl; i++) {
  10.284 -					int c;
  10.285 -					c = ReadNumber(src);
  10.286 -					if(c < 0)
  10.287 -						ERROR("file truncated");
  10.288 -					row[i] = c;
  10.289 -				}
  10.290 -			}
  10.291 -		} else {
  10.292 -			Uint8 *dst = (kind == PBM) ? buf : row;
  10.293 -			if(!SDL_RWread(src, dst, bpl, 1))
  10.294 -				ERROR("file truncated");
  10.295 -			if(kind == PBM) {
  10.296 -				/* expand bitmap to 8bpp */
  10.297 -				int i;
  10.298 -				for(i = 0; i < width; i++) {
  10.299 -					int bit = 7 - (i & 7);
  10.300 -					row[i] = (buf[i >> 3] >> bit) & 1;
  10.301 -				}
  10.302 -			}
  10.303 -		}
  10.304 -		if(maxval < 255) {
  10.305 -			/* scale up to full dynamic range (slow) */
  10.306 -			int i;
  10.307 -			for(i = 0; i < bpl; i++)
  10.308 -				row[i] = row[i] * 255 / maxval;
  10.309 -		}
  10.310 -		row += surface->pitch;
  10.311 -	}
  10.312 +    /* Read the image into the surface */
  10.313 +    row = (Uint8 *)surface->pixels;
  10.314 +    for(y = 0; y < height; y++) {
  10.315 +        if(ascii) {
  10.316 +            int i;
  10.317 +            if(kind == PBM) {
  10.318 +                for(i = 0; i < width; i++) {
  10.319 +                    Uint8 ch;
  10.320 +                    do {
  10.321 +                        if(!SDL_RWread(src, &ch,
  10.322 +                                   1, 1))
  10.323 +                               ERROR("file truncated");
  10.324 +                        ch -= '0';
  10.325 +                    } while(ch > 1);
  10.326 +                    row[i] = ch;
  10.327 +                }
  10.328 +            } else {
  10.329 +                for(i = 0; i < bpl; i++) {
  10.330 +                    int c;
  10.331 +                    c = ReadNumber(src);
  10.332 +                    if(c < 0)
  10.333 +                        ERROR("file truncated");
  10.334 +                    row[i] = c;
  10.335 +                }
  10.336 +            }
  10.337 +        } else {
  10.338 +            Uint8 *dst = (kind == PBM) ? buf : row;
  10.339 +            if(!SDL_RWread(src, dst, bpl, 1))
  10.340 +                ERROR("file truncated");
  10.341 +            if(kind == PBM) {
  10.342 +                /* expand bitmap to 8bpp */
  10.343 +                int i;
  10.344 +                for(i = 0; i < width; i++) {
  10.345 +                    int bit = 7 - (i & 7);
  10.346 +                    row[i] = (buf[i >> 3] >> bit) & 1;
  10.347 +                }
  10.348 +            }
  10.349 +        }
  10.350 +        if(maxval < 255) {
  10.351 +            /* scale up to full dynamic range (slow) */
  10.352 +            int i;
  10.353 +            for(i = 0; i < bpl; i++)
  10.354 +                row[i] = row[i] * 255 / maxval;
  10.355 +        }
  10.356 +        row += surface->pitch;
  10.357 +    }
  10.358  done:
  10.359 -	SDL_free(buf);
  10.360 -	if(error) {
  10.361 -		SDL_RWseek(src, start, RW_SEEK_SET);
  10.362 -		if ( surface ) {
  10.363 -			SDL_FreeSurface(surface);
  10.364 -			surface = NULL;
  10.365 -		}
  10.366 -		IMG_SetError(error);
  10.367 -	}
  10.368 -	return(surface);
  10.369 +    SDL_free(buf);
  10.370 +    if(error) {
  10.371 +        SDL_RWseek(src, start, RW_SEEK_SET);
  10.372 +        if ( surface ) {
  10.373 +            SDL_FreeSurface(surface);
  10.374 +            surface = NULL;
  10.375 +        }
  10.376 +        IMG_SetError(error);
  10.377 +    }
  10.378 +    return(surface);
  10.379  }
  10.380  
  10.381  #else
  10.382 @@ -246,13 +246,13 @@
  10.383  /* See if an image is contained in a data source */
  10.384  int IMG_isPNM(SDL_RWops *src)
  10.385  {
  10.386 -	return(0);
  10.387 +    return(0);
  10.388  }
  10.389  
  10.390  /* Load a PNM type image from an SDL datasource */
  10.391  SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src)
  10.392  {
  10.393 -	return(NULL);
  10.394 +    return(NULL);
  10.395  }
  10.396  
  10.397  #endif /* LOAD_PNM */
    11.1 --- a/IMG_tga.c	Thu Apr 25 00:22:51 2013 -0700
    11.2 +++ b/IMG_tga.c	Tue May 21 21:24:32 2013 -0700
    11.3 @@ -44,19 +44,19 @@
    11.4   */
    11.5  
    11.6  struct TGAheader {
    11.7 -    Uint8 infolen;		/* length of info field */
    11.8 -    Uint8 has_cmap;		/* 1 if image has colormap, 0 otherwise */
    11.9 +    Uint8 infolen;      /* length of info field */
   11.10 +    Uint8 has_cmap;     /* 1 if image has colormap, 0 otherwise */
   11.11      Uint8 type;
   11.12  
   11.13 -    Uint8 cmap_start[2];	/* index of first colormap entry */
   11.14 -    Uint8 cmap_len[2];		/* number of entries in colormap */
   11.15 -    Uint8 cmap_bits;		/* bits per colormap entry */
   11.16 +    Uint8 cmap_start[2];    /* index of first colormap entry */
   11.17 +    Uint8 cmap_len[2];      /* number of entries in colormap */
   11.18 +    Uint8 cmap_bits;        /* bits per colormap entry */
   11.19  
   11.20 -    Uint8 yorigin[2];		/* image origin (ignored here) */
   11.21 +    Uint8 yorigin[2];       /* image origin (ignored here) */
   11.22      Uint8 xorigin[2];
   11.23 -    Uint8 width[2];		/* image size */
   11.24 +    Uint8 width[2];     /* image size */
   11.25      Uint8 height[2];
   11.26 -    Uint8 pixel_bits;		/* bits/pixel */
   11.27 +    Uint8 pixel_bits;       /* bits/pixel */
   11.28      Uint8 flags;
   11.29  };
   11.30  
   11.31 @@ -69,16 +69,16 @@
   11.32      TGA_TYPE_RLE_BW = 11
   11.33  };
   11.34  
   11.35 -#define TGA_INTERLEAVE_MASK	0xc0
   11.36 -#define TGA_INTERLEAVE_NONE	0x00
   11.37 -#define TGA_INTERLEAVE_2WAY	0x40
   11.38 -#define TGA_INTERLEAVE_4WAY	0x80
   11.39 +#define TGA_INTERLEAVE_MASK 0xc0
   11.40 +#define TGA_INTERLEAVE_NONE 0x00
   11.41 +#define TGA_INTERLEAVE_2WAY 0x40
   11.42 +#define TGA_INTERLEAVE_4WAY 0x80
   11.43  
   11.44 -#define TGA_ORIGIN_MASK		0x30
   11.45 -#define TGA_ORIGIN_LEFT		0x00
   11.46 -#define TGA_ORIGIN_RIGHT	0x10
   11.47 -#define TGA_ORIGIN_LOWER	0x00
   11.48 -#define TGA_ORIGIN_UPPER	0x20
   11.49 +#define TGA_ORIGIN_MASK     0x30
   11.50 +#define TGA_ORIGIN_LEFT     0x00
   11.51 +#define TGA_ORIGIN_RIGHT    0x10
   11.52 +#define TGA_ORIGIN_LOWER    0x00
   11.53 +#define TGA_ORIGIN_UPPER    0x20
   11.54  
   11.55  /* read/write unaligned little-endian 16-bit ints */
   11.56  #define LE16(p) ((p)[0] + ((p)[1] << 8))
   11.57 @@ -113,35 +113,35 @@
   11.58  
   11.59      if(!SDL_RWread(src, &hdr, sizeof(hdr), 1)) {
   11.60          error = "Error reading TGA data";
   11.61 -	goto error;
   11.62 +    goto error;
   11.63      }
   11.64      ncols = LE16(hdr.cmap_len);
   11.65      switch(hdr.type) {
   11.66      case TGA_TYPE_RLE_INDEXED:
   11.67 -	rle = 1;
   11.68 -	/* fallthrough */
   11.69 +    rle = 1;
   11.70 +    /* fallthrough */
   11.71      case TGA_TYPE_INDEXED:
   11.72 -	if(!hdr.has_cmap || hdr.pixel_bits != 8 || ncols > 256)
   11.73 -	    goto unsupported;
   11.74 -	indexed = 1;
   11.75 -	break;
   11.76 +    if(!hdr.has_cmap || hdr.pixel_bits != 8 || ncols > 256)
   11.77 +        goto unsupported;
   11.78 +    indexed = 1;
   11.79 +    break;
   11.80  
   11.81      case TGA_TYPE_RLE_RGB:
   11.82 -	rle = 1;
   11.83 -	/* fallthrough */
   11.84 +    rle = 1;
   11.85 +    /* fallthrough */
   11.86      case TGA_TYPE_RGB:
   11.87 -	indexed = 0;
   11.88 -	break;
   11.89 +    indexed = 0;
   11.90 +    break;
   11.91  
   11.92      case TGA_TYPE_RLE_BW:
   11.93 -	rle = 1;
   11.94 -	/* fallthrough */
   11.95 +    rle = 1;
   11.96 +    /* fallthrough */
   11.97      case TGA_TYPE_BW:
   11.98 -	if(hdr.pixel_bits != 8)
   11.99 -	    goto unsupported;
  11.100 -	/* Treat greyscale as 8bpp indexed images */
  11.101 -	indexed = grey = 1;
  11.102 -	break;
  11.103 +    if(hdr.pixel_bits != 8)
  11.104 +        goto unsupported;
  11.105 +    /* Treat greyscale as 8bpp indexed images */
  11.106 +    indexed = grey = 1;
  11.107 +    break;
  11.108  
  11.109      default:
  11.110          goto unsupported;
  11.111 @@ -151,39 +151,39 @@
  11.112      rmask = gmask = bmask = amask = 0;
  11.113      switch(hdr.pixel_bits) {
  11.114      case 8:
  11.115 -	if(!indexed) {
  11.116 +    if(!indexed) {
  11.117              goto unsupported;
  11.118 -	}
  11.119 -	break;
  11.120 +    }
  11.121 +    break;
  11.122  
  11.123      case 15:
  11.124      case 16:
  11.125 -	/* 15 and 16bpp both seem to use 5 bits/plane. The extra alpha bit
  11.126 -	   is ignored for now. */
  11.127 -	rmask = 0x7c00;
  11.128 -	gmask = 0x03e0;
  11.129 -	bmask = 0x001f;
  11.130 -	break;
  11.131 +    /* 15 and 16bpp both seem to use 5 bits/plane. The extra alpha bit
  11.132 +       is ignored for now. */
  11.133 +    rmask = 0x7c00;
  11.134 +    gmask = 0x03e0;
  11.135 +    bmask = 0x001f;
  11.136 +    break;
  11.137  
  11.138      case 32:
  11.139 -	alpha = 1;
  11.140 -	/* fallthrough */
  11.141 +    alpha = 1;
  11.142 +    /* fallthrough */
  11.143      case 24:
  11.144  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  11.145 -		{
  11.146 -	    int s = alpha ? 0 : 8;
  11.147 -	    amask = 0x000000ff >> s;
  11.148 -	    rmask = 0x0000ff00 >> s;
  11.149 -	    gmask = 0x00ff0000 >> s;
  11.150 -	    bmask = 0xff000000 >> s;
  11.151 -		}
  11.152 +        {
  11.153 +        int s = alpha ? 0 : 8;
  11.154 +        amask = 0x000000ff >> s;
  11.155 +        rmask = 0x0000ff00 >> s;
  11.156 +        gmask = 0x00ff0000 >> s;
  11.157 +        bmask = 0xff000000 >> s;
  11.158 +        }
  11.159  #else
  11.160 -	    amask = alpha ? 0xff000000 : 0;
  11.161 -	    rmask = 0x00ff0000;
  11.162 -	    gmask = 0x0000ff00;
  11.163 -	    bmask = 0x000000ff;
  11.164 +        amask = alpha ? 0xff000000 : 0;
  11.165 +        rmask = 0x00ff0000;
  11.166 +        gmask = 0x0000ff00;
  11.167 +        bmask = 0x000000ff;
  11.168  #endif
  11.169 -	break;
  11.170 +    break;
  11.171  
  11.172      default:
  11.173          goto unsupported;
  11.174 @@ -193,125 +193,125 @@
  11.175         || hdr.flags & TGA_ORIGIN_RIGHT) {
  11.176          goto unsupported;
  11.177      }
  11.178 -    
  11.179 +
  11.180      SDL_RWseek(src, hdr.infolen, RW_SEEK_CUR); /* skip info field */
  11.181  
  11.182      w = LE16(hdr.width);
  11.183      h = LE16(hdr.height);
  11.184      img = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
  11.185 -			       bpp * 8,
  11.186 -			       rmask, gmask, bmask, amask);
  11.187 +                   bpp * 8,
  11.188 +                   rmask, gmask, bmask, amask);
  11.189      if(img == NULL) {
  11.190          error = "Out of memory";
  11.191          goto error;
  11.192      }
  11.193  
  11.194      if(hdr.has_cmap) {
  11.195 -	int palsiz = ncols * ((hdr.cmap_bits + 7) >> 3);
  11.196 -	if(indexed && !grey) {
  11.197 -	    Uint8 *pal = (Uint8 *)SDL_malloc(palsiz), *p = pal;
  11.198 -	    SDL_Color *colors = img->format->palette->colors;
  11.199 -	    img->format->palette->ncolors = ncols;
  11.200 -	    SDL_RWread(src, pal, palsiz, 1);
  11.201 -	    for(i = 0; i < ncols; i++) {
  11.202 -		switch(hdr.cmap_bits) {
  11.203 -		case 15:
  11.204 -		case 16:
  11.205 -		    {
  11.206 -			Uint16 c = p[0] + (p[1] << 8);
  11.207 -			p += 2;
  11.208 -			colors[i].r = (c >> 7) & 0xf8;
  11.209 -			colors[i].g = (c >> 2) & 0xf8;
  11.210 -			colors[i].b = c << 3;
  11.211 -		    }
  11.212 -		    break;
  11.213 -		case 24:
  11.214 -		case 32:
  11.215 -		    colors[i].b = *p++;
  11.216 -		    colors[i].g = *p++;
  11.217 -		    colors[i].r = *p++;
  11.218 -		    if(hdr.cmap_bits == 32 && *p++ < 128)
  11.219 -			ckey = i;
  11.220 -		    break;
  11.221 -		}
  11.222 -	    }
  11.223 -	    SDL_free(pal);
  11.224 -	    if(ckey >= 0)
  11.225 -		SDL_SetColorKey(img, SDL_TRUE, ckey);
  11.226 -	} else {
  11.227 -	    /* skip unneeded colormap */
  11.228 -	    SDL_RWseek(src, palsiz, RW_SEEK_CUR);
  11.229 -	}
  11.230 +    int palsiz = ncols * ((hdr.cmap_bits + 7) >> 3);
  11.231 +    if(indexed && !grey) {
  11.232 +        Uint8 *pal = (Uint8 *)SDL_malloc(palsiz), *p = pal;
  11.233 +        SDL_Color *colors = img->format->palette->colors;
  11.234 +        img->format->palette->ncolors = ncols;
  11.235 +        SDL_RWread(src, pal, palsiz, 1);
  11.236 +        for(i = 0; i < ncols; i++) {
  11.237 +        switch(hdr.cmap_bits) {
  11.238 +        case 15:
  11.239 +        case 16:
  11.240 +            {
  11.241 +            Uint16 c = p[0] + (p[1] << 8);
  11.242 +            p += 2;
  11.243 +            colors[i].r = (c >> 7) & 0xf8;
  11.244 +            colors[i].g = (c >> 2) & 0xf8;
  11.245 +            colors[i].b = c << 3;
  11.246 +            }
  11.247 +            break;
  11.248 +        case 24:
  11.249 +        case 32:
  11.250 +            colors[i].b = *p++;
  11.251 +            colors[i].g = *p++;
  11.252 +            colors[i].r = *p++;
  11.253 +            if(hdr.cmap_bits == 32 && *p++ < 128)
  11.254 +            ckey = i;
  11.255 +            break;
  11.256 +        }
  11.257 +        }
  11.258 +        SDL_free(pal);
  11.259 +        if(ckey >= 0)
  11.260 +        SDL_SetColorKey(img, SDL_TRUE, ckey);
  11.261 +    } else {
  11.262 +        /* skip unneeded colormap */
  11.263 +        SDL_RWseek(src, palsiz, RW_SEEK_CUR);
  11.264 +    }
  11.265      }
  11.266  
  11.267      if(grey) {
  11.268 -	SDL_Color *colors = img->format->palette->colors;
  11.269 -	for(i = 0; i < 256; i++)
  11.270 -	    colors[i].r = colors[i].g = colors[i].b = i;
  11.271 -	img->format->palette->ncolors = 256;
  11.272 +    SDL_Color *colors = img->format->palette->colors;
  11.273 +    for(i = 0; i < 256; i++)
  11.274 +        colors[i].r = colors[i].g = colors[i].b = i;
  11.275 +    img->format->palette->ncolors = 256;
  11.276      }
  11.277  
  11.278      if(hdr.flags & TGA_ORIGIN_UPPER) {
  11.279 -		lstep = img->pitch;
  11.280 -		dst = (Uint8 *)img->pixels;
  11.281 +        lstep = img->pitch;
  11.282 +        dst = (Uint8 *)img->pixels;
  11.283      } else {
  11.284 -		lstep = -img->pitch;
  11.285 -		dst = (Uint8 *)img->pixels + (h - 1) * img->pitch;
  11.286 +        lstep = -img->pitch;
  11.287 +        dst = (Uint8 *)img->pixels + (h - 1) * img->pitch;
  11.288      }
  11.289  
  11.290      /* The RLE decoding code is slightly convoluted since we can't rely on
  11.291         spans not to wrap across scan lines */
  11.292      count = rep = 0;
  11.293      for(i = 0; i < h; i++) {
  11.294 -	if(rle) {
  11.295 -	    int x = 0;
  11.296 -	    for(;;) {
  11.297 -		Uint8 c;
  11.298 +    if(rle) {
  11.299 +        int x = 0;
  11.300 +        for(;;) {
  11.301 +        Uint8 c;
  11.302  
  11.303 -		if(count) {
  11.304 -		    int n = count;
  11.305 -		    if(n > w - x)
  11.306 -			n = w - x;
  11.307 -		    SDL_RWread(src, dst + x * bpp, n * bpp, 1);
  11.308 -		    count -= n;
  11.309 -		    x += n;
  11.310 -		    if(x == w)
  11.311 -			break;
  11.312 -		} else if(rep) {
  11.313 -		    int n = rep;
  11.314 -		    if(n > w - x)
  11.315 -			n = w - x;
  11.316 -		    rep -= n;
  11.317 -		    while(n--) {
  11.318 -			SDL_memcpy(dst + x * bpp, &pixel, bpp);
  11.319 -			x++;
  11.320 -		    }
  11.321 -		    if(x == w)
  11.322 -			break;
  11.323 -		}
  11.324 +        if(count) {
  11.325 +            int n = count;
  11.326 +            if(n > w - x)
  11.327 +            n = w - x;
  11.328 +            SDL_RWread(src, dst + x * bpp, n * bpp, 1);
  11.329 +            count -= n;
  11.330 +            x += n;
  11.331 +            if(x == w)
  11.332 +            break;
  11.333 +        } else if(rep) {
  11.334 +            int n = rep;
  11.335 +            if(n > w - x)
  11.336 +            n = w - x;
  11.337 +            rep -= n;
  11.338 +            while(n--) {
  11.339 +            SDL_memcpy(dst + x * bpp, &pixel, bpp);
  11.340 +            x++;
  11.341 +            }
  11.342 +            if(x == w)
  11.343 +            break;
  11.344 +        }
  11.345  
  11.346 -		SDL_RWread(src, &c, 1, 1);
  11.347 -		if(c & 0x80) {
  11.348 -		    SDL_RWread(src, &pixel, bpp, 1);
  11.349 -		    rep = (c & 0x7f) + 1;
  11.350 -		} else {
  11.351 -		    count = c + 1;
  11.352 -		}
  11.353 -	    }
  11.354 +        SDL_RWread(src, &c, 1, 1);
  11.355 +        if(c & 0x80) {
  11.356 +            SDL_RWread(src, &pixel, bpp, 1);
  11.357 +            rep = (c & 0x7f) + 1;
  11.358 +        } else {
  11.359 +            count = c + 1;
  11.360 +        }
  11.361 +        }
  11.362  
  11.363 -	} else {
  11.364 -	    SDL_RWread(src, dst, w * bpp, 1);
  11.365 -	}
  11.366 +    } else {
  11.367 +        SDL_RWread(src, dst, w * bpp, 1);
  11.368 +    }
  11.369  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  11.370 -	if (bpp == 2) {
  11.371 -	    /* swap byte order */
  11.372 -	    int x;
  11.373 -	    Uint16 *p = (Uint16 *)dst;
  11.374 -	    for(x = 0; x < w; x++)
  11.375 -		p[x] = SDL_Swap16(p[x]);
  11.376 -	}
  11.377 +    if (bpp == 2) {
  11.378 +        /* swap byte order */
  11.379 +        int x;
  11.380 +        Uint16 *p = (Uint16 *)dst;
  11.381 +        for(x = 0; x < w; x++)
  11.382 +        p[x] = SDL_Swap16(p[x]);
  11.383 +    }
  11.384  #endif
  11.385 -	dst += lstep;
  11.386 +    dst += lstep;
  11.387      }
  11.388      return img;
  11.389  
  11.390 @@ -332,7 +332,7 @@
  11.391  /* dummy TGA load routine */
  11.392  SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src)
  11.393  {
  11.394 -	return(NULL);
  11.395 +    return(NULL);
  11.396  }
  11.397  
  11.398  #endif /* LOAD_TGA */
    12.1 --- a/IMG_tif.c	Thu Apr 25 00:22:51 2013 -0700
    12.2 +++ b/IMG_tif.c	Tue May 21 21:24:32 2013 -0700
    12.3 @@ -32,95 +32,95 @@
    12.4  #include <tiffio.h>
    12.5  
    12.6  static struct {
    12.7 -	int loaded;
    12.8 -	void *handle;
    12.9 -	TIFF* (*TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc);
   12.10 -	void (*TIFFClose)(TIFF*);
   12.11 -	int (*TIFFGetField)(TIFF*, ttag_t, ...);
   12.12 -	int (*TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int);
   12.13 -	TIFFErrorHandler (*TIFFSetErrorHandler)(TIFFErrorHandler);
   12.14 +    int loaded;
   12.15 +    void *handle;
   12.16 +    TIFF* (*TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc);
   12.17 +    void (*TIFFClose)(TIFF*);
   12.18 +    int (*TIFFGetField)(TIFF*, ttag_t, ...);
   12.19 +    int (*TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int);
   12.20 +    TIFFErrorHandler (*TIFFSetErrorHandler)(TIFFErrorHandler);
   12.21  } lib;
   12.22  
   12.23  #ifdef LOAD_TIF_DYNAMIC
   12.24  int IMG_InitTIF()
   12.25  {
   12.26 -	if ( lib.loaded == 0 ) {
   12.27 -		lib.handle = SDL_LoadObject(LOAD_TIF_DYNAMIC);
   12.28 -		if ( lib.handle == NULL ) {
   12.29 -			return -1;
   12.30 -		}
   12.31 -		lib.TIFFClientOpen =
   12.32 -			(TIFF* (*)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc))
   12.33 -			SDL_LoadFunction(lib.handle, "TIFFClientOpen");
   12.34 -		if ( lib.TIFFClientOpen == NULL ) {
   12.35 -			SDL_UnloadObject(lib.handle);
   12.36 -			return -1;
   12.37 -		}
   12.38 -		lib.TIFFClose =
   12.39 -			(void (*)(TIFF*))
   12.40 -			SDL_LoadFunction(lib.handle, "TIFFClose");
   12.41 -		if ( lib.TIFFClose == NULL ) {
   12.42 -			SDL_UnloadObject(lib.handle);
   12.43 -			return -1;
   12.44 -		}
   12.45 -		lib.TIFFGetField =
   12.46 -			(int (*)(TIFF*, ttag_t, ...))
   12.47 -			SDL_LoadFunction(lib.handle, "TIFFGetField");
   12.48 -		if ( lib.TIFFGetField == NULL ) {
   12.49 -			SDL_UnloadObject(lib.handle);
   12.50 -			return -1;
   12.51 -		}
   12.52 -		lib.TIFFReadRGBAImage =
   12.53 -			(int (*)(TIFF*, uint32, uint32, uint32*, int))
   12.54 -			SDL_LoadFunction(lib.handle, "TIFFReadRGBAImage");
   12.55 -		if ( lib.TIFFReadRGBAImage == NULL ) {
   12.56 -			SDL_UnloadObject(lib.handle);
   12.57 -			return -1;
   12.58 -		}
   12.59 -		lib.TIFFSetErrorHandler =
   12.60 -			(TIFFErrorHandler (*)(TIFFErrorHandler))
   12.61 -			SDL_LoadFunction(lib.handle, "TIFFSetErrorHandler");
   12.62 -		if ( lib.TIFFSetErrorHandler == NULL ) {
   12.63 -			SDL_UnloadObject(lib.handle);
   12.64 -			return -1;
   12.65 -		}
   12.66 -	}
   12.67 -	++lib.loaded;
   12.68 +    if ( lib.loaded == 0 ) {
   12.69 +        lib.handle = SDL_LoadObject(LOAD_TIF_DYNAMIC);
   12.70 +        if ( lib.handle == NULL ) {
   12.71 +            return -1;
   12.72 +        }
   12.73 +        lib.TIFFClientOpen =
   12.74 +            (TIFF* (*)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc))
   12.75 +            SDL_LoadFunction(lib.handle, "TIFFClientOpen");
   12.76 +        if ( lib.TIFFClientOpen == NULL ) {
   12.77 +            SDL_UnloadObject(lib.handle);
   12.78 +            return -1;
   12.79 +        }
   12.80 +        lib.TIFFClose =
   12.81 +            (void (*)(TIFF*))
   12.82 +            SDL_LoadFunction(lib.handle, "TIFFClose");
   12.83 +        if ( lib.TIFFClose == NULL ) {
   12.84 +            SDL_UnloadObject(lib.handle);
   12.85 +            return -1;
   12.86 +        }
   12.87 +        lib.TIFFGetField =
   12.88 +            (int (*)(TIFF*, ttag_t, ...))
   12.89 +            SDL_LoadFunction(lib.handle, "TIFFGetField");
   12.90 +        if ( lib.TIFFGetField == NULL ) {
   12.91 +            SDL_UnloadObject(lib.handle);
   12.92 +            return -1;
   12.93 +        }
   12.94 +        lib.TIFFReadRGBAImage =
   12.95 +            (int (*)(TIFF*, uint32, uint32, uint32*, int))
   12.96 +            SDL_LoadFunction(lib.handle, "TIFFReadRGBAImage");
   12.97 +        if ( lib.TIFFReadRGBAImage == NULL ) {
   12.98 +            SDL_UnloadObject(lib.handle);
   12.99 +            return -1;
  12.100 +        }
  12.101 +        lib.TIFFSetErrorHandler =
  12.102 +            (TIFFErrorHandler (*)(TIFFErrorHandler))
  12.103 +            SDL_LoadFunction(lib.handle, "TIFFSetErrorHandler");
  12.104 +        if ( lib.TIFFSetErrorHandler == NULL ) {
  12.105 +            SDL_UnloadObject(lib.handle);
  12.106 +            return -1;
  12.107 +        }
  12.108 +    }
  12.109 +    ++lib.loaded;
  12.110  
  12.111 -	return 0;
  12.112 +    return 0;
  12.113  }
  12.114  void IMG_QuitTIF()
  12.115  {
  12.116 -	if ( lib.loaded == 0 ) {
  12.117 -		return;
  12.118 -	}
  12.119 -	if ( lib.loaded == 1 ) {
  12.120 -		SDL_UnloadObject(lib.handle);
  12.121 -	}
  12.122 -	--lib.loaded;
  12.123 +    if ( lib.loaded == 0 ) {
  12.124 +        return;
  12.125 +    }
  12.126 +    if ( lib.loaded == 1 ) {
  12.127 +        SDL_UnloadObject(lib.handle);
  12.128 +    }
  12.129 +    --lib.loaded;
  12.130  }
  12.131  #else
  12.132  int IMG_InitTIF()
  12.133  {
  12.134 -	if ( lib.loaded == 0 ) {
  12.135 -		lib.TIFFClientOpen = TIFFClientOpen;
  12.136 -		lib.TIFFClose = TIFFClose;
  12.137 -		lib.TIFFGetField = TIFFGetField;
  12.138 -		lib.TIFFReadRGBAImage = TIFFReadRGBAImage;
  12.139 -		lib.TIFFSetErrorHandler = TIFFSetErrorHandler;
  12.140 -	}
  12.141 -	++lib.loaded;
  12.142 +    if ( lib.loaded == 0 ) {
  12.143 +        lib.TIFFClientOpen = TIFFClientOpen;
  12.144 +        lib.TIFFClose = TIFFClose;
  12.145 +        lib.TIFFGetField = TIFFGetField;
  12.146 +        lib.TIFFReadRGBAImage = TIFFReadRGBAImage;
  12.147 +        lib.TIFFSetErrorHandler = TIFFSetErrorHandler;
  12.148 +    }
  12.149 +    ++lib.loaded;
  12.150  
  12.151 -	return 0;
  12.152 +    return 0;
  12.153  }
  12.154  void IMG_QuitTIF()
  12.155  {
  12.156 -	if ( lib.loaded == 0 ) {
  12.157 -		return;
  12.158 -	}
  12.159 -	if ( lib.loaded == 1 ) {
  12.160 -	}
  12.161 -	--lib.loaded;
  12.162 +    if ( lib.loaded == 0 ) {
  12.163 +        return;
  12.164 +    }
  12.165 +    if ( lib.loaded == 1 ) {
  12.166 +    }
  12.167 +    --lib.loaded;
  12.168  }
  12.169  #endif /* LOAD_TIF_DYNAMIC */
  12.170  
  12.171 @@ -131,150 +131,150 @@
  12.172  
  12.173  static tsize_t tiff_read(thandle_t fd, tdata_t buf, tsize_t size)
  12.174  {
  12.175 -	return SDL_RWread((SDL_RWops*)fd, buf, 1, size);
  12.176 +    return SDL_RWread((SDL_RWops*)fd, buf, 1, size);
  12.177  }
  12.178  
  12.179  static toff_t tiff_seek(thandle_t fd, toff_t offset, int origin)
  12.180  {
  12.181 -	return SDL_RWseek((SDL_RWops*)fd, offset, origin);
  12.182 +    return SDL_RWseek((SDL_RWops*)fd, offset, origin);
  12.183  }
  12.184  
  12.185  static tsize_t tiff_write(thandle_t fd, tdata_t buf, tsize_t size)
  12.186  {
  12.187 -	return SDL_RWwrite((SDL_RWops*)fd, buf, 1, size);
  12.188 +    return SDL_RWwrite((SDL_RWops*)fd, buf, 1, size);
  12.189  }
  12.190  
  12.191  static int tiff_close(thandle_t fd)
  12.192  {
  12.193 -	/*
  12.194 -	 * We don't want libtiff closing our SDL_RWops*, but if it's not given
  12.195 +    /*
  12.196 +     * We don't want libtiff closing our SDL_RWops*, but if it's not given
  12.197           * a routine to try, and if the image isn't a TIFF, it'll segfault.
  12.198 -	 */
  12.199 -	return 0;
  12.200 +     */
  12.201 +    return 0;
  12.202  }
  12.203  
  12.204  static int tiff_map(thandle_t fd, tdata_t* pbase, toff_t* psize)
  12.205  {
  12.206 -	return (0);
  12.207 +    return (0);
  12.208  }
  12.209  
  12.210  static void tiff_unmap(thandle_t fd, tdata_t base, toff_t size)
  12.211  {
  12.212 -	return;
  12.213 +    return;
  12.214  }
  12.215  
  12.216  static toff_t tiff_size(thandle_t fd)
  12.217  {
  12.218 -	Sint64 save_pos;
  12.219 -	toff_t size;
  12.220 +    Sint64 save_pos;
  12.221 +    toff_t size;
  12.222  
  12.223 -	save_pos = SDL_RWtell((SDL_RWops*)fd);
  12.224 -	SDL_RWseek((SDL_RWops*)fd, 0, RW_SEEK_END);
  12.225 +    save_pos = SDL_RWtell((SDL_RWops*)fd);
  12.226 +    SDL_RWseek((SDL_RWops*)fd, 0, RW_SEEK_END);
  12.227      size = SDL_RWtell((SDL_RWops*)fd);
  12.228 -	SDL_RWseek((SDL_RWops*)fd, save_pos, RW_SEEK_SET);
  12.229 -	return size;
  12.230 +    SDL_RWseek((SDL_RWops*)fd, save_pos, RW_SEEK_SET);
  12.231 +    return size;
  12.232  }
  12.233  
  12.234  int IMG_isTIF(SDL_RWops* src)
  12.235  {
  12.236 -	Sint64 start;
  12.237 -	int is_TIF;
  12.238 -	Uint8 magic[4];
  12.239 +    Sint64 start;
  12.240 +    int is_TIF;
  12.241 +    Uint8 magic[4];
  12.242  
  12.243 -	if ( !src )
  12.244 -		return 0;
  12.245 -	start = SDL_RWtell(src);
  12.246 -	is_TIF = 0;
  12.247 -	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
  12.248 -		if ( (magic[0] == 'I' &&
  12.249 +    if ( !src )
  12.250 +        return 0;
  12.251 +    start = SDL_RWtell(src);
  12.252 +    is_TIF = 0;
  12.253 +    if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
  12.254 +        if ( (magic[0] == 'I' &&
  12.255                        magic[1] == 'I' &&
  12.256 -		      magic[2] == 0x2a &&
  12.257 +              magic[2] == 0x2a &&
  12.258                        magic[3] == 0x00) ||
  12.259 -		     (magic[0] == 'M' &&
  12.260 +             (magic[0] == 'M' &&
  12.261                        magic[1] == 'M' &&
  12.262 -		      magic[2] == 0x00 &&
  12.263 +              magic[2] == 0x00 &&
  12.264                        magic[3] == 0x2a) ) {
  12.265 -			is_TIF = 1;
  12.266 -		}
  12.267 -	}
  12.268 -	SDL_RWseek(src, start, RW_SEEK_SET);
  12.269 -	return(is_TIF);
  12.270 +            is_TIF = 1;
  12.271 +        }
  12.272 +    }
  12.273 +    SDL_RWseek(src, start, RW_SEEK_SET);
  12.274 +    return(is_TIF);
  12.275  }
  12.276  
  12.277  SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src)
  12.278  {
  12.279 -	Sint64 start;
  12.280 -	TIFF* tiff;
  12.281 -	SDL_Surface* surface = NULL;
  12.282 -	Uint32 img_width, img_height;
  12.283 -	Uint32 Rmask, Gmask, Bmask, Amask;
  12.284 -	Uint32 x, y;
  12.285 -	Uint32 half;
  12.286 +    Sint64 start;
  12.287 +    TIFF* tiff;
  12.288 +    SDL_Surface* surface = NULL;
  12.289 +    Uint32 img_width, img_height;
  12.290 +    Uint32 Rmask, Gmask, Bmask, Amask;
  12.291 +    Uint32 x, y;
  12.292 +    Uint32 half;
  12.293  
  12.294 -	if ( !src ) {
  12.295 -		/* The error message has been set in SDL_RWFromFile */
  12.296 -		return NULL;
  12.297 -	}
  12.298 -	start = SDL_RWtell(src);
  12.299 +    if ( !src ) {
  12.300 +        /* The error message has been set in SDL_RWFromFile */
  12.301 +        return NULL;
  12.302 +    }
  12.303 +    start = SDL_RWtell(src);
  12.304  
  12.305 -	if ( !IMG_Init(IMG_INIT_TIF) ) {
  12.306 -		return NULL;
  12.307 -	}
  12.308 +    if ( !IMG_Init(IMG_INIT_TIF) ) {
  12.309 +        return NULL;
  12.310 +    }
  12.311  
  12.312 -	/* turn off memory mapped access with the m flag */
  12.313 -	tiff = lib.TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
  12.314 -		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, tiff_map, tiff_unmap);
  12.315 -	if(!tiff)
  12.316 -		goto error;
  12.317 +    /* turn off memory mapped access with the m flag */
  12.318 +    tiff = lib.TIFFClientOpen("SDL_image", "rm", (thandle_t)src,
  12.319 +        tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, tiff_map, tiff_unmap);
  12.320 +    if(!tiff)
  12.321 +        goto error;
  12.322  
  12.323 -	/* Retrieve the dimensions of the image from the TIFF tags */
  12.324 -	lib.TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width);
  12.325 -	lib.TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &img_height);
  12.326 +    /* Retrieve the dimensions of the image from the TIFF tags */
  12.327 +    lib.TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width);
  12.328 +    lib.TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &img_height);
  12.329  
  12.330 -	Rmask = 0x000000FF;
  12.331 -	Gmask = 0x0000FF00;
  12.332 -	Bmask = 0x00FF0000;
  12.333 -	Amask = 0xFF000000;
  12.334 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, img_width, img_height, 32,
  12.335 -		Rmask, Gmask, Bmask, Amask);
  12.336 -	if(!surface)
  12.337 -		goto error;
  12.338 -	
  12.339 -	if(!lib.TIFFReadRGBAImage(tiff, img_width, img_height, (uint32 *)surface->pixels, 0))
  12.340 -		goto error;
  12.341 +    Rmask = 0x000000FF;
  12.342 +    Gmask = 0x0000FF00;
  12.343 +    Bmask = 0x00FF0000;
  12.344 +    Amask = 0xFF000000;
  12.345 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, img_width, img_height, 32,
  12.346 +        Rmask, Gmask, Bmask, Amask);
  12.347 +    if(!surface)
  12.348 +        goto error;
  12.349  
  12.350 -	/* libtiff loads the image upside-down, flip it back */
  12.351 -	half = img_height / 2;
  12.352 -	for(y = 0; y < half; y++)
  12.353 -	{
  12.354 -	        Uint32 *top = (Uint32 *)surface->pixels + y * surface->pitch/4;
  12.355 -	        Uint32 *bot = (Uint32 *)surface->pixels
  12.356 -		              + (img_height - y - 1) * surface->pitch/4;
  12.357 -		for(x = 0; x < img_width; x++)
  12.358 -		{
  12.359 -		        Uint32 tmp = top[x];
  12.360 -			top[x] = bot[x];
  12.361 -			bot[x] = tmp;
  12.362 -		}
  12.363 -	}
  12.364 -	lib.TIFFClose(tiff);
  12.365 -	
  12.366 -	return surface;
  12.367 +    if(!lib.TIFFReadRGBAImage(tiff, img_width, img_height, (uint32 *)surface->pixels, 0))
  12.368 +        goto error;
  12.369 +
  12.370 +    /* libtiff loads the image upside-down, flip it back */
  12.371 +    half = img_height / 2;
  12.372 +    for(y = 0; y < half; y++)
  12.373 +    {
  12.374 +            Uint32 *top = (Uint32 *)surface->pixels + y * surface->pitch/4;
  12.375 +            Uint32 *bot = (Uint32 *)surface->pixels
  12.376 +                      + (img_height - y - 1) * surface->pitch/4;
  12.377 +        for(x = 0; x < img_width; x++)
  12.378 +        {
  12.379 +                Uint32 tmp = top[x];
  12.380 +            top[x] = bot[x];
  12.381 +            bot[x] = tmp;
  12.382 +        }
  12.383 +    }
  12.384 +    lib.TIFFClose(tiff);
  12.385 +
  12.386 +    return surface;
  12.387  
  12.388  error:
  12.389 -	SDL_RWseek(src, start, RW_SEEK_SET);
  12.390 -	if ( surface ) {
  12.391 -		SDL_FreeSurface(surface);
  12.392 -	}
  12.393 -	return NULL;
  12.394 +    SDL_RWseek(src, start, RW_SEEK_SET);
  12.395 +    if ( surface ) {
  12.396 +        SDL_FreeSurface(surface);
  12.397 +    }
  12.398 +    return NULL;
  12.399  }
  12.400  
  12.401  #else
  12.402  
  12.403  int IMG_InitTIF()
  12.404  {
  12.405 -	IMG_SetError("TIFF images are not supported");
  12.406 -	return(-1);
  12.407 +    IMG_SetError("TIFF images are not supported");
  12.408 +    return(-1);
  12.409  }
  12.410  
  12.411  void IMG_QuitTIF()
  12.412 @@ -284,13 +284,13 @@
  12.413  /* See if an image is contained in a data source */
  12.414  int IMG_isTIF(SDL_RWops *src)
  12.415  {
  12.416 -	return(0);
  12.417 +    return(0);
  12.418  }
  12.419  
  12.420  /* Load a TIFF type image from an SDL datasource */
  12.421  SDL_Surface *IMG_LoadTIF_RW(SDL_RWops *src)
  12.422  {
  12.423 -	return(NULL);
  12.424 +    return(NULL);
  12.425  }
  12.426  
  12.427  #endif /* LOAD_TIF */
    13.1 --- a/IMG_webp.c	Thu Apr 25 00:22:51 2013 -0700
    13.2 +++ b/IMG_webp.c	Tue May 21 21:24:32 2013 -0700
    13.3 @@ -30,8 +30,8 @@
    13.4  
    13.5  /*=============================================================================
    13.6          File: SDL_webp.c
    13.7 -     Purpose: A WEBP loader for the SDL library      
    13.8 -    Revision: 
    13.9 +     Purpose: A WEBP loader for the SDL library
   13.10 +    Revision:
   13.11    Created by: Michael Bonfils (Murlock) (26 November 2011)
   13.12                murlock42@gmail.com
   13.13  
   13.14 @@ -45,246 +45,246 @@
   13.15  #include <webp/decode.h>
   13.16  
   13.17  static struct {
   13.18 -	int loaded;
   13.19 -	void *handle;
   13.20 -	int/*VP8StatuCode*/ (*webp_get_features_internal) (const uint8_t *data, uint32_t data_size, WebPBitstreamFeatures* const features, int decoder_abi_version);
   13.21 -	uint8_t*	(*webp_decode_rgb_into) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);
   13.22 -	uint8_t*	(*webp_decode_rgba_into) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);
   13.23 +    int loaded;
   13.24 +    void *handle;
   13.25 +    int/*VP8StatuCode*/ (*webp_get_features_internal) (const uint8_t *data, uint32_t data_size, WebPBitstreamFeatures* const features, int decoder_abi_version);
   13.26 +    uint8_t*    (*webp_decode_rgb_into) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);
   13.27 +    uint8_t*    (*webp_decode_rgba_into) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);
   13.28  } lib;
   13.29  
   13.30  #ifdef LOAD_WEBP_DYNAMIC
   13.31  int IMG_InitWEBP()
   13.32  {
   13.33 -	if ( lib.loaded == 0 ) {
   13.34 -		lib.handle = SDL_LoadObject(LOAD_WEBP_DYNAMIC);
   13.35 -		if ( lib.handle == NULL ) {
   13.36 -			return -1;
   13.37 -		}
   13.38 -		lib.webp_get_features_internal = 
   13.39 -			( int (*) (const uint8_t *, uint32_t, WebPBitstreamFeatures* const, int) )
   13.40 -			SDL_LoadFunction(lib.handle, "WebPGetFeaturesInternal" );
   13.41 -		if ( lib.webp_get_features_internal == NULL ) {
   13.42 -			SDL_UnloadObject(lib.handle);
   13.43 -			return -1;
   13.44 -		}
   13.45 +    if ( lib.loaded == 0 ) {
   13.46 +        lib.handle = SDL_LoadObject(LOAD_WEBP_DYNAMIC);
   13.47 +        if ( lib.handle == NULL ) {
   13.48 +            return -1;
   13.49 +        }
   13.50 +        lib.webp_get_features_internal =
   13.51 +            ( int (*) (const uint8_t *, uint32_t, WebPBitstreamFeatures* const, int) )
   13.52 +            SDL_LoadFunction(lib.handle, "WebPGetFeaturesInternal" );
   13.53 +        if ( lib.webp_get_features_internal == NULL ) {
   13.54 +            SDL_UnloadObject(lib.handle);
   13.55 +            return -1;
   13.56 +        }
   13.57  
   13.58 -		lib.webp_decode_rgb_into = 
   13.59 -			( uint8_t* (*) (const uint8_t*, uint32_t, uint8_t*, int, int ) )
   13.60 -			SDL_LoadFunction(lib.handle, "WebPDecodeRGBInto" );
   13.61 -		if ( lib.webp_decode_rgb_into == NULL ) {
   13.62 -			SDL_UnloadObject(lib.handle);
   13.63 -			return -1;
   13.64 -		}
   13.65 +        lib.webp_decode_rgb_into =
   13.66 +            ( uint8_t* (*) (const uint8_t*, uint32_t, uint8_t*, int, int ) )
   13.67 +            SDL_LoadFunction(lib.handle, "WebPDecodeRGBInto" );
   13.68 +        if ( lib.webp_decode_rgb_into == NULL ) {
   13.69 +            SDL_UnloadObject(lib.handle);
   13.70 +            return -1;
   13.71 +        }
   13.72  
   13.73 -		lib.webp_decode_rgba_into = 
   13.74 -			( uint8_t* (*) (const uint8_t*, uint32_t, uint8_t*, int, int ) )
   13.75 -			SDL_LoadFunction(lib.handle, "WebPDecodeRGBAInto" );
   13.76 -		if ( lib.webp_decode_rgba_into == NULL ) {
   13.77 -			SDL_UnloadObject(lib.handle);
   13.78 -			return -1;
   13.79 -		}
   13.80 -	}
   13.81 -	++lib.loaded;
   13.82 +        lib.webp_decode_rgba_into =
   13.83 +            ( uint8_t* (*) (const uint8_t*, uint32_t, uint8_t*, int, int ) )
   13.84 +            SDL_LoadFunction(lib.handle, "WebPDecodeRGBAInto" );
   13.85 +        if ( lib.webp_decode_rgba_into == NULL ) {
   13.86 +            SDL_UnloadObject(lib.handle);
   13.87 +            return -1;
   13.88 +        }
   13.89 +    }
   13.90 +    ++lib.loaded;
   13.91  
   13.92 -	return 0;
   13.93 +    return 0;
   13.94  }
   13.95  void IMG_QuitWEBP()
   13.96  {
   13.97 -	if ( lib.loaded == 0 ) {
   13.98 -		return;
   13.99 -	}
  13.100 -	if ( lib.loaded == 1 ) {
  13.101 -		SDL_UnloadObject(lib.handle);
  13.102 -	}
  13.103 -	--lib.loaded;
  13.104 +    if ( lib.loaded == 0 ) {
  13.105 +        return;
  13.106 +    }
  13.107 +    if ( lib.loaded == 1 ) {
  13.108 +        SDL_UnloadObject(lib.handle);
  13.109 +    }
  13.110 +    --lib.loaded;
  13.111  }
  13.112  #else
  13.113  int IMG_InitWEBP()
  13.114  {
  13.115 -	if ( lib.loaded == 0 ) {
  13.116 -		lib.webp_get_features_internal = WebPGetFeaturesInternal;
  13.117 -		lib.webp_decode_rgb_into = WebPDecodeRGBInto;
  13.118 -		lib.webp_decode_rgba_into = WebPDecodeRGBAInto;
  13.119 -	}
  13.120 -	++lib.loaded;
  13.121 +    if ( lib.loaded == 0 ) {
  13.122 +        lib.webp_get_features_internal = WebPGetFeaturesInternal;
  13.123 +        lib.webp_decode_rgb_into = WebPDecodeRGBInto;
  13.124 +        lib.webp_decode_rgba_into = WebPDecodeRGBAInto;
  13.125 +    }
  13.126 +    ++lib.loaded;
  13.127  
  13.128 -	return 0;
  13.129 +    return 0;
  13.130  }
  13.131  void IMG_QuitWEBP()
  13.132  {
  13.133 -	if ( lib.loaded == 0 ) {
  13.134 -		return;
  13.135 -	}
  13.136 -	if ( lib.loaded == 1 ) {
  13.137 -	}
  13.138 -	--lib.loaded;
  13.139 +    if ( lib.loaded == 0 ) {
  13.140 +        return;
  13.141 +    }
  13.142 +    if ( lib.loaded == 1 ) {
  13.143 +    }
  13.144 +    --lib.loaded;
  13.145  }
  13.146  #endif /* LOAD_WEBP_DYNAMIC */
  13.147  
  13.148  static int webp_getinfo( SDL_RWops *src, int *datasize ) {
  13.149 -	Sint64 start;
  13.150 -	int is_WEBP;
  13.151 -	Uint8 magic[20];
  13.152 +    Sint64 start;
  13.153 +    int is_WEBP;
  13.154 +    Uint8 magic[20];
  13.155  
  13.156 -	if ( !src )
  13.157 -		return 0;
  13.158 -	start = SDL_RWtell(src);
  13.159 -	is_WEBP = 0;
  13.160 -	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
  13.161 -		if ( magic[ 0] == 'R' &&
  13.162 +    if ( !src )
  13.163 +        return 0;
  13.164 +    start = SDL_RWtell(src);
  13.165 +    is_WEBP = 0;
  13.166 +    if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
  13.167 +        if ( magic[ 0] == 'R' &&
  13.168                       magic[ 1] == 'I' &&
  13.169                       magic[ 2] == 'F' &&
  13.170                       magic[ 3] == 'F' &&
  13.171 -										 magic[ 8] == 'W' &&
  13.172 -										 magic[ 9] == 'E' &&
  13.173 -										 magic[10] == 'B' &&
  13.174 -										 magic[11] == 'P' &&
  13.175 -										 magic[12] == 'V' &&
  13.176 -										 magic[13] == 'P' &&
  13.177 -										 magic[14] == '8' &&
  13.178 +                                         magic[ 8] == 'W' &&
  13.179 +                                         magic[ 9] == 'E' &&
  13.180 +                                         magic[10] == 'B' &&
  13.181 +                                         magic[11] == 'P' &&
  13.182 +                                         magic[12] == 'V' &&
  13.183 +                                         magic[13] == 'P' &&
  13.184 +                                         magic[14] == '8' &&
  13.185  #if WEBP_DECODER_ABI_VERSION < 0x0003 /* old versions don't support WEBPVP8X and WEBPVP8L */
  13.186 -										 magic[15] == ' ') {
  13.187 +                                         magic[15] == ' ') {
  13.188  #else
  13.189 -										 (magic[15] == ' ' || magic[15] == 'X' || magic[15] == 'L')) {
  13.190 +                                         (magic[15] == ' ' || magic[15] == 'X' || magic[15] == 'L')) {
  13.191  #endif
  13.192 -			is_WEBP = 1;
  13.193 -			if ( datasize ) {
  13.194 -				*datasize = SDL_RWseek(src, 0, SEEK_END);
  13.195 -			}
  13.196 -		}
  13.197 -	}
  13.198 -	SDL_RWseek(src, start, RW_SEEK_SET);
  13.199 -	return(is_WEBP);
  13.200 +            is_WEBP = 1;
  13.201 +            if ( datasize ) {
  13.202 +                *datasize = SDL_RWseek(src, 0, SEEK_END);
  13.203 +            }
  13.204 +        }
  13.205 +    }
  13.206 +    SDL_RWseek(src, start, RW_SEEK_SET);
  13.207 +    return(is_WEBP);
  13.208  }
  13.209  
  13.210  /* See if an image is contained in a data source */
  13.211  int IMG_isWEBP(SDL_RWops *src)
  13.212  {
  13.213 -	return webp_getinfo( src, NULL );
  13.214 +    return webp_getinfo( src, NULL );
  13.215  }
  13.216  
  13.217  SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src)
  13.218  {
  13.219 -	Sint64 start;
  13.220 -	const char *error = NULL;
  13.221 -	SDL_Surface *volatile surface = NULL;
  13.222 -	Uint32 Rmask;
  13.223 -	Uint32 Gmask;
  13.224 -	Uint32 Bmask;
  13.225 -	Uint32 Amask;
  13.226 -	WebPBitstreamFeatures features;
  13.227 -	int raw_data_size;
  13.228 -	uint8_t *raw_data = NULL;
  13.229 -	int r, s;
  13.230 -	uint8_t *ret;
  13.231 +    Sint64 start;
  13.232 +    const char *error = NULL;
  13.233 +    SDL_Surface *volatile surface = NULL;
  13.234 +    Uint32 Rmask;
  13.235 +    Uint32 Gmask;
  13.236 +    Uint32 Bmask;
  13.237 +    Uint32 Amask;
  13.238 +    WebPBitstreamFeatures features;
  13.239 +    int raw_data_size;
  13.240 +    uint8_t *raw_data = NULL;
  13.241 +    int r, s;
  13.242 +    uint8_t *ret;
  13.243  
  13.244 -	if ( !src ) {
  13.245 -		/* The error message has been set in SDL_RWFromFile */
  13.246 -		return NULL;
  13.247 -	}
  13.248 +    if ( !src ) {
  13.249 +        /* The error message has been set in SDL_RWFromFile */
  13.250 +        return NULL;
  13.251 +    }
  13.252  
  13.253 -	start = SDL_RWtell(src);
  13.254 +    start = SDL_RWtell(src);
  13.255  
  13.256 -	if ( !IMG_Init(IMG_INIT_WEBP) ) {
  13.257 -		goto error;
  13.258 -	}
  13.259 +    if ( !IMG_Init(IMG_INIT_WEBP) ) {
  13.260 +        goto error;
  13.261 +    }
  13.262  
  13.263 -	raw_data_size = -1;
  13.264 -	if ( !webp_getinfo( src, &raw_data_size ) ) {
  13.265 -		error = "Invalid WEBP";
  13.266 -		goto error;
  13.267 -	}
  13.268 +    raw_data_size = -1;
  13.269 +    if ( !webp_getinfo( src, &raw_data_size ) ) {
  13.270 +        error = "Invalid WEBP";
  13.271 +        goto error;
  13.272 +    }
  13.273  
  13.274 -	// seek to start of file
  13.275 -	SDL_RWseek(src, 0, RW_SEEK_SET );
  13.276 +    // seek to start of file
  13.277 +    SDL_RWseek(src, 0, RW_SEEK_SET );
  13.278  
  13.279 -	raw_data = (uint8_t*) SDL_malloc( raw_data_size );
  13.280 -	if ( raw_data == NULL ) {
  13.281 -		error = "Failed to allocate enought buffer for WEBP";
  13.282 -		goto error;
  13.283 -	}
  13.284 +    raw_data = (uint8_t*) SDL_malloc( raw_data_size );
  13.285 +    if ( raw_data == NULL ) {
  13.286 +        error = "Failed to allocate enought buffer for WEBP";
  13.287 +        goto error;
  13.288 +    }
  13.289  
  13.290 -	r = SDL_RWread(src, raw_data, 1, raw_data_size );
  13.291 -	if ( r != raw_data_size ) {
  13.292 -		error = "Failed to read WEBP";
  13.293 -		goto error;
  13.294 -	}
  13.295 -	
  13.296 +    r = SDL_RWread(src, raw_data, 1, raw_data_size );
  13.297 +    if ( r != raw_data_size ) {
  13.298 +        error = "Failed to read WEBP";
  13.299 +        goto error;
  13.300 +    }
  13.301 +
  13.302  #if 0
  13.303 -	// extract size of picture, not interesting since we don't know about alpha channel
  13.304 -	int width = -1, height = -1;
  13.305 -	if ( !WebPGetInfo( raw_data, raw_data_size, &width, &height ) ) {
  13.306 -		printf("WebPGetInfo has failed\n" );
  13.307 -		return NULL;
  13.308 -	}
  13.309 +    // extract size of picture, not interesting since we don't know about alpha channel
  13.310 +    int width = -1, height = -1;
  13.311 +    if ( !WebPGetInfo( raw_data, raw_data_size, &width, &height ) ) {
  13.312 +        printf("WebPGetInfo has failed\n" );
  13.313 +        return NULL;
  13.314 +    }
  13.315  #endif
  13.316  
  13.317 -	if ( lib.webp_get_features_internal( raw_data, raw_data_size, &features, WEBP_DECODER_ABI_VERSION ) != VP8_STATUS_OK ) {
  13.318 -		error = "WebPGetFeatures has failed";
  13.319 -		goto error;
  13.320 -	}
  13.321 +    if ( lib.webp_get_features_internal( raw_data, raw_data_size, &features, WEBP_DECODER_ABI_VERSION ) != VP8_STATUS_OK ) {
  13.322 +        error = "WebPGetFeatures has failed";
  13.323 +        goto error;
  13.324 +    }
  13.325  
  13.326 -	/* Check if it's ok !*/
  13.327 +    /* Check if it's ok !*/
  13.328  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  13.329 -	Rmask = 0x000000FF;
  13.330 -	Gmask = 0x0000FF00;
  13.331 -	Bmask = 0x00FF0000;
  13.332 -	Amask = (features.has_alpha) ? 0xFF000000 : 0;
  13.333 +    Rmask = 0x000000FF;
  13.334 +    Gmask = 0x0000FF00;
  13.335 +    Bmask = 0x00FF0000;
  13.336 +    Amask = (features.has_alpha) ? 0xFF000000 : 0;
  13.337  #else
  13.338 -	s = (features.has_alpha) ? 0 : 8;
  13.339 -	Rmask = 0xFF000000 >> s;
  13.340 -	Gmask = 0x00FF0000 >> s;
  13.341 -	Bmask = 0x0000FF00 >> s;
  13.342 -	Amask = 0x000000FF >> s;
  13.343 +    s = (features.has_alpha) ? 0 : 8;
  13.344 +    Rmask = 0xFF000000 >> s;
  13.345 +    Gmask = 0x00FF0000 >> s;
  13.346 +    Bmask = 0x0000FF00 >> s;
  13.347 +    Amask = 0x000000FF >> s;
  13.348  #endif
  13.349  
  13.350 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
  13.351 -			features.width, features.height,
  13.352 -			features.has_alpha?32:24, Rmask,Gmask,Bmask,Amask);
  13.353 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
  13.354 +            features.width, features.height,
  13.355 +            features.has_alpha?32:24, Rmask,Gmask,Bmask,Amask);
  13.356  
  13.357 -	if ( surface == NULL ) {
  13.358 -		error = "Failed to allocate SDL_Surface";
  13.359 -		goto error;
  13.360 -	}
  13.361 +    if ( surface == NULL ) {
  13.362 +        error = "Failed to allocate SDL_Surface";
  13.363 +        goto error;
  13.364 +    }
  13.365  
  13.366 -	if ( features.has_alpha ) {
  13.367 -		ret = lib.webp_decode_rgba_into( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h,  surface->pitch );
  13.368 -	} else {
  13.369 -		ret = lib.webp_decode_rgb_into( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h,  surface->pitch );
  13.370 -	}
  13.371 +    if ( features.has_alpha ) {
  13.372 +        ret = lib.webp_decode_rgba_into( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h,  surface->pitch );
  13.373 +    } else {
  13.374 +        ret = lib.webp_decode_rgb_into( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h,  surface->pitch );
  13.375 +    }
  13.376  
  13.377 -	if ( !ret ) {
  13.378 -		error = "Failed to decode WEBP";
  13.379 -		goto error;
  13.380 -	}
  13.381 +    if ( !ret ) {
  13.382 +        error = "Failed to decode WEBP";
  13.383 +        goto error;
  13.384 +    }
  13.385  
  13.386 -	return surface;
  13.387 +    return surface;
  13.388  
  13.389  
  13.390  error:
  13.391  
  13.392 -	if ( surface ) {
  13.393 -		SDL_FreeSurface( surface );
  13.394 -	}
  13.395 +    if ( surface ) {
  13.396 +        SDL_FreeSurface( surface );
  13.397 +    }
  13.398  
  13.399 -	if ( raw_data ) {
  13.400 -		SDL_free( raw_data );
  13.401 -	}
  13.402 +    if ( raw_data ) {
  13.403 +        SDL_free( raw_data );
  13.404 +    }
  13.405  
  13.406 -	if ( error ) {
  13.407 -		IMG_SetError( error );
  13.408 -	}
  13.409 +    if ( error ) {
  13.410 +        IMG_SetError( error );
  13.411 +    }
  13.412  
  13.413 -	SDL_RWseek(src, start, RW_SEEK_SET);
  13.414 -	return(NULL);
  13.415 +    SDL_RWseek(src, start, RW_SEEK_SET);
  13.416 +    return(NULL);
  13.417  }
  13.418  
  13.419  #else
  13.420  
  13.421  int IMG_InitWEBP()
  13.422  {
  13.423 -	IMG_SetError("WEBP images are not supported");
  13.424 -	return(-1);
  13.425 +    IMG_SetError("WEBP images are not supported");
  13.426 +    return(-1);
  13.427  }
  13.428  
  13.429  void IMG_QuitWEBP()
  13.430 @@ -294,13 +294,13 @@
  13.431  /* See if an image is contained in a data source */
  13.432  int IMG_isWEBP(SDL_RWops *src)
  13.433  {
  13.434 -	return(0);
  13.435 +    return(0);
  13.436  }
  13.437  
  13.438  /* Load a WEBP type image from an SDL datasource */
  13.439  SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src)
  13.440  {
  13.441 -	return(NULL);
  13.442 +    return(NULL);
  13.443  }
  13.444  
  13.445  #endif /* LOAD_WEBP */
    14.1 --- a/IMG_xcf.c	Thu Apr 25 00:22:51 2013 -0700
    14.2 +++ b/IMG_xcf.c	Tue May 21 21:24:32 2013 -0700
    14.3 @@ -208,21 +208,21 @@
    14.4  /* See if an image is contained in a data source */
    14.5  int IMG_isXCF(SDL_RWops *src)
    14.6  {
    14.7 -	Sint64 start;
    14.8 -	int is_XCF;
    14.9 -	char magic[14];
   14.10 +    Sint64 start;
   14.11 +    int is_XCF;
   14.12 +    char magic[14];
   14.13  
   14.14 -	if ( !src )
   14.15 -		return 0;
   14.16 -	start = SDL_RWtell(src);
   14.17 -	is_XCF = 0;
   14.18 -	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   14.19 -		if (SDL_strncmp(magic, "gimp xcf ", 9) == 0) {
   14.20 -			is_XCF = 1;
   14.21 -		}
   14.22 -	}
   14.23 -	SDL_RWseek(src, start, RW_SEEK_SET);
   14.24 -	return(is_XCF);
   14.25 +    if ( !src )
   14.26 +        return 0;
   14.27 +    start = SDL_RWtell(src);
   14.28 +    is_XCF = 0;
   14.29 +    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   14.30 +        if (SDL_strncmp(magic, "gimp xcf ", 9) == 0) {
   14.31 +            is_XCF = 1;
   14.32 +        }
   14.33 +    }
   14.34 +    SDL_RWseek(src, start, RW_SEEK_SET);
   14.35 +    return(is_XCF);
   14.36  }
   14.37  
   14.38  static char * read_string (SDL_RWops * src) {
   14.39 @@ -381,8 +381,8 @@
   14.40        break;
   14.41      case PROP_COLOR:
   14.42        l->color = ((Uint32) prop.data.color[0] << 16)
   14.43 -	| ((Uint32) prop.data.color[1] << 8)
   14.44 -	| ((Uint32) prop.data.color[2]);
   14.45 +    | ((Uint32) prop.data.color[1] << 8)
   14.46 +    | ((Uint32) prop.data.color[2]);
   14.47        break;
   14.48      case PROP_SELECTION:
   14.49        l->selection = 1;
   14.50 @@ -474,42 +474,42 @@
   14.51      d    = data + i;
   14.52      size = x*y;
   14.53      count = 0;
   14.54 - 
   14.55 +
   14.56      while (size > 0) {
   14.57        val = *t++;
   14.58  
   14.59        length = val;
   14.60        if (length >= 128) {
   14.61 -	length = 255 - (length - 1);
   14.62 -	if (length == 128) {
   14.63 -	  length = (*t << 8) + t[1];
   14.64 -	  t += 2;
   14.65 -	}
   14.66 +    length = 255 - (length - 1);
   14.67 +    if (length == 128) {
   14.68 +      length = (*t << 8) + t[1];
   14.69 +      t += 2;
   14.70 +    }
   14.71  
   14.72 -	count += length;
   14.73 -	size -= length;
   14.74 +    count += length;
   14.75 +    size -= length;
   14.76  
   14.77 -	while (length-- > 0) {
   14.78 -	  *d = *t++;
   14.79 -	  d += bpp;
   14.80 -	}
   14.81 +    while (length-- > 0) {
   14.82 +      *d = *t++;
   14.83 +      d += bpp;
   14.84 +    }
   14.85        }
   14.86        else {
   14.87 -	length += 1;
   14.88 -	if (length == 128) {
   14.89 -	  length = (*t << 8) + t[1];
   14.90 -	  t += 2;
   14.91 -	}
   14.92 +    length += 1;
   14.93 +    if (length == 128) {
   14.94 +      length = (*t << 8) + t[1];
   14.95 +      t += 2;
   14.96 +    }
   14.97  
   14.98 -	count += length;
   14.99 -	size -= length;
  14.100 +    count += length;
  14.101 +    size -= length;
  14.102  
  14.103 -	val = *t++;
  14.104 +    val = *t++;
  14.105  
  14.106 -	for (j = 0; j < length; j++) {
  14.107 -	  *d = val;
  14.108 -	  d += bpp;
  14.109 -	}
  14.110 +    for (j = 0; j < length; j++) {
  14.111 +      *d = val;
  14.112 +      d += bpp;
  14.113 +    }
  14.114        }
  14.115      }
  14.116    }
  14.117 @@ -568,98 +568,98 @@
  14.118        oy = ty+64 > level->height ? level->height % 64 : 64;
  14.119  
  14.120        if (level->tile_file_offsets [j+1]) {
  14.121 -	tile = load_tile
  14.122 -	  (src,
  14.123 -	   level->tile_file_offsets [j+1] - level->tile_file_offsets [j],
  14.124 -	   hierarchy->bpp,
  14.125 -	   ox, oy);
  14.126 +    tile = load_tile
  14.127 +      (src,
  14.128 +       level->tile_file_offsets [j+1] - level->tile_file_offsets [j],
  14.129 +       hierarchy->bpp,
  14.130 +       ox, oy);
  14.131        }
  14.132        else {
  14.133 -	tile = load_tile
  14.134 -	  (src,
  14.135 -	   ox*oy*6,
  14.136 -	   hierarchy->bpp,
  14.137 -	   ox, oy);
  14.138 +    tile = load_tile
  14.139 +      (src,
  14.140 +       ox*oy*6,
  14.141 +       hierarchy->bpp,
  14.142 +       ox, oy);
  14.143        }
  14.144  
  14.145        p8  = tile;
  14.146        p16 = (Uint16 *) p8;
  14.147        p   = (Uint32 *) p8;
  14.148        for (y=ty; y < ty+oy; y++) {
  14.149 -	row = (Uint32 *)((Uint8 *)surface->pixels + y*surface->pitch + tx*4);
  14.150 -	switch (hierarchy->bpp) {
  14.151 -	case 4:
  14.152 -	  for (x=tx; x < tx+ox; x++)
  14.153 -	    *row++ = Swap32 (*p++);
  14.154 -	  break;
  14.155 -	case 3:
  14.156 -	  for (x=tx; x < tx+ox; x++) {
  14.157 -	    *row = 0xFF000000;
  14.158 -	    *row |= ((Uint32) *(p8++) << 16);
  14.159 -	    *row |= ((Uint32) *(p8++) << 8);
  14.160 -	    *row |= ((Uint32) *(p8++) << 0);
  14.161 -	    row++;
  14.162 -	  }
  14.163 -	  break;
  14.164 -	case 2: // Indexed/Greyscale + Alpha
  14.165 -	  switch (head->image_type) {
  14.166 -	  case IMAGE_INDEXED:
  14.167 -	    for (x=tx; x < tx+ox; x++) {
  14.168 -	      *row =  ((Uint32) (head->cm_map [*p8*3])     << 16);
  14.169 -	      *row |= ((Uint32) (head->cm_map [*p8*3+1])   << 8);
  14.170 -	      *row |= ((Uint32) (head->cm_map [*p8++*3+2]) << 0);
  14.171 -	      *row |= ((Uint32) *p8++ << 24);;
  14.172 -	      row++;
  14.173 -	    }
  14.174 -	    break;
  14.175 -	  case IMAGE_GREYSCALE:
  14.176 -	    for (x=tx; x < tx+ox; x++) {
  14.177 -	      *row = ((Uint32) *p8 << 16);
  14.178 -	      *row |= ((Uint32) *p8 << 8);
  14.179 -	      *row |= ((Uint32) *p8++ << 0);
  14.180 -	      *row |= ((Uint32) *p8++ << 24);;
  14.181 -	      row++;
  14.182 -	    }
  14.183 -	    break;	    
  14.184 -	  default:
  14.185 -	    fprintf (stderr, "Unknown Gimp image type (%d)\n", head->image_type);
  14.186 -	    return 1;
  14.187 -	  }
  14.188 -	  break;
  14.189 -	case 1: // Indexed/Greyscale
  14.190 -	  switch (head->image_type) {
  14.191 -	  case IMAGE_INDEXED:
  14.192 -	    for (x = tx; x < tx+ox; x++) {
  14.193 -	      *row++ = 0xFF000000
  14.194 -		| ((Uint32) (head->cm_map [*p8*3]) << 16)
  14.195 -		| ((Uint32) (head->cm_map [*p8*3+1]) << 8)
  14.196 -		| ((Uint32) (head->cm_map [*p8*3+2]) << 0);
  14.197 -	      p8++;
  14.198 -	    }
  14.199 -	    break;
  14.200 -	  case IMAGE_GREYSCALE:
  14.201 -	    for (x=tx; x < tx+ox; x++) {
  14.202 -	      *row++ = 0xFF000000
  14.203 -		| (((Uint32) (*p8)) << 16)
  14.204 -		| (((Uint32) (*p8)) << 8)
  14.205 -		| (((Uint32) (*p8)) << 0);
  14.206 -			++p8;
  14.207 -	    }
  14.208 -	    break;	    
  14.209 -	  default:
  14.210 -	    fprintf (stderr, "Unknown Gimp image type (%d)\n", head->image_type);
  14.211 -	    return 1;
  14.212 -	  }
  14.213 -	  break;
  14.214 -	}
  14.215 +    row = (Uint32 *)((Uint8 *)surface->pixels + y*surface->pitch + tx*4);
  14.216 +    switch (hierarchy->bpp) {
  14.217 +    case 4:
  14.218 +      for (x=tx; x < tx+ox; x++)
  14.219 +        *row++ = Swap32 (*p++);
  14.220 +      break;
  14.221 +    case 3:
  14.222 +      for (x=tx; x < tx+ox; x++) {
  14.223 +        *row = 0xFF000000;
  14.224 +        *row |= ((Uint32) *(p8++) << 16);
  14.225 +        *row |= ((Uint32) *(p8++) << 8);
  14.226 +        *row |= ((Uint32) *(p8++) << 0);
  14.227 +        row++;
  14.228 +      }
  14.229 +      break;
  14.230 +    case 2: // Indexed/Greyscale + Alpha
  14.231 +      switch (head->image_type) {
  14.232 +      case IMAGE_INDEXED:
  14.233 +        for (x=tx; x < tx+ox; x++) {
  14.234 +          *row =  ((Uint32) (head->cm_map [*p8*3])     << 16);
  14.235 +          *row |= ((Uint32) (head->cm_map [*p8*3+1])   << 8);
  14.236 +          *row |= ((Uint32) (head->cm_map [*p8++*3+2]) << 0);
  14.237 +          *row |= ((Uint32) *p8++ << 24);;
  14.238 +          row++;
  14.239 +        }
  14.240 +        break;
  14.241 +      case IMAGE_GREYSCALE:
  14.242 +        for (x=tx; x < tx+ox; x++) {
  14.243 +          *row = ((Uint32) *p8 << 16);
  14.244 +          *row |= ((Uint32) *p8 << 8);
  14.245 +          *row |= ((Uint32) *p8++ << 0);
  14.246 +          *row |= ((Uint32) *p8++ << 24);;
  14.247 +          row++;
  14.248 +        }
  14.249 +        break;
  14.250 +      default:
  14.251 +        fprintf (stderr, "Unknown Gimp image type (%d)\n", head->image_type);
  14.252 +        return 1;
  14.253 +      }
  14.254 +      break;
  14.255 +    case 1: // Indexed/Greyscale
  14.256 +      switch (head->image_type) {
  14.257 +      case IMAGE_INDEXED:
  14.258 +        for (x = tx; x < tx+ox; x++) {
  14.259 +          *row++ = 0xFF000000
  14.260 +        | ((Uint32) (head->cm_map [*p8*3]) << 16)
  14.261 +        | ((Uint32) (head->cm_map [*p8*3+1]) << 8)
  14.262 +        | ((Uint32) (head->cm_map [*p8*3+2]) << 0);
  14.263 +          p8++;
  14.264 +        }
  14.265 +        break;
  14.266 +      case IMAGE_GREYSCALE:
  14.267 +        for (x=tx; x < tx+ox; x++) {
  14.268 +          *row++ = 0xFF000000
  14.269 +        | (((Uint32) (*p8)) << 16)
  14.270 +        | (((Uint32) (*p8)) << 8)
  14.271 +        | (((Uint32) (*p8)) << 0);
  14.272 +            ++p8;
  14.273 +        }
  14.274 +        break;
  14.275 +      default:
  14.276 +        fprintf (stderr, "Unknown Gimp image type (%d)\n", head->image_type);
  14.277 +        return 1;
  14.278 +      }
  14.279 +      break;
  14.280 +    }
  14.281        }
  14.282        tx += 64;
  14.283        if (tx >= level->width) {
  14.284 -	tx = 0;
  14.285 -	ty += 64;
  14.286 +    tx = 0;
  14.287 +    ty += 64;
  14.288        }
  14.289        if (ty >= level->height) {
  14.290 -	break;
  14.291 +    break;
  14.292        }
  14.293  
  14.294        free_xcf_tile (tile);
  14.295 @@ -668,7 +668,7 @@
  14.296    }
  14.297  
  14.298    free_xcf_hierarchy (hierarchy);
  14.299 -  
  14.300 +
  14.301    return 0;
  14.302  }
  14.303  
  14.304 @@ -711,7 +711,7 @@
  14.305  
  14.306    /* Create the surface of the appropriate type */
  14.307    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
  14.308 -			     0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
  14.309 +                 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
  14.310  
  14.311    if ( surface == NULL ) {
  14.312      error = "Out of memory";
  14.313 @@ -727,9 +727,9 @@
  14.314      offsets++;
  14.315    }
  14.316    fp = SDL_RWtell (src);
  14.317 - 
  14.318 +
  14.319    lays = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
  14.320 -			  0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
  14.321 +              0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
  14.322  
  14.323    if ( lays == NULL ) {
  14.324      error = "Out of memory";
  14.325 @@ -769,14 +769,14 @@
  14.326      fp = SDL_RWtell (src);
  14.327      SDL_RWseek (src, offset, RW_SEEK_SET);
  14.328      channel [chnls++] = (read_xcf_channel (src));
  14.329 -    SDL_RWseek (src, fp, RW_SEEK_SET);    
  14.330 +    SDL_RWseek (src, fp, RW_SEEK_SET);
  14.331    }
  14.332  
  14.333    if (chnls) {
  14.334      SDL_Surface * chs;
  14.335  
  14.336      chs = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
  14.337 -			   0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
  14.338 +               0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
  14.339  
  14.340      if (chs == NULL) {
  14.341        error = "Out of memory";
  14.342 @@ -785,8 +785,8 @@
  14.343      for (i = 0; i < chnls; i++) {
  14.344        //      printf ("CNLBLT %i\n", i);
  14.345        if (!channel [i]->selection && channel [i]->visible) {
  14.346 -	create_channel_surface (chs, (xcf_image_type)head->image_type, channel [i]->color, channel [i]->opacity);
  14.347 -	SDL_BlitSurface (chs, NULL, surface, NULL);
  14.348 +    create_channel_surface (chs, (xcf_image_type)head->image_type, channel [i]->color, channel [i]->opacity);
  14.349 +    SDL_BlitSurface (chs, NULL, surface, NULL);
  14.350        }
  14.351        free_xcf_channel (channel [i]);
  14.352      }
    15.1 --- a/IMG_xpm.c	Thu Apr 25 00:22:51 2013 -0700
    15.2 +++ b/IMG_xpm.c	Tue May 21 21:24:32 2013 -0700
    15.3 @@ -31,7 +31,7 @@
    15.4   *
    15.5   * The result is an 8bpp indexed surface if possible, otherwise 32bpp.
    15.6   * The colourkey is correctly set if transparency is used.
    15.7 - * 
    15.8 + *
    15.9   * Besides the standard API, also provides
   15.10   *
   15.11   *     SDL_Surface *IMG_ReadXPMFromArray(char **xpm)
   15.12 @@ -54,92 +54,92 @@
   15.13  /* See if an image is contained in a data source */
   15.14  int IMG_isXPM(SDL_RWops *src)
   15.15  {
   15.16 -	Sint64 start;
   15.17 -	int is_XPM;
   15.18 -	char magic[9];
   15.19 +    Sint64 start;
   15.20 +    int is_XPM;
   15.21 +    char magic[9];
   15.22  
   15.23 -	if ( !src )
   15.24 -		return 0;
   15.25 -	start = SDL_RWtell(src);
   15.26 -	is_XPM = 0;
   15.27 -	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   15.28 -		if ( SDL_memcmp(magic, "/* XPM */", sizeof(magic)) == 0 ) {
   15.29 -			is_XPM = 1;
   15.30 -		}
   15.31 -	}
   15.32 -	SDL_RWseek(src, start, RW_SEEK_SET);
   15.33 -	return(is_XPM);
   15.34 +    if ( !src )
   15.35 +        return 0;
   15.36 +    start = SDL_RWtell(src);
   15.37 +    is_XPM = 0;
   15.38 +    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   15.39 +        if ( SDL_memcmp(magic, "/* XPM */", sizeof(magic)) == 0 ) {
   15.40 +            is_XPM = 1;
   15.41 +        }
   15.42 +    }
   15.43 +    SDL_RWseek(src, start, RW_SEEK_SET);
   15.44 +    return(is_XPM);
   15.45  }
   15.46  
   15.47  /* Hash table to look up colors from pixel strings */
   15.48  #define STARTING_HASH_SIZE 256
   15.49  
   15.50  struct hash_entry {
   15.51 -	char *key;
   15.52 -	Uint32 color;
   15.53 -	struct hash_entry *next;
   15.54 +    char *key;
   15.55 +    Uint32 color;
   15.56 +    struct hash_entry *next;
   15.57  };
   15.58  
   15.59  struct color_hash {
   15.60 -	struct hash_entry **table;
   15.61 -	struct hash_entry *entries; /* array of all entries */
   15.62 -	struct hash_entry *next_free;
   15.63 -	int size;
   15.64 -	int maxnum;
   15.65 +    struct hash_entry **table;
   15.66 +    struct hash_entry *entries; /* array of all entries */
   15.67 +    struct hash_entry *next_free;
   15.68 +    int size;
   15.69 +    int maxnum;
   15.70  };
   15.71  
   15.72  static int hash_key(const char *key, int cpp, int size)
   15.73  {
   15.74 -	int hash;
   15.75 +    int hash;
   15.76  
   15.77 -	hash = 0;
   15.78 -	while ( cpp-- > 0 ) {
   15.79 -		hash = hash * 33 + *key++;
   15.80 -	}
   15.81 -	return hash & (size - 1);
   15.82 +    hash = 0;
   15.83 +    while ( cpp-- > 0 ) {
   15.84 +        hash = hash * 33 + *key++;
   15.85 +    }
   15.86 +    return hash & (size - 1);
   15.87  }
   15.88  
   15.89  static struct color_hash *create_colorhash(int maxnum)
   15.90  {
   15.91 -	int bytes, s;
   15.92 -	struct color_hash *hash;
   15.93 +    int bytes, s;
   15.94 +    struct color_hash *hash;
   15.95  
   15.96 -	/* we know how many entries we need, so we can allocate
   15.97 -	   everything here */
   15.98 -	hash = (struct color_hash *)SDL_malloc(sizeof *hash);
   15.99 -	if(!hash)
  15.100 -		return NULL;
  15.101 +    /* we know how many entries we need, so we can allocate
  15.102 +       everything here */
  15.103 +    hash = (struct color_hash *)SDL_malloc(sizeof *hash);
  15.104 +    if(!hash)
  15.105 +        return NULL;
  15.106  
  15.107 -	/* use power-of-2 sized hash table for decoding speed */
  15.108 -	for(s = STARTING_HASH_SIZE; s < maxnum; s <<= 1)
  15.109 -		;
  15.110 -	hash->size = s;
  15.111 -	hash->maxnum = maxnum;
  15.112 -	bytes = hash->size * sizeof(struct hash_entry **);
  15.113 -	hash->entries = NULL;	/* in case malloc fails */
  15.114 -	hash->table = (struct hash_entry **)SDL_malloc(bytes);
  15.115 -	if(!hash->table)
  15.116 -		return NULL;
  15.117 -	memset(hash->table, 0, bytes);
  15.118 -	hash->entries = (struct hash_entry *)SDL_malloc(maxnum * sizeof(struct hash_entry));
  15.119 -	if(!hash->entries) {
  15.120 -		SDL_free(hash->table);
  15.121 -		return NULL;
  15.122 -	}
  15.123 -	hash->next_free = hash->entries;
  15.124 -	return hash;
  15.125 +    /* use power-of-2 sized hash table for decoding speed */
  15.126 +    for(s = STARTING_HASH_SIZE; s < maxnum; s <<= 1)
  15.127 +        ;
  15.128 +    hash->size = s;
  15.129 +    hash->maxnum = maxnum;
  15.130 +    bytes = hash->size * sizeof(struct hash_entry **);
  15.131 +    hash->entries = NULL;   /* in case malloc fails */
  15.132 +    hash->table = (struct hash_entry **)SDL_malloc(bytes);
  15.133 +    if(!hash->table)
  15.134 +        return NULL;
  15.135 +    memset(hash->table, 0, bytes);
  15.136 +    hash->entries = (struct hash_entry *)SDL_malloc(maxnum * sizeof(struct hash_entry));
  15.137 +    if(!hash->entries) {
  15.138 +        SDL_free(hash->table);
  15.139 +        return NULL;
  15.140 +    }
  15.141 +    hash->next_free = hash->entries;
  15.142 +    return hash;
  15.143  }
  15.144  
  15.145  static int add_colorhash(struct color_hash *hash,
  15.146                           char *key, int cpp, Uint32 color)
  15.147  {
  15.148 -	int index = hash_key(key, cpp, hash->size);
  15.149 -	struct hash_entry *e = hash->next_free++;
  15.150 -	e->color = color;
  15.151 -	e->key = key;
  15.152 -	e->next = hash->table[index];
  15.153 -	hash->table[index] = e;
  15.154 -	return 1;
  15.155 +    int index = hash_key(key, cpp, hash->size);
  15.156 +    struct hash_entry *e = hash->next_free++;
  15.157 +    e->color = color;
  15.158 +    e->key = key;
  15.159 +    e->next = hash->table[index];
  15.160 +    hash->table[index] = e;
  15.161 +    return 1;
  15.162  }
  15.163  
  15.164  /* fast lookup that works if cpp == 1 */
  15.165 @@ -147,24 +147,24 @@
  15.166  
  15.167  static Uint32 get_colorhash(struct color_hash *hash, const char *key, int cpp)
  15.168  {
  15.169 -	struct hash_entry *entry = hash->table[hash_key(key, cpp, hash->size)];
  15.170 -	while(entry) {
  15.171 -		if(SDL_memcmp(key, entry->key, cpp) == 0)
  15.172 -			return entry->color;
  15.173 -		entry = entry->next;
  15.174 -	}
  15.175 -	return 0;		/* garbage in - garbage out */
  15.176 +    struct hash_entry *entry = hash->table[hash_key(key, cpp, hash->size)];
  15.177 +    while(entry) {
  15.178 +        if(SDL_memcmp(key, entry->key, cpp) == 0)
  15.179 +            return entry->color;
  15.180 +        entry = entry->next;
  15.181 +    }
  15.182 +    return 0;       /* garbage in - garbage out */
  15.183  }
  15.184  
  15.185  static void free_colorhash(struct color_hash *hash)
  15.186  {
  15.187 -	if(hash) {
  15.188 -		if(hash->table)
  15.189 -			SDL_free(hash->table);
  15.190 -		if(hash->entries)
  15.191 -			SDL_free(hash->entries);
  15.192 -		SDL_free(hash);
  15.193 -	}
  15.194 +    if(hash) {
  15.195 +        if(hash->table)
  15.196 +            SDL_free(hash->table);
  15.197 +        if(hash->entries)
  15.198 +            SDL_free(hash->entries);
  15.199 +        SDL_free(hash);
  15.200 +    }
  15.201  }
  15.202  
  15.203  /*
  15.204 @@ -173,729 +173,729 @@
  15.205   */
  15.206  static int color_to_rgb(char *spec, int speclen, Uint32 *rgb)
  15.207  {
  15.208 -	/* poor man's rgb.txt */
  15.209 -	static struct { char *name; Uint32 rgb; } known[] = {
  15.210 -		{ "none",                 0xFFFFFF },
  15.211 -		{ "black",                0x000000 },
  15.212 -		{ "white",                0xFFFFFF },
  15.213 -		{ "red",                  0xFF0000 },
  15.214 -		{ "green",                0x00FF00 },
  15.215 -		{ "blue",                 0x0000FF },
  15.216 +    /* poor man's rgb.txt */
  15.217 +    static struct { char *name; Uint32 rgb; } known[] = {
  15.218 +        { "none",                 0xFFFFFF },
  15.219 +        { "black",                0x000000 },
  15.220 +        { "white",                0xFFFFFF },
  15.221 +        { "red",                  0xFF0000 },
  15.222 +        { "green",                0x00FF00 },
  15.223 +        { "blue",                 0x0000FF },
  15.224  /* This table increases the size of the library by 40K, so it's disabled by default */
  15.225  #ifdef EXTENDED_XPM_COLORS
  15.226 -		{ "aliceblue",            0xf0f8ff },
  15.227 -		{ "antiquewhite",         0xfaebd7 },
  15.228 -		{ "antiquewhite1",        0xffefdb },
  15.229 -		{ "antiquewhite2",        0xeedfcc },
  15.230 -		{ "antiquewhite3",        0xcdc0b0 },
  15.231 -		{ "antiquewhite4",        0x8b8378 },
  15.232 -		{ "aqua",                 0x00ffff },
  15.233 -		{ "aquamarine",           0x7fffd4 },
  15.234 -		{ "aquamarine1",          0x7fffd4 },
  15.235 -		{ "aquamarine2",          0x76eec6 },
  15.236 -		{ "aquamarine3",          0x66cdaa },
  15.237 -		{ "aquamarine4",          0x458b74 },
  15.238 -		{ "azure",                0xf0ffff },
  15.239 -		{ "azure1",               0xf0ffff },
  15.240 -		{ "azure2",               0xe0eeee },
  15.241 -		{ "azure3",               0xc1cdcd },
  15.242 -		{ "azure4",               0x838b8b },
  15.243 -		{ "beige",                0xf5f5dc },
  15.244 -		{ "bisque",               0xffe4c4 },
  15.245 -		{ "bisque1",              0xffe4c4 },
  15.246 -		{ "bisque2",              0xeed5b7 },
  15.247 -		{ "bisque3",              0xcdb79e },
  15.248 -		{ "bisque4",              0x8b7d6b },
  15.249 -		{ "black",                0x000000 },
  15.250 -		{ "blanchedalmond",       0xffebcd },
  15.251 -		{ "blue",                 0x0000ff },
  15.252 -		{ "blue1",                0x0000ff },
  15.253 -		{ "blue2",                0x0000ee },
  15.254 -		{ "blue3",                0x0000cd },
  15.255 -		{ "blue4",                0x00008B },
  15.256 -		{ "blueviolet",           0x8a2be2 },
  15.257 -		{ "brown",                0xA52A2A },
  15.258 -		{ "brown1",               0xFF4040 },
  15.259 -		{ "brown2",               0xEE3B3B },
  15.260 -		{ "brown3",               0xCD3333 },
  15.261 -		{ "brown4",               0x8B2323 },
  15.262 -		{ "burlywood",            0xDEB887 },
  15.263 -		{ "burlywood1",           0xFFD39B },
  15.264 -		{ "burlywood2",           0xEEC591 },
  15.265 -		{ "burlywood3",           0xCDAA7D },
  15.266 -		{ "burlywood4",           0x8B7355 },
  15.267 -		{ "cadetblue",            0x5F9EA0 },
  15.268 -		{ "cadetblue",            0x5f9ea0 },
  15.269 -		{ "cadetblue1",           0x98f5ff },
  15.270 -		{ "cadetblue2",           0x8ee5ee },
  15.271 -		{ "cadetblue3",           0x7ac5cd },
  15.272 -		{ "cadetblue4",           0x53868b },
  15.273 -		{ "chartreuse",           0x7FFF00 },
  15.274 -		{ "chartreuse1",          0x7FFF00 },
  15.275 -		{ "chartreuse2",          0x76EE00 },
  15.276 -		{ "chartreuse3",          0x66CD00 },
  15.277 -		{ "chartreuse4",          0x458B00 },
  15.278 -		{ "chocolate",            0xD2691E },
  15.279 -		{ "chocolate1",           0xFF7F24 },
  15.280 -		{ "chocolate2",           0xEE7621 },
  15.281 -		{ "chocolate3",           0xCD661D },
  15.282 -		{ "chocolate4",           0x8B4513 },
  15.283 -		{ "coral",                0xFF7F50 },
  15.284 -		{ "coral1",               0xFF7256 },
  15.285 -		{ "coral2",               0xEE6A50 },
  15.286 -		{ "coral3",               0xCD5B45 },
  15.287 -		{ "coral4",               0x8B3E2F },
  15.288 -		{ "cornflowerblue",       0x6495ed },
  15.289 -		{ "cornsilk",             0xFFF8DC },
  15.290 -		{ "cornsilk1",            0xFFF8DC },
  15.291 -		{ "cornsilk2",            0xEEE8CD },
  15.292 -		{ "cornsilk3",            0xCDC8B1 },
  15.293 -		{ "cornsilk4",            0x8B8878 },
  15.294 -		{ "crimson",              0xDC143C },
  15.295 -		{ "cyan",                 0x00FFFF },
  15.296 -		{ "cyan1",                0x00FFFF },
  15.297 -		{ "cyan2",                0x00EEEE },
  15.298 -		{ "cyan3",                0x00CDCD },
  15.299 -		{ "cyan4",                0x008B8B },
  15.300 -		{ "darkblue",             0x00008b },
  15.301 -		{ "darkcyan",             0x008b8b },
  15.302 -		{ "darkgoldenrod",        0xb8860b },
  15.303 -		{ "darkgoldenrod1",       0xffb90f },
  15.304 -		{ "darkgoldenrod2",       0xeead0e },
  15.305 -		{ "darkgoldenrod3",       0xcd950c },
  15.306 -		{ "darkgoldenrod4",       0x8b6508 },
  15.307 -		{ "darkgray",             0xa9a9a9 },
  15.308 -		{ "darkgreen",            0x006400 },
  15.309 -		{ "darkgrey",             0xa9a9a9 },
  15.310 -		{ "darkkhaki",            0xbdb76b },
  15.311 -		{ "darkmagenta",          0x8b008b },
  15.312 -		{ "darkolivegreen",       0x556b2f },
  15.313 -		{ "darkolivegreen1",      0xcaff70 },
  15.314 -		{ "darkolivegreen2",      0xbcee68 },
  15.315 -		{ "darkolivegreen3",      0xa2cd5a },
  15.316 -		{ "darkolivegreen4",      0x6e8b3d },
  15.317 -		{ "darkorange",           0xff8c00 },
  15.318 -		{ "darkorange1",          0xff7f00 },
  15.319 -		{ "darkorange2",          0xee7600 },
  15.320 -		{ "darkorange3",          0xcd6600 },
  15.321 -		{ "darkorange4",          0x8b4500 },
  15.322 -		{ "darkorchid",           0x9932cc },
  15.323 -		{ "darkorchid1",          0xbf3eff },
  15.324 -		{ "darkorchid2",          0xb23aee },
  15.325 -		{ "darkorchid3",          0x9a32cd },
  15.326 -		{ "darkorchid4",          0x68228b },
  15.327 -		{ "darkred",              0x8b0000 },
  15.328 -		{ "darksalmon",           0xe9967a },
  15.329 -		{ "darkseagreen",         0x8fbc8f },
  15.330 -		{ "darkseagreen1",        0xc1ffc1 },
  15.331 -		{ "darkseagreen2",        0xb4eeb4 },
  15.332 -		{ "darkseagreen3",        0x9bcd9b },
  15.333 -		{ "darkseagreen4",        0x698b69 },
  15.334 -		{ "darkslateblue",        0x483d8b },
  15.335 -		{ "darkslategray",        0x2f4f4f },
  15.336 -		{ "darkslategray1",       0x97ffff },
  15.337 -		{ "darkslategray2",       0x8deeee },
  15.338 -		{ "darkslategray3",       0x79cdcd },
  15.339 -		{ "darkslategray4",       0x528b8b },
  15.340 -		{ "darkslategrey",        0x2f4f4f },
  15.341 -		{ "darkturquoise",        0x00ced1 },
  15.342 -		{ "darkviolet",           0x9400D3 },
  15.343 -		{ "darkviolet",           0x9400d3 },
  15.344 -		{ "deeppink",             0xff1493 },
  15.345 -		{ "deeppink1",            0xff1493 },
  15.346 -		{ "deeppink2",            0xee1289 },
  15.347 -		{ "deeppink3",            0xcd1076 },
  15.348 -		{ "deeppink4",            0x8b0a50 },
  15.349 -		{ "deepskyblue",          0x00bfff },
  15.350 -		{ "deepskyblue1",         0x00bfff },
  15.351 -		{ "deepskyblue2",         0x00b2ee },
  15.352 -		{ "deepskyblue3",         0x009acd },
  15.353 -		{ "deepskyblue4",         0x00688b },
  15.354 -		{ "dimgray",              0x696969 },
  15.355 -		{ "dimgrey",              0x696969 },
  15.356 -		{ "dodgerblue",           0x1e90ff },
  15.357 -		{ "dodgerblue1",          0x1e90ff },
  15.358 -		{ "dodgerblue2",          0x1c86ee },
  15.359 -		{ "dodgerblue3",          0x1874cd },
  15.360 -		{ "dodgerblue4",          0x104e8b },
  15.361 -		{ "firebrick",            0xB22222 },
  15.362 -		{ "firebrick1",           0xFF3030 },
  15.363 -		{ "firebrick2",           0xEE2C2C },
  15.364 -		{ "firebrick3",           0xCD2626 },
  15.365 -		{ "firebrick4",           0x8B1A1A },
  15.366 -		{ "floralwhite",          0xfffaf0 },
  15.367 -		{ "forestgreen",          0x228b22 },
  15.368 -		{ "fractal",              0x808080 },
  15.369 -		{ "fuchsia",              0xFF00FF },
  15.370 -		{ "gainsboro",            0xDCDCDC },
  15.371 -		{ "ghostwhite",           0xf8f8ff },
  15.372 -		{ "gold",                 0xFFD700 },
  15.373 -		{ "gold1",                0xFFD700 },
  15.374 -		{ "gold2",                0xEEC900 },
  15.375 -		{ "gold3",                0xCDAD00 },
  15.376 -		{ "gold4",                0x8B7500 },
  15.377 -		{ "goldenrod",            0xDAA520 },
  15.378 -		{ "goldenrod1",           0xFFC125 },
  15.379 -		{ "goldenrod2",           0xEEB422 },
  15.380 -		{ "goldenrod3",           0xCD9B1D },
  15.381 -		{ "goldenrod4",           0x8B6914 },
  15.382 -		{ "gray",                 0x7E7E7E },
  15.383 -		{ "gray",                 0xBEBEBE },
  15.384 -		{ "gray0",                0x000000 },
  15.385 -		{ "gray1",                0x030303 },
  15.386 -		{ "gray10",               0x1A1A1A },
  15.387 -		{ "gray100",              0xFFFFFF },
  15.388 -		{ "gray11",               0x1C1C1C },
  15.389 -		{ "gray12",               0x1F1F1F },
  15.390 -		{ "gray13",               0x212121 },
  15.391 -		{ "gray14",               0x242424 },
  15.392 -		{ "gray15",               0x262626 },
  15.393 -		{ "gray16",               0x292929 },
  15.394 -		{ "gray17",               0x2B2B2B },
  15.395 -		{ "gray18",               0x2E2E2E },
  15.396 -		{ "gray19",               0x303030 },
  15.397 -		{ "gray2",                0x050505 },
  15.398 -		{ "gray20",               0x333333 },
  15.399 -		{ "gray21",               0x363636 },
  15.400 -		{ "gray22",               0x383838 },
  15.401 -		{ "gray23",               0x3B3B3B },
  15.402 -		{ "gray24",               0x3D3D3D },
  15.403 -		{ "gray25",               0x404040 },
  15.404 -		{ "gray26",               0x424242 },
  15.405 -		{ "gray27",               0x454545 },
  15.406 -		{ "gray28",               0x474747 },
  15.407 -		{ "gray29",               0x4A4A4A },
  15.408 -		{ "gray3",                0x080808 },
  15.409 -		{ "gray30",               0x4D4D4D },
  15.410 -		{ "gray31",               0x4F4F4F },
  15.411 -		{ "gray32",               0x525252 },
  15.412 -		{ "gray33",