Added support for dynamically loading libjpeg, libpng, and libtiff.
authorSam Lantinga <slouken@libsdl.org>
Fri, 12 May 2006 05:08:03 +0000
changeset 143e01fee7bdf3b
parent 142 54ce80c86f72
child 144 2ea01e919685
Added support for dynamically loading libjpeg, libpng, and libtiff.
CHANGES
IMG_jpg.c
IMG_png.c
IMG_tif.c
configure.in
     1.1 --- a/CHANGES	Fri May 12 02:58:31 2006 +0000
     1.2 +++ b/CHANGES	Fri May 12 05:08:03 2006 +0000
     1.3 @@ -1,4 +1,6 @@
     1.4  1.2.5:
     1.5 +Sam Lantinga - Thu May 11 21:51:19 PDT 2006
     1.6 + * Added support for dynamically loading libjpeg, libpng, and libtiff.
     1.7  Sam Lantinga - Sun Apr 30 01:48:40 PDT 2006
     1.8   * Added gcc-fat.sh for generating Universal binaries on Mac OS X
     1.9   * Updated libtool support to version 1.5.22
     2.1 --- a/IMG_jpg.c	Fri May 12 02:58:31 2006 +0000
     2.2 +++ b/IMG_jpg.c	Fri May 12 05:08:03 2006 +0000
     2.3 @@ -38,6 +38,133 @@
     2.4  /* Define this for quicker (but less perfect) JPEG identification */
     2.5  #define FAST_IS_JPEG
     2.6  
     2.7 +static struct {
     2.8 +	int loaded;
     2.9 +	void *handle;
    2.10 +	void (*jpeg_calc_output_dimensions) (j_decompress_ptr cinfo);
    2.11 +	void (*jpeg_CreateDecompress) (j_decompress_ptr cinfo, int version, size_t structsize);
    2.12 +	void (*jpeg_destroy_decompress) (j_decompress_ptr cinfo);
    2.13 +	boolean (*jpeg_finish_decompress) (j_decompress_ptr cinfo);
    2.14 +	int (*jpeg_read_header) (j_decompress_ptr cinfo, boolean require_image);
    2.15 +	JDIMENSION (*jpeg_read_scanlines) (j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines);
    2.16 +	boolean (*jpeg_resync_to_restart) (j_decompress_ptr cinfo, int desired);
    2.17 +	boolean (*jpeg_start_decompress) (j_decompress_ptr cinfo);
    2.18 +	struct jpeg_error_mgr * (*jpeg_std_error) (struct jpeg_error_mgr * err);
    2.19 +} lib;
    2.20 +
    2.21 +#ifdef LOAD_JPG_DYNAMIC
    2.22 +int IMG_InitJPG()
    2.23 +{
    2.24 +	if ( lib.loaded == 0 ) {
    2.25 +		lib.handle = SDL_LoadObject(LOAD_JPG_DYNAMIC);
    2.26 +		if ( lib.handle == NULL ) {
    2.27 +			return -1;
    2.28 +		}
    2.29 +		lib.jpeg_calc_output_dimensions =
    2.30 +			(void (*) (j_decompress_ptr))
    2.31 +			SDL_LoadFunction(lib.handle, "jpeg_calc_output_dimensions");
    2.32 +		if ( lib.jpeg_calc_output_dimensions == NULL ) {
    2.33 +			SDL_UnloadObject(lib.handle);
    2.34 +			return -1;
    2.35 +		}
    2.36 +		lib.jpeg_CreateDecompress = 
    2.37 +			(void (*) (j_decompress_ptr, int, size_t))
    2.38 +			SDL_LoadFunction(lib.handle, "jpeg_CreateDecompress");
    2.39 +		if ( lib.jpeg_CreateDecompress == NULL ) {
    2.40 +			SDL_UnloadObject(lib.handle);
    2.41 +			return -1;
    2.42 +		}
    2.43 +		lib.jpeg_destroy_decompress = 
    2.44 +			(void (*) (j_decompress_ptr))
    2.45 +			SDL_LoadFunction(lib.handle, "jpeg_destroy_decompress");
    2.46 +		if ( lib.jpeg_destroy_decompress == NULL ) {
    2.47 +			SDL_UnloadObject(lib.handle);
    2.48 +			return -1;
    2.49 +		}
    2.50 +		lib.jpeg_finish_decompress = 
    2.51 +			(boolean (*) (j_decompress_ptr))
    2.52 +			SDL_LoadFunction(lib.handle, "jpeg_finish_decompress");
    2.53 +		if ( lib.jpeg_finish_decompress == NULL ) {
    2.54 +			SDL_UnloadObject(lib.handle);
    2.55 +			return -1;
    2.56 +		}
    2.57 +		lib.jpeg_read_header = 
    2.58 +			(int (*) (j_decompress_ptr, boolean))
    2.59 +			SDL_LoadFunction(lib.handle, "jpeg_read_header");
    2.60 +		if ( lib.jpeg_read_header == NULL ) {
    2.61 +			SDL_UnloadObject(lib.handle);
    2.62 +			return -1;
    2.63 +		}
    2.64 +		lib.jpeg_read_scanlines = 
    2.65 +			(JDIMENSION (*) (j_decompress_ptr, JSAMPARRAY, JDIMENSION))
    2.66 +			SDL_LoadFunction(lib.handle, "jpeg_read_scanlines");
    2.67 +		if ( lib.jpeg_read_scanlines == NULL ) {
    2.68 +			SDL_UnloadObject(lib.handle);
    2.69 +			return -1;
    2.70 +		}
    2.71 +		lib.jpeg_resync_to_restart = 
    2.72 +			(boolean (*) (j_decompress_ptr, int))
    2.73 +			SDL_LoadFunction(lib.handle, "jpeg_resync_to_restart");
    2.74 +		if ( lib.jpeg_resync_to_restart == NULL ) {
    2.75 +			SDL_UnloadObject(lib.handle);
    2.76 +			return -1;
    2.77 +		}
    2.78 +		lib.jpeg_start_decompress = 
    2.79 +			(boolean (*) (j_decompress_ptr))
    2.80 +			SDL_LoadFunction(lib.handle, "jpeg_start_decompress");
    2.81 +		if ( lib.jpeg_start_decompress == NULL ) {
    2.82 +			SDL_UnloadObject(lib.handle);
    2.83 +			return -1;
    2.84 +		}
    2.85 +		lib.jpeg_std_error = 
    2.86 +			(struct jpeg_error_mgr * (*) (struct jpeg_error_mgr *))
    2.87 +			SDL_LoadFunction(lib.handle, "jpeg_std_error");
    2.88 +		if ( lib.jpeg_std_error == NULL ) {
    2.89 +			SDL_UnloadObject(lib.handle);
    2.90 +			return -1;
    2.91 +		}
    2.92 +	}
    2.93 +	++lib.loaded;
    2.94 +
    2.95 +	return 0;
    2.96 +}
    2.97 +void IMG_QuitJPG()
    2.98 +{
    2.99 +	if ( lib.loaded == 0 ) {
   2.100 +		return;
   2.101 +	}
   2.102 +	if ( lib.loaded == 1 ) {
   2.103 +		SDL_UnloadObject(lib.handle);
   2.104 +	}
   2.105 +	--lib.loaded;
   2.106 +}
   2.107 +#else
   2.108 +int IMG_InitJPG()
   2.109 +{
   2.110 +	if ( lib.loaded == 0 ) {
   2.111 +		lib.jpeg_calc_output_dimensions = jpeg_calc_output_dimensions;
   2.112 +		lib.jpeg_CreateDecompress = jpeg_CreateDecompress;
   2.113 +		lib.jpeg_destroy_decompress = jpeg_destroy_decompress;
   2.114 +		lib.jpeg_finish_decompress = jpeg_finish_decompress;
   2.115 +		lib.jpeg_read_header = jpeg_read_header;
   2.116 +		lib.jpeg_read_scanlines = jpeg_read_scanlines;
   2.117 +		lib.jpeg_resync_to_restart = jpeg_resync_to_restart;
   2.118 +		lib.jpeg_start_decompress = jpeg_start_decompress;
   2.119 +		lib.jpeg_std_error = jpeg_std_error;
   2.120 +	}
   2.121 +	++lib.loaded;
   2.122 +}
   2.123 +void IMG_QuitJPG()
   2.124 +{
   2.125 +	if ( lib.loaded == 0 ) {
   2.126 +		return;
   2.127 +	}
   2.128 +	if ( lib.loaded == 1 ) {
   2.129 +	}
   2.130 +	--lib.loaded;
   2.131 +}
   2.132 +#endif /* LOAD_JPG_DYNAMIC */
   2.133 +
   2.134  /* See if an image is contained in a data source */
   2.135  int IMG_isJPG(SDL_RWops *src)
   2.136  {
   2.137 @@ -210,7 +337,7 @@
   2.138    src->pub.init_source = init_source;
   2.139    src->pub.fill_input_buffer = fill_input_buffer;
   2.140    src->pub.skip_input_data = skip_input_data;
   2.141 -  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
   2.142 +  src->pub.resync_to_restart = lib.jpeg_resync_to_restart; /* use default method */
   2.143    src->pub.term_source = term_source;
   2.144    src->ctx = ctx;
   2.145    src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
   2.146 @@ -248,30 +375,35 @@
   2.147  	}
   2.148  	start = SDL_RWtell(src);
   2.149  
   2.150 +	if ( IMG_InitJPG() < 0 ) {
   2.151 +		return NULL;
   2.152 +	}
   2.153 +
   2.154  	/* Create a decompression structure and load the JPEG header */
   2.155 -	cinfo.err = jpeg_std_error(&jerr.errmgr);
   2.156 +	cinfo.err = lib.jpeg_std_error(&jerr.errmgr);
   2.157  	jerr.errmgr.error_exit = my_error_exit;
   2.158  	jerr.errmgr.output_message = output_no_message;
   2.159  	if(setjmp(jerr.escape)) {
   2.160  		/* If we get here, libjpeg found an error */
   2.161 -		jpeg_destroy_decompress(&cinfo);
   2.162 +		lib.jpeg_destroy_decompress(&cinfo);
   2.163  		if ( surface != NULL ) {
   2.164  			SDL_FreeSurface(surface);
   2.165  		}
   2.166  		SDL_RWseek(src, start, SEEK_SET);
   2.167 +		IMG_QuitJPG();
   2.168  		IMG_SetError("JPEG loading error");
   2.169  		return NULL;
   2.170  	}
   2.171  
   2.172 -	jpeg_create_decompress(&cinfo);
   2.173 +	lib.jpeg_create_decompress(&cinfo);
   2.174  	jpeg_SDL_RW_src(&cinfo, src);
   2.175 -	jpeg_read_header(&cinfo, TRUE);
   2.176 +	lib.jpeg_read_header(&cinfo, TRUE);
   2.177  
   2.178  	if(cinfo.num_components == 4) {
   2.179  		/* Set 32-bit Raw output */
   2.180  		cinfo.out_color_space = JCS_CMYK;
   2.181  		cinfo.quantize_colors = FALSE;
   2.182 -		jpeg_calc_output_dimensions(&cinfo);
   2.183 +		lib.jpeg_calc_output_dimensions(&cinfo);
   2.184  
   2.185  		/* Allocate an output surface to hold the image */
   2.186  		surface = SDL_AllocSurface(SDL_SWSURFACE,
   2.187 @@ -291,7 +423,7 @@
   2.188  		cinfo.dct_method = JDCT_FASTEST;
   2.189  		cinfo.do_fancy_upsampling = FALSE;
   2.190  #endif
   2.191 -		jpeg_calc_output_dimensions(&cinfo);
   2.192 +		lib.jpeg_calc_output_dimensions(&cinfo);
   2.193  
   2.194  		/* Allocate an output surface to hold the image */
   2.195  		surface = SDL_AllocSurface(SDL_SWSURFACE,
   2.196 @@ -305,21 +437,24 @@
   2.197  	}
   2.198  
   2.199  	if ( surface == NULL ) {
   2.200 -		jpeg_destroy_decompress(&cinfo);
   2.201 +		lib.jpeg_destroy_decompress(&cinfo);
   2.202  		SDL_RWseek(src, start, SEEK_SET);
   2.203 +		IMG_QuitJPG();
   2.204  		IMG_SetError("Out of memory");
   2.205  		return NULL;
   2.206  	}
   2.207  
   2.208  	/* Decompress the image */
   2.209 -	jpeg_start_decompress(&cinfo);
   2.210 +	lib.jpeg_start_decompress(&cinfo);
   2.211  	while ( cinfo.output_scanline < cinfo.output_height ) {
   2.212  		rowptr[0] = (JSAMPROW)(Uint8 *)surface->pixels +
   2.213  		                    cinfo.output_scanline * surface->pitch;
   2.214 -		jpeg_read_scanlines(&cinfo, rowptr, (JDIMENSION) 1);
   2.215 +		lib.jpeg_read_scanlines(&cinfo, rowptr, (JDIMENSION) 1);
   2.216  	}
   2.217 -	jpeg_finish_decompress(&cinfo);
   2.218 -	jpeg_destroy_decompress(&cinfo);
   2.219 +	lib.jpeg_finish_decompress(&cinfo);
   2.220 +	lib.jpeg_destroy_decompress(&cinfo);
   2.221 +
   2.222 +	IMG_QuitJPG();
   2.223  
   2.224  	return(surface);
   2.225  }
     3.1 --- a/IMG_png.c	Fri May 12 02:58:31 2006 +0000
     3.2 +++ b/IMG_png.c	Fri May 12 05:08:03 2006 +0000
     3.3 @@ -71,6 +71,196 @@
     3.4  
     3.5  #define PNG_BYTES_TO_CHECK 4
     3.6  
     3.7 +static struct {
     3.8 +	int loaded;
     3.9 +	void *handle;
    3.10 +	png_infop (*png_create_info_struct) (png_structp png_ptr);
    3.11 +	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);
    3.12 +	void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
    3.13 +	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);
    3.14 +	png_voidp (*png_get_io_ptr) (png_structp png_ptr);
    3.15 +	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);
    3.16 +	png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
    3.17 +	void (*png_read_image) (png_structp png_ptr, png_bytepp image);
    3.18 +	void (*png_read_info) (png_structp png_ptr, png_infop info_ptr);
    3.19 +	void (*png_read_update_info) (png_structp png_ptr, png_infop info_ptr);
    3.20 +	void (*png_set_expand) (png_structp png_ptr);
    3.21 +	void (*png_set_gray_to_rgb) (png_structp png_ptr);
    3.22 +	void (*png_set_packing) (png_structp png_ptr);
    3.23 +	void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
    3.24 +	void (*png_set_strip_16) (png_structp png_ptr);
    3.25 +	int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
    3.26 +} lib;
    3.27 +
    3.28 +#ifdef LOAD_PNG_DYNAMIC
    3.29 +int IMG_InitPNG()
    3.30 +{
    3.31 +	if ( lib.loaded == 0 ) {
    3.32 +		lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC);
    3.33 +		if ( lib.handle == NULL ) {
    3.34 +			return -1;
    3.35 +		}
    3.36 +		lib.png_create_info_struct =
    3.37 +			(png_infop (*) (png_structp))
    3.38 +			SDL_LoadFunction(lib.handle, "png_create_info_struct");
    3.39 +		if ( lib.png_create_info_struct == NULL ) {
    3.40 +			SDL_UnloadObject(lib.handle);
    3.41 +			return -1;
    3.42 +		}
    3.43 +		lib.png_create_read_struct =
    3.44 +			(png_structp (*) (png_const_charp, png_voidp, png_error_ptr, png_error_ptr))
    3.45 +			SDL_LoadFunction(lib.handle, "png_create_read_struct");
    3.46 +		if ( lib.png_create_read_struct == NULL ) {
    3.47 +			SDL_UnloadObject(lib.handle);
    3.48 +			return -1;
    3.49 +		}
    3.50 +		lib.png_destroy_read_struct =
    3.51 +			(void (*) (png_structpp, png_infopp, png_infopp))
    3.52 +			SDL_LoadFunction(lib.handle, "png_destroy_read_struct");
    3.53 +		if ( lib.png_destroy_read_struct == NULL ) {
    3.54 +			SDL_UnloadObject(lib.handle);
    3.55 +			return -1;
    3.56 +		}
    3.57 +		lib.png_get_IHDR =
    3.58 +			(png_uint_32 (*) (png_structp, png_infop, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *))
    3.59 +			SDL_LoadFunction(lib.handle, "png_get_IHDR");
    3.60 +		if ( lib.png_get_IHDR == NULL ) {
    3.61 +			SDL_UnloadObject(lib.handle);
    3.62 +			return -1;
    3.63 +		}
    3.64 +		lib.png_get_io_ptr =
    3.65 +			(png_voidp (*) (png_structp))
    3.66 +			SDL_LoadFunction(lib.handle, "png_get_io_ptr");
    3.67 +		if ( lib.png_get_io_ptr == NULL ) {
    3.68 +			SDL_UnloadObject(lib.handle);
    3.69 +			return -1;
    3.70 +		}
    3.71 +		lib.png_get_tRNS =
    3.72 +			(png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
    3.73 +			SDL_LoadFunction(lib.handle, "png_get_tRNS");
    3.74 +		if ( lib.png_get_tRNS == NULL ) {
    3.75 +			SDL_UnloadObject(lib.handle);
    3.76 +			return -1;
    3.77 +		}
    3.78 +		lib.png_get_valid =
    3.79 +			(png_uint_32 (*) (png_structp, png_infop, png_uint_32))
    3.80 +			SDL_LoadFunction(lib.handle, "png_get_valid");
    3.81 +		if ( lib.png_get_valid == NULL ) {
    3.82 +			SDL_UnloadObject(lib.handle);
    3.83 +			return -1;
    3.84 +		}
    3.85 +		lib.png_read_image =
    3.86 +			(void (*) (png_structp, png_bytepp))
    3.87 +			SDL_LoadFunction(lib.handle, "png_read_image");
    3.88 +		if ( lib.png_read_image == NULL ) {
    3.89 +			SDL_UnloadObject(lib.handle);
    3.90 +			return -1;
    3.91 +		}
    3.92 +		lib.png_read_info =
    3.93 +			(void (*) (png_structp, png_infop))
    3.94 +			SDL_LoadFunction(lib.handle, "png_read_info");
    3.95 +		if ( lib.png_read_info == NULL ) {
    3.96 +			SDL_UnloadObject(lib.handle);
    3.97 +			return -1;
    3.98 +		}
    3.99 +		lib.png_read_update_info =
   3.100 +			(void (*) (png_structp, png_infop))
   3.101 +			SDL_LoadFunction(lib.handle, "png_read_update_info");
   3.102 +		if ( lib.png_read_update_info == NULL ) {
   3.103 +			SDL_UnloadObject(lib.handle);
   3.104 +			return -1;
   3.105 +		}
   3.106 +		lib.png_set_expand =
   3.107 +			(void (*) (png_structp))
   3.108 +			SDL_LoadFunction(lib.handle, "png_set_expand");
   3.109 +		if ( lib.png_set_expand == NULL ) {
   3.110 +			SDL_UnloadObject(lib.handle);
   3.111 +			return -1;
   3.112 +		}
   3.113 +		lib.png_set_gray_to_rgb =
   3.114 +			(void (*) (png_structp))
   3.115 +			SDL_LoadFunction(lib.handle, "png_set_gray_to_rgb");
   3.116 +		if ( lib.png_set_gray_to_rgb == NULL ) {
   3.117 +			SDL_UnloadObject(lib.handle);
   3.118 +			return -1;
   3.119 +		}
   3.120 +		lib.png_set_packing =
   3.121 +			(void (*) (png_structp))
   3.122 +			SDL_LoadFunction(lib.handle, "png_set_packing");
   3.123 +		if ( lib.png_set_packing == NULL ) {
   3.124 +			SDL_UnloadObject(lib.handle);
   3.125 +			return -1;
   3.126 +		}
   3.127 +		lib.png_set_read_fn =
   3.128 +			(void (*) (png_structp, png_voidp, png_rw_ptr))
   3.129 +			SDL_LoadFunction(lib.handle, "png_set_read_fn");
   3.130 +		if ( lib.png_set_read_fn == NULL ) {
   3.131 +			SDL_UnloadObject(lib.handle);
   3.132 +			return -1;
   3.133 +		}
   3.134 +		lib.png_set_strip_16 =
   3.135 +			(void (*) (png_structp))
   3.136 +			SDL_LoadFunction(lib.handle, "png_set_strip_16");
   3.137 +		if ( lib.png_set_strip_16 == NULL ) {
   3.138 +			SDL_UnloadObject(lib.handle);
   3.139 +			return -1;
   3.140 +		}
   3.141 +		lib.png_sig_cmp =
   3.142 +			(int (*) (png_bytep, png_size_t, png_size_t))
   3.143 +			SDL_LoadFunction(lib.handle, "png_sig_cmp");
   3.144 +		if ( lib.png_sig_cmp == NULL ) {
   3.145 +			SDL_UnloadObject(lib.handle);
   3.146 +			return -1;
   3.147 +		}
   3.148 +	}
   3.149 +	++lib.loaded;
   3.150 +
   3.151 +	return 0;
   3.152 +}
   3.153 +void IMG_QuitPNG()
   3.154 +{
   3.155 +	if ( lib.loaded == 0 ) {
   3.156 +		return;
   3.157 +	}
   3.158 +	if ( lib.loaded == 1 ) {
   3.159 +		SDL_UnloadObject(lib.handle);
   3.160 +	}
   3.161 +	--lib.loaded;
   3.162 +}
   3.163 +#else
   3.164 +int IMG_InitPNG()
   3.165 +{
   3.166 +	if ( lib.loaded == 0 ) {
   3.167 +		lib.png_create_info_struct = png_create_info_struct;
   3.168 +		lib.png_create_read_struct = png_create_read_struct;
   3.169 +		lib.png_destroy_read_struct = png_destroy_read_struct;
   3.170 +		lib.png_get_IHDR = png_get_IHDR;
   3.171 +		lib.png_get_io_ptr = png_get_io_ptr;
   3.172 +		lib.png_get_tRNS = png_get_tRNS;
   3.173 +		lib.png_get_valid = png_get_valid;
   3.174 +		lib.png_read_image = png_read_image;
   3.175 +		lib.png_read_info = png_read_info;
   3.176 +		lib.png_read_update_info = png_read_update_info;
   3.177 +		lib.png_set_expand = png_set_expand;
   3.178 +		lib.png_set_gray_to_rgb = png_set_gray_to_rgb;
   3.179 +		lib.png_set_packing = png_set_packing;
   3.180 +		lib.png_set_read_fn = png_set_read_fn;
   3.181 +		lib.png_set_strip_16 = png_set_strip_16;
   3.182 +		lib.png_sig_cmp = png_sig_cmp;
   3.183 +	}
   3.184 +	++lib.loaded;
   3.185 +}
   3.186 +void IMG_QuitPNG()
   3.187 +{
   3.188 +	if ( lib.loaded == 0 ) {
   3.189 +		return;
   3.190 +	}
   3.191 +	if ( lib.loaded == 1 ) {
   3.192 +	}
   3.193 +	--lib.loaded;
   3.194 +}
   3.195 +#endif /* LOAD_PNG_DYNAMIC */
   3.196 +
   3.197  /* See if an image is contained in a data source */
   3.198  int IMG_isPNG(SDL_RWops *src)
   3.199  {
   3.200 @@ -78,12 +268,16 @@
   3.201  	int is_PNG;
   3.202  	unsigned char buf[PNG_BYTES_TO_CHECK];
   3.203  
   3.204 +	if ( IMG_InitPNG() < 0 ) {
   3.205 +		return 0;
   3.206 +	}
   3.207  	start = SDL_RWtell(src);
   3.208  	is_PNG = 0;
   3.209  	if ( SDL_RWread(src, buf, 1, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK ) {
   3.210 -		is_PNG = (png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK) == 0);
   3.211 +		is_PNG = (lib.png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK) == 0);
   3.212  	}
   3.213  	SDL_RWseek(src, start, SEEK_SET);
   3.214 +	IMG_QuitPNG();
   3.215  	return(is_PNG);
   3.216  }
   3.217  
   3.218 @@ -92,7 +286,7 @@
   3.219  {
   3.220  	SDL_RWops *src;
   3.221  
   3.222 -	src = (SDL_RWops *)png_get_io_ptr(ctx);
   3.223 +	src = (SDL_RWops *)lib.png_get_io_ptr(ctx);
   3.224  	SDL_RWread(src, area, size, 1);
   3.225  }
   3.226  SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
   3.227 @@ -120,12 +314,16 @@
   3.228  	}
   3.229  	start = SDL_RWtell(src);
   3.230  
   3.231 +	if ( IMG_InitPNG() < 0 ) {
   3.232 +		return NULL;
   3.233 +	}
   3.234 +
   3.235  	/* Initialize the data we will clean up when we're done */
   3.236  	error = NULL;
   3.237  	png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL;
   3.238  
   3.239  	/* Create the PNG loading context structure */
   3.240 -	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
   3.241 +	png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
   3.242  					  NULL,NULL,NULL);
   3.243  	if (png_ptr == NULL){
   3.244  		error = "Couldn't allocate memory for PNG file or incompatible PNG dll";
   3.245 @@ -133,7 +331,7 @@
   3.246  	}
   3.247  
   3.248  	 /* Allocate/initialize the memory for image information.  REQUIRED. */
   3.249 -	info_ptr = png_create_info_struct(png_ptr);
   3.250 +	info_ptr = lib.png_create_info_struct(png_ptr);
   3.251  	if (info_ptr == NULL) {
   3.252  		error = "Couldn't create image information for PNG file";
   3.253  		goto done;
   3.254 @@ -149,32 +347,32 @@
   3.255  	}
   3.256  
   3.257  	/* Set up the input control */
   3.258 -	png_set_read_fn(png_ptr, src, png_read_data);
   3.259 +	lib.png_set_read_fn(png_ptr, src, png_read_data);
   3.260  
   3.261  	/* Read PNG header info */
   3.262 -	png_read_info(png_ptr, info_ptr);
   3.263 -	png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   3.264 +	lib.png_read_info(png_ptr, info_ptr);
   3.265 +	lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   3.266  			&color_type, &interlace_type, NULL, NULL);
   3.267  
   3.268  	/* tell libpng to strip 16 bit/color files down to 8 bits/color */
   3.269 -	png_set_strip_16(png_ptr) ;
   3.270 +	lib.png_set_strip_16(png_ptr) ;
   3.271  
   3.272  	/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
   3.273  	 * byte into separate bytes (useful for paletted and grayscale images).
   3.274  	 */
   3.275 -	png_set_packing(png_ptr);
   3.276 +	lib.png_set_packing(png_ptr);
   3.277  
   3.278  	/* scale greyscale values to the range 0..255 */
   3.279  	if(color_type == PNG_COLOR_TYPE_GRAY)
   3.280 -		png_set_expand(png_ptr);
   3.281 +		lib.png_set_expand(png_ptr);
   3.282  
   3.283  	/* For images with a single "transparent colour", set colour key;
   3.284  	   if more than one index has transparency, or if partially transparent
   3.285  	   entries exist, use full alpha channel */
   3.286 -	if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
   3.287 +	if (lib.png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
   3.288  	        int num_trans;
   3.289  		Uint8 *trans;
   3.290 -		png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
   3.291 +		lib.png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
   3.292  			     &transv);
   3.293  		if(color_type == PNG_COLOR_TYPE_PALETTE) {
   3.294  		    /* Check if all tRNS entries are opaque except one */
   3.295 @@ -191,18 +389,18 @@
   3.296  			ckey = t;
   3.297  		    } else {
   3.298  			/* more than one transparent index, or translucency */
   3.299 -			png_set_expand(png_ptr);
   3.300 +			lib.png_set_expand(png_ptr);
   3.301  		    }
   3.302  		} else
   3.303  		    ckey = 0; /* actual value will be set later */
   3.304  	}
   3.305  
   3.306  	if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
   3.307 -		png_set_gray_to_rgb(png_ptr);
   3.308 +		lib.png_set_gray_to_rgb(png_ptr);
   3.309  
   3.310 -	png_read_update_info(png_ptr, info_ptr);
   3.311 +	lib.png_read_update_info(png_ptr, info_ptr);
   3.312  
   3.313 -	png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   3.314 +	lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
   3.315  			&color_type, &interlace_type, NULL, NULL);
   3.316  
   3.317  	/* Allocate the SDL surface to hold the image */
   3.318 @@ -250,14 +448,14 @@
   3.319  	}
   3.320  
   3.321  	/* Read the entire image in one go */
   3.322 -	png_read_image(png_ptr, row_pointers);
   3.323 +	lib.png_read_image(png_ptr, row_pointers);
   3.324  
   3.325  	/* and we're done!  (png_read_end() can be omitted if no processing of
   3.326  	 * post-IDAT text/time/etc. is desired)
   3.327  	 * In some cases it can't read PNG's created by some popular programs (ACDSEE),
   3.328  	 * we do not want to process comments, so we omit png_read_end
   3.329  
   3.330 -	png_read_end(png_ptr, info_ptr);
   3.331 +	lib.png_read_end(png_ptr, info_ptr);
   3.332  	*/
   3.333  
   3.334  	/* Load the palette, if any */
   3.335 @@ -282,7 +480,7 @@
   3.336  
   3.337  done:	/* Clean up and return */
   3.338  	if ( png_ptr ) {
   3.339 -		png_destroy_read_struct(&png_ptr,
   3.340 +		lib.png_destroy_read_struct(&png_ptr,
   3.341  		                        info_ptr ? &info_ptr : (png_infopp)0,
   3.342  								(png_infopp)0);
   3.343  	}
   3.344 @@ -295,7 +493,10 @@
   3.345  			SDL_FreeSurface(surface);
   3.346  			surface = NULL;
   3.347  		}
   3.348 +		IMG_QuitPNG();
   3.349  		IMG_SetError(error);
   3.350 +	} else {
   3.351 +		IMG_QuitPNG();
   3.352  	}
   3.353  	return(surface); 
   3.354  }
     4.1 --- a/IMG_tif.c	Fri May 12 02:58:31 2006 +0000
     4.2 +++ b/IMG_tif.c	Fri May 12 05:08:03 2006 +0000
     4.3 @@ -30,6 +30,97 @@
     4.4  
     4.5  #include <tiffio.h>
     4.6  
     4.7 +static struct {
     4.8 +	int loaded;
     4.9 +	void *handle;
    4.10 +	TIFF* (*TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc);
    4.11 +	void (*TIFFClose)(TIFF*);
    4.12 +	int (*TIFFGetField)(TIFF*, ttag_t, ...);
    4.13 +	int (*TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int);
    4.14 +	TIFFErrorHandler (*TIFFSetErrorHandler)(TIFFErrorHandler);
    4.15 +} lib;
    4.16 +
    4.17 +#ifdef LOAD_TIF_DYNAMIC
    4.18 +int IMG_InitTIF()
    4.19 +{
    4.20 +	if ( lib.loaded == 0 ) {
    4.21 +		lib.handle = SDL_LoadObject(LOAD_TIF_DYNAMIC);
    4.22 +		if ( lib.handle == NULL ) {
    4.23 +			return -1;
    4.24 +		}
    4.25 +		lib.TIFFClientOpen =
    4.26 +			(TIFF* (*)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc))
    4.27 +			SDL_LoadFunction(lib.handle, "TIFFClientOpen");
    4.28 +		if ( lib.TIFFClientOpen == NULL ) {
    4.29 +			SDL_UnloadObject(lib.handle);
    4.30 +			return -1;
    4.31 +		}
    4.32 +		lib.TIFFClose =
    4.33 +			(void (*)(TIFF*))
    4.34 +			SDL_LoadFunction(lib.handle, "TIFFClose");
    4.35 +		if ( lib.TIFFClose == NULL ) {
    4.36 +			SDL_UnloadObject(lib.handle);
    4.37 +			return -1;
    4.38 +		}
    4.39 +		lib.TIFFGetField =
    4.40 +			(int (*)(TIFF*, ttag_t, ...))
    4.41 +			SDL_LoadFunction(lib.handle, "TIFFGetField");
    4.42 +		if ( lib.TIFFGetField == NULL ) {
    4.43 +			SDL_UnloadObject(lib.handle);
    4.44 +			return -1;
    4.45 +		}
    4.46 +		lib.TIFFReadRGBAImage =
    4.47 +			(int (*)(TIFF*, uint32, uint32, uint32*, int))
    4.48 +			SDL_LoadFunction(lib.handle, "TIFFReadRGBAImage");
    4.49 +		if ( lib.TIFFReadRGBAImage == NULL ) {
    4.50 +			SDL_UnloadObject(lib.handle);
    4.51 +			return -1;
    4.52 +		}
    4.53 +		lib.TIFFSetErrorHandler =
    4.54 +			(TIFFErrorHandler (*)(TIFFErrorHandler))
    4.55 +			SDL_LoadFunction(lib.handle, "TIFFSetErrorHandler");
    4.56 +		if ( lib.TIFFSetErrorHandler == NULL ) {
    4.57 +			SDL_UnloadObject(lib.handle);
    4.58 +			return -1;
    4.59 +		}
    4.60 +	}
    4.61 +	++lib.loaded;
    4.62 +
    4.63 +	return 0;
    4.64 +}
    4.65 +void IMG_QuitTIF()
    4.66 +{
    4.67 +	if ( lib.loaded == 0 ) {
    4.68 +		return;
    4.69 +	}
    4.70 +	if ( lib.loaded == 1 ) {
    4.71 +		SDL_UnloadObject(lib.handle);
    4.72 +	}
    4.73 +	--lib.loaded;
    4.74 +}
    4.75 +#else
    4.76 +int IMG_InitTIF()
    4.77 +{
    4.78 +	if ( lib.loaded == 0 ) {
    4.79 +		lib.TIFFClientOpen = TIFFClientOpen;
    4.80 +		lib.TIFFClose = TIFFClose;
    4.81 +		lib.TIFFGetField = TIFFGetField;
    4.82 +		lib.TIFFReadRGBAImage = TIFFReadRGBAImage;
    4.83 +		lib.TIFFSetErrorHandler = TIFFSetErrorHandler;
    4.84 +	}
    4.85 +	++lib.loaded;
    4.86 +}
    4.87 +void IMG_QuitTIF()
    4.88 +{
    4.89 +	if ( lib.loaded == 0 ) {
    4.90 +		return;
    4.91 +	}
    4.92 +	if ( lib.loaded == 1 ) {
    4.93 +	}
    4.94 +	--lib.loaded;
    4.95 +}
    4.96 +#endif /* LOAD_TIF_DYNAMIC */
    4.97 +
    4.98  /*
    4.99   * These are the thunking routine to use the SDL_RWops* routines from
   4.100   * libtiff's internals.
   4.101 @@ -78,28 +169,32 @@
   4.102  	TIFF* tiff;
   4.103  	TIFFErrorHandler prev_handler;
   4.104  
   4.105 +	if ( IMG_InitTIF() < 0 ) {
   4.106 +		return 0;
   4.107 +	}
   4.108  	start = SDL_RWtell(src);
   4.109  	is_TIF = 0;
   4.110  
   4.111  	/* Suppress output from libtiff */
   4.112 -	prev_handler = TIFFSetErrorHandler(NULL);
   4.113 +	prev_handler = lib.TIFFSetErrorHandler(NULL);
   4.114  	
   4.115  	/* Attempt to process the given file data */
   4.116  	/* turn off memory mapped access with the m flag */
   4.117 -	tiff = TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
   4.118 +	tiff = lib.TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
   4.119  		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, NULL, NULL);
   4.120  
   4.121  	/* Reset the default error handler, since it can be useful for info */
   4.122 -	TIFFSetErrorHandler(prev_handler);
   4.123 +	lib.TIFFSetErrorHandler(prev_handler);
   4.124  
   4.125  	/* If it's not a TIFF, then tiff will be NULL. */
   4.126  	if ( tiff ) {
   4.127  		is_TIF = 1;
   4.128  
   4.129  		/* Free up any dynamically allocated memory libtiff uses */
   4.130 -		TIFFClose(tiff);
   4.131 +		lib.TIFFClose(tiff);
   4.132  	}
   4.133  	SDL_RWseek(src, start, SEEK_SET);
   4.134 +	IMG_QuitTIF();
   4.135  	return(is_TIF);
   4.136  }
   4.137  
   4.138 @@ -119,15 +214,19 @@
   4.139  	}
   4.140  	start = SDL_RWtell(src);
   4.141  
   4.142 +	if ( IMG_InitTIF() < 0 ) {
   4.143 +		return NULL;
   4.144 +	}
   4.145 +
   4.146  	/* turn off memory mapped access with the m flag */
   4.147 -	tiff = TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
   4.148 +	tiff = lib.TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
   4.149  		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, NULL, NULL);
   4.150  	if(!tiff)
   4.151  		goto error;
   4.152  
   4.153  	/* Retrieve the dimensions of the image from the TIFF tags */
   4.154 -	TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width);
   4.155 -	TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &img_height);
   4.156 +	lib.TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width);
   4.157 +	lib.TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &img_height);
   4.158  
   4.159  	Rmask = 0x000000FF;
   4.160  	Gmask = 0x0000FF00;
   4.161 @@ -138,7 +237,7 @@
   4.162  	if(!surface)
   4.163  		goto error;
   4.164  	
   4.165 -	if(!TIFFReadRGBAImage(tiff, img_width, img_height, surface->pixels, 0))
   4.166 +	if(!lib.TIFFReadRGBAImage(tiff, img_width, img_height, surface->pixels, 0))
   4.167  		goto error;
   4.168  
   4.169  	/* libtiff loads the image upside-down, flip it back */
   4.170 @@ -155,7 +254,8 @@
   4.171  			bot[x] = tmp;
   4.172  		}
   4.173  	}
   4.174 -	TIFFClose(tiff);
   4.175 +	lib.TIFFClose(tiff);
   4.176 +	IMG_QuitTIF();
   4.177  	
   4.178  	return surface;
   4.179  
   4.180 @@ -164,6 +264,7 @@
   4.181  	if ( surface ) {
   4.182  		SDL_FreeSurface(surface);
   4.183  	}
   4.184 +	IMG_QuitTIF();
   4.185  	return NULL;
   4.186  }
   4.187  
     5.1 --- a/configure.in	Fri May 12 02:58:31 2006 +0000
     5.2 +++ b/configure.in	Fri May 12 05:08:03 2006 +0000
     5.3 @@ -89,18 +89,24 @@
     5.4   [], [enable_gif=yes])
     5.5  AC_ARG_ENABLE([jpg], [AC_HELP_STRING([--enable-jpg], [support loading JPG images [default=yes]])],
     5.6   [], [enable_jpg=yes])
     5.7 +AC_ARG_ENABLE([jpg-shared], AC_HELP_STRING([--enable-jpg-shared], [dynamically load JPG support [[default=yes]]]),
     5.8 + [], [enable_jpg_shared=yes])
     5.9  AC_ARG_ENABLE([lbm], [AC_HELP_STRING([--enable-lbm], [support loading LBM images [default=yes]])],
    5.10   [], [enable_lbm=yes])
    5.11  AC_ARG_ENABLE([pcx], [AC_HELP_STRING([--enable-pcx], [support loading PCX images [default=yes]])],
    5.12   [], [enable_pcx=yes])
    5.13 -AC_ARG_ENABLE([png], [AC_HELP_STRING([--enable-bmp], [support loading PNG images [default=yes]])],
    5.14 +AC_ARG_ENABLE([png], [AC_HELP_STRING([--enable-png], [support loading PNG images [default=yes]])],
    5.15   [], [enable_png=yes])
    5.16 +AC_ARG_ENABLE([png-shared], AC_HELP_STRING([--enable-png-shared], [dynamically load PNG support [[default=yes]]]),
    5.17 + [], [enable_png_shared=yes])
    5.18  AC_ARG_ENABLE([pnm], [AC_HELP_STRING([--enable-pnm], [support loading PNM images [default=yes]])],
    5.19   [], [enable_pnm=yes])
    5.20  AC_ARG_ENABLE([tga], [AC_HELP_STRING([--enable-tga], [support loading TGA images [default=yes]])],
    5.21   [], [enable_tga=yes])
    5.22 -AC_ARG_ENABLE([tif], [AC_HELP_STRING([--enable-tif], [support loading TIFF images [default=no]])],
    5.23 - [], [enable_tif=no])
    5.24 +AC_ARG_ENABLE([tif], [AC_HELP_STRING([--enable-tif], [support loading TIFF images [default=yes]])],
    5.25 + [], [enable_tif=yes])
    5.26 +AC_ARG_ENABLE([tif-shared], AC_HELP_STRING([--enable-tif-shared], [dynamically load TIFF support [[default=yes]]]),
    5.27 + [], [enable_tif_shared=yes])
    5.28  AC_ARG_ENABLE([xcf], [AC_HELP_STRING([--enable-xcf], [support loading XCF images [default=yes]])],
    5.29   [], [enable_xcf=yes])
    5.30  AC_ARG_ENABLE([xpm], [AC_HELP_STRING([--enable-xpm], [support loading XPM images [default=yes]])],
    5.31 @@ -108,21 +114,35 @@
    5.32  AC_ARG_ENABLE([xv], [AC_HELP_STRING([--enable-xv], [support loading XV images [default=yes]])],
    5.33   [], [enable_xv=yes])
    5.34  
    5.35 -if test x$enable_png = xyes || x$enable_tif = xyes; then
    5.36 +if test x$enable_png = xyes || test x$enable_tif = xyes; then
    5.37      AC_CHECK_LIB([z], [uncompress], [
    5.38          LIBS="-lz $LIBS"
    5.39 -        IMG_LIBS="-lz $IMG_LIBS"
    5.40      ])
    5.41  fi
    5.42  
    5.43 -if test x$enable_jpg = xyes || x$enable_tif = xyes; then
    5.44 +if test x$enable_jpg = xyes || test x$enable_tif = xyes; then
    5.45      AC_CHECK_LIB([jpeg], [jpeg_CreateDecompress], [have_libjpeg=yes])
    5.46      if test x$have_libjpeg = xyes; then
    5.47          if test x$enable_jpg = xyes; then
    5.48              AC_DEFINE(LOAD_JPG)
    5.49          fi
    5.50          LIBS="-ljpeg $LIBS"
    5.51 -        IMG_LIBS="-ljpeg $IMG_LIBS"
    5.52 +
    5.53 +        case "$host" in
    5.54 +            *-*-darwin*) # FIXME when Mac OS X ships with libjpeg
    5.55 +                jpg_lib=''
    5.56 +                ;;
    5.57 +            *-*-cygwin* | *-*-mingw32*)
    5.58 +                jpg_lib='jpeg.dll'
    5.59 +                ;;
    5.60 +            *)
    5.61 +                for path in /usr/lib /usr/local/lib; do
    5.62 +                    if test x$jpg_lib = x; then
    5.63 +                        jpg_lib=[`ls -- $path/libjpeg.so.[0-9][0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
    5.64 +                    fi
    5.65 +                done
    5.66 +                ;;
    5.67 +        esac
    5.68      elif test x$enable_jpg = xyes; then
    5.69          AC_MSG_WARN([*** Unable to find JPEG library (http://www.ijg.org/)])
    5.70          AC_MSG_WARN([JPG image loading disabled])
    5.71 @@ -133,7 +153,22 @@
    5.72      AC_CHECK_LIB([png], [png_create_read_struct], [have_libpng=yes])
    5.73      if test x$have_libpng = xyes; then
    5.74          AC_DEFINE([LOAD_PNG])
    5.75 -        IMG_LIBS="-lpng $IMG_LIBS"
    5.76 +
    5.77 +        case "$host" in
    5.78 +            *-*-darwin*) # FIXME when Mac OS X ships with libpng
    5.79 +                png_lib=''
    5.80 +                ;;
    5.81 +            *-*-cygwin* | *-*-mingw32*)
    5.82 +                png_lib='libpng13.dll'
    5.83 +                ;;
    5.84 +            *)
    5.85 +                for path in /usr/lib /usr/local/lib; do
    5.86 +                    if test x$png_lib = x; then
    5.87 +                        png_lib=[`ls -- $path/libpng.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
    5.88 +                    fi
    5.89 +                done
    5.90 +                ;;
    5.91 +        esac
    5.92      else
    5.93          AC_MSG_WARN([*** Unable to find PNG library (http://www.libpng.org/pub/png/libpng.html)])
    5.94          AC_MSG_WARN([PNG image loading disabled])
    5.95 @@ -144,9 +179,24 @@
    5.96      AC_CHECK_LIB([tiff], [TIFFClientOpen], [have_libtiff=yes])
    5.97      if test x$have_libtiff = xyes; then
    5.98          AC_DEFINE([LOAD_TIF])
    5.99 -        IMG_LIBS="-ltiff $IMG_LIBS"
   5.100 +
   5.101 +        case "$host" in
   5.102 +            *-*-darwin*) # FIXME when Mac OS X ships with libtiff
   5.103 +                tif_lib=''
   5.104 +                ;;
   5.105 +            *-*-cygwin* | *-*-mingw32*)
   5.106 +                tif_lib='libtiff.dll'
   5.107 +                ;;
   5.108 +            *)
   5.109 +                for path in /usr/lib /usr/local/lib; do
   5.110 +                    if test x$tif_lib = x; then
   5.111 +                        tif_lib=[`ls -- $path/libtiff.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   5.112 +                    fi
   5.113 +                done
   5.114 +                ;;
   5.115 +        esac
   5.116      else
   5.117 -        AC_MSG_WARN([*** Unable to find Tiff library (ftp://ftp.sgi.com/graphics/tiff/)])
   5.118 +        AC_MSG_WARN([*** Unable to find Tiff library (http://www.remotesensing.org/libtiff/)])
   5.119          AC_MSG_WARN([TIF image loading disabled])
   5.120      fi
   5.121  fi
   5.122 @@ -187,6 +237,36 @@
   5.123      AC_DEFINE([LOAD_XV])
   5.124  fi
   5.125  
   5.126 +if test x$enable_tif = xyes; then
   5.127 +    if test x$enable_tif_shared = xyes && test x$tif_lib != x; then
   5.128 +        echo "-- dynamic libtiff -> $tif_lib"
   5.129 +        AC_DEFINE_UNQUOTED(LOAD_TIF_DYNAMIC, "$tif_lib")
   5.130 +    else
   5.131 +        if test x$have_libjpeg = xyes; then
   5.132 +            # Disable dynamic jpeg since we're linking it explicitly
   5.133 +            jpg_lib=''
   5.134 +            IMG_LIBS="-ljpeg $IMG_LIBS"
   5.135 +        fi
   5.136 +        IMG_LIBS="-ltiff -lz"
   5.137 +    fi
   5.138 +fi
   5.139 +if test x$enable_jpg = xyes; then
   5.140 +    if test x$enable_jpg_shared = xyes && test x$jpg_lib != x; then
   5.141 +        echo "-- dynamic libjpeg -> $jpg_lib"
   5.142 +        AC_DEFINE_UNQUOTED(LOAD_JPG_DYNAMIC, "$jpg_lib")
   5.143 +    else
   5.144 +        IMG_LIBS="-ljpeg $IMG_LIBS"
   5.145 +    fi
   5.146 +fi
   5.147 +if test x$enable_png = xyes; then
   5.148 +    if test x$enable_png_shared = xyes && test x$png_lib != x; then
   5.149 +        echo "-- dynamic libpng -> $png_lib"
   5.150 +        AC_DEFINE_UNQUOTED(LOAD_PNG_DYNAMIC, "$png_lib")
   5.151 +    else
   5.152 +        IMG_LIBS="-lpng -lz $IMG_LIBS"
   5.153 +    fi
   5.154 +fi
   5.155 +
   5.156  LIBS="$saved_LIBS"
   5.157  
   5.158  AC_SUBST([IMG_LIBS])