aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorDaniel Colascione2012-10-07 14:31:58 -0800
committerDaniel Colascione2012-10-07 14:31:58 -0800
commit36a305a723c63fd345be65c536c52fe9765c14be (patch)
treefb89d9e103552863214c60297a65320917109357 /src/image.c
parent2ab329f3b5d52a39f0a45c3d9c129f1c19560142 (diff)
parent795b1482a9e314cda32d62ac2988f573d359366e (diff)
downloademacs-36a305a723c63fd345be65c536c52fe9765c14be.tar.gz
emacs-36a305a723c63fd345be65c536c52fe9765c14be.zip
Merge from trunk
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c656
1 files changed, 331 insertions, 325 deletions
diff --git a/src/image.c b/src/image.c
index a562868d94d..6fc459f0bbc 100644
--- a/src/image.c
+++ b/src/image.c
@@ -190,11 +190,11 @@ x_bitmap_width (FRAME_PTR f, ptrdiff_t id)
190} 190}
191 191
192#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) 192#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
193int 193ptrdiff_t
194x_bitmap_pixmap (FRAME_PTR f, ptrdiff_t id) 194x_bitmap_pixmap (FRAME_PTR f, ptrdiff_t id)
195{ 195{
196 /* HAVE_NTGUI needs the explicit cast here. */ 196 /* HAVE_NTGUI needs the explicit cast here. */
197 return (int) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap; 197 return (ptrdiff_t) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap;
198} 198}
199#endif 199#endif
200 200
@@ -411,9 +411,9 @@ x_destroy_bitmap (FRAME_PTR f, ptrdiff_t id)
411 411
412 if (--bm->refcount == 0) 412 if (--bm->refcount == 0)
413 { 413 {
414 BLOCK_INPUT; 414 block_input ();
415 free_bitmap_record (dpyinfo, bm); 415 free_bitmap_record (dpyinfo, bm);
416 UNBLOCK_INPUT; 416 unblock_input ();
417 } 417 }
418 } 418 }
419} 419}
@@ -433,6 +433,9 @@ x_destroy_all_bitmaps (Display_Info *dpyinfo)
433 dpyinfo->bitmaps_last = 0; 433 dpyinfo->bitmaps_last = 0;
434} 434}
435 435
436static bool x_create_x_image_and_pixmap (struct frame *, int, int, int,
437 XImagePtr *, Pixmap *);
438static void x_destroy_x_image (XImagePtr ximg);
436 439
437#ifdef HAVE_X_WINDOWS 440#ifdef HAVE_X_WINDOWS
438 441
@@ -444,23 +447,17 @@ static unsigned long four_corners_best (XImagePtr ximg,
444 unsigned long width, 447 unsigned long width,
445 unsigned long height); 448 unsigned long height);
446 449
447static int x_create_x_image_and_pixmap (struct frame *f, int width, int height,
448 int depth, XImagePtr *ximg,
449 Pixmap *pixmap);
450
451static void x_destroy_x_image (XImagePtr ximg);
452
453 450
454/* Create a mask of a bitmap. Note is this not a perfect mask. 451/* Create a mask of a bitmap. Note is this not a perfect mask.
455 It's nicer with some borders in this context */ 452 It's nicer with some borders in this context */
456 453
457int 454void
458x_create_bitmap_mask (struct frame *f, ptrdiff_t id) 455x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
459{ 456{
460 Pixmap pixmap, mask; 457 Pixmap pixmap, mask;
461 XImagePtr ximg, mask_img; 458 XImagePtr ximg, mask_img;
462 unsigned long width, height; 459 unsigned long width, height;
463 int result; 460 bool result;
464 unsigned long bg; 461 unsigned long bg;
465 unsigned long x, y, xp, xm, yp, ym; 462 unsigned long x, y, xp, xm, yp, ym;
466 GC gc; 463 GC gc;
@@ -468,29 +465,29 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
468 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 465 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
469 466
470 if (!(id > 0)) 467 if (!(id > 0))
471 return -1; 468 return;
472 469
473 pixmap = x_bitmap_pixmap (f, id); 470 pixmap = x_bitmap_pixmap (f, id);
474 width = x_bitmap_width (f, id); 471 width = x_bitmap_width (f, id);
475 height = x_bitmap_height (f, id); 472 height = x_bitmap_height (f, id);
476 473
477 BLOCK_INPUT; 474 block_input ();
478 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height, 475 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height,
479 ~0, ZPixmap); 476 ~0, ZPixmap);
480 477
481 if (!ximg) 478 if (!ximg)
482 { 479 {
483 UNBLOCK_INPUT; 480 unblock_input ();
484 return -1; 481 return;
485 } 482 }
486 483
487 result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask); 484 result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask);
488 485
489 UNBLOCK_INPUT; 486 unblock_input ();
490 if (!result) 487 if (!result)
491 { 488 {
492 XDestroyImage (ximg); 489 XDestroyImage (ximg);
493 return -1; 490 return;
494 } 491 }
495 492
496 bg = four_corners_best (ximg, NULL, width, height); 493 bg = four_corners_best (ximg, NULL, width, height);
@@ -518,7 +515,7 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
518 } 515 }
519 } 516 }
520 517
521 eassert (interrupt_input_blocked); 518 eassert (input_blocked_p ());
522 gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL); 519 gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL);
523 XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0, 520 XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0,
524 width, height); 521 width, height);
@@ -529,8 +526,6 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
529 526
530 XDestroyImage (ximg); 527 XDestroyImage (ximg);
531 x_destroy_x_image (mask_img); 528 x_destroy_x_image (mask_img);
532
533 return 0;
534} 529}
535 530
536#endif /* HAVE_X_WINDOWS */ 531#endif /* HAVE_X_WINDOWS */
@@ -563,15 +558,13 @@ static Lisp_Object QCcrop, QCrotation;
563static Lisp_Object Qcount, Qextension_data, Qdelay; 558static Lisp_Object Qcount, Qextension_data, Qdelay;
564static Lisp_Object Qlaplace, Qemboss, Qedge_detection, Qheuristic; 559static Lisp_Object Qlaplace, Qemboss, Qedge_detection, Qheuristic;
565 560
566/* Function prototypes. */ 561/* Forward function prototypes. */
567 562
568static Lisp_Object define_image_type (struct image_type *type, int loaded); 563static struct image_type *lookup_image_type (Lisp_Object);
569static struct image_type *lookup_image_type (Lisp_Object symbol);
570static void image_error (const char *format, Lisp_Object, Lisp_Object);
571static void x_laplace (struct frame *, struct image *); 564static void x_laplace (struct frame *, struct image *);
572static void x_emboss (struct frame *, struct image *); 565static void x_emboss (struct frame *, struct image *);
573static int x_build_heuristic_mask (struct frame *, struct image *, 566static void x_build_heuristic_mask (struct frame *, struct image *,
574 Lisp_Object); 567 Lisp_Object);
575#ifdef WINDOWSNT 568#ifdef WINDOWSNT
576extern Lisp_Object Vlibrary_cache; 569extern Lisp_Object Vlibrary_cache;
577#define CACHE_IMAGE_TYPE(type, status) \ 570#define CACHE_IMAGE_TYPE(type, status) \
@@ -586,60 +579,61 @@ extern Lisp_Object Vlibrary_cache;
586/* Define a new image type from TYPE. This adds a copy of TYPE to 579/* Define a new image type from TYPE. This adds a copy of TYPE to
587 image_types and caches the loading status of TYPE. */ 580 image_types and caches the loading status of TYPE. */
588 581
589static Lisp_Object 582static struct image_type *
590define_image_type (struct image_type *type, int loaded) 583define_image_type (struct image_type *type)
591{ 584{
592 Lisp_Object success; 585 struct image_type *p = NULL;
586 Lisp_Object target_type = *type->type;
587 bool type_valid = 1;
593 588
594 if (!loaded) 589 block_input ();
595 success = Qnil; 590
596 else 591 for (p = image_types; p; p = p->next)
592 if (EQ (*p->type, target_type))
593 goto done;
594
595 if (type->init)
596 {
597#if defined (HAVE_NTGUI) && defined (WINDOWSNT)
598 /* If we failed to load the library before, don't try again. */
599 Lisp_Object tested = Fassq (target_type, Vlibrary_cache);
600 if (CONSP (tested) && NILP (XCDR (tested)))
601 type_valid = 0;
602 else
603#endif
604 {
605 type_valid = type->init ();
606 CACHE_IMAGE_TYPE (target_type, type_valid ? Qt : Qnil);
607 }
608 }
609
610 if (type_valid)
597 { 611 {
598 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs. 612 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
599 The initialized data segment is read-only. */ 613 The initialized data segment is read-only. */
600 struct image_type *p = xmalloc (sizeof *p); 614 p = xmalloc (sizeof *p);
601 *p = *type; 615 *p = *type;
602 p->next = image_types; 616 p->next = image_types;
603 image_types = p; 617 image_types = p;
604 success = Qt;
605 } 618 }
606 619
607 CACHE_IMAGE_TYPE (*type->type, success); 620 done:
608 return success; 621 unblock_input ();
609} 622 return p;
610
611
612/* Look up image type SYMBOL, and return a pointer to its image_type
613 structure. Value is null if SYMBOL is not a known image type. */
614
615static inline struct image_type *
616lookup_image_type (Lisp_Object symbol)
617{
618 struct image_type *type;
619
620 /* We must initialize the image-type if it hasn't been already. */
621 if (NILP (Finit_image_library (symbol, Vdynamic_library_alist)))
622 return 0; /* unimplemented */
623
624 for (type = image_types; type; type = type->next)
625 if (EQ (symbol, *type->type))
626 break;
627
628 return type;
629} 623}
630 624
631 625
632/* Value is non-zero if OBJECT is a valid Lisp image specification. A 626/* Value is true if OBJECT is a valid Lisp image specification. A
633 valid image specification is a list whose car is the symbol 627 valid image specification is a list whose car is the symbol
634 `image', and whose rest is a property list. The property list must 628 `image', and whose rest is a property list. The property list must
635 contain a value for key `:type'. That value must be the name of a 629 contain a value for key `:type'. That value must be the name of a
636 supported image type. The rest of the property list depends on the 630 supported image type. The rest of the property list depends on the
637 image type. */ 631 image type. */
638 632
639int 633bool
640valid_image_p (Lisp_Object object) 634valid_image_p (Lisp_Object object)
641{ 635{
642 int valid_p = 0; 636 bool valid_p = 0;
643 637
644 if (IMAGEP (object)) 638 if (IMAGEP (object))
645 { 639 {
@@ -709,8 +703,8 @@ struct image_keyword
709 /* The type of value allowed. */ 703 /* The type of value allowed. */
710 enum image_value_type type; 704 enum image_value_type type;
711 705
712 /* Non-zero means key must be present. */ 706 /* True means key must be present. */
713 int mandatory_p; 707 bool mandatory_p;
714 708
715 /* Used to recognize duplicate keywords in a property list. */ 709 /* Used to recognize duplicate keywords in a property list. */
716 int count; 710 int count;
@@ -720,18 +714,13 @@ struct image_keyword
720}; 714};
721 715
722 716
723static int parse_image_spec (Lisp_Object, struct image_keyword *,
724 int, Lisp_Object);
725static Lisp_Object image_spec_value (Lisp_Object, Lisp_Object, int *);
726
727
728/* Parse image spec SPEC according to KEYWORDS. A valid image spec 717/* Parse image spec SPEC according to KEYWORDS. A valid image spec
729 has the format (image KEYWORD VALUE ...). One of the keyword/ 718 has the format (image KEYWORD VALUE ...). One of the keyword/
730 value pairs must be `:type TYPE'. KEYWORDS is a vector of 719 value pairs must be `:type TYPE'. KEYWORDS is a vector of
731 image_keywords structures of size NKEYWORDS describing other 720 image_keywords structures of size NKEYWORDS describing other
732 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */ 721 allowed keyword/value pairs. Value is true if SPEC is valid. */
733 722
734static int 723static bool
735parse_image_spec (Lisp_Object spec, struct image_keyword *keywords, 724parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
736 int nkeywords, Lisp_Object type) 725 int nkeywords, Lisp_Object type)
737{ 726{
@@ -863,11 +852,11 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
863 852
864 853
865/* Return the value of KEY in image specification SPEC. Value is nil 854/* Return the value of KEY in image specification SPEC. Value is nil
866 if KEY is not present in SPEC. if FOUND is not null, set *FOUND 855 if KEY is not present in SPEC. Set *FOUND depending on whether KEY
867 to 1 if KEY was found in SPEC, set it to 0 otherwise. */ 856 was found in SPEC. */
868 857
869static Lisp_Object 858static Lisp_Object
870image_spec_value (Lisp_Object spec, Lisp_Object key, int *found) 859image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found)
871{ 860{
872 Lisp_Object tail; 861 Lisp_Object tail;
873 862
@@ -971,8 +960,6 @@ or omitted means use the selected frame. */)
971 Image type independent image structures 960 Image type independent image structures
972 ***********************************************************************/ 961 ***********************************************************************/
973 962
974static void free_image (struct frame *f, struct image *img);
975
976#define MAX_IMAGE_SIZE 10.0 963#define MAX_IMAGE_SIZE 10.0
977/* Allocate and return a new image structure for image specification 964/* Allocate and return a new image structure for image specification
978 SPEC. SPEC has a hash value of HASH. */ 965 SPEC. SPEC has a hash value of HASH. */
@@ -1022,10 +1009,9 @@ free_image (struct frame *f, struct image *img)
1022 } 1009 }
1023} 1010}
1024 1011
1025/* Return 1 if the given widths and heights are valid for display; 1012/* Return true if the given widths and heights are valid for display. */
1026 otherwise, return 0. */
1027 1013
1028static int 1014static bool
1029check_image_size (struct frame *f, int width, int height) 1015check_image_size (struct frame *f, int width, int height)
1030{ 1016{
1031 int w, h; 1017 int w, h;
@@ -1064,7 +1050,7 @@ prepare_image_for_display (struct frame *f, struct image *img)
1064 /* If IMG doesn't have a pixmap yet, load it now, using the image 1050 /* If IMG doesn't have a pixmap yet, load it now, using the image
1065 type dependent loader function. */ 1051 type dependent loader function. */
1066 if (img->pixmap == NO_PIXMAP && !img->load_failed_p) 1052 if (img->pixmap == NO_PIXMAP && !img->load_failed_p)
1067 img->load_failed_p = img->type->load (f, img) == 0; 1053 img->load_failed_p = ! img->type->load (f, img);
1068 1054
1069} 1055}
1070 1056
@@ -1197,7 +1183,7 @@ image_background (struct image *img, struct frame *f, XImagePtr_or_DC ximg)
1197 if (! img->background_valid) 1183 if (! img->background_valid)
1198 /* IMG doesn't have a background yet, try to guess a reasonable value. */ 1184 /* IMG doesn't have a background yet, try to guess a reasonable value. */
1199 { 1185 {
1200 int free_ximg = !ximg; 1186 bool free_ximg = !ximg;
1201#ifdef HAVE_NTGUI 1187#ifdef HAVE_NTGUI
1202 HGDIOBJ prev; 1188 HGDIOBJ prev;
1203#endif /* HAVE_NTGUI */ 1189#endif /* HAVE_NTGUI */
@@ -1238,7 +1224,7 @@ image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_D
1238 { 1224 {
1239 if (img->mask) 1225 if (img->mask)
1240 { 1226 {
1241 int free_mask = !mask; 1227 bool free_mask = !mask;
1242#ifdef HAVE_NTGUI 1228#ifdef HAVE_NTGUI
1243 HGDIOBJ prev; 1229 HGDIOBJ prev;
1244#endif /* HAVE_NTGUI */ 1230#endif /* HAVE_NTGUI */
@@ -1276,23 +1262,13 @@ image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_D
1276 Helper functions for X image types 1262 Helper functions for X image types
1277 ***********************************************************************/ 1263 ***********************************************************************/
1278 1264
1279static void x_clear_image_1 (struct frame *, struct image *, int, 1265/* Clear X resources of image IMG on frame F. PIXMAP_P means free the
1280 int, int); 1266 pixmap if any. MASK_P means clear the mask pixmap if any.
1281static void x_clear_image (struct frame *f, struct image *img); 1267 COLORS_P means free colors allocated for the image, if any. */
1282static unsigned long x_alloc_image_color (struct frame *f,
1283 struct image *img,
1284 Lisp_Object color_name,
1285 unsigned long dflt);
1286
1287
1288/* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
1289 free the pixmap if any. MASK_P non-zero means clear the mask
1290 pixmap if any. COLORS_P non-zero means free colors allocated for
1291 the image, if any. */
1292 1268
1293static void 1269static void
1294x_clear_image_1 (struct frame *f, struct image *img, int pixmap_p, int mask_p, 1270x_clear_image_1 (struct frame *f, struct image *img, bool pixmap_p,
1295 int colors_p) 1271 bool mask_p, bool colors_p)
1296{ 1272{
1297 if (pixmap_p && img->pixmap) 1273 if (pixmap_p && img->pixmap)
1298 { 1274 {
@@ -1327,9 +1303,9 @@ x_clear_image_1 (struct frame *f, struct image *img, int pixmap_p, int mask_p,
1327static void 1303static void
1328x_clear_image (struct frame *f, struct image *img) 1304x_clear_image (struct frame *f, struct image *img)
1329{ 1305{
1330 BLOCK_INPUT; 1306 block_input ();
1331 x_clear_image_1 (f, img, 1, 1, 1); 1307 x_clear_image_1 (f, img, 1, 1, 1);
1332 UNBLOCK_INPUT; 1308 unblock_input ();
1333} 1309}
1334 1310
1335 1311
@@ -1372,7 +1348,6 @@ x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name,
1372 ***********************************************************************/ 1348 ***********************************************************************/
1373 1349
1374static void cache_image (struct frame *f, struct image *img); 1350static void cache_image (struct frame *f, struct image *img);
1375static void postprocess_image (struct frame *, struct image *);
1376 1351
1377/* Return a new, initialized image cache that is allocated from the 1352/* Return a new, initialized image cache that is allocated from the
1378 heap. Call free_image_cache to free an image cache. */ 1353 heap. Call free_image_cache to free an image cache. */
@@ -1484,7 +1459,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
1484 1459
1485 /* Block input so that we won't be interrupted by a SIGIO 1460 /* Block input so that we won't be interrupted by a SIGIO
1486 while being in an inconsistent state. */ 1461 while being in an inconsistent state. */
1487 BLOCK_INPUT; 1462 block_input ();
1488 1463
1489 if (!NILP (filter)) 1464 if (!NILP (filter))
1490 { 1465 {
@@ -1550,7 +1525,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
1550 ++windows_or_buffers_changed; 1525 ++windows_or_buffers_changed;
1551 } 1526 }
1552 1527
1553 UNBLOCK_INPUT; 1528 unblock_input ();
1554 } 1529 }
1555} 1530}
1556 1531
@@ -1645,7 +1620,7 @@ postprocess_image (struct frame *f, struct image *img)
1645 x_build_heuristic_mask (f, img, mask); 1620 x_build_heuristic_mask (f, img, mask);
1646 else 1621 else
1647 { 1622 {
1648 int found_p; 1623 bool found_p;
1649 1624
1650 mask = image_spec_value (spec, QCmask, &found_p); 1625 mask = image_spec_value (spec, QCmask, &found_p);
1651 1626
@@ -1715,10 +1690,10 @@ lookup_image (struct frame *f, Lisp_Object spec)
1715 /* If not found, create a new image and cache it. */ 1690 /* If not found, create a new image and cache it. */
1716 if (img == NULL) 1691 if (img == NULL)
1717 { 1692 {
1718 BLOCK_INPUT; 1693 block_input ();
1719 img = make_image (spec, hash); 1694 img = make_image (spec, hash);
1720 cache_image (f, img); 1695 cache_image (f, img);
1721 img->load_failed_p = img->type->load (f, img) == 0; 1696 img->load_failed_p = ! img->type->load (f, img);
1722 img->frame_foreground = FRAME_FOREGROUND_PIXEL (f); 1697 img->frame_foreground = FRAME_FOREGROUND_PIXEL (f);
1723 img->frame_background = FRAME_BACKGROUND_PIXEL (f); 1698 img->frame_background = FRAME_BACKGROUND_PIXEL (f);
1724 1699
@@ -1786,7 +1761,7 @@ lookup_image (struct frame *f, Lisp_Object spec)
1786 postprocess_image (f, img); 1761 postprocess_image (f, img);
1787 } 1762 }
1788 1763
1789 UNBLOCK_INPUT; 1764 unblock_input ();
1790 } 1765 }
1791 1766
1792 /* We're using IMG, so set its timestamp to `now'. */ 1767 /* We're using IMG, so set its timestamp to `now'. */
@@ -1877,16 +1852,11 @@ mark_image_cache (struct image_cache *c)
1877 1852
1878#endif /* WINDOWSNT */ 1853#endif /* WINDOWSNT */
1879 1854
1880static int x_create_x_image_and_pixmap (struct frame *, int, int, int, 1855/* Return true if XIMG's size WIDTH x HEIGHT doesn't break the
1881 XImagePtr *, Pixmap *);
1882static void x_destroy_x_image (XImagePtr);
1883static void x_put_x_image (struct frame *, XImagePtr, Pixmap, int, int);
1884
1885/* Return nonzero if XIMG's size WIDTH x HEIGHT doesn't break the
1886 windowing system. 1856 windowing system.
1887 WIDTH and HEIGHT must both be positive. 1857 WIDTH and HEIGHT must both be positive.
1888 If XIMG is null, assume it is a bitmap. */ 1858 If XIMG is null, assume it is a bitmap. */
1889static int 1859static bool
1890x_check_image_size (XImagePtr ximg, int width, int height) 1860x_check_image_size (XImagePtr ximg, int width, int height)
1891{ 1861{
1892#ifdef HAVE_X_WINDOWS 1862#ifdef HAVE_X_WINDOWS
@@ -1925,12 +1895,12 @@ x_check_image_size (XImagePtr ximg, int width, int height)
1925 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created. 1895 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
1926 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated 1896 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
1927 via xmalloc. Print error messages via image_error if an error 1897 via xmalloc. Print error messages via image_error if an error
1928 occurs. Value is non-zero if successful. 1898 occurs. Value is true if successful.
1929 1899
1930 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH 1900 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH
1931 should indicate the bit depth of the image. */ 1901 should indicate the bit depth of the image. */
1932 1902
1933static int 1903static bool
1934x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, 1904x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
1935 XImagePtr *ximg, Pixmap *pixmap) 1905 XImagePtr *ximg, Pixmap *pixmap)
1936{ 1906{
@@ -1939,7 +1909,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
1939 Window window = FRAME_X_WINDOW (f); 1909 Window window = FRAME_X_WINDOW (f);
1940 Screen *screen = FRAME_X_SCREEN (f); 1910 Screen *screen = FRAME_X_SCREEN (f);
1941 1911
1942 eassert (interrupt_input_blocked); 1912 eassert (input_blocked_p ());
1943 1913
1944 if (depth <= 0) 1914 if (depth <= 0)
1945 depth = DefaultDepthOfScreen (screen); 1915 depth = DefaultDepthOfScreen (screen);
@@ -2077,7 +2047,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
2077static void 2047static void
2078x_destroy_x_image (XImagePtr ximg) 2048x_destroy_x_image (XImagePtr ximg)
2079{ 2049{
2080 eassert (interrupt_input_blocked); 2050 eassert (input_blocked_p ());
2081 if (ximg) 2051 if (ximg)
2082 { 2052 {
2083#ifdef HAVE_X_WINDOWS 2053#ifdef HAVE_X_WINDOWS
@@ -2106,7 +2076,7 @@ x_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int he
2106#ifdef HAVE_X_WINDOWS 2076#ifdef HAVE_X_WINDOWS
2107 GC gc; 2077 GC gc;
2108 2078
2109 eassert (interrupt_input_blocked); 2079 eassert (input_blocked_p ());
2110 gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL); 2080 gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL);
2111 XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, width, height); 2081 XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, width, height);
2112 XFreeGC (FRAME_X_DISPLAY (f), gc); 2082 XFreeGC (FRAME_X_DISPLAY (f), gc);
@@ -2202,15 +2172,9 @@ slurp_file (char *file, ptrdiff_t *size)
2202 XBM images 2172 XBM images
2203 ***********************************************************************/ 2173 ***********************************************************************/
2204 2174
2205static int xbm_scan (unsigned char **, unsigned char *, char *, int *); 2175static bool xbm_load (struct frame *f, struct image *img);
2206static int xbm_load (struct frame *f, struct image *img); 2176static bool xbm_image_p (Lisp_Object object);
2207static int xbm_load_image (struct frame *f, struct image *img, 2177static bool xbm_file_p (Lisp_Object);
2208 unsigned char *, unsigned char *);
2209static int xbm_image_p (Lisp_Object object);
2210static int xbm_read_bitmap_data (struct frame *f,
2211 unsigned char *, unsigned char *,
2212 int *, int *, char **, int);
2213static int xbm_file_p (Lisp_Object);
2214 2178
2215 2179
2216/* Indices of image specification fields in xbm_format, below. */ 2180/* Indices of image specification fields in xbm_format, below. */
@@ -2261,6 +2225,7 @@ static struct image_type xbm_type =
2261 xbm_image_p, 2225 xbm_image_p,
2262 xbm_load, 2226 xbm_load,
2263 x_clear_image, 2227 x_clear_image,
2228 NULL,
2264 NULL 2229 NULL
2265}; 2230};
2266 2231
@@ -2273,10 +2238,10 @@ enum xbm_token
2273}; 2238};
2274 2239
2275 2240
2276/* Return non-zero if OBJECT is a valid XBM-type image specification. 2241/* Return true if OBJECT is a valid XBM-type image specification.
2277 A valid specification is a list starting with the symbol `image' 2242 A valid specification is a list starting with the symbol `image'
2278 The rest of the list is a property list which must contain an 2243 The rest of the list is a property list which must contain an
2279 entry `:type xbm.. 2244 entry `:type xbm'.
2280 2245
2281 If the specification specifies a file to load, it must contain 2246 If the specification specifies a file to load, it must contain
2282 an entry `:file FILENAME' where FILENAME is a string. 2247 an entry `:file FILENAME' where FILENAME is a string.
@@ -2302,7 +2267,7 @@ enum xbm_token
2302 foreground and background of the frame on which the image is 2267 foreground and background of the frame on which the image is
2303 displayed is used. */ 2268 displayed is used. */
2304 2269
2305static int 2270static bool
2306xbm_image_p (Lisp_Object object) 2271xbm_image_p (Lisp_Object object)
2307{ 2272{
2308 struct image_keyword kw[XBM_LAST]; 2273 struct image_keyword kw[XBM_LAST];
@@ -2560,7 +2525,7 @@ convert_mono_to_color_image (struct frame *f, struct image *img,
2560static void 2525static void
2561Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data, 2526Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
2562 RGB_PIXEL_COLOR fg, RGB_PIXEL_COLOR bg, 2527 RGB_PIXEL_COLOR fg, RGB_PIXEL_COLOR bg,
2563 int non_default_colors) 2528 bool non_default_colors)
2564{ 2529{
2565#ifdef HAVE_NTGUI 2530#ifdef HAVE_NTGUI
2566 img->pixmap 2531 img->pixmap
@@ -2592,20 +2557,20 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
2592 X versions. CONTENTS is a pointer to a buffer to parse; END is the 2557 X versions. CONTENTS is a pointer to a buffer to parse; END is the
2593 buffer's end. Set *WIDTH and *HEIGHT to the width and height of 2558 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
2594 the image. Return in *DATA the bitmap data allocated with xmalloc. 2559 the image. Return in *DATA the bitmap data allocated with xmalloc.
2595 Value is non-zero if successful. DATA null means just test if 2560 Value is true if successful. DATA null means just test if
2596 CONTENTS looks like an in-memory XBM file. If INHIBIT_IMAGE_ERROR 2561 CONTENTS looks like an in-memory XBM file. If INHIBIT_IMAGE_ERROR,
2597 is non-zero, inhibit the call to image_error when the image size is 2562 inhibit the call to image_error when the image size is invalid (the
2598 invalid (the bitmap remains unread). */ 2563 bitmap remains unread). */
2599 2564
2600static int 2565static bool
2601xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *end, 2566xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *end,
2602 int *width, int *height, char **data, 2567 int *width, int *height, char **data,
2603 int inhibit_image_error) 2568 bool inhibit_image_error)
2604{ 2569{
2605 unsigned char *s = contents; 2570 unsigned char *s = contents;
2606 char buffer[BUFSIZ]; 2571 char buffer[BUFSIZ];
2607 int padding_p = 0; 2572 bool padding_p = 0;
2608 int v10 = 0; 2573 bool v10 = 0;
2609 int bytes_per_line, i, nbytes; 2574 int bytes_per_line, i, nbytes;
2610 char *p; 2575 char *p;
2611 int value; 2576 int value;
@@ -2752,16 +2717,16 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e
2752 2717
2753 2718
2754/* Load XBM image IMG which will be displayed on frame F from buffer 2719/* Load XBM image IMG which will be displayed on frame F from buffer
2755 CONTENTS. END is the end of the buffer. Value is non-zero if 2720 CONTENTS. END is the end of the buffer. Value is true if
2756 successful. */ 2721 successful. */
2757 2722
2758static int 2723static bool
2759xbm_load_image (struct frame *f, struct image *img, unsigned char *contents, 2724xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2760 unsigned char *end) 2725 unsigned char *end)
2761{ 2726{
2762 int rc; 2727 bool rc;
2763 char *data; 2728 char *data;
2764 int success_p = 0; 2729 bool success_p = 0;
2765 2730
2766 rc = xbm_read_bitmap_data (f, contents, end, &img->width, &img->height, 2731 rc = xbm_read_bitmap_data (f, contents, end, &img->width, &img->height,
2767 &data, 0); 2732 &data, 0);
@@ -2769,7 +2734,7 @@ xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2769 { 2734 {
2770 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); 2735 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
2771 unsigned long background = FRAME_BACKGROUND_PIXEL (f); 2736 unsigned long background = FRAME_BACKGROUND_PIXEL (f);
2772 int non_default_colors = 0; 2737 bool non_default_colors = 0;
2773 Lisp_Object value; 2738 Lisp_Object value;
2774 2739
2775 eassert (img->width > 0 && img->height > 0); 2740 eassert (img->width > 0 && img->height > 0);
@@ -2810,9 +2775,9 @@ xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2810} 2775}
2811 2776
2812 2777
2813/* Value is non-zero if DATA looks like an in-memory XBM file. */ 2778/* Value is true if DATA looks like an in-memory XBM file. */
2814 2779
2815static int 2780static bool
2816xbm_file_p (Lisp_Object data) 2781xbm_file_p (Lisp_Object data)
2817{ 2782{
2818 int w, h; 2783 int w, h;
@@ -2824,12 +2789,12 @@ xbm_file_p (Lisp_Object data)
2824 2789
2825 2790
2826/* Fill image IMG which is used on frame F with pixmap data. Value is 2791/* Fill image IMG which is used on frame F with pixmap data. Value is
2827 non-zero if successful. */ 2792 true if successful. */
2828 2793
2829static int 2794static bool
2830xbm_load (struct frame *f, struct image *img) 2795xbm_load (struct frame *f, struct image *img)
2831{ 2796{
2832 int success_p = 0; 2797 bool success_p = 0;
2833 Lisp_Object file_name; 2798 Lisp_Object file_name;
2834 2799
2835 eassert (xbm_image_p (img->spec)); 2800 eassert (xbm_image_p (img->spec));
@@ -2865,10 +2830,10 @@ xbm_load (struct frame *f, struct image *img)
2865 Lisp_Object data; 2830 Lisp_Object data;
2866 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); 2831 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
2867 unsigned long background = FRAME_BACKGROUND_PIXEL (f); 2832 unsigned long background = FRAME_BACKGROUND_PIXEL (f);
2868 int non_default_colors = 0; 2833 bool non_default_colors = 0;
2869 char *bits; 2834 char *bits;
2870 int parsed_p; 2835 bool parsed_p;
2871 int in_memory_file_p = 0; 2836 bool in_memory_file_p = 0;
2872 2837
2873 /* See if data looks like an in-memory XBM file. */ 2838 /* See if data looks like an in-memory XBM file. */
2874 data = image_spec_value (img->spec, QCdata, NULL); 2839 data = image_spec_value (img->spec, QCdata, NULL);
@@ -2877,7 +2842,6 @@ xbm_load (struct frame *f, struct image *img)
2877 /* Parse the image specification. */ 2842 /* Parse the image specification. */
2878 memcpy (fmt, xbm_format, sizeof fmt); 2843 memcpy (fmt, xbm_format, sizeof fmt);
2879 parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm); 2844 parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm);
2880 (void) parsed_p;
2881 eassert (parsed_p); 2845 eassert (parsed_p);
2882 2846
2883 /* Get specified width, and height. */ 2847 /* Get specified width, and height. */
@@ -2982,9 +2946,8 @@ xbm_load (struct frame *f, struct image *img)
2982 2946
2983#if defined (HAVE_XPM) || defined (HAVE_NS) 2947#if defined (HAVE_XPM) || defined (HAVE_NS)
2984 2948
2985static int xpm_image_p (Lisp_Object object); 2949static bool xpm_image_p (Lisp_Object object);
2986static int xpm_load (struct frame *f, struct image *img); 2950static bool xpm_load (struct frame *f, struct image *img);
2987static int xpm_valid_color_symbols_p (Lisp_Object);
2988 2951
2989#endif /* HAVE_XPM || HAVE_NS */ 2952#endif /* HAVE_XPM || HAVE_NS */
2990 2953
@@ -3050,6 +3013,12 @@ static const struct image_keyword xpm_format[XPM_LAST] =
3050 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 3013 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
3051}; 3014};
3052 3015
3016#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
3017static bool init_xpm_functions (void);
3018#else
3019#define init_xpm_functions NULL
3020#endif
3021
3053/* Structure describing the image type XPM. */ 3022/* Structure describing the image type XPM. */
3054 3023
3055static struct image_type xpm_type = 3024static struct image_type xpm_type =
@@ -3058,6 +3027,7 @@ static struct image_type xpm_type =
3058 xpm_image_p, 3027 xpm_image_p,
3059 xpm_load, 3028 xpm_load,
3060 x_clear_image, 3029 x_clear_image,
3030 init_xpm_functions,
3061 NULL 3031 NULL
3062}; 3032};
3063 3033
@@ -3075,10 +3045,6 @@ static struct image_type xpm_type =
3075 3045
3076#ifdef ALLOC_XPM_COLORS 3046#ifdef ALLOC_XPM_COLORS
3077 3047
3078static void xpm_init_color_cache (struct frame *, XpmAttributes *);
3079static void xpm_free_color_cache (void);
3080static int xpm_lookup_color (struct frame *, char *, XColor *);
3081static int xpm_color_bucket (char *);
3082static struct xpm_cached_color *xpm_cache_color (struct frame *, char *, 3048static struct xpm_cached_color *xpm_cache_color (struct frame *, char *,
3083 XColor *, int); 3049 XColor *, int);
3084 3050
@@ -3185,10 +3151,10 @@ xpm_cache_color (struct frame *f, char *color_name, XColor *color, int bucket)
3185 3151
3186/* Look up color COLOR_NAME for frame F in the color cache. If found, 3152/* Look up color COLOR_NAME for frame F in the color cache. If found,
3187 return the cached definition in *COLOR. Otherwise, make a new 3153 return the cached definition in *COLOR. Otherwise, make a new
3188 entry in the cache and allocate the color. Value is zero if color 3154 entry in the cache and allocate the color. Value is false if color
3189 allocation failed. */ 3155 allocation failed. */
3190 3156
3191static int 3157static bool
3192xpm_lookup_color (struct frame *f, char *color_name, XColor *color) 3158xpm_lookup_color (struct frame *f, char *color_name, XColor *color)
3193{ 3159{
3194 struct xpm_cached_color *p; 3160 struct xpm_cached_color *p;
@@ -3257,12 +3223,12 @@ DEF_IMGLIB_FN (int, XpmReadFileToImage, (Display *, char *, xpm_XImage **,
3257 xpm_XImage **, XpmAttributes *)); 3223 xpm_XImage **, XpmAttributes *));
3258DEF_IMGLIB_FN (void, XImageFree, (xpm_XImage *)); 3224DEF_IMGLIB_FN (void, XImageFree, (xpm_XImage *));
3259 3225
3260static int 3226static bool
3261init_xpm_functions (Lisp_Object libraries) 3227init_xpm_functions (void)
3262{ 3228{
3263 HMODULE library; 3229 HMODULE library;
3264 3230
3265 if (!(library = w32_delayed_load (libraries, Qxpm))) 3231 if (!(library = w32_delayed_load (Qxpm)))
3266 return 0; 3232 return 0;
3267 3233
3268 LOAD_IMGLIB_FN (library, XpmFreeAttributes); 3234 LOAD_IMGLIB_FN (library, XpmFreeAttributes);
@@ -3282,11 +3248,11 @@ init_xpm_functions (Lisp_Object libraries)
3282#define fn_XpmFreeAttributes XpmFreeAttributes 3248#define fn_XpmFreeAttributes XpmFreeAttributes
3283#endif /* HAVE_NTGUI */ 3249#endif /* HAVE_NTGUI */
3284 3250
3285/* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list 3251/* Value is true if COLOR_SYMBOLS is a valid color symbols list
3286 for XPM images. Such a list must consist of conses whose car and 3252 for XPM images. Such a list must consist of conses whose car and
3287 cdr are strings. */ 3253 cdr are strings. */
3288 3254
3289static int 3255static bool
3290xpm_valid_color_symbols_p (Lisp_Object color_symbols) 3256xpm_valid_color_symbols_p (Lisp_Object color_symbols)
3291{ 3257{
3292 while (CONSP (color_symbols)) 3258 while (CONSP (color_symbols))
@@ -3303,9 +3269,9 @@ xpm_valid_color_symbols_p (Lisp_Object color_symbols)
3303} 3269}
3304 3270
3305 3271
3306/* Value is non-zero if OBJECT is a valid XPM image specification. */ 3272/* Value is true if OBJECT is a valid XPM image specification. */
3307 3273
3308static int 3274static bool
3309xpm_image_p (Lisp_Object object) 3275xpm_image_p (Lisp_Object object)
3310{ 3276{
3311 struct image_keyword fmt[XPM_LAST]; 3277 struct image_keyword fmt[XPM_LAST];
@@ -3362,11 +3328,11 @@ x_create_bitmap_from_xpm_data (struct frame *f, const char **bits)
3362#endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */ 3328#endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
3363 3329
3364/* Load image IMG which will be displayed on frame F. Value is 3330/* Load image IMG which will be displayed on frame F. Value is
3365 non-zero if successful. */ 3331 true if successful. */
3366 3332
3367#ifdef HAVE_XPM 3333#ifdef HAVE_XPM
3368 3334
3369static int 3335static bool
3370xpm_load (struct frame *f, struct image *img) 3336xpm_load (struct frame *f, struct image *img)
3371{ 3337{
3372 int rc; 3338 int rc;
@@ -3820,7 +3786,7 @@ xpm_str_to_color_key (const char *s)
3820 return -1; 3786 return -1;
3821} 3787}
3822 3788
3823static int 3789static bool
3824xpm_load_image (struct frame *f, 3790xpm_load_image (struct frame *f,
3825 struct image *img, 3791 struct image *img,
3826 const unsigned char *contents, 3792 const unsigned char *contents,
@@ -3835,7 +3801,8 @@ xpm_load_image (struct frame *f,
3835 void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object); 3801 void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object);
3836 Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int); 3802 Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int);
3837 Lisp_Object frame, color_symbols, color_table; 3803 Lisp_Object frame, color_symbols, color_table;
3838 int best_key, have_mask = 0; 3804 int best_key;
3805 bool have_mask = 0;
3839 XImagePtr ximg = NULL, mask_img = NULL; 3806 XImagePtr ximg = NULL, mask_img = NULL;
3840 3807
3841#define match() \ 3808#define match() \
@@ -4055,11 +4022,11 @@ xpm_load_image (struct frame *f,
4055#undef expect_ident 4022#undef expect_ident
4056} 4023}
4057 4024
4058static int 4025static bool
4059xpm_load (struct frame *f, 4026xpm_load (struct frame *f,
4060 struct image *img) 4027 struct image *img)
4061{ 4028{
4062 int success_p = 0; 4029 bool success_p = 0;
4063 Lisp_Object file_name; 4030 Lisp_Object file_name;
4064 4031
4065 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 4032 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -4230,7 +4197,7 @@ lookup_rgb_color (struct frame *f, int r, int g, int b)
4230#ifdef HAVE_X_WINDOWS 4197#ifdef HAVE_X_WINDOWS
4231 XColor color; 4198 XColor color;
4232 Colormap cmap; 4199 Colormap cmap;
4233 int rc; 4200 bool rc;
4234#else 4201#else
4235 COLORREF color; 4202 COLORREF color;
4236#endif 4203#endif
@@ -4298,7 +4265,7 @@ lookup_pixel_color (struct frame *f, unsigned long pixel)
4298 { 4265 {
4299 XColor color; 4266 XColor color;
4300 Colormap cmap; 4267 Colormap cmap;
4301 int rc; 4268 bool rc;
4302 4269
4303 if (ct_colors_allocated_max <= ct_colors_allocated) 4270 if (ct_colors_allocated_max <= ct_colors_allocated)
4304 return FRAME_FOREGROUND_PIXEL (f); 4271 return FRAME_FOREGROUND_PIXEL (f);
@@ -4309,12 +4276,12 @@ lookup_pixel_color (struct frame *f, unsigned long pixel)
4309 x_query_color (f, &color); 4276 x_query_color (f, &color);
4310 rc = x_alloc_nearest_color (f, cmap, &color); 4277 rc = x_alloc_nearest_color (f, cmap, &color);
4311#else 4278#else
4312 BLOCK_INPUT; 4279 block_input ();
4313 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); 4280 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
4314 color.pixel = pixel; 4281 color.pixel = pixel;
4315 XQueryColor (NULL, cmap, &color); 4282 XQueryColor (NULL, cmap, &color);
4316 rc = x_alloc_nearest_color (f, cmap, &color); 4283 rc = x_alloc_nearest_color (f, cmap, &color);
4317 UNBLOCK_INPUT; 4284 unblock_input ();
4318#endif /* HAVE_X_WINDOWS */ 4285#endif /* HAVE_X_WINDOWS */
4319 4286
4320 if (rc) 4287 if (rc)
@@ -4392,14 +4359,6 @@ init_color_table (void)
4392 Algorithms 4359 Algorithms
4393 ***********************************************************************/ 4360 ***********************************************************************/
4394 4361
4395static XColor *x_to_xcolors (struct frame *, struct image *, int);
4396static void x_from_xcolors (struct frame *, struct image *, XColor *);
4397static void x_detect_edges (struct frame *, struct image *, int[9], int);
4398
4399#ifdef HAVE_NTGUI
4400static void XPutPixel (XImagePtr , int, int, COLORREF);
4401#endif /* HAVE_NTGUI */
4402
4403/* Edge detection matrices for different edge-detection 4362/* Edge detection matrices for different edge-detection
4404 strategies. */ 4363 strategies. */
4405 4364
@@ -4425,12 +4384,12 @@ static int laplace_matrix[9] = {
4425 4384
4426/* On frame F, return an array of XColor structures describing image 4385/* On frame F, return an array of XColor structures describing image
4427 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P 4386 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
4428 non-zero means also fill the red/green/blue members of the XColor 4387 means also fill the red/green/blue members of the XColor
4429 structures. Value is a pointer to the array of XColors structures, 4388 structures. Value is a pointer to the array of XColors structures,
4430 allocated with xmalloc; it must be freed by the caller. */ 4389 allocated with xmalloc; it must be freed by the caller. */
4431 4390
4432static XColor * 4391static XColor *
4433x_to_xcolors (struct frame *f, struct image *img, int rgb_p) 4392x_to_xcolors (struct frame *f, struct image *img, bool rgb_p)
4434{ 4393{
4435 int x, y; 4394 int x, y;
4436 XColor *colors, *p; 4395 XColor *colors, *p;
@@ -4806,9 +4765,9 @@ x_disable_image (struct frame *f, struct image *img)
4806 determine the background color of IMG. If it is a list '(R G B)', 4765 determine the background color of IMG. If it is a list '(R G B)',
4807 with R, G, and B being integers >= 0, take that as the color of the 4766 with R, G, and B being integers >= 0, take that as the color of the
4808 background. Otherwise, determine the background color of IMG 4767 background. Otherwise, determine the background color of IMG
4809 heuristically. Value is non-zero if successful. */ 4768 heuristically. */
4810 4769
4811static int 4770static void
4812x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how) 4771x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4813{ 4772{
4814 XImagePtr_or_DC ximg; 4773 XImagePtr_or_DC ximg;
@@ -4820,7 +4779,8 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4820 char *mask_img; 4779 char *mask_img;
4821 int row_width; 4780 int row_width;
4822#endif /* HAVE_NTGUI */ 4781#endif /* HAVE_NTGUI */
4823 int x, y, rc, use_img_background; 4782 int x, y;
4783 bool rc, use_img_background;
4824 unsigned long bg = 0; 4784 unsigned long bg = 0;
4825 4785
4826 if (img->mask) 4786 if (img->mask)
@@ -4836,7 +4796,7 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4836 rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1, 4796 rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1,
4837 &mask_img, &img->mask); 4797 &mask_img, &img->mask);
4838 if (!rc) 4798 if (!rc)
4839 return 0; 4799 return;
4840#endif /* !HAVE_NS */ 4800#endif /* !HAVE_NS */
4841 4801
4842 /* Get the X image of IMG->pixmap. */ 4802 /* Get the X image of IMG->pixmap. */
@@ -4926,8 +4886,6 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4926#endif /* HAVE_NTGUI */ 4886#endif /* HAVE_NTGUI */
4927 4887
4928 Destroy_Image (ximg, prev); 4888 Destroy_Image (ximg, prev);
4929
4930 return 1;
4931} 4889}
4932 4890
4933 4891
@@ -4935,9 +4893,8 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4935 PBM (mono, gray, color) 4893 PBM (mono, gray, color)
4936 ***********************************************************************/ 4894 ***********************************************************************/
4937 4895
4938static int pbm_image_p (Lisp_Object object); 4896static bool pbm_image_p (Lisp_Object object);
4939static int pbm_load (struct frame *f, struct image *img); 4897static bool pbm_load (struct frame *f, struct image *img);
4940static int pbm_scan_number (unsigned char **, unsigned char *);
4941 4898
4942/* The symbol `pbm' identifying images of this type. */ 4899/* The symbol `pbm' identifying images of this type. */
4943 4900
@@ -4987,13 +4944,14 @@ static struct image_type pbm_type =
4987 pbm_image_p, 4944 pbm_image_p,
4988 pbm_load, 4945 pbm_load,
4989 x_clear_image, 4946 x_clear_image,
4947 NULL,
4990 NULL 4948 NULL
4991}; 4949};
4992 4950
4993 4951
4994/* Return non-zero if OBJECT is a valid PBM image specification. */ 4952/* Return true if OBJECT is a valid PBM image specification. */
4995 4953
4996static int 4954static bool
4997pbm_image_p (Lisp_Object object) 4955pbm_image_p (Lisp_Object object)
4998{ 4956{
4999 struct image_keyword fmt[PBM_LAST]; 4957 struct image_keyword fmt[PBM_LAST];
@@ -5086,10 +5044,11 @@ pbm_read_file (Lisp_Object file, int *size)
5086 5044
5087/* Load PBM image IMG for use on frame F. */ 5045/* Load PBM image IMG for use on frame F. */
5088 5046
5089static int 5047static bool
5090pbm_load (struct frame *f, struct image *img) 5048pbm_load (struct frame *f, struct image *img)
5091{ 5049{
5092 int raw_p, x, y; 5050 bool raw_p;
5051 int x, y;
5093 int width, height, max_color_idx = 0; 5052 int width, height, max_color_idx = 0;
5094 XImagePtr ximg; 5053 XImagePtr ximg;
5095 Lisp_Object file, specified_file; 5054 Lisp_Object file, specified_file;
@@ -5352,8 +5311,8 @@ pbm_load (struct frame *f, struct image *img)
5352 5311
5353/* Function prototypes. */ 5312/* Function prototypes. */
5354 5313
5355static int png_image_p (Lisp_Object object); 5314static bool png_image_p (Lisp_Object object);
5356static int png_load (struct frame *f, struct image *img); 5315static bool png_load (struct frame *f, struct image *img);
5357 5316
5358/* The symbol `png' identifying images of this type. */ 5317/* The symbol `png' identifying images of this type. */
5359 5318
@@ -5393,6 +5352,12 @@ static const struct image_keyword png_format[PNG_LAST] =
5393 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 5352 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
5394}; 5353};
5395 5354
5355#if defined(HAVE_NTGUI) && defined (WINDOWSNT)
5356static bool init_png_functions (void);
5357#else
5358#define init_png_functions NULL
5359#endif
5360
5396/* Structure describing the image type `png'. */ 5361/* Structure describing the image type `png'. */
5397 5362
5398static struct image_type png_type = 5363static struct image_type png_type =
@@ -5401,12 +5366,13 @@ static struct image_type png_type =
5401 png_image_p, 5366 png_image_p,
5402 png_load, 5367 png_load,
5403 x_clear_image, 5368 x_clear_image,
5369 init_png_functions,
5404 NULL 5370 NULL
5405}; 5371};
5406 5372
5407/* Return non-zero if OBJECT is a valid PNG image specification. */ 5373/* Return true if OBJECT is a valid PNG image specification. */
5408 5374
5409static int 5375static bool
5410png_image_p (Lisp_Object object) 5376png_image_p (Lisp_Object object)
5411{ 5377{
5412 struct image_keyword fmt[PNG_LAST]; 5378 struct image_keyword fmt[PNG_LAST];
@@ -5458,12 +5424,12 @@ DEF_IMGLIB_FN (void, png_longjmp, (png_structp, int));
5458DEF_IMGLIB_FN (jmp_buf *, png_set_longjmp_fn, (png_structp, png_longjmp_ptr, size_t)); 5424DEF_IMGLIB_FN (jmp_buf *, png_set_longjmp_fn, (png_structp, png_longjmp_ptr, size_t));
5459#endif /* libpng version >= 1.5 */ 5425#endif /* libpng version >= 1.5 */
5460 5426
5461static int 5427static bool
5462init_png_functions (Lisp_Object libraries) 5428init_png_functions (void)
5463{ 5429{
5464 HMODULE library; 5430 HMODULE library;
5465 5431
5466 if (!(library = w32_delayed_load (libraries, Qpng))) 5432 if (!(library = w32_delayed_load (Qpng)))
5467 return 0; 5433 return 0;
5468 5434
5469 LOAD_IMGLIB_FN (library, png_get_io_ptr); 5435 LOAD_IMGLIB_FN (library, png_get_io_ptr);
@@ -5609,7 +5575,7 @@ png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length)
5609} 5575}
5610 5576
5611 5577
5612/* Load PNG image IMG for use on frame F. Value is non-zero if 5578/* Load PNG image IMG for use on frame F. Value is true if
5613 successful. */ 5579 successful. */
5614 5580
5615struct png_load_context 5581struct png_load_context
@@ -5623,7 +5589,7 @@ struct png_load_context
5623 png_byte **rows; 5589 png_byte **rows;
5624}; 5590};
5625 5591
5626static int 5592static bool
5627png_load_body (struct frame *f, struct image *img, struct png_load_context *c) 5593png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5628{ 5594{
5629 Lisp_Object file, specified_file; 5595 Lisp_Object file, specified_file;
@@ -5641,7 +5607,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5641 int bit_depth, color_type, interlace_type; 5607 int bit_depth, color_type, interlace_type;
5642 png_byte channels; 5608 png_byte channels;
5643 png_uint_32 row_bytes; 5609 png_uint_32 row_bytes;
5644 int transparent_p; 5610 bool transparent_p;
5645 struct png_memory_storage tbr; /* Data to be read */ 5611 struct png_memory_storage tbr; /* Data to be read */
5646 5612
5647 /* Find out what file to load. */ 5613 /* Find out what file to load. */
@@ -5974,7 +5940,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5974 return 1; 5940 return 1;
5975} 5941}
5976 5942
5977static int 5943static bool
5978png_load (struct frame *f, struct image *img) 5944png_load (struct frame *f, struct image *img)
5979{ 5945{
5980 struct png_load_context c; 5946 struct png_load_context c;
@@ -5984,7 +5950,7 @@ png_load (struct frame *f, struct image *img)
5984#else /* HAVE_PNG */ 5950#else /* HAVE_PNG */
5985 5951
5986#ifdef HAVE_NS 5952#ifdef HAVE_NS
5987static int 5953static bool
5988png_load (struct frame *f, struct image *img) 5954png_load (struct frame *f, struct image *img)
5989{ 5955{
5990 return ns_load_image (f, img, 5956 return ns_load_image (f, img,
@@ -6004,8 +5970,8 @@ png_load (struct frame *f, struct image *img)
6004 5970
6005#if defined (HAVE_JPEG) || defined (HAVE_NS) 5971#if defined (HAVE_JPEG) || defined (HAVE_NS)
6006 5972
6007static int jpeg_image_p (Lisp_Object object); 5973static bool jpeg_image_p (Lisp_Object object);
6008static int jpeg_load (struct frame *f, struct image *img); 5974static bool jpeg_load (struct frame *f, struct image *img);
6009 5975
6010/* The symbol `jpeg' identifying images of this type. */ 5976/* The symbol `jpeg' identifying images of this type. */
6011 5977
@@ -6045,6 +6011,12 @@ static const struct image_keyword jpeg_format[JPEG_LAST] =
6045 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 6011 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
6046}; 6012};
6047 6013
6014#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
6015static bool init_jpeg_functions (void);
6016#else
6017#define init_jpeg_functions NULL
6018#endif
6019
6048/* Structure describing the image type `jpeg'. */ 6020/* Structure describing the image type `jpeg'. */
6049 6021
6050static struct image_type jpeg_type = 6022static struct image_type jpeg_type =
@@ -6053,12 +6025,13 @@ static struct image_type jpeg_type =
6053 jpeg_image_p, 6025 jpeg_image_p,
6054 jpeg_load, 6026 jpeg_load,
6055 x_clear_image, 6027 x_clear_image,
6028 init_jpeg_functions,
6056 NULL 6029 NULL
6057}; 6030};
6058 6031
6059/* Return non-zero if OBJECT is a valid JPEG image specification. */ 6032/* Return true if OBJECT is a valid JPEG image specification. */
6060 6033
6061static int 6034static bool
6062jpeg_image_p (Lisp_Object object) 6035jpeg_image_p (Lisp_Object object)
6063{ 6036{
6064 struct image_keyword fmt[JPEG_LAST]; 6037 struct image_keyword fmt[JPEG_LAST];
@@ -6113,12 +6086,12 @@ DEF_IMGLIB_FN (JDIMENSION, jpeg_read_scanlines, (j_decompress_ptr, JSAMPARRAY, J
6113DEF_IMGLIB_FN (struct jpeg_error_mgr *, jpeg_std_error, (struct jpeg_error_mgr *)); 6086DEF_IMGLIB_FN (struct jpeg_error_mgr *, jpeg_std_error, (struct jpeg_error_mgr *));
6114DEF_IMGLIB_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int)); 6087DEF_IMGLIB_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int));
6115 6088
6116static int 6089static bool
6117init_jpeg_functions (Lisp_Object libraries) 6090init_jpeg_functions (void)
6118{ 6091{
6119 HMODULE library; 6092 HMODULE library;
6120 6093
6121 if (!(library = w32_delayed_load (libraries, Qjpeg))) 6094 if (!(library = w32_delayed_load (Qjpeg)))
6122 return 0; 6095 return 0;
6123 6096
6124 LOAD_IMGLIB_FN (library, jpeg_finish_decompress); 6097 LOAD_IMGLIB_FN (library, jpeg_finish_decompress);
@@ -6383,7 +6356,7 @@ jpeg_file_src (j_decompress_ptr cinfo, FILE *fp)
6383/* Load image IMG for use on frame F. Patterned after example.c 6356/* Load image IMG for use on frame F. Patterned after example.c
6384 from the JPEG lib. */ 6357 from the JPEG lib. */
6385 6358
6386static int 6359static bool
6387jpeg_load_body (struct frame *f, struct image *img, 6360jpeg_load_body (struct frame *f, struct image *img,
6388 struct my_jpeg_error_mgr *mgr) 6361 struct my_jpeg_error_mgr *mgr)
6389{ 6362{
@@ -6564,7 +6537,7 @@ jpeg_load_body (struct frame *f, struct image *img,
6564 return 1; 6537 return 1;
6565} 6538}
6566 6539
6567static int 6540static bool
6568jpeg_load (struct frame *f, struct image *img) 6541jpeg_load (struct frame *f, struct image *img)
6569{ 6542{
6570 struct my_jpeg_error_mgr mgr; 6543 struct my_jpeg_error_mgr mgr;
@@ -6574,7 +6547,7 @@ jpeg_load (struct frame *f, struct image *img)
6574#else /* HAVE_JPEG */ 6547#else /* HAVE_JPEG */
6575 6548
6576#ifdef HAVE_NS 6549#ifdef HAVE_NS
6577static int 6550static bool
6578jpeg_load (struct frame *f, struct image *img) 6551jpeg_load (struct frame *f, struct image *img)
6579{ 6552{
6580 return ns_load_image (f, img, 6553 return ns_load_image (f, img,
@@ -6593,8 +6566,8 @@ jpeg_load (struct frame *f, struct image *img)
6593 6566
6594#if defined (HAVE_TIFF) || defined (HAVE_NS) 6567#if defined (HAVE_TIFF) || defined (HAVE_NS)
6595 6568
6596static int tiff_image_p (Lisp_Object object); 6569static bool tiff_image_p (Lisp_Object object);
6597static int tiff_load (struct frame *f, struct image *img); 6570static bool tiff_load (struct frame *f, struct image *img);
6598 6571
6599/* The symbol `tiff' identifying images of this type. */ 6572/* The symbol `tiff' identifying images of this type. */
6600 6573
@@ -6636,6 +6609,12 @@ static const struct image_keyword tiff_format[TIFF_LAST] =
6636 {":index", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0} 6609 {":index", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0}
6637}; 6610};
6638 6611
6612#ifdef HAVE_NTGUI
6613static bool init_tiff_functions (void);
6614#else
6615#define init_tiff_functions NULL
6616#endif
6617
6639/* Structure describing the image type `tiff'. */ 6618/* Structure describing the image type `tiff'. */
6640 6619
6641static struct image_type tiff_type = 6620static struct image_type tiff_type =
@@ -6644,12 +6623,13 @@ static struct image_type tiff_type =
6644 tiff_image_p, 6623 tiff_image_p,
6645 tiff_load, 6624 tiff_load,
6646 x_clear_image, 6625 x_clear_image,
6626 init_tiff_functions,
6647 NULL 6627 NULL
6648}; 6628};
6649 6629
6650/* Return non-zero if OBJECT is a valid TIFF image specification. */ 6630/* Return true if OBJECT is a valid TIFF image specification. */
6651 6631
6652static int 6632static bool
6653tiff_image_p (Lisp_Object object) 6633tiff_image_p (Lisp_Object object)
6654{ 6634{
6655 struct image_keyword fmt[TIFF_LAST]; 6635 struct image_keyword fmt[TIFF_LAST];
@@ -6683,12 +6663,12 @@ DEF_IMGLIB_FN (int, TIFFReadRGBAImage, (TIFF *, uint32, uint32, uint32 *, int));
6683DEF_IMGLIB_FN (void, TIFFClose, (TIFF *)); 6663DEF_IMGLIB_FN (void, TIFFClose, (TIFF *));
6684DEF_IMGLIB_FN (int, TIFFSetDirectory, (TIFF *, tdir_t)); 6664DEF_IMGLIB_FN (int, TIFFSetDirectory, (TIFF *, tdir_t));
6685 6665
6686static int 6666static bool
6687init_tiff_functions (Lisp_Object libraries) 6667init_tiff_functions (void)
6688{ 6668{
6689 HMODULE library; 6669 HMODULE library;
6690 6670
6691 if (!(library = w32_delayed_load (libraries, Qtiff))) 6671 if (!(library = w32_delayed_load (Qtiff)))
6692 return 0; 6672 return 0;
6693 6673
6694 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler); 6674 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler);
@@ -6853,10 +6833,10 @@ tiff_warning_handler (const char *title, const char *format, va_list ap)
6853} 6833}
6854 6834
6855 6835
6856/* Load TIFF image IMG for use on frame F. Value is non-zero if 6836/* Load TIFF image IMG for use on frame F. Value is true if
6857 successful. */ 6837 successful. */
6858 6838
6859static int 6839static bool
6860tiff_load (struct frame *f, struct image *img) 6840tiff_load (struct frame *f, struct image *img)
6861{ 6841{
6862 Lisp_Object file, specified_file; 6842 Lisp_Object file, specified_file;
@@ -7021,7 +7001,7 @@ tiff_load (struct frame *f, struct image *img)
7021#else /* HAVE_TIFF */ 7001#else /* HAVE_TIFF */
7022 7002
7023#ifdef HAVE_NS 7003#ifdef HAVE_NS
7024static int 7004static bool
7025tiff_load (struct frame *f, struct image *img) 7005tiff_load (struct frame *f, struct image *img)
7026{ 7006{
7027 return ns_load_image (f, img, 7007 return ns_load_image (f, img,
@@ -7040,8 +7020,8 @@ tiff_load (struct frame *f, struct image *img)
7040 7020
7041#if defined (HAVE_GIF) || defined (HAVE_NS) 7021#if defined (HAVE_GIF) || defined (HAVE_NS)
7042 7022
7043static int gif_image_p (Lisp_Object object); 7023static bool gif_image_p (Lisp_Object object);
7044static int gif_load (struct frame *f, struct image *img); 7024static bool gif_load (struct frame *f, struct image *img);
7045static void gif_clear_image (struct frame *f, struct image *img); 7025static void gif_clear_image (struct frame *f, struct image *img);
7046 7026
7047/* The symbol `gif' identifying images of this type. */ 7027/* The symbol `gif' identifying images of this type. */
@@ -7084,6 +7064,12 @@ static const struct image_keyword gif_format[GIF_LAST] =
7084 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 7064 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
7085}; 7065};
7086 7066
7067#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
7068static bool init_gif_functions (void);
7069#else
7070#define init_gif_functions NULL
7071#endif
7072
7087/* Structure describing the image type `gif'. */ 7073/* Structure describing the image type `gif'. */
7088 7074
7089static struct image_type gif_type = 7075static struct image_type gif_type =
@@ -7092,6 +7078,7 @@ static struct image_type gif_type =
7092 gif_image_p, 7078 gif_image_p,
7093 gif_load, 7079 gif_load,
7094 gif_clear_image, 7080 gif_clear_image,
7081 init_gif_functions,
7095 NULL 7082 NULL
7096}; 7083};
7097 7084
@@ -7104,9 +7091,9 @@ gif_clear_image (struct frame *f, struct image *img)
7104 x_clear_image (f, img); 7091 x_clear_image (f, img);
7105} 7092}
7106 7093
7107/* Return non-zero if OBJECT is a valid GIF image specification. */ 7094/* Return true if OBJECT is a valid GIF image specification. */
7108 7095
7109static int 7096static bool
7110gif_image_p (Lisp_Object object) 7097gif_image_p (Lisp_Object object)
7111{ 7098{
7112 struct image_keyword fmt[GIF_LAST]; 7099 struct image_keyword fmt[GIF_LAST];
@@ -7149,12 +7136,12 @@ DEF_IMGLIB_FN (int, DGifSlurp, (GifFileType *));
7149DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc)); 7136DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc));
7150DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *)); 7137DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *));
7151 7138
7152static int 7139static bool
7153init_gif_functions (Lisp_Object libraries) 7140init_gif_functions (void)
7154{ 7141{
7155 HMODULE library; 7142 HMODULE library;
7156 7143
7157 if (!(library = w32_delayed_load (libraries, Qgif))) 7144 if (!(library = w32_delayed_load (Qgif)))
7158 return 0; 7145 return 0;
7159 7146
7160 LOAD_IMGLIB_FN (library, DGifCloseFile); 7147 LOAD_IMGLIB_FN (library, DGifCloseFile);
@@ -7203,7 +7190,7 @@ gif_read_from_memory (GifFileType *file, GifByteType *buf, int len)
7203} 7190}
7204 7191
7205 7192
7206/* Load GIF image IMG for use on frame F. Value is non-zero if 7193/* Load GIF image IMG for use on frame F. Value is true if
7207 successful. */ 7194 successful. */
7208 7195
7209static const int interlace_start[] = {0, 4, 2, 1}; 7196static const int interlace_start[] = {0, 4, 2, 1};
@@ -7211,7 +7198,7 @@ static const int interlace_increment[] = {8, 8, 4, 2};
7211 7198
7212#define GIF_LOCAL_DESCRIPTOR_EXTENSION 249 7199#define GIF_LOCAL_DESCRIPTOR_EXTENSION 249
7213 7200
7214static int 7201static bool
7215gif_load (struct frame *f, struct image *img) 7202gif_load (struct frame *f, struct image *img)
7216{ 7203{
7217 Lisp_Object file; 7204 Lisp_Object file;
@@ -7509,7 +7496,7 @@ gif_load (struct frame *f, struct image *img)
7509#else /* !HAVE_GIF */ 7496#else /* !HAVE_GIF */
7510 7497
7511#ifdef HAVE_NS 7498#ifdef HAVE_NS
7512static int 7499static bool
7513gif_load (struct frame *f, struct image *img) 7500gif_load (struct frame *f, struct image *img)
7514{ 7501{
7515 return ns_load_image (f, img, 7502 return ns_load_image (f, img,
@@ -7528,8 +7515,8 @@ gif_load (struct frame *f, struct image *img)
7528 7515
7529static Lisp_Object Qimagemagick; 7516static Lisp_Object Qimagemagick;
7530 7517
7531static int imagemagick_image_p (Lisp_Object); 7518static bool imagemagick_image_p (Lisp_Object);
7532static int imagemagick_load (struct frame *, struct image *); 7519static bool imagemagick_load (struct frame *, struct image *);
7533static void imagemagick_clear_image (struct frame *, struct image *); 7520static void imagemagick_clear_image (struct frame *, struct image *);
7534 7521
7535/* Indices of image specification fields in imagemagick_format. */ 7522/* Indices of image specification fields in imagemagick_format. */
@@ -7574,6 +7561,12 @@ static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] =
7574 {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0} 7561 {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0}
7575 }; 7562 };
7576 7563
7564#ifdef HAVE_NTGUI
7565static bool init_imagemagick_functions (void);
7566#else
7567#define init_imagemagick_functions NULL
7568#endif
7569
7577/* Structure describing the image type for any image handled via 7570/* Structure describing the image type for any image handled via
7578 ImageMagick. */ 7571 ImageMagick. */
7579 7572
@@ -7583,6 +7576,7 @@ static struct image_type imagemagick_type =
7583 imagemagick_image_p, 7576 imagemagick_image_p,
7584 imagemagick_load, 7577 imagemagick_load,
7585 imagemagick_clear_image, 7578 imagemagick_clear_image,
7579 init_imagemagick_functions,
7586 NULL 7580 NULL
7587 }; 7581 };
7588 7582
@@ -7595,11 +7589,11 @@ imagemagick_clear_image (struct frame *f,
7595 x_clear_image (f, img); 7589 x_clear_image (f, img);
7596} 7590}
7597 7591
7598/* Return non-zero if OBJECT is a valid IMAGEMAGICK image specification. Do 7592/* Return true if OBJECT is a valid IMAGEMAGICK image specification. Do
7599 this by calling parse_image_spec and supplying the keywords that 7593 this by calling parse_image_spec and supplying the keywords that
7600 identify the IMAGEMAGICK format. */ 7594 identify the IMAGEMAGICK format. */
7601 7595
7602static int 7596static bool
7603imagemagick_image_p (Lisp_Object object) 7597imagemagick_image_p (Lisp_Object object)
7604{ 7598{
7605 struct image_keyword fmt[IMAGEMAGICK_LAST]; 7599 struct image_keyword fmt[IMAGEMAGICK_LAST];
@@ -7651,9 +7645,9 @@ imagemagick_error (MagickWand *wand)
7651 be parsed; SIZE is the number of bytes of data; and FILENAME is 7645 be parsed; SIZE is the number of bytes of data; and FILENAME is
7652 either the file name or the image data. 7646 either the file name or the image data.
7653 7647
7654 Return non-zero if successful. */ 7648 Return true if successful. */
7655 7649
7656static int 7650static bool
7657imagemagick_load_image (struct frame *f, struct image *img, 7651imagemagick_load_image (struct frame *f, struct image *img,
7658 unsigned char *contents, unsigned int size, 7652 unsigned char *contents, unsigned int size,
7659 char *filename) 7653 char *filename)
@@ -7991,14 +7985,14 @@ imagemagick_load_image (struct frame *f, struct image *img,
7991} 7985}
7992 7986
7993 7987
7994/* Load IMAGEMAGICK image IMG for use on frame F. Value is non-zero if 7988/* Load IMAGEMAGICK image IMG for use on frame F. Value is true if
7995 successful. this function will go into the imagemagick_type structure, and 7989 successful. this function will go into the imagemagick_type structure, and
7996 the prototype thus needs to be compatible with that structure. */ 7990 the prototype thus needs to be compatible with that structure. */
7997 7991
7998static int 7992static bool
7999imagemagick_load (struct frame *f, struct image *img) 7993imagemagick_load (struct frame *f, struct image *img)
8000{ 7994{
8001 int success_p = 0; 7995 bool success_p = 0;
8002 Lisp_Object file_name; 7996 Lisp_Object file_name;
8003 7997
8004 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 7998 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -8077,11 +8071,11 @@ and `imagemagick-types-inhibit'. */)
8077 8071
8078/* Function prototypes. */ 8072/* Function prototypes. */
8079 8073
8080static int svg_image_p (Lisp_Object object); 8074static bool svg_image_p (Lisp_Object object);
8081static int svg_load (struct frame *f, struct image *img); 8075static bool svg_load (struct frame *f, struct image *img);
8082 8076
8083static int svg_load_image (struct frame *, struct image *, 8077static bool svg_load_image (struct frame *, struct image *,
8084 unsigned char *, ptrdiff_t); 8078 unsigned char *, ptrdiff_t);
8085 8079
8086/* The symbol `svg' identifying images of this type. */ 8080/* The symbol `svg' identifying images of this type. */
8087 8081
@@ -8121,31 +8115,32 @@ static const struct image_keyword svg_format[SVG_LAST] =
8121 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 8115 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
8122}; 8116};
8123 8117
8118#ifdef HAVE_NTGUI
8119static bool init_svg_functions (void);
8120#else
8121#define init_svg_functions NULL
8122#endif
8123
8124/* Structure describing the image type `svg'. Its the same type of 8124/* Structure describing the image type `svg'. Its the same type of
8125 structure defined for all image formats, handled by emacs image 8125 structure defined for all image formats, handled by emacs image
8126 functions. See struct image_type in dispextern.h. */ 8126 functions. See struct image_type in dispextern.h. */
8127 8127
8128static struct image_type svg_type = 8128static struct image_type svg_type =
8129{ 8129{
8130 /* An identifier showing that this is an image structure for the SVG format. */
8131 &Qsvg, 8130 &Qsvg,
8132 /* Handle to a function that can be used to identify a SVG file. */
8133 svg_image_p, 8131 svg_image_p,
8134 /* Handle to function used to load a SVG file. */
8135 svg_load, 8132 svg_load,
8136 /* Handle to function to free sresources for SVG. */
8137 x_clear_image, 8133 x_clear_image,
8138 /* An internal field to link to the next image type in a list of 8134 init_svg_functions,
8139 image types, will be filled in when registering the format. */
8140 NULL 8135 NULL
8141}; 8136};
8142 8137
8143 8138
8144/* Return non-zero if OBJECT is a valid SVG image specification. Do 8139/* Return true if OBJECT is a valid SVG image specification. Do
8145 this by calling parse_image_spec and supplying the keywords that 8140 this by calling parse_image_spec and supplying the keywords that
8146 identify the SVG format. */ 8141 identify the SVG format. */
8147 8142
8148static int 8143static bool
8149svg_image_p (Lisp_Object object) 8144svg_image_p (Lisp_Object object)
8150{ 8145{
8151 struct image_keyword fmt[SVG_LAST]; 8146 struct image_keyword fmt[SVG_LAST];
@@ -8184,15 +8179,15 @@ DEF_IMGLIB_FN (void, g_error_free);
8184 8179
8185Lisp_Object Qgdk_pixbuf, Qglib, Qgobject; 8180Lisp_Object Qgdk_pixbuf, Qglib, Qgobject;
8186 8181
8187static int 8182static bool
8188init_svg_functions (Lisp_Object libraries) 8183init_svg_functions (void)
8189{ 8184{
8190 HMODULE library, gdklib, glib, gobject; 8185 HMODULE library, gdklib, glib, gobject;
8191 8186
8192 if (!(glib = w32_delayed_load (libraries, Qglib)) 8187 if (!(glib = w32_delayed_load (Qglib))
8193 || !(gobject = w32_delayed_load (libraries, Qgobject)) 8188 || !(gobject = w32_delayed_load (Qgobject))
8194 || !(gdklib = w32_delayed_load (libraries, Qgdk_pixbuf)) 8189 || !(gdklib = w32_delayed_load (Qgdk_pixbuf))
8195 || !(library = w32_delayed_load (libraries, Qsvg))) 8190 || !(library = w32_delayed_load (Qsvg)))
8196 return 0; 8191 return 0;
8197 8192
8198 LOAD_IMGLIB_FN (library, rsvg_handle_new); 8193 LOAD_IMGLIB_FN (library, rsvg_handle_new);
@@ -8240,14 +8235,13 @@ init_svg_functions (Lisp_Object libraries)
8240#define fn_g_error_free g_error_free 8235#define fn_g_error_free g_error_free
8241#endif /* !WINDOWSNT */ 8236#endif /* !WINDOWSNT */
8242 8237
8243/* Load SVG image IMG for use on frame F. Value is non-zero if 8238/* Load SVG image IMG for use on frame F. Value is true if
8244 successful. this function will go into the svg_type structure, and 8239 successful. */
8245 the prototype thus needs to be compatible with that structure. */
8246 8240
8247static int 8241static bool
8248svg_load (struct frame *f, struct image *img) 8242svg_load (struct frame *f, struct image *img)
8249{ 8243{
8250 int success_p = 0; 8244 bool success_p = 0;
8251 Lisp_Object file_name; 8245 Lisp_Object file_name;
8252 8246
8253 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 8247 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -8300,8 +8294,8 @@ svg_load (struct frame *f, struct image *img)
8300 8294
8301 Uses librsvg to do most of the image processing. 8295 Uses librsvg to do most of the image processing.
8302 8296
8303 Returns non-zero when successful. */ 8297 Returns true when successful. */
8304static int 8298static bool
8305svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */ 8299svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */
8306 struct image *img, /* Pointer to emacs image structure. */ 8300 struct image *img, /* Pointer to emacs image structure. */
8307 unsigned char *contents, /* String containing the SVG XML data to be parsed. */ 8301 unsigned char *contents, /* String containing the SVG XML data to be parsed. */
@@ -8468,8 +8462,8 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
8468 8462
8469#ifdef HAVE_GHOSTSCRIPT 8463#ifdef HAVE_GHOSTSCRIPT
8470 8464
8471static int gs_image_p (Lisp_Object object); 8465static bool gs_image_p (Lisp_Object object);
8472static int gs_load (struct frame *f, struct image *img); 8466static bool gs_load (struct frame *f, struct image *img);
8473static void gs_clear_image (struct frame *f, struct image *img); 8467static void gs_clear_image (struct frame *f, struct image *img);
8474 8468
8475/* Keyword symbols. */ 8469/* Keyword symbols. */
@@ -8524,6 +8518,7 @@ static struct image_type gs_type =
8524 gs_image_p, 8518 gs_image_p,
8525 gs_load, 8519 gs_load,
8526 gs_clear_image, 8520 gs_clear_image,
8521 NULL,
8527 NULL 8522 NULL
8528}; 8523};
8529 8524
@@ -8537,10 +8532,10 @@ gs_clear_image (struct frame *f, struct image *img)
8537} 8532}
8538 8533
8539 8534
8540/* Return non-zero if OBJECT is a valid Ghostscript image 8535/* Return true if OBJECT is a valid Ghostscript image
8541 specification. */ 8536 specification. */
8542 8537
8543static int 8538static bool
8544gs_image_p (Lisp_Object object) 8539gs_image_p (Lisp_Object object)
8545{ 8540{
8546 struct image_keyword fmt[GS_LAST]; 8541 struct image_keyword fmt[GS_LAST];
@@ -8577,10 +8572,10 @@ gs_image_p (Lisp_Object object)
8577} 8572}
8578 8573
8579 8574
8580/* Load Ghostscript image IMG for use on frame F. Value is non-zero 8575/* Load Ghostscript image IMG for use on frame F. Value is true
8581 if successful. */ 8576 if successful. */
8582 8577
8583static int 8578static bool
8584gs_load (struct frame *f, struct image *img) 8579gs_load (struct frame *f, struct image *img)
8585{ 8580{
8586 uprintmax_t printnum1, printnum2; 8581 uprintmax_t printnum1, printnum2;
@@ -8616,11 +8611,11 @@ gs_load (struct frame *f, struct image *img)
8616 if (x_check_image_size (0, img->width, img->height)) 8611 if (x_check_image_size (0, img->width, img->height))
8617 { 8612 {
8618 /* Only W32 version did BLOCK_INPUT here. ++kfs */ 8613 /* Only W32 version did BLOCK_INPUT here. ++kfs */
8619 BLOCK_INPUT; 8614 block_input ();
8620 img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 8615 img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
8621 img->width, img->height, 8616 img->width, img->height,
8622 DefaultDepthOfScreen (FRAME_X_SCREEN (f))); 8617 DefaultDepthOfScreen (FRAME_X_SCREEN (f)));
8623 UNBLOCK_INPUT; 8618 unblock_input ();
8624 } 8619 }
8625 8620
8626 if (!img->pixmap) 8621 if (!img->pixmap)
@@ -8696,7 +8691,7 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f)
8696 { 8691 {
8697 XImagePtr ximg; 8692 XImagePtr ximg;
8698 8693
8699 BLOCK_INPUT; 8694 block_input ();
8700 8695
8701 /* Try to get an XImage for img->pixmep. */ 8696 /* Try to get an XImage for img->pixmep. */
8702 ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, 8697 ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap,
@@ -8739,15 +8734,15 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f)
8739 image_error ("Cannot get X image of `%s'; colors will not be freed", 8734 image_error ("Cannot get X image of `%s'; colors will not be freed",
8740 img->spec, Qnil); 8735 img->spec, Qnil);
8741 8736
8742 UNBLOCK_INPUT; 8737 unblock_input ();
8743 } 8738 }
8744#endif /* HAVE_X_WINDOWS */ 8739#endif /* HAVE_X_WINDOWS */
8745 8740
8746 /* Now that we have the pixmap, compute mask and transform the 8741 /* Now that we have the pixmap, compute mask and transform the
8747 image if requested. */ 8742 image if requested. */
8748 BLOCK_INPUT; 8743 block_input ();
8749 postprocess_image (f, img); 8744 postprocess_image (f, img);
8750 UNBLOCK_INPUT; 8745 unblock_input ();
8751} 8746}
8752 8747
8753#endif /* HAVE_GHOSTSCRIPT */ 8748#endif /* HAVE_GHOSTSCRIPT */
@@ -8796,78 +8791,92 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "")
8796 define_image_type (image_type, 1) 8791 define_image_type (image_type, 1)
8797#endif /* WINDOWSNT */ 8792#endif /* WINDOWSNT */
8798 8793
8799DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0, 8794DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 1, 1, 0,
8800 doc: /* Initialize image library implementing image type TYPE. 8795 doc: /* Initialize image library implementing image type TYPE.
8801Return non-nil if TYPE is a supported image type. 8796Return non-nil if TYPE is a supported image type.
8802 8797
8803Image types pbm and xbm are prebuilt; other types are loaded here. 8798If image libraries are loaded dynamically (currently only the case on
8804Libraries to load are specified in alist LIBRARIES (usually, the value 8799MS-Windows), load the library for TYPE if it is not yet loaded, using
8805of `dynamic-library-alist', which see). */) 8800the library file(s) specified by `dynamic-library-alist'. */)
8806 (Lisp_Object type, Lisp_Object libraries) 8801 (Lisp_Object type)
8807{ 8802{
8808#ifdef WINDOWSNT 8803 return lookup_image_type (type) ? Qt : Qnil;
8809 /* Don't try to reload the library. */ 8804}
8810 Lisp_Object tested = Fassq (type, Vlibrary_cache);
8811 if (CONSP (tested))
8812 return XCDR (tested);
8813#endif
8814 8805
8806/* Look up image type TYPE, and return a pointer to its image_type
8807 structure. Return 0 if TYPE is not a known image type. */
8808
8809static struct image_type *
8810lookup_image_type (Lisp_Object type)
8811{
8815 /* Types pbm and xbm are built-in and always available. */ 8812 /* Types pbm and xbm are built-in and always available. */
8816 if (EQ (type, Qpbm) || EQ (type, Qxbm)) 8813 if (EQ (type, Qpbm))
8817 return Qt; 8814 return define_image_type (&pbm_type);
8815
8816 if (EQ (type, Qxbm))
8817 return define_image_type (&xbm_type);
8818 8818
8819#if defined (HAVE_XPM) || defined (HAVE_NS) 8819#if defined (HAVE_XPM) || defined (HAVE_NS)
8820 if (EQ (type, Qxpm)) 8820 if (EQ (type, Qxpm))
8821 return CHECK_LIB_AVAILABLE (&xpm_type, init_xpm_functions, libraries); 8821 return define_image_type (&xpm_type);
8822#endif 8822#endif
8823 8823
8824#if defined (HAVE_JPEG) || defined (HAVE_NS) 8824#if defined (HAVE_JPEG) || defined (HAVE_NS)
8825 if (EQ (type, Qjpeg)) 8825 if (EQ (type, Qjpeg))
8826 return CHECK_LIB_AVAILABLE (&jpeg_type, init_jpeg_functions, libraries); 8826 return define_image_type (&jpeg_type);
8827#endif 8827#endif
8828 8828
8829#if defined (HAVE_TIFF) || defined (HAVE_NS) 8829#if defined (HAVE_TIFF) || defined (HAVE_NS)
8830 if (EQ (type, Qtiff)) 8830 if (EQ (type, Qtiff))
8831 return CHECK_LIB_AVAILABLE (&tiff_type, init_tiff_functions, libraries); 8831 return define_image_type (&tiff_type);
8832#endif 8832#endif
8833 8833
8834#if defined (HAVE_GIF) || defined (HAVE_NS) 8834#if defined (HAVE_GIF) || defined (HAVE_NS)
8835 if (EQ (type, Qgif)) 8835 if (EQ (type, Qgif))
8836 return CHECK_LIB_AVAILABLE (&gif_type, init_gif_functions, libraries); 8836 return define_image_type (&gif_type);
8837#endif 8837#endif
8838 8838
8839#if defined (HAVE_PNG) || defined (HAVE_NS) 8839#if defined (HAVE_PNG) || defined (HAVE_NS)
8840 if (EQ (type, Qpng)) 8840 if (EQ (type, Qpng))
8841 return CHECK_LIB_AVAILABLE (&png_type, init_png_functions, libraries); 8841 return define_image_type (&png_type);
8842#endif 8842#endif
8843 8843
8844#if defined (HAVE_RSVG) 8844#if defined (HAVE_RSVG)
8845 if (EQ (type, Qsvg)) 8845 if (EQ (type, Qsvg))
8846 return CHECK_LIB_AVAILABLE (&svg_type, init_svg_functions, libraries); 8846 return define_image_type (&svg_type);
8847#endif 8847#endif
8848 8848
8849#if defined (HAVE_IMAGEMAGICK) 8849#if defined (HAVE_IMAGEMAGICK)
8850 if (EQ (type, Qimagemagick)) 8850 if (EQ (type, Qimagemagick))
8851 return CHECK_LIB_AVAILABLE (&imagemagick_type, init_imagemagick_functions, 8851 return define_image_type (&imagemagick_type);
8852 libraries);
8853#endif 8852#endif
8854 8853
8855#ifdef HAVE_GHOSTSCRIPT 8854#ifdef HAVE_GHOSTSCRIPT
8856 if (EQ (type, Qpostscript)) 8855 if (EQ (type, Qpostscript))
8857 return CHECK_LIB_AVAILABLE (&gs_type, init_gs_functions, libraries); 8856 return define_image_type (&gs_type);
8858#endif 8857#endif
8859 8858
8860 /* If the type is not recognized, avoid testing it ever again. */ 8859 return NULL;
8861 CACHE_IMAGE_TYPE (type, Qnil); 8860}
8862 return Qnil; 8861
8862/* Reset image_types before dumping.
8863 Called from Fdump_emacs. */
8864
8865void
8866reset_image_types (void)
8867{
8868 while (image_types)
8869 {
8870 struct image_type *next = image_types->next;
8871 xfree (image_types);
8872 image_types = next;
8873 }
8863} 8874}
8864 8875
8865void 8876void
8866syms_of_image (void) 8877syms_of_image (void)
8867{ 8878{
8868 /* Initialize this only once, since that's what we do with Vimage_types 8879 /* Initialize this only once; it will be reset before dumping. */
8869 and they are supposed to be in sync. Initializing here gives correct
8870 operation on GNU/Linux of calling dump-emacs after loading some images. */
8871 image_types = NULL; 8880 image_types = NULL;
8872 8881
8873 /* Must be defined now because we're going to update it below, while 8882 /* Must be defined now because we're going to update it below, while
@@ -8890,15 +8899,6 @@ as a ratio to the frame height and width. If the value is
8890non-numeric, there is no explicit limit on the size of images. */); 8899non-numeric, there is no explicit limit on the size of images. */);
8891 Vmax_image_size = make_float (MAX_IMAGE_SIZE); 8900 Vmax_image_size = make_float (MAX_IMAGE_SIZE);
8892 8901
8893 DEFSYM (Qpbm, "pbm");
8894 ADD_IMAGE_TYPE (Qpbm);
8895
8896 DEFSYM (Qxbm, "xbm");
8897 ADD_IMAGE_TYPE (Qxbm);
8898
8899 define_image_type (&xbm_type, 1);
8900 define_image_type (&pbm_type, 1);
8901
8902 DEFSYM (Qcount, "count"); 8902 DEFSYM (Qcount, "count");
8903 DEFSYM (Qextension_data, "extension-data"); 8903 DEFSYM (Qextension_data, "extension-data");
8904 DEFSYM (Qdelay, "delay"); 8904 DEFSYM (Qdelay, "delay");
@@ -8942,6 +8942,12 @@ non-numeric, there is no explicit limit on the size of images. */);
8942 ); 8942 );
8943#endif 8943#endif
8944 8944
8945 DEFSYM (Qpbm, "pbm");
8946 ADD_IMAGE_TYPE (Qpbm);
8947
8948 DEFSYM (Qxbm, "xbm");
8949 ADD_IMAGE_TYPE (Qxbm);
8950
8945#if defined (HAVE_XPM) || defined (HAVE_NS) 8951#if defined (HAVE_XPM) || defined (HAVE_NS)
8946 DEFSYM (Qxpm, "xpm"); 8952 DEFSYM (Qxpm, "xpm");
8947 ADD_IMAGE_TYPE (Qxpm); 8953 ADD_IMAGE_TYPE (Qxpm);