IMG_png.c
changeset 368 8a61842d00ce
parent 362 3c7768075145
child 378 f83e70f2ec6c
     1.1 --- a/IMG_png.c	Thu Apr 25 00:22:51 2013 -0700
     1.2 +++ b/IMG_png.c	Tue May 21 21:24:32 2013 -0700
     1.3 @@ -32,25 +32,25 @@
     1.4  
     1.5  /*=============================================================================
     1.6          File: SDL_png.c
     1.7 -     Purpose: A PNG loader and saver for the SDL library      
     1.8 -    Revision: 
     1.9 +     Purpose: A PNG loader and saver for the SDL library
    1.10 +    Revision:
    1.11    Created by: Philippe Lavoie          (2 November 1998)
    1.12                lavoie@zeus.genie.uottawa.ca
    1.13 - Modified by: 
    1.14 + Modified by:
    1.15  
    1.16   Copyright notice:
    1.17            Copyright (C) 1998 Philippe Lavoie
    1.18 - 
    1.19 +
    1.20            This library is free software; you can redistribute it and/or
    1.21            modify it under the terms of the GNU Library General Public
    1.22            License as published by the Free Software Foundation; either
    1.23            version 2 of the License, or (at your option) any later version.
    1.24 - 
    1.25 +
    1.26            This library is distributed in the hope that it will be useful,
    1.27            but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.28            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.29            Library General Public License for more details.
    1.30 - 
    1.31 +
    1.32            You should have received a copy of the GNU Library General Public
    1.33            License along with this library; if not, write to the Free
    1.34            Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    1.35 @@ -76,488 +76,488 @@
    1.36  #endif
    1.37  
    1.38  static struct {
    1.39 -	int loaded;
    1.40 -	void *handle;
    1.41 -	png_infop (*png_create_info_struct) (png_structp png_ptr);
    1.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);
    1.43 -	void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
    1.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);
    1.45 -	png_voidp (*png_get_io_ptr) (png_structp png_ptr);
    1.46 -	png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
    1.47 -	png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
    1.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);
    1.49 -	png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
    1.50 -	void (*png_read_image) (png_structp png_ptr, png_bytepp image);
    1.51 -	void (*png_read_info) (png_structp png_ptr, png_infop info_ptr);
    1.52 -	void (*png_read_update_info) (png_structp png_ptr, png_infop info_ptr);
    1.53 -	void (*png_set_expand) (png_structp png_ptr);
    1.54 -	void (*png_set_gray_to_rgb) (png_structp png_ptr);
    1.55 -	void (*png_set_packing) (png_structp png_ptr);
    1.56 -	void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
    1.57 -	void (*png_set_strip_16) (png_structp png_ptr);
    1.58 -	int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
    1.59 +    int loaded;
    1.60 +    void *handle;
    1.61 +    png_infop (*png_create_info_struct) (png_structp png_ptr);
    1.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);
    1.63 +    void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
    1.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);
    1.65 +    png_voidp (*png_get_io_ptr) (png_structp png_ptr);
    1.66 +    png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
    1.67 +    png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
    1.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);
    1.69 +    png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
    1.70 +    void (*png_read_image) (png_structp png_ptr, png_bytepp image);
    1.71 +    void (*png_read_info) (png_structp png_ptr, png_infop info_ptr);
    1.72 +    void (*png_read_update_info) (png_structp png_ptr, png_infop info_ptr);
    1.73 +    void (*png_set_expand) (png_structp png_ptr);
    1.74 +    void (*png_set_gray_to_rgb) (png_structp png_ptr);
    1.75 +    void (*png_set_packing) (png_structp png_ptr);
    1.76 +    void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
    1.77 +    void (*png_set_strip_16) (png_structp png_ptr);
    1.78 +    int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
    1.79  #ifndef LIBPNG_VERSION_12
    1.80 -	jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
    1.81 +    jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
    1.82  #endif
    1.83  } lib;
    1.84  
    1.85  #ifdef LOAD_PNG_DYNAMIC
    1.86  int IMG_InitPNG()
    1.87  {
    1.88 -	if ( lib.loaded == 0 ) {
    1.89 -		lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC);
    1.90 -		if ( lib.handle == NULL ) {
    1.91 -			return -1;
    1.92 -		}
    1.93 -		lib.png_create_info_struct =
    1.94 -			(png_infop (*) (png_structp))
    1.95 -			SDL_LoadFunction(lib.handle, "png_create_info_struct");
    1.96 -		if ( lib.png_create_info_struct == NULL ) {
    1.97 -			SDL_UnloadObject(lib.handle);
    1.98 -			return -1;
    1.99 -		}
   1.100 -		lib.png_create_read_struct =
   1.101 -			(png_structp (*) (png_const_charp, png_voidp, png_error_ptr, png_error_ptr))
   1.102 -			SDL_LoadFunction(lib.handle, "png_create_read_struct");
   1.103 -		if ( lib.png_create_read_struct == NULL ) {
   1.104 -			SDL_UnloadObject(lib.handle);
   1.105 -			return -1;
   1.106 -		}
   1.107 -		lib.png_destroy_read_struct =
   1.108 -			(void (*) (png_structpp, png_infopp, png_infopp))
   1.109 -			SDL_LoadFunction(lib.handle, "png_destroy_read_struct");
   1.110 -		if ( lib.png_destroy_read_struct == NULL ) {
   1.111 -			SDL_UnloadObject(lib.handle);
   1.112 -			return -1;
   1.113 -		}
   1.114 -		lib.png_get_IHDR =
   1.115 -			(png_uint_32 (*) (png_structp, png_infop, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *))
   1.116 -			SDL_LoadFunction(lib.handle, "png_get_IHDR");
   1.117 -		if ( lib.png_get_IHDR == NULL ) {
   1.118 -			SDL_UnloadObject(lib.handle);
   1.119 -			return -1;
   1.120 -		}
   1.121 -		lib.png_get_channels =
   1.122 -			(png_byte (*) (png_structp, png_infop))
   1.123 -			SDL_LoadFunction(lib.handle, "png_get_channels");
   1.124 -		if ( lib.png_get_channels == NULL ) {
   1.125 -			SDL_UnloadObject(lib.handle);
   1.126 -			return -1;
   1.127 -		}
   1.128 -		lib.png_get_io_ptr =
   1.129 -			(png_voidp (*) (png_structp))
   1.130 -			SDL_LoadFunction(lib.handle, "png_get_io_ptr");
   1.131 -		if ( lib.png_get_io_ptr == NULL ) {
   1.132 -			SDL_UnloadObject(lib.handle);
   1.133 -			return -1;
   1.134 -		}
   1.135 -		lib.png_get_PLTE =
   1.136 -			(png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
   1.137 -			SDL_LoadFunction(lib.handle, "png_get_PLTE");
   1.138 -		if ( lib.png_get_PLTE == NULL ) {
   1.139 -			SDL_UnloadObject(lib.handle);
   1.140 -			return -1;
   1.141 -		}
   1.142 -		lib.png_get_tRNS =
   1.143 -			(png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
   1.144 -			SDL_LoadFunction(lib.handle, "png_get_tRNS");
   1.145 -		if ( lib.png_get_tRNS == NULL ) {
   1.146 -			SDL_UnloadObject(lib.handle);
   1.147 -			return -1;
   1.148 -		}
   1.149 -		lib.png_get_valid =
   1.150 -			(png_uint_32 (*) (png_structp, png_infop, png_uint_32))
   1.151 -			SDL_LoadFunction(lib.handle, "png_get_valid");
   1.152 -		if ( lib.png_get_valid == NULL ) {
   1.153 -			SDL_UnloadObject(lib.handle);
   1.154 -			return -1;
   1.155 -		}
   1.156 -		lib.png_read_image =
   1.157 -			(void (*) (png_structp, png_bytepp))
   1.158 -			SDL_LoadFunction(lib.handle, "png_read_image");
   1.159 -		if ( lib.png_read_image == NULL ) {
   1.160 -			SDL_UnloadObject(lib.handle);
   1.161 -			return -1;
   1.162 -		}
   1.163 -		lib.png_read_info =
   1.164 -			(void (*) (png_structp, png_infop))
   1.165 -			SDL_LoadFunction(lib.handle, "png_read_info");
   1.166 -		if ( lib.png_read_info == NULL ) {
   1.167 -			SDL_UnloadObject(lib.handle);
   1.168 -			return -1;
   1.169 -		}
   1.170 -		lib.png_read_update_info =
   1.171 -			(void (*) (png_structp, png_infop))
   1.172 -			SDL_LoadFunction(lib.handle, "png_read_update_info");
   1.173 -		if ( lib.png_read_update_info == NULL ) {
   1.174 -			SDL_UnloadObject(lib.handle);
   1.175 -			return -1;
   1.176 -		}
   1.177 -		lib.png_set_expand =
   1.178 -			(void (*) (png_structp))
   1.179 -			SDL_LoadFunction(lib.handle, "png_set_expand");
   1.180 -		if ( lib.png_set_expand == NULL ) {
   1.181 -			SDL_UnloadObject(lib.handle);
   1.182 -			return -1;
   1.183 -		}
   1.184 -		lib.png_set_gray_to_rgb =
   1.185 -			(void (*) (png_structp))
   1.186 -			SDL_LoadFunction(lib.handle, "png_set_gray_to_rgb");
   1.187 -		if ( lib.png_set_gray_to_rgb == NULL ) {
   1.188 -			SDL_UnloadObject(lib.handle);
   1.189 -			return -1;
   1.190 -		}
   1.191 -		lib.png_set_packing =
   1.192 -			(void (*) (png_structp))
   1.193 -			SDL_LoadFunction(lib.handle, "png_set_packing");
   1.194 -		if ( lib.png_set_packing == NULL ) {
   1.195 -			SDL_UnloadObject(lib.handle);
   1.196 -			return -1;
   1.197 -		}
   1.198 -		lib.png_set_read_fn =
   1.199 -			(void (*) (png_structp, png_voidp, png_rw_ptr))
   1.200 -			SDL_LoadFunction(lib.handle, "png_set_read_fn");
   1.201 -		if ( lib.png_set_read_fn == NULL ) {
   1.202 -			SDL_UnloadObject(lib.handle);
   1.203 -			return -1;
   1.204 -		}
   1.205 -		lib.png_set_strip_16 =
   1.206 -			(void (*) (png_structp))
   1.207 -			SDL_LoadFunction(lib.handle, "png_set_strip_16");
   1.208 -		if ( lib.png_set_strip_16 == NULL ) {
   1.209 -			SDL_UnloadObject(lib.handle);
   1.210 -			return -1;
   1.211 -		}
   1.212 -		lib.png_sig_cmp =
   1.213 -			(int (*) (png_bytep, png_size_t, png_size_t))
   1.214 -			SDL_LoadFunction(lib.handle, "png_sig_cmp");
   1.215 -		if ( lib.png_sig_cmp == NULL ) {
   1.216 -			SDL_UnloadObject(lib.handle);
   1.217 -			return -1;
   1.218 -		}
   1.219 +    if ( lib.loaded == 0 ) {
   1.220 +        lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC);
   1.221 +        if ( lib.handle == NULL ) {
   1.222 +            return -1;
   1.223 +        }
   1.224 +        lib.png_create_info_struct =
   1.225 +            (png_infop (*) (png_structp))
   1.226 +            SDL_LoadFunction(lib.handle, "png_create_info_struct");
   1.227 +        if ( lib.png_create_info_struct == NULL ) {
   1.228 +            SDL_UnloadObject(lib.handle);
   1.229 +            return -1;
   1.230 +        }
   1.231 +        lib.png_create_read_struct =
   1.232 +            (png_structp (*) (png_const_charp, png_voidp, png_error_ptr, png_error_ptr))
   1.233 +            SDL_LoadFunction(lib.handle, "png_create_read_struct");
   1.234 +        if ( lib.png_create_read_struct == NULL ) {
   1.235 +            SDL_UnloadObject(lib.handle);
   1.236 +            return -1;
   1.237 +        }
   1.238 +        lib.png_destroy_read_struct =
   1.239 +            (void (*) (png_structpp, png_infopp, png_infopp))
   1.240 +            SDL_LoadFunction(lib.handle, "png_destroy_read_struct");
   1.241 +        if ( lib.png_destroy_read_struct == NULL ) {
   1.242 +            SDL_UnloadObject(lib.handle);
   1.243 +            return -1;
   1.244 +        }
   1.245 +        lib.png_get_IHDR =
   1.246 +            (png_uint_32 (*) (png_structp, png_infop, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *))
   1.247 +            SDL_LoadFunction(lib.handle, "png_get_IHDR");
   1.248 +        if ( lib.png_get_IHDR == NULL ) {
   1.249 +            SDL_UnloadObject(lib.handle);
   1.250 +            return -1;
   1.251 +        }
   1.252 +        lib.png_get_channels =
   1.253 +            (png_byte (*) (png_structp, png_infop))
   1.254 +            SDL_LoadFunction(lib.handle, "png_get_channels");
   1.255 +        if ( lib.png_get_channels == NULL ) {
   1.256 +            SDL_UnloadObject(lib.handle);
   1.257 +            return -1;
   1.258 +        }
   1.259 +        lib.png_get_io_ptr =
   1.260 +            (png_voidp (*) (png_structp))
   1.261 +            SDL_LoadFunction(lib.handle, "png_get_io_ptr");
   1.262 +        if ( lib.png_get_io_ptr == NULL ) {
   1.263 +            SDL_UnloadObject(lib.handle);
   1.264 +            return -1;
   1.265 +        }
   1.266 +        lib.png_get_PLTE =
   1.267 +            (png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
   1.268 +            SDL_LoadFunction(lib.handle, "png_get_PLTE");
   1.269 +        if ( lib.png_get_PLTE == NULL ) {
   1.270 +            SDL_UnloadObject(lib.handle);
   1.271 +            return -1;
   1.272 +        }
   1.273 +        lib.png_get_tRNS =
   1.274 +            (png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
   1.275 +            SDL_LoadFunction(lib.handle, "png_get_tRNS");
   1.276 +        if ( lib.png_get_tRNS == NULL ) {
   1.277 +            SDL_UnloadObject(lib.handle);
   1.278 +            return -1;
   1.279 +        }
   1.280 +        lib.png_get_valid =
   1.281 +            (png_uint_32 (*) (png_structp, png_infop, png_uint_32))
   1.282 +            SDL_LoadFunction(lib.handle, "png_get_valid");
   1.283 +        if ( lib.png_get_valid == NULL ) {
   1.284 +            SDL_UnloadObject(lib.handle);
   1.285 +            return -1;
   1.286 +        }
   1.287 +        lib.png_read_image =
   1.288 +            (void (*) (png_structp, png_bytepp))
   1.289 +            SDL_LoadFunction(lib.handle, "png_read_image");
   1.290 +        if ( lib.png_read_image == NULL ) {
   1.291 +            SDL_UnloadObject(lib.handle);
   1.292 +            return -1;
   1.293 +        }
   1.294 +        lib.png_read_info =
   1.295 +            (void (*) (png_structp, png_infop))
   1.296 +            SDL_LoadFunction(lib.handle, "png_read_info");
   1.297 +        if ( lib.png_read_info == NULL ) {
   1.298 +            SDL_UnloadObject(lib.handle);
   1.299 +            return -1;
   1.300 +        }
   1.301 +        lib.png_read_update_info =
   1.302 +            (void (*) (png_structp, png_infop))
   1.303 +            SDL_LoadFunction(lib.handle, "png_read_update_info");
   1.304 +        if ( lib.png_read_update_info == NULL ) {
   1.305 +            SDL_UnloadObject(lib.handle);
   1.306 +            return -1;
   1.307 +        }
   1.308 +        lib.png_set_expand =
   1.309 +            (void (*) (png_structp))
   1.310 +            SDL_LoadFunction(lib.handle, "png_set_expand");
   1.311 +        if ( lib.png_set_expand == NULL ) {
   1.312 +            SDL_UnloadObject(lib.handle);
   1.313 +            return -1;
   1.314 +        }
   1.315 +        lib.png_set_gray_to_rgb =
   1.316 +            (void (*) (png_structp))
   1.317 +            SDL_LoadFunction(lib.handle, "png_set_gray_to_rgb");
   1.318 +        if ( lib.png_set_gray_to_rgb == NULL ) {
   1.319 +            SDL_UnloadObject(lib.handle);
   1.320 +            return -1;
   1.321 +        }
   1.322 +        lib.png_set_packing =
   1.323 +            (void (*) (png_structp))
   1.324 +            SDL_LoadFunction(lib.handle, "png_set_packing");
   1.325 +        if ( lib.png_set_packing == NULL ) {
   1.326 +            SDL_UnloadObject(lib.handle);
   1.327 +            return -1;
   1.328 +        }
   1.329 +        lib.png_set_read_fn =
   1.330 +            (void (*) (png_structp, png_voidp, png_rw_ptr))
   1.331 +            SDL_LoadFunction(lib.handle, "png_set_read_fn");
   1.332 +        if ( lib.png_set_read_fn == NULL ) {
   1.333 +            SDL_UnloadObject(lib.handle);
   1.334 +            return -1;
   1.335 +        }
   1.336 +        lib.png_set_strip_16 =
   1.337 +            (void (*) (png_structp))
   1.338 +            SDL_LoadFunction(lib.handle, "png_set_strip_16");
   1.339 +        if ( lib.png_set_strip_16 == NULL ) {
   1.340 +            SDL_UnloadObject(lib.handle);
   1.341 +            return -1;
   1.342 +        }
   1.343 +        lib.png_sig_cmp =
   1.344 +            (int (*) (png_bytep, png_size_t, png_size_t))
   1.345 +            SDL_LoadFunction(lib.handle, "png_sig_cmp");
   1.346 +        if ( lib.png_sig_cmp == NULL ) {
   1.347 +            SDL_UnloadObject(lib.handle);
   1.348 +            return -1;
   1.349 +        }
   1.350  #ifndef LIBPNG_VERSION_12
   1.351 -		lib.png_set_longjmp_fn =
   1.352 -			(jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
   1.353 -			SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
   1.354 -		if ( lib.png_set_longjmp_fn == NULL ) {
   1.355 -			SDL_UnloadObject(lib.handle);
   1.356 -			return -1;
   1.357 -		}
   1.358 +        lib.png_set_longjmp_fn =
   1.359 +            (jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
   1.360 +            SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
   1.361 +        if ( lib.png_set_longjmp_fn == NULL ) {
   1.362 +            SDL_UnloadObject(lib.handle);
   1.363 +            return -1;
   1.364 +        }
   1.365  #endif
   1.366 -	}
   1.367 -	++lib.loaded;
   1.368 +    }
   1.369 +    ++lib.loaded;
   1.370  
   1.371 -	return 0;
   1.372 +    return 0;
   1.373  }
   1.374  void IMG_QuitPNG()
   1.375  {
   1.376 -	if ( lib.loaded == 0 ) {
   1.377 -		return;
   1.378 -	}
   1.379 -	if ( lib.loaded == 1 ) {
   1.380 -		SDL_UnloadObject(lib.handle);
   1.381 -	}
   1.382 -	--lib.loaded;
   1.383 +    if ( lib.loaded == 0 ) {
   1.384 +        return;
   1.385 +    }
   1.386 +    if ( lib.loaded == 1 ) {
   1.387 +        SDL_UnloadObject(lib.handle);
   1.388 +    }
   1.389 +    --lib.loaded;
   1.390  }
   1.391  #else
   1.392  int IMG_InitPNG()
   1.393  {
   1.394 -	if ( lib.loaded == 0 ) {
   1.395 -		lib.png_create_info_struct = png_create_info_struct;
   1.396 -		lib.png_create_read_struct = png_create_read_struct;
   1.397 -		lib.png_destroy_read_struct = png_destroy_read_struct;
   1.398 -		lib.png_get_IHDR = png_get_IHDR;
   1.399 -		lib.png_get_channels = png_get_channels;
   1.400 -		lib.png_get_io_ptr = png_get_io_ptr;
   1.401 -		lib.png_get_PLTE = png_get_PLTE;
   1.402 -		lib.png_get_tRNS = png_get_tRNS;
   1.403 -		lib.png_get_valid = png_get_valid;
   1.404 -		lib.png_read_image = png_read_image;
   1.405 -		lib.png_read_info = png_read_info;
   1.406 -		lib.png_read_update_info = png_read_update_info;
   1.407 -		lib.png_set_expand = png_set_expand;
   1.408 -		lib.png_set_gray_to_rgb = png_set_gray_to_rgb;
   1.409 -		lib.png_set_packing = png_set_packing;
   1.410 -		lib.png_set_read_fn = png_set_read_fn;
   1.411 -		lib.png_set_strip_16 = png_set_strip_16;
   1.412 -		lib.png_sig_cmp = png_sig_cmp;
   1.413 +    if ( lib.loaded == 0 ) {
   1.414 +        lib.png_create_info_struct = png_create_info_struct;
   1.415 +        lib.png_create_read_struct = png_create_read_struct;
   1.416 +        lib.png_destroy_read_struct = png_destroy_read_struct;
   1.417 +        lib.png_get_IHDR = png_get_IHDR;
   1.418 +        lib.png_get_channels = png_get_channels;
   1.419 +        lib.png_get_io_ptr = png_get_io_ptr;
   1.420 +        lib.png_get_PLTE = png_get_PLTE;
   1.421 +        lib.png_get_tRNS = png_get_tRNS;
   1.422 +        lib.png_get_valid = png_get_valid;
   1.423 +        lib.png_read_image = png_read_image;
   1.424 +        lib.png_read_info = png_read_info;
   1.425 +        lib.png_read_update_info = png_read_update_info;
   1.426 +        lib.png_set_expand = png_set_expand;
   1.427 +        lib.png_set_gray_to_rgb = png_set_gray_to_rgb;
   1.428 +        lib.png_set_packing = png_set_packing;
   1.429 +        lib.png_set_read_fn = png_set_read_fn;
   1.430 +        lib.png_set_strip_16 = png_set_strip_16;
   1.431 +        lib.png_sig_cmp = png_sig_cmp;
   1.432  #ifndef LIBPNG_VERSION_12
   1.433 -		lib.png_set_longjmp_fn = png_set_longjmp_fn;
   1.434 +        lib.png_set_longjmp_fn = png_set_longjmp_fn;
   1.435  #endif
   1.436 -	}
   1.437 -	++lib.loaded;
   1.438 +    }
   1.439 +    ++lib.loaded;
   1.440  
   1.441 -	return 0;
   1.442 +    return 0;
   1.443  }
   1.444  void IMG_QuitPNG()
   1.445  {
   1.446 -	if ( lib.loaded == 0 ) {
   1.447 -		return;
   1.448 -	}
   1.449 -	if ( lib.loaded == 1 ) {
   1.450 -	}
   1.451 -	--lib.loaded;
   1.452 +    if ( lib.loaded == 0 ) {
   1.453 +        return;
   1.454 +    }
   1.455 +    if ( lib.loaded == 1 ) {
   1.456 +    }
   1.457 +    --lib.loaded;
   1.458  }
   1.459  #endif /* LOAD_PNG_DYNAMIC */
   1.460  
   1.461  /* See if an image is contained in a data source */
   1.462  int IMG_isPNG(SDL_RWops *src)
   1.463  {
   1.464 -	Sint64 start;
   1.465 -	int is_PNG;
   1.466 -	Uint8 magic[4];
   1.467 +    Sint64 start;
   1.468 +    int is_PNG;
   1.469 +    Uint8 magic[4];
   1.470  
   1.471 -	if ( !src )
   1.472 -		return 0;
   1.473 -	start = SDL_RWtell(src);
   1.474 -	is_PNG = 0;
   1.475 -	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   1.476 +    if ( !src )
   1.477 +        return 0;
   1.478 +    start = SDL_RWtell(src);
   1.479 +    is_PNG = 0;
   1.480 +    if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   1.481                  if ( magic[0] == 0x89 &&
   1.482                       magic[1] == 'P' &&
   1.483                       magic[2] == 'N' &&
   1.484                       magic[3] == 'G' ) {
   1.485 -			is_PNG = 1;
   1.486 -		}
   1.487 -	}
   1.488 -	SDL_RWseek(src, start, RW_SEEK_SET);
   1.489 -	return(is_PNG);
   1.490 +            is_PNG = 1;
   1.491 +        }
   1.492 +    }
   1.493 +    SDL_RWseek(src, start, RW_SEEK_SET);
   1.494 +    return(is_PNG);
   1.495  }
   1.496  
   1.497  /* Load a PNG type image from an SDL datasource */
   1.498  static void png_read_data(png_structp ctx, png_bytep area, png_size_t size)
   1.499  {
   1.500 -	SDL_RWops *src;
   1.501 +    SDL_RWops *src;
   1.502  
   1.503 -	src = (SDL_RWops *)lib.png_get_io_ptr(ctx);
   1.504 -	SDL_RWread(src, area, size, 1);
   1.505 +    src = (SDL_RWops *)lib.png_get_io_ptr(ctx);
   1.506 +    SDL_RWread(src, area, size, 1);
   1.507  }
   1.508  SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
   1.509  {
   1.510 -	Sint64 start;
   1.511 -	const char *error;
   1.512 -	SDL_Surface *volatile surface;
   1.513 -	png_structp png_ptr;
   1.514 -	png_infop info_ptr;
   1.515 -	png_uint_32 width, height;
   1.516 -	int bit_depth, color_type, interlace_type, num_channels;
   1.517 -	Uint32 Rmask;
   1.518 -	Uint32 Gmask;
   1.519 -	Uint32 Bmask;
   1.520 -	Uint32 Amask;
   1.521 -	SDL_Palette *palette;
   1.522 -	png_bytep *volatile row_pointers;
   1.523 -	int row, i;
   1.524 -	int ckey = -1;
   1.525 -	png_color_16 *transv;
   1.526 +    Sint64 start;
   1.527 +    const char *error;
   1.528 +    SDL_Surface *volatile surface;
   1.529 +    png_structp png_ptr;
   1.530 +    png_infop info_ptr;
   1.531 +    png_uint_32 width, height;
   1.532 +    int bit_depth, color_type, interlace_type, num_channels;
   1.533 +    Uint32 Rmask;
   1.534 +    Uint32 Gmask;
   1.535 +    Uint32 Bmask;
   1.536 +    Uint32 Amask;
   1.537 +    SDL_Palette *palette;
   1.538 +    png_bytep *volatile row_pointers;
   1.539 +    int row, i;
   1.540 +    int ckey = -1;
   1.541 +    png_color_16 *transv;
   1.542  
   1.543 -	if ( !src ) {
   1.544 -		/* The error message has been set in SDL_RWFromFile */
   1.545 -		return NULL;
   1.546 -	}
   1.547 -	start = SDL_RWtell(src);
   1.548 +    if ( !src ) {
   1.549 +        /* The error message has been set in SDL_RWFromFile */
   1.550 +        return NULL;
   1.551 +    }
   1.552 +    start = SDL_RWtell(src);
   1.553  
   1.554 -	if ( !IMG_Init(IMG_INIT_PNG) ) {
   1.555 -		return NULL;
   1.556 -	}
   1.557 +    if ( !IMG_Init(IMG_INIT_PNG) ) {
   1.558 +        return NULL;
   1.559 +    }
   1.560  
   1.561 -	/* Initialize the data we will clean up when we're done */
   1.562 -	error = NULL;
   1.563 -	png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL;
   1.564 +    /* Initialize the data we will clean up when we're done */
   1.565 +    error = NULL;
   1.566 +    png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL;
   1.567  
   1.568 -	/* Create the PNG loading context structure */
   1.569 -	png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
   1.570 -					  NULL,NULL,NULL);
   1.571 -	if (png_ptr == NULL){
   1.572 -		error = "Couldn't allocate memory for PNG file or incompatible PNG dll";
   1.573 -		goto done;
   1.574 -	}
   1.575 +    /* Create the PNG loading context structure */
   1.576 +    png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
   1.577 +                      NULL,NULL,NULL);
   1.578 +    if (png_ptr == NULL){
   1.579 +        error = "Couldn't allocate memory for PNG file or incompatible PNG dll";
   1.580 +        goto done;
   1.581 +    }
   1.582  
   1.583 -	 /* Allocate/initialize the memory for image information.  REQUIRED. */
   1.584 -	info_ptr = lib.png_create_info_struct(png_ptr);
   1.585 -	if (info_ptr == NULL) {
   1.586 -		error = "Couldn't create image information for PNG file";
   1.587 -		goto done;
   1.588 -	}
   1.589 +     /* Allocate/initialize the memory for image information.  REQUIRED. */
   1.590 +    info_ptr = lib.png_create_info_struct(png_ptr);
   1.591 +    if (info_ptr == NULL) {
   1.592 +        error = "Couldn't create image information for PNG file";
   1.593 +        goto done;
   1.594 +    }
   1.595  
   1.596 -	/* Set error handling if you are using setjmp/longjmp method (this is
   1.597 -	 * the normal method of doing things with libpng).  REQUIRED unless you
   1.598 -	 * set up your own error handlers in png_create_read_struct() earlier.
   1.599 -	 */
   1.600 +    /* Set error handling if you are using setjmp/longjmp method (this is
   1.601 +     * the normal method of doing things with libpng).  REQUIRED unless you
   1.602 +     * set up your own error handlers in png_create_read_struct() earlier.
   1.603 +     */
   1.604  #ifndef LIBPNG_VERSION_12
   1.605 -	if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
   1.606 +    if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
   1.607  #else
   1.608 -	if ( setjmp(png_ptr->jmpbuf) )
   1.609 +    if ( setjmp(png_ptr->jmpbuf) )
   1.610  #endif
   1.611 -	{
   1.612 -		error = "Error reading the PNG file.";
   1.613 -		goto done;
   1.614 -	}
   1.615 +    {
   1.616 +        error = "Error reading the PNG file.";
   1.617 +        goto done;
   1.618 +    }
   1.619  
   1.620 -	/* Set up the input control */
   1.621 -	lib.png_set_read_fn(png_ptr, src, png_read_data);
   1.622 +    /* Set up the input control */
   1.623 +    lib.png_set_read_fn(png_ptr, src, png_read_data);
   1.624  
   1.625 -	/* Read PNG header info */
   1.626 -	lib.png_read_info(png_ptr, info_ptr);
   1.627 -	lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   1.628 -			&color_type, &interlace_type, NULL, NULL);
   1.629 +    /* Read PNG header info */
   1.630 +    lib.png_read_info(png_ptr, info_ptr);
   1.631 +    lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   1.632 +            &color_type, &interlace_type, NULL, NULL);
   1.633  
   1.634 -	/* tell libpng to strip 16 bit/color files down to 8 bits/color */
   1.635 -	lib.png_set_strip_16(png_ptr) ;
   1.636 +    /* tell libpng to strip 16 bit/color files down to 8 bits/color */
   1.637 +    lib.png_set_strip_16(png_ptr) ;
   1.638  
   1.639 -	/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
   1.640 -	 * byte into separate bytes (useful for paletted and grayscale images).
   1.641 -	 */
   1.642 -	lib.png_set_packing(png_ptr);
   1.643 +    /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
   1.644 +     * byte into separate bytes (useful for paletted and grayscale images).
   1.645 +     */
   1.646 +    lib.png_set_packing(png_ptr);
   1.647  
   1.648 -	/* scale greyscale values to the range 0..255 */
   1.649 -	if (color_type == PNG_COLOR_TYPE_GRAY)
   1.650 -		lib.png_set_expand(png_ptr);
   1.651 +    /* scale greyscale values to the range 0..255 */
   1.652 +    if (color_type == PNG_COLOR_TYPE_GRAY)
   1.653 +        lib.png_set_expand(png_ptr);
   1.654  
   1.655 -	/* For images with a single "transparent colour", set colour key;
   1.656 -	   if more than one index has transparency, or if partially transparent
   1.657 -	   entries exist, use full alpha channel */
   1.658 -	if (lib.png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
   1.659 -	        int num_trans;
   1.660 -		Uint8 *trans;
   1.661 -		lib.png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
   1.662 -			     &transv);
   1.663 -		if (color_type == PNG_COLOR_TYPE_PALETTE) {
   1.664 -		    /* Check if all tRNS entries are opaque except one */
   1.665 -		    int j, t = -1;
   1.666 -		    for (j = 0; j < num_trans; j++) {
   1.667 -			if (trans[j] == 0) {
   1.668 -			    if (t >= 0) {
   1.669 -				break;
   1.670 +    /* For images with a single "transparent colour", set colour key;
   1.671 +       if more than one index has transparency, or if partially transparent
   1.672 +       entries exist, use full alpha channel */
   1.673 +    if (lib.png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
   1.674 +            int num_trans;
   1.675 +        Uint8 *trans;
   1.676 +        lib.png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
   1.677 +                 &transv);
   1.678 +        if (color_type == PNG_COLOR_TYPE_PALETTE) {
   1.679 +            /* Check if all tRNS entries are opaque except one */
   1.680 +            int j, t = -1;
   1.681 +            for (j = 0; j < num_trans; j++) {
   1.682 +            if (trans[j] == 0) {
   1.683 +                if (t >= 0) {
   1.684 +                break;
   1.685                              }
   1.686 -			    t = j;
   1.687 -			} else if (trans[j] != 255) {
   1.688 -			    break;
   1.689 +                t = j;
   1.690 +            } else if (trans[j] != 255) {
   1.691 +                break;
   1.692                          }
   1.693                      }
   1.694 -		    if (j == num_trans) {
   1.695 -			/* exactly one transparent index */
   1.696 -			ckey = t;
   1.697 -		    } else {
   1.698 -			/* more than one transparent index, or translucency */
   1.699 -			lib.png_set_expand(png_ptr);
   1.700 -		    }
   1.701 -		} else
   1.702 -		    ckey = 0; /* actual value will be set later */
   1.703 -	}
   1.704 +            if (j == num_trans) {
   1.705 +            /* exactly one transparent index */
   1.706 +            ckey = t;
   1.707 +            } else {
   1.708 +            /* more than one transparent index, or translucency */
   1.709 +            lib.png_set_expand(png_ptr);
   1.710 +            }
   1.711 +        } else
   1.712 +            ckey = 0; /* actual value will be set later */
   1.713 +    }
   1.714  
   1.715 -	if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
   1.716 -		lib.png_set_gray_to_rgb(png_ptr);
   1.717 +    if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
   1.718 +        lib.png_set_gray_to_rgb(png_ptr);
   1.719  
   1.720 -	lib.png_read_update_info(png_ptr, info_ptr);
   1.721 +    lib.png_read_update_info(png_ptr, info_ptr);
   1.722  
   1.723 -	lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   1.724 -			&color_type, &interlace_type, NULL, NULL);
   1.725 +    lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   1.726 +            &color_type, &interlace_type, NULL, NULL);
   1.727  
   1.728 -	/* Allocate the SDL surface to hold the image */
   1.729 -	Rmask = Gmask = Bmask = Amask = 0 ;
   1.730 -	num_channels = lib.png_get_channels(png_ptr, info_ptr);
   1.731 -	if ( num_channels >= 3 ) {
   1.732 +    /* Allocate the SDL surface to hold the image */
   1.733 +    Rmask = Gmask = Bmask = Amask = 0 ;
   1.734 +    num_channels = lib.png_get_channels(png_ptr, info_ptr);
   1.735 +    if ( num_channels >= 3 ) {
   1.736  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.737 -			Rmask = 0x000000FF;
   1.738 -			Gmask = 0x0000FF00;
   1.739 -			Bmask = 0x00FF0000;
   1.740 -			Amask = (num_channels == 4) ? 0xFF000000 : 0;
   1.741 +            Rmask = 0x000000FF;
   1.742 +            Gmask = 0x0000FF00;
   1.743 +            Bmask = 0x00FF0000;
   1.744 +            Amask = (num_channels == 4) ? 0xFF000000 : 0;
   1.745  #else
   1.746 -			int s = (num_channels == 4) ? 0 : 8;
   1.747 -			Rmask = 0xFF000000 >> s;
   1.748 -			Gmask = 0x00FF0000 >> s;
   1.749 -			Bmask = 0x0000FF00 >> s;
   1.750 -			Amask = 0x000000FF >> s;
   1.751 +            int s = (num_channels == 4) ? 0 : 8;
   1.752 +            Rmask = 0xFF000000 >> s;
   1.753 +            Gmask = 0x00FF0000 >> s;
   1.754 +            Bmask = 0x0000FF00 >> s;
   1.755 +            Amask = 0x000000FF >> s;
   1.756  #endif
   1.757 -	}
   1.758 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
   1.759 -			bit_depth*num_channels, Rmask,Gmask,Bmask,Amask);
   1.760 -	if ( surface == NULL ) {
   1.761 -		error = SDL_GetError();
   1.762 -		goto done;
   1.763 -	}
   1.764 +    }
   1.765 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
   1.766 +            bit_depth*num_channels, Rmask,Gmask,Bmask,Amask);
   1.767 +    if ( surface == NULL ) {
   1.768 +        error = SDL_GetError();
   1.769 +        goto done;
   1.770 +    }
   1.771  
   1.772 -	if (ckey != -1) {
   1.773 -	        if (color_type != PNG_COLOR_TYPE_PALETTE)
   1.774 -			/* FIXME: Should these be truncated or shifted down? */
   1.775 -		        ckey = SDL_MapRGB(surface->format,
   1.776 -			                 (Uint8)transv->red,
   1.777 -			                 (Uint8)transv->green,
   1.778 -			                 (Uint8)transv->blue);
   1.779 -	        SDL_SetColorKey(surface, SDL_TRUE, ckey);
   1.780 -	}
   1.781 +    if (ckey != -1) {
   1.782 +            if (color_type != PNG_COLOR_TYPE_PALETTE)
   1.783 +            /* FIXME: Should these be truncated or shifted down? */
   1.784 +                ckey = SDL_MapRGB(surface->format,
   1.785 +                             (Uint8)transv->red,
   1.786 +                             (Uint8)transv->green,
   1.787 +                             (Uint8)transv->blue);
   1.788 +            SDL_SetColorKey(surface, SDL_TRUE, ckey);
   1.789 +    }
   1.790  
   1.791 -	/* Create the array of pointers to image data */
   1.792 -	row_pointers = (png_bytep*) SDL_malloc(sizeof(png_bytep)*height);
   1.793 -	if ( (row_pointers == NULL) ) {
   1.794 -		error = "Out of memory";
   1.795 -		goto done;
   1.796 -	}
   1.797 -	for (row = 0; row < (int)height; row++) {
   1.798 -		row_pointers[row] = (png_bytep)
   1.799 -				(Uint8 *)surface->pixels + row*surface->pitch;
   1.800 -	}
   1.801 +    /* Create the array of pointers to image data */
   1.802 +    row_pointers = (png_bytep*) SDL_malloc(sizeof(png_bytep)*height);
   1.803 +    if ( (row_pointers == NULL) ) {
   1.804 +        error = "Out of memory";
   1.805 +        goto done;
   1.806 +    }
   1.807 +    for (row = 0; row < (int)height; row++) {
   1.808 +        row_pointers[row] = (png_bytep)
   1.809 +                (Uint8 *)surface->pixels + row*surface->pitch;
   1.810 +    }
   1.811  
   1.812 -	/* Read the entire image in one go */
   1.813 -	lib.png_read_image(png_ptr, row_pointers);
   1.814 +    /* Read the entire image in one go */
   1.815 +    lib.png_read_image(png_ptr, row_pointers);
   1.816  
   1.817 -	/* and we're done!  (png_read_end() can be omitted if no processing of
   1.818 -	 * post-IDAT text/time/etc. is desired)
   1.819 -	 * In some cases it can't read PNG's created by some popular programs (ACDSEE),
   1.820 -	 * we do not want to process comments, so we omit png_read_end
   1.821 +    /* and we're done!  (png_read_end() can be omitted if no processing of
   1.822 +     * post-IDAT text/time/etc. is desired)
   1.823 +     * In some cases it can't read PNG's created by some popular programs (ACDSEE),
   1.824 +     * we do not want to process comments, so we omit png_read_end
   1.825  
   1.826 -	lib.png_read_end(png_ptr, info_ptr);
   1.827 -	*/
   1.828 +    lib.png_read_end(png_ptr, info_ptr);
   1.829 +    */
   1.830  
   1.831 -	/* Load the palette, if any */
   1.832 -	palette = surface->format->palette;
   1.833 -	if ( palette ) {
   1.834 -	    int png_num_palette;
   1.835 -	    png_colorp png_palette;
   1.836 -	    lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
   1.837 -	    if (color_type == PNG_COLOR_TYPE_GRAY) {
   1.838 -		palette->ncolors = 256;
   1.839 -		for (i = 0; i < 256; i++) {
   1.840 -		    palette->colors[i].r = i;
   1.841 -		    palette->colors[i].g = i;
   1.842 -		    palette->colors[i].b = i;
   1.843 -		}
   1.844 -	    } else if (png_num_palette > 0 ) {
   1.845 -		palette->ncolors = png_num_palette; 
   1.846 -		for ( i=0; i<png_num_palette; ++i ) {
   1.847 -		    palette->colors[i].b = png_palette[i].blue;
   1.848 -		    palette->colors[i].g = png_palette[i].green;
   1.849 -		    palette->colors[i].r = png_palette[i].red;
   1.850 -		}
   1.851 -	    }
   1.852 -	}
   1.853 +    /* Load the palette, if any */
   1.854 +    palette = surface->format->palette;
   1.855 +    if ( palette ) {
   1.856 +        int png_num_palette;
   1.857 +        png_colorp png_palette;
   1.858 +        lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
   1.859 +        if (color_type == PNG_COLOR_TYPE_GRAY) {
   1.860 +        palette->ncolors = 256;
   1.861 +        for (i = 0; i < 256; i++) {
   1.862 +            palette->colors[i].r = i;
   1.863 +            palette->colors[i].g = i;
   1.864 +            palette->colors[i].b = i;
   1.865 +        }
   1.866 +        } else if (png_num_palette > 0 ) {
   1.867 +        palette->ncolors = png_num_palette;
   1.868 +        for ( i=0; i<png_num_palette; ++i ) {
   1.869 +            palette->colors[i].b = png_palette[i].blue;
   1.870 +            palette->colors[i].g = png_palette[i].green;
   1.871 +            palette->colors[i].r = png_palette[i].red;
   1.872 +        }
   1.873 +        }
   1.874 +    }
   1.875  
   1.876 -done:	/* Clean up and return */
   1.877 -	if ( png_ptr ) {
   1.878 -		lib.png_destroy_read_struct(&png_ptr,
   1.879 -		                        info_ptr ? &info_ptr : (png_infopp)0,
   1.880 -								(png_infopp)0);
   1.881 -	}
   1.882 -	if ( row_pointers ) {
   1.883 -		SDL_free(row_pointers);
   1.884 -	}
   1.885 -	if ( error ) {
   1.886 -		SDL_RWseek(src, start, RW_SEEK_SET);
   1.887 -		if ( surface ) {
   1.888 -			SDL_FreeSurface(surface);
   1.889 -			surface = NULL;
   1.890 -		}
   1.891 -		IMG_SetError(error);
   1.892 -	}
   1.893 -	return(surface); 
   1.894 +done:   /* Clean up and return */
   1.895 +    if ( png_ptr ) {
   1.896 +        lib.png_destroy_read_struct(&png_ptr,
   1.897 +                                info_ptr ? &info_ptr : (png_infopp)0,
   1.898 +                                (png_infopp)0);
   1.899 +    }
   1.900 +    if ( row_pointers ) {
   1.901 +        SDL_free(row_pointers);
   1.902 +    }
   1.903 +    if ( error ) {
   1.904 +        SDL_RWseek(src, start, RW_SEEK_SET);
   1.905 +        if ( surface ) {
   1.906 +            SDL_FreeSurface(surface);
   1.907 +            surface = NULL;
   1.908 +        }
   1.909 +        IMG_SetError(error);
   1.910 +    }
   1.911 +    return(surface);
   1.912  }
   1.913  
   1.914  #else
   1.915  
   1.916  int IMG_InitPNG()
   1.917  {
   1.918 -	IMG_SetError("PNG images are not supported");
   1.919 -	return(-1);
   1.920 +    IMG_SetError("PNG images are not supported");
   1.921 +    return(-1);
   1.922  }
   1.923  
   1.924  void IMG_QuitPNG()
   1.925 @@ -567,13 +567,13 @@
   1.926  /* See if an image is contained in a data source */
   1.927  int IMG_isPNG(SDL_RWops *src)
   1.928  {
   1.929 -	return(0);
   1.930 +    return(0);
   1.931  }
   1.932  
   1.933  /* Load a PNG type image from an SDL datasource */
   1.934  SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
   1.935  {
   1.936 -	return(NULL);
   1.937 +    return(NULL);
   1.938  }
   1.939  
   1.940  #endif /* LOAD_PNG */