aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuanma Barranquero2004-06-14 20:47:25 +0000
committerJuanma Barranquero2004-06-14 20:47:25 +0000
commit0855eb52193e94cfa102ac899b740b0e875fce34 (patch)
tree722805e9ee6a626c3928f75086ba237564832ee3 /src
parent15469ae8ffc65e1a0cdee7214dfe07e1055ba543 (diff)
downloademacs-0855eb52193e94cfa102ac899b740b0e875fce34.tar.gz
emacs-0855eb52193e94cfa102ac899b740b0e875fce34.zip
(Vimage_types): Move from xdisp.c.
(Vimage_type_cache): New variable. (define_image_type): New argument indicating whether an image library was loaded; cache loaded status and return t on success, nil otherwise. (CACHE_IMAGE_TYPE, ADD_IMAGE_TYPE): New macros. (w32_delayed_load): New function to load an image library from a list of possible filenames. (init_xpm_functions, init_png_functions, init_jpeg_functions) (init_tiff_functions, init_gif_functions): Use `w32_delayed_load'. (CHECK_LIB_AVAILABLE): Call `define_image_library' with new argument. (Finit_image_library): New function, extracted from `init_image'. Try to initialize an image library on demand and cache whether we were successful or not. (syms_of_image): Initialize `Vimage_types' and `Vimage_type_cache'. Add recognized image types to Vimage_types. Export `init-image-library'. (init_image): Remove initialization of all image types, except xbm and pbm.
Diffstat (limited to 'src')
-rw-r--r--src/image.c229
1 files changed, 155 insertions, 74 deletions
diff --git a/src/image.c b/src/image.c
index 41762030b9e..3eccf0f001e 100644
--- a/src/image.c
+++ b/src/image.c
@@ -606,6 +606,14 @@ x_create_bitmap_mask (f, id)
606 606
607static struct image_type *image_types; 607static struct image_type *image_types;
608 608
609/* A list of symbols, one for each supported image type. */
610
611Lisp_Object Vimage_types;
612
613/* Cache for delayed-loading image types. */
614
615static Lisp_Object Vimage_type_cache;
616
609/* The symbol `xbm' which is used as the type symbol for XBM images. */ 617/* The symbol `xbm' which is used as the type symbol for XBM images. */
610 618
611Lisp_Object Qxbm; 619Lisp_Object Qxbm;
@@ -630,7 +638,7 @@ Lisp_Object Vimage_cache_eviction_delay;
630 638
631/* Function prototypes. */ 639/* Function prototypes. */
632 640
633static void define_image_type P_ ((struct image_type *type)); 641static Lisp_Object define_image_type P_ ((struct image_type *type, int loaded));
634static struct image_type *lookup_image_type P_ ((Lisp_Object symbol)); 642static struct image_type *lookup_image_type P_ ((Lisp_Object symbol));
635static void image_error P_ ((char *format, Lisp_Object, Lisp_Object)); 643static void image_error P_ ((char *format, Lisp_Object, Lisp_Object));
636static void x_laplace P_ ((struct frame *, struct image *)); 644static void x_laplace P_ ((struct frame *, struct image *));
@@ -638,21 +646,37 @@ static void x_emboss P_ ((struct frame *, struct image *));
638static int x_build_heuristic_mask P_ ((struct frame *, struct image *, 646static int x_build_heuristic_mask P_ ((struct frame *, struct image *,
639 Lisp_Object)); 647 Lisp_Object));
640 648
649#define CACHE_IMAGE_TYPE(type, status) \
650 do { Vimage_type_cache = Fcons (Fcons (type, status), Vimage_type_cache); } while (0)
651
652#define ADD_IMAGE_TYPE(type) \
653 do { Vimage_types = Fcons (type, Vimage_types); } while (0)
641 654
642/* Define a new image type from TYPE. This adds a copy of TYPE to 655/* Define a new image type from TYPE. This adds a copy of TYPE to
643 image_types and adds the symbol *TYPE->type to Vimage_types. */ 656 image_types and caches the loading status of TYPE. */
644 657
645static void 658static Lisp_Object
646define_image_type (type) 659define_image_type (type, loaded)
647 struct image_type *type; 660 struct image_type *type;
661 int loaded;
648{ 662{
649 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs. 663 Lisp_Object success;
650 The initialized data segment is read-only. */ 664
651 struct image_type *p = (struct image_type *) xmalloc (sizeof *p); 665 if (!loaded)
652 bcopy (type, p, sizeof *p); 666 success = Qnil;
653 p->next = image_types; 667 else
654 image_types = p; 668 {
655 Vimage_types = Fcons (*p->type, Vimage_types); 669 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
670 The initialized data segment is read-only. */
671 struct image_type *p = (struct image_type *) xmalloc (sizeof *p);
672 bcopy (type, p, sizeof *p);
673 p->next = image_types;
674 image_types = p;
675 success = Qt;
676 }
677
678 CACHE_IMAGE_TYPE(*type->type, success);
679 return success;
656} 680}
657 681
658 682
@@ -1789,6 +1813,33 @@ forall_images_in_image_cache (f, fn)
1789 if (!fn_##func) return 0; \ 1813 if (!fn_##func) return 0; \
1790 } 1814 }
1791 1815
1816/* Load a DLL implementing an image type.
1817 The `image-library-alist' variable associates a symbol,
1818 identifying an image type, to a list of possible filenames.
1819 The function returns NULL if no library could be loaded for
1820 the given image type, or if the library was previously loaded;
1821 else the handle of the DLL. */
1822static HMODULE
1823w32_delayed_load (Lisp_Object libraries, Lisp_Object type)
1824{
1825 HMODULE library = NULL;
1826
1827 if (CONSP (libraries) && NILP (Fassq (type, Vimage_type_cache)))
1828 {
1829 Lisp_Object dlls = Fassq (type, libraries);
1830
1831 if (CONSP (dlls))
1832 for (dlls = XCDR (dlls); CONSP (dlls); dlls = XCDR (dlls))
1833 {
1834 CHECK_STRING_CAR (dlls);
1835 if (library = LoadLibrary (SDATA (XCAR (dlls))))
1836 break;
1837 }
1838 }
1839
1840 return library;
1841}
1842
1792#endif /* HAVE_NTGUI */ 1843#endif /* HAVE_NTGUI */
1793 1844
1794static int x_create_x_image_and_pixmap P_ ((struct frame *, int, int, int, 1845static int x_create_x_image_and_pixmap P_ ((struct frame *, int, int, int,
@@ -3489,13 +3540,12 @@ DEF_IMGLIB_FN (XpmCreateImageFromBuffer);
3489DEF_IMGLIB_FN (XpmReadFileToImage); 3540DEF_IMGLIB_FN (XpmReadFileToImage);
3490DEF_IMGLIB_FN (XImageFree); 3541DEF_IMGLIB_FN (XImageFree);
3491 3542
3492
3493static int 3543static int
3494init_xpm_functions (void) 3544init_xpm_functions (Lisp_Object libraries)
3495{ 3545{
3496 HMODULE library; 3546 HMODULE library;
3497 3547
3498 if (!(library = LoadLibrary ("libXpm.dll"))) 3548 if (!(library = w32_delayed_load (libraries, Qxpm)))
3499 return 0; 3549 return 0;
3500 3550
3501 LOAD_IMGLIB_FN (library, XpmFreeAttributes); 3551 LOAD_IMGLIB_FN (library, XpmFreeAttributes);
@@ -5589,21 +5639,12 @@ DEF_IMGLIB_FN (png_read_end);
5589DEF_IMGLIB_FN (png_error); 5639DEF_IMGLIB_FN (png_error);
5590 5640
5591static int 5641static int
5592init_png_functions (void) 5642init_png_functions (Lisp_Object libraries)
5593{ 5643{
5594 HMODULE library; 5644 HMODULE library;
5595 5645
5596 /* Ensure zlib is loaded. Try debug version first. */
5597 if (!LoadLibrary ("zlibd.dll")
5598 && !LoadLibrary ("zlib.dll"))
5599 return 0;
5600
5601 /* Try loading libpng under probable names. */ 5646 /* Try loading libpng under probable names. */
5602 if (!(library = LoadLibrary ("libpng13d.dll")) 5647 if (!(library = w32_delayed_load (libraries, Qpng)))
5603 && !(library = LoadLibrary ("libpng13.dll"))
5604 && !(library = LoadLibrary ("libpng12d.dll"))
5605 && !(library = LoadLibrary ("libpng12.dll"))
5606 && !(library = LoadLibrary ("libpng.dll")))
5607 return 0; 5648 return 0;
5608 5649
5609 LOAD_IMGLIB_FN (library, png_get_io_ptr); 5650 LOAD_IMGLIB_FN (library, png_get_io_ptr);
@@ -6247,13 +6288,11 @@ DEF_IMGLIB_FN (jpeg_std_error);
6247DEF_IMGLIB_FN (jpeg_resync_to_restart); 6288DEF_IMGLIB_FN (jpeg_resync_to_restart);
6248 6289
6249static int 6290static int
6250init_jpeg_functions (void) 6291init_jpeg_functions (Lisp_Object libraries)
6251{ 6292{
6252 HMODULE library; 6293 HMODULE library;
6253 6294
6254 if (!(library = LoadLibrary ("libjpeg.dll")) 6295 if (!(library = w32_delayed_load (libraries, Qjpeg)))
6255 && !(library = LoadLibrary ("jpeg-62.dll"))
6256 && !(library = LoadLibrary ("jpeg.dll")))
6257 return 0; 6296 return 0;
6258 6297
6259 LOAD_IMGLIB_FN (library, jpeg_finish_decompress); 6298 LOAD_IMGLIB_FN (library, jpeg_finish_decompress);
@@ -6684,11 +6723,11 @@ DEF_IMGLIB_FN (TIFFReadRGBAImage);
6684DEF_IMGLIB_FN (TIFFClose); 6723DEF_IMGLIB_FN (TIFFClose);
6685 6724
6686static int 6725static int
6687init_tiff_functions (void) 6726init_tiff_functions (Lisp_Object libraries)
6688{ 6727{
6689 HMODULE library; 6728 HMODULE library;
6690 6729
6691 if (!(library = LoadLibrary ("libtiff.dll"))) 6730 if (!(library = w32_delayed_load (libraries, Qtiff)))
6692 return 0; 6731 return 0;
6693 6732
6694 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler); 6733 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler);
@@ -7104,11 +7143,11 @@ DEF_IMGLIB_FN (DGifOpen);
7104DEF_IMGLIB_FN (DGifOpenFileName); 7143DEF_IMGLIB_FN (DGifOpenFileName);
7105 7144
7106static int 7145static int
7107init_gif_functions (void) 7146init_gif_functions (Lisp_Object libraries)
7108{ 7147{
7109 HMODULE library; 7148 HMODULE library;
7110 7149
7111 if (!(library = LoadLibrary ("libungif.dll"))) 7150 if (!(library = w32_delayed_load (libraries, Qgif)))
7112 return 0; 7151 return 0;
7113 7152
7114 LOAD_IMGLIB_FN (library, DGifCloseFile); 7153 LOAD_IMGLIB_FN (library, DGifCloseFile);
@@ -7881,9 +7920,81 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "")
7881 Initialization 7920 Initialization
7882 ***********************************************************************/ 7921 ***********************************************************************/
7883 7922
7923#ifdef HAVE_NTGUI
7924/* Image types that rely on external libraries are loaded dynamically
7925 if the library is available. */
7926#define CHECK_LIB_AVAILABLE(image_type, init_lib_fn) \
7927 define_image_type (image_type, init_lib_fn (libraries))
7928#else
7929#define CHECK_LIB_AVAILABLE(image_type, init_lib_fn) \
7930 define_image_type (image_type, TRUE)
7931#endif /* HAVE_NTGUI */
7932
7933DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0,
7934 doc: /* Initialize image library implementing image type TYPE.
7935Return non-nil if TYPE is a supported image type.
7936
7937Image types pbm and xbm are prebuilt; other types are loaded here.
7938Libraries to load are specified in alist LIBRARIES (usually, the value
7939of `image-library-alist', which see. */)
7940 (type, libraries)
7941{
7942 Lisp_Object tested;
7943
7944 /* Don't try to reload the library. */
7945 tested = Fassq (type, Vimage_type_cache);
7946 if (CONSP (tested))
7947 return XCDR (tested);
7948
7949#if defined (HAVE_XPM) || defined (MAC_OS)
7950 if (EQ (type, Qxpm))
7951 return CHECK_LIB_AVAILABLE(&xpm_type, init_xpm_functions);
7952#endif
7953
7954#if defined (HAVE_JPEG) || defined (MAC_OS)
7955 if (EQ (type, Qjpeg))
7956 return CHECK_LIB_AVAILABLE(&jpeg_type, init_jpeg_functions);
7957#endif
7958
7959#if defined (HAVE_TIFF) || defined (MAC_OS)
7960 if (EQ (type, Qtiff))
7961 return CHECK_LIB_AVAILABLE(&tiff_type, init_tiff_functions);
7962#endif
7963
7964#if defined (HAVE_GIF) || defined (MAC_OS)
7965 if (EQ (type, Qgif))
7966 return CHECK_LIB_AVAILABLE(&gif_type, init_gif_functions);
7967#endif
7968
7969#if defined (HAVE_PNG) || defined (MAC_OS)
7970 if (EQ (type, Qpng))
7971 return CHECK_LIB_AVAILABLE(&png_type, init_png_functions);
7972#endif
7973
7974#ifdef HAVE_GHOSTSCRIPT
7975 if (EQ (type, Qpostscript))
7976 return CHECK_LIB_AVAILABLE(&gs_type, init_gs_functions);
7977#endif
7978
7979 /* If the type is not recognized, avoid testing it ever again. */
7980 CACHE_IMAGE_TYPE(type, Qnil);
7981 return Qnil;
7982}
7983
7884void 7984void
7885syms_of_image () 7985syms_of_image ()
7886{ 7986{
7987 /* Must be defined now becase we're going to update it below, while
7988 defining the supported image types. */
7989 DEFVAR_LISP ("image-types", &Vimage_types,
7990 doc: /* List of potentially supported image types.
7991Each element of the list is a symbol for a image type, like 'jpeg or 'png.
7992To check whether it is really supported, use `image-type-available-p'. */);
7993 Vimage_types = Qnil;
7994
7995 Vimage_type_cache = Qnil;
7996 staticpro (&Vimage_type_cache);
7997
7887 QCascent = intern (":ascent"); 7998 QCascent = intern (":ascent");
7888 staticpro (&QCascent); 7999 staticpro (&QCascent);
7889 QCmargin = intern (":margin"); 8000 QCmargin = intern (":margin");
@@ -7917,6 +8028,7 @@ syms_of_image ()
7917 Qpostscript = intern ("postscript"); 8028 Qpostscript = intern ("postscript");
7918 staticpro (&Qpostscript); 8029 staticpro (&Qpostscript);
7919#ifdef HAVE_GHOSTSCRIPT 8030#ifdef HAVE_GHOSTSCRIPT
8031 ADD_IMAGE_TYPE(Qpostscript);
7920 QCloader = intern (":loader"); 8032 QCloader = intern (":loader");
7921 staticpro (&QCloader); 8033 staticpro (&QCloader);
7922 QCbounding_box = intern (":bounding-box"); 8034 QCbounding_box = intern (":bounding-box");
@@ -7929,35 +8041,43 @@ syms_of_image ()
7929 8041
7930 Qpbm = intern ("pbm"); 8042 Qpbm = intern ("pbm");
7931 staticpro (&Qpbm); 8043 staticpro (&Qpbm);
8044 ADD_IMAGE_TYPE(Qpbm);
7932 8045
7933 Qxbm = intern ("xbm"); 8046 Qxbm = intern ("xbm");
7934 staticpro (&Qxbm); 8047 staticpro (&Qxbm);
8048 ADD_IMAGE_TYPE(Qxbm);
7935 8049
7936#if defined (HAVE_XPM) || defined (MAC_OS) 8050#if defined (HAVE_XPM) || defined (MAC_OS)
7937 Qxpm = intern ("xpm"); 8051 Qxpm = intern ("xpm");
7938 staticpro (&Qxpm); 8052 staticpro (&Qxpm);
8053 ADD_IMAGE_TYPE(Qxpm);
7939#endif 8054#endif
7940 8055
7941#if defined (HAVE_JPEG) || defined (MAC_OS) 8056#if defined (HAVE_JPEG) || defined (MAC_OS)
7942 Qjpeg = intern ("jpeg"); 8057 Qjpeg = intern ("jpeg");
7943 staticpro (&Qjpeg); 8058 staticpro (&Qjpeg);
8059 ADD_IMAGE_TYPE(Qjpeg);
7944#endif 8060#endif
7945 8061
7946#if defined (HAVE_TIFF) || defined (MAC_OS) 8062#if defined (HAVE_TIFF) || defined (MAC_OS)
7947 Qtiff = intern ("tiff"); 8063 Qtiff = intern ("tiff");
7948 staticpro (&Qtiff); 8064 staticpro (&Qtiff);
8065 ADD_IMAGE_TYPE(Qtiff);
7949#endif 8066#endif
7950 8067
7951#if defined (HAVE_GIF) || defined (MAC_OS) 8068#if defined (HAVE_GIF) || defined (MAC_OS)
7952 Qgif = intern ("gif"); 8069 Qgif = intern ("gif");
7953 staticpro (&Qgif); 8070 staticpro (&Qgif);
8071 ADD_IMAGE_TYPE(Qgif);
7954#endif 8072#endif
7955 8073
7956#if defined (HAVE_PNG) || defined (MAC_OS) 8074#if defined (HAVE_PNG) || defined (MAC_OS)
7957 Qpng = intern ("png"); 8075 Qpng = intern ("png");
7958 staticpro (&Qpng); 8076 staticpro (&Qpng);
8077 ADD_IMAGE_TYPE(Qpng);
7959#endif 8078#endif
7960 8079
8080 defsubr (&Sinit_image_library);
7961 defsubr (&Sclear_image_cache); 8081 defsubr (&Sclear_image_cache);
7962 defsubr (&Simage_size); 8082 defsubr (&Simage_size);
7963 defsubr (&Simage_mask_p); 8083 defsubr (&Simage_mask_p);
@@ -7985,52 +8105,13 @@ meaning don't clear the cache. */);
7985 Vimage_cache_eviction_delay = make_number (30 * 60); 8105 Vimage_cache_eviction_delay = make_number (30 * 60);
7986} 8106}
7987 8107
7988
7989#ifdef HAVE_NTGUI
7990/* Image types that rely on external libraries are loaded dynamically
7991 if the library is available. */
7992#define IF_LIB_AVAILABLE(init_lib_fn) if (init_lib_fn())
7993#else
7994#define IF_LIB_AVAILABLE(init_func) /* Load unconditionally */
7995#endif /* HAVE_NTGUI */
7996
7997void 8108void
7998init_image () 8109init_image ()
7999{ 8110{
8000 image_types = NULL; 8111 image_types = NULL;
8001 Vimage_types = Qnil;
8002 8112
8003 define_image_type (&xbm_type); 8113 define_image_type (&xbm_type, TRUE);
8004 define_image_type (&pbm_type); 8114 define_image_type (&pbm_type, TRUE);
8005
8006#if defined (HAVE_XPM) || defined (MAC_OS)
8007 IF_LIB_AVAILABLE(init_xpm_functions)
8008 define_image_type (&xpm_type);
8009#endif
8010
8011#if defined (HAVE_JPEG) || defined (MAC_OS)
8012 IF_LIB_AVAILABLE(init_jpeg_functions)
8013 define_image_type (&jpeg_type);
8014#endif
8015
8016#if defined (HAVE_TIFF) || defined (MAC_OS)
8017 IF_LIB_AVAILABLE(init_tiff_functions)
8018 define_image_type (&tiff_type);
8019#endif
8020
8021#if defined (HAVE_GIF) || defined (MAC_OS)
8022 IF_LIB_AVAILABLE(init_gif_functions)
8023 define_image_type (&gif_type);
8024#endif
8025
8026#if defined (HAVE_PNG) || defined (MAC_OS)
8027 IF_LIB_AVAILABLE(init_png_functions)
8028 define_image_type (&png_type);
8029#endif
8030
8031#ifdef HAVE_GHOSTSCRIPT
8032 define_image_type (&gs_type);
8033#endif
8034 8115
8035#ifdef MAC_OS 8116#ifdef MAC_OS
8036 /* Animated gifs use QuickTime Movie Toolbox. So initialize it here. */ 8117 /* Animated gifs use QuickTime Movie Toolbox. So initialize it here. */