+#ifdef HAVE_NTGUI
+/* Image types that rely on external libraries are loaded dynamically
+ if the library is available. */
+#define CHECK_LIB_AVAILABLE(image_type, init_lib_fn, libraries) \
+ define_image_type (image_type, init_lib_fn (libraries))
+#else
+#define CHECK_LIB_AVAILABLE(image_type, init_lib_fn, libraries) \
+ define_image_type (image_type, 1)
+#endif /* HAVE_NTGUI */
+
+DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0,
+ doc: /* Initialize image library implementing image type TYPE.
+Return non-nil if TYPE is a supported image type.
+
+Image types pbm and xbm are prebuilt; other types are loaded here.
+Libraries to load are specified in alist LIBRARIES (usually, the value
+of `image-library-alist', which see). */)
+ (type, libraries)
+ Lisp_Object type, libraries;
+{
+ Lisp_Object tested;
+
+ /* Don't try to reload the library. */
+ tested = Fassq (type, Vimage_type_cache);
+ if (CONSP (tested))
+ return XCDR (tested);
+
+#if defined (HAVE_XPM) || defined (MAC_OS)
+ if (EQ (type, Qxpm))
+ return CHECK_LIB_AVAILABLE (&xpm_type, init_xpm_functions, libraries);
+#endif
+
+#if defined (HAVE_JPEG) || defined (MAC_OS)
+ if (EQ (type, Qjpeg))
+ return CHECK_LIB_AVAILABLE (&jpeg_type, init_jpeg_functions, libraries);
+#endif
+
+#if defined (HAVE_TIFF) || defined (MAC_OS)
+ if (EQ (type, Qtiff))
+ return CHECK_LIB_AVAILABLE (&tiff_type, init_tiff_functions, libraries);
+#endif
+
+#if defined (HAVE_GIF) || defined (MAC_OS)
+ if (EQ (type, Qgif))
+ return CHECK_LIB_AVAILABLE (&gif_type, init_gif_functions, libraries);
+#endif
+
+#if defined (HAVE_PNG) || defined (MAC_OS)
+ if (EQ (type, Qpng))
+ return CHECK_LIB_AVAILABLE (&png_type, init_png_functions, libraries);
+#endif
+
+#ifdef HAVE_GHOSTSCRIPT
+ if (EQ (type, Qpostscript))
+ return CHECK_LIB_AVAILABLE (&gs_type, init_gs_functions, libraries);
+#endif
+
+ /* If the type is not recognized, avoid testing it ever again. */
+ CACHE_IMAGE_TYPE (type, Qnil);
+ return Qnil;
+}
+