aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorKenichi Handa2012-09-30 23:39:46 +0900
committerKenichi Handa2012-09-30 23:39:46 +0900
commitc194970e15b6d6efa07697679a25dfab3aa76442 (patch)
tree49aec8be9d2dcc74ad3c81f562e48308d8e27b75 /src/image.c
parent95402d5faa114a311cabfb8c64cf22a93787a066 (diff)
parentdd946752ab8810149a66a3eff469eb128709972d (diff)
downloademacs-c194970e15b6d6efa07697679a25dfab3aa76442.tar.gz
emacs-c194970e15b6d6efa07697679a25dfab3aa76442.zip
merge trunk
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c553
1 files changed, 247 insertions, 306 deletions
diff --git a/src/image.c b/src/image.c
index 0060d0d4148..7901b95f236 100644
--- a/src/image.c
+++ b/src/image.c
@@ -407,9 +407,9 @@ x_destroy_bitmap (FRAME_PTR f, ptrdiff_t id)
407 407
408 if (--bm->refcount == 0) 408 if (--bm->refcount == 0)
409 { 409 {
410 BLOCK_INPUT; 410 block_input ();
411 free_bitmap_record (dpyinfo, bm); 411 free_bitmap_record (dpyinfo, bm);
412 UNBLOCK_INPUT; 412 unblock_input ();
413 } 413 }
414 } 414 }
415} 415}
@@ -429,6 +429,9 @@ x_destroy_all_bitmaps (Display_Info *dpyinfo)
429 dpyinfo->bitmaps_last = 0; 429 dpyinfo->bitmaps_last = 0;
430} 430}
431 431
432static bool x_create_x_image_and_pixmap (struct frame *, int, int, int,
433 XImagePtr *, Pixmap *);
434static void x_destroy_x_image (XImagePtr ximg);
432 435
433#ifdef HAVE_X_WINDOWS 436#ifdef HAVE_X_WINDOWS
434 437
@@ -440,23 +443,17 @@ static unsigned long four_corners_best (XImagePtr ximg,
440 unsigned long width, 443 unsigned long width,
441 unsigned long height); 444 unsigned long height);
442 445
443static int x_create_x_image_and_pixmap (struct frame *f, int width, int height,
444 int depth, XImagePtr *ximg,
445 Pixmap *pixmap);
446
447static void x_destroy_x_image (XImagePtr ximg);
448
449 446
450/* Create a mask of a bitmap. Note is this not a perfect mask. 447/* Create a mask of a bitmap. Note is this not a perfect mask.
451 It's nicer with some borders in this context */ 448 It's nicer with some borders in this context */
452 449
453int 450void
454x_create_bitmap_mask (struct frame *f, ptrdiff_t id) 451x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
455{ 452{
456 Pixmap pixmap, mask; 453 Pixmap pixmap, mask;
457 XImagePtr ximg, mask_img; 454 XImagePtr ximg, mask_img;
458 unsigned long width, height; 455 unsigned long width, height;
459 int result; 456 bool result;
460 unsigned long bg; 457 unsigned long bg;
461 unsigned long x, y, xp, xm, yp, ym; 458 unsigned long x, y, xp, xm, yp, ym;
462 GC gc; 459 GC gc;
@@ -464,29 +461,29 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
464 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 461 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
465 462
466 if (!(id > 0)) 463 if (!(id > 0))
467 return -1; 464 return;
468 465
469 pixmap = x_bitmap_pixmap (f, id); 466 pixmap = x_bitmap_pixmap (f, id);
470 width = x_bitmap_width (f, id); 467 width = x_bitmap_width (f, id);
471 height = x_bitmap_height (f, id); 468 height = x_bitmap_height (f, id);
472 469
473 BLOCK_INPUT; 470 block_input ();
474 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height, 471 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height,
475 ~0, ZPixmap); 472 ~0, ZPixmap);
476 473
477 if (!ximg) 474 if (!ximg)
478 { 475 {
479 UNBLOCK_INPUT; 476 unblock_input ();
480 return -1; 477 return;
481 } 478 }
482 479
483 result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask); 480 result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask);
484 481
485 UNBLOCK_INPUT; 482 unblock_input ();
486 if (!result) 483 if (!result)
487 { 484 {
488 XDestroyImage (ximg); 485 XDestroyImage (ximg);
489 return -1; 486 return;
490 } 487 }
491 488
492 bg = four_corners_best (ximg, NULL, width, height); 489 bg = four_corners_best (ximg, NULL, width, height);
@@ -514,7 +511,7 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
514 } 511 }
515 } 512 }
516 513
517 eassert (interrupt_input_blocked); 514 eassert (input_blocked_p ());
518 gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL); 515 gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL);
519 XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0, 516 XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0,
520 width, height); 517 width, height);
@@ -525,8 +522,6 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
525 522
526 XDestroyImage (ximg); 523 XDestroyImage (ximg);
527 x_destroy_x_image (mask_img); 524 x_destroy_x_image (mask_img);
528
529 return 0;
530} 525}
531 526
532#endif /* HAVE_X_WINDOWS */ 527#endif /* HAVE_X_WINDOWS */
@@ -559,15 +554,13 @@ static Lisp_Object QCcrop, QCrotation;
559static Lisp_Object Qcount, Qextension_data, Qdelay; 554static Lisp_Object Qcount, Qextension_data, Qdelay;
560static Lisp_Object Qlaplace, Qemboss, Qedge_detection, Qheuristic; 555static Lisp_Object Qlaplace, Qemboss, Qedge_detection, Qheuristic;
561 556
562/* Function prototypes. */ 557/* Forward function prototypes. */
563 558
564static struct image_type *define_image_type (struct image_type *, Lisp_Object); 559static struct image_type *lookup_image_type (Lisp_Object);
565static struct image_type *lookup_image_type (Lisp_Object, Lisp_Object);
566static void image_error (const char *format, Lisp_Object, Lisp_Object);
567static void x_laplace (struct frame *, struct image *); 560static void x_laplace (struct frame *, struct image *);
568static void x_emboss (struct frame *, struct image *); 561static void x_emboss (struct frame *, struct image *);
569static int x_build_heuristic_mask (struct frame *, struct image *, 562static void x_build_heuristic_mask (struct frame *, struct image *,
570 Lisp_Object); 563 Lisp_Object);
571#ifdef HAVE_NTGUI 564#ifdef HAVE_NTGUI
572#define CACHE_IMAGE_TYPE(type, status) \ 565#define CACHE_IMAGE_TYPE(type, status) \
573 do { Vlibrary_cache = Fcons (Fcons (type, status), Vlibrary_cache); } while (0) 566 do { Vlibrary_cache = Fcons (Fcons (type, status), Vlibrary_cache); } while (0)
@@ -579,21 +572,16 @@ static int x_build_heuristic_mask (struct frame *, struct image *,
579 do { Vimage_types = Fcons (type, Vimage_types); } while (0) 572 do { Vimage_types = Fcons (type, Vimage_types); } while (0)
580 573
581/* Define a new image type from TYPE. This adds a copy of TYPE to 574/* Define a new image type from TYPE. This adds a copy of TYPE to
582 image_types and caches the loading status of TYPE. 575 image_types and caches the loading status of TYPE. */
583
584 LIBRARIES is an alist associating dynamic libraries to external
585 files implementing them, which is passed to the image library
586 initialization function if necessary. A nil value defaults to
587 Vdynamic_library_alist. */
588 576
589static struct image_type * 577static struct image_type *
590define_image_type (struct image_type *type, Lisp_Object libraries) 578define_image_type (struct image_type *type)
591{ 579{
592 struct image_type *p = NULL; 580 struct image_type *p = NULL;
593 Lisp_Object target_type = *type->type; 581 Lisp_Object target_type = *type->type;
594 int type_valid = 1; 582 bool type_valid = 1;
595 583
596 BLOCK_INPUT; 584 block_input ();
597 585
598 for (p = image_types; p; p = p->next) 586 for (p = image_types; p; p = p->next)
599 if (EQ (*p->type, target_type)) 587 if (EQ (*p->type, target_type))
@@ -609,7 +597,7 @@ define_image_type (struct image_type *type, Lisp_Object libraries)
609 else 597 else
610#endif 598#endif
611 { 599 {
612 type_valid = type->init (libraries); 600 type_valid = type->init ();
613 CACHE_IMAGE_TYPE (target_type, type_valid ? Qt : Qnil); 601 CACHE_IMAGE_TYPE (target_type, type_valid ? Qt : Qnil);
614 } 602 }
615 } 603 }
@@ -625,22 +613,22 @@ define_image_type (struct image_type *type, Lisp_Object libraries)
625 } 613 }
626 614
627 done: 615 done:
628 UNBLOCK_INPUT; 616 unblock_input ();
629 return p; 617 return p;
630} 618}
631 619
632 620
633/* Value is non-zero if OBJECT is a valid Lisp image specification. A 621/* Value is true if OBJECT is a valid Lisp image specification. A
634 valid image specification is a list whose car is the symbol 622 valid image specification is a list whose car is the symbol
635 `image', and whose rest is a property list. The property list must 623 `image', and whose rest is a property list. The property list must
636 contain a value for key `:type'. That value must be the name of a 624 contain a value for key `:type'. That value must be the name of a
637 supported image type. The rest of the property list depends on the 625 supported image type. The rest of the property list depends on the
638 image type. */ 626 image type. */
639 627
640int 628bool
641valid_image_p (Lisp_Object object) 629valid_image_p (Lisp_Object object)
642{ 630{
643 int valid_p = 0; 631 bool valid_p = 0;
644 632
645 if (IMAGEP (object)) 633 if (IMAGEP (object))
646 { 634 {
@@ -653,7 +641,7 @@ valid_image_p (Lisp_Object object)
653 if (CONSP (tem) && SYMBOLP (XCAR (tem))) 641 if (CONSP (tem) && SYMBOLP (XCAR (tem)))
654 { 642 {
655 struct image_type *type; 643 struct image_type *type;
656 type = lookup_image_type (XCAR (tem), Qnil); 644 type = lookup_image_type (XCAR (tem));
657 if (type) 645 if (type)
658 valid_p = type->valid_p (object); 646 valid_p = type->valid_p (object);
659 } 647 }
@@ -710,8 +698,8 @@ struct image_keyword
710 /* The type of value allowed. */ 698 /* The type of value allowed. */
711 enum image_value_type type; 699 enum image_value_type type;
712 700
713 /* Non-zero means key must be present. */ 701 /* True means key must be present. */
714 int mandatory_p; 702 bool mandatory_p;
715 703
716 /* Used to recognize duplicate keywords in a property list. */ 704 /* Used to recognize duplicate keywords in a property list. */
717 int count; 705 int count;
@@ -721,18 +709,13 @@ struct image_keyword
721}; 709};
722 710
723 711
724static int parse_image_spec (Lisp_Object, struct image_keyword *,
725 int, Lisp_Object);
726static Lisp_Object image_spec_value (Lisp_Object, Lisp_Object, int *);
727
728
729/* Parse image spec SPEC according to KEYWORDS. A valid image spec 712/* Parse image spec SPEC according to KEYWORDS. A valid image spec
730 has the format (image KEYWORD VALUE ...). One of the keyword/ 713 has the format (image KEYWORD VALUE ...). One of the keyword/
731 value pairs must be `:type TYPE'. KEYWORDS is a vector of 714 value pairs must be `:type TYPE'. KEYWORDS is a vector of
732 image_keywords structures of size NKEYWORDS describing other 715 image_keywords structures of size NKEYWORDS describing other
733 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */ 716 allowed keyword/value pairs. Value is true if SPEC is valid. */
734 717
735static int 718static bool
736parse_image_spec (Lisp_Object spec, struct image_keyword *keywords, 719parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
737 int nkeywords, Lisp_Object type) 720 int nkeywords, Lisp_Object type)
738{ 721{
@@ -864,11 +847,11 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
864 847
865 848
866/* Return the value of KEY in image specification SPEC. Value is nil 849/* Return the value of KEY in image specification SPEC. Value is nil
867 if KEY is not present in SPEC. if FOUND is not null, set *FOUND 850 if KEY is not present in SPEC. Set *FOUND depending on whether KEY
868 to 1 if KEY was found in SPEC, set it to 0 otherwise. */ 851 was found in SPEC. */
869 852
870static Lisp_Object 853static Lisp_Object
871image_spec_value (Lisp_Object spec, Lisp_Object key, int *found) 854image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found)
872{ 855{
873 Lisp_Object tail; 856 Lisp_Object tail;
874 857
@@ -972,8 +955,6 @@ or omitted means use the selected frame. */)
972 Image type independent image structures 955 Image type independent image structures
973 ***********************************************************************/ 956 ***********************************************************************/
974 957
975static void free_image (struct frame *f, struct image *img);
976
977#define MAX_IMAGE_SIZE 10.0 958#define MAX_IMAGE_SIZE 10.0
978/* Allocate and return a new image structure for image specification 959/* Allocate and return a new image structure for image specification
979 SPEC. SPEC has a hash value of HASH. */ 960 SPEC. SPEC has a hash value of HASH. */
@@ -986,7 +967,7 @@ make_image (Lisp_Object spec, EMACS_UINT hash)
986 967
987 eassert (valid_image_p (spec)); 968 eassert (valid_image_p (spec));
988 img->dependencies = NILP (file) ? Qnil : list1 (file); 969 img->dependencies = NILP (file) ? Qnil : list1 (file);
989 img->type = lookup_image_type (image_spec_value (spec, QCtype, NULL), Qnil); 970 img->type = lookup_image_type (image_spec_value (spec, QCtype, NULL));
990 eassert (img->type != NULL); 971 eassert (img->type != NULL);
991 img->spec = spec; 972 img->spec = spec;
992 img->lisp_data = Qnil; 973 img->lisp_data = Qnil;
@@ -1023,10 +1004,9 @@ free_image (struct frame *f, struct image *img)
1023 } 1004 }
1024} 1005}
1025 1006
1026/* Return 1 if the given widths and heights are valid for display; 1007/* Return true if the given widths and heights are valid for display. */
1027 otherwise, return 0. */
1028 1008
1029static int 1009static bool
1030check_image_size (struct frame *f, int width, int height) 1010check_image_size (struct frame *f, int width, int height)
1031{ 1011{
1032 int w, h; 1012 int w, h;
@@ -1065,7 +1045,7 @@ prepare_image_for_display (struct frame *f, struct image *img)
1065 /* If IMG doesn't have a pixmap yet, load it now, using the image 1045 /* If IMG doesn't have a pixmap yet, load it now, using the image
1066 type dependent loader function. */ 1046 type dependent loader function. */
1067 if (img->pixmap == NO_PIXMAP && !img->load_failed_p) 1047 if (img->pixmap == NO_PIXMAP && !img->load_failed_p)
1068 img->load_failed_p = img->type->load (f, img) == 0; 1048 img->load_failed_p = ! img->type->load (f, img);
1069 1049
1070} 1050}
1071 1051
@@ -1198,7 +1178,7 @@ image_background (struct image *img, struct frame *f, XImagePtr_or_DC ximg)
1198 if (! img->background_valid) 1178 if (! img->background_valid)
1199 /* IMG doesn't have a background yet, try to guess a reasonable value. */ 1179 /* IMG doesn't have a background yet, try to guess a reasonable value. */
1200 { 1180 {
1201 int free_ximg = !ximg; 1181 bool free_ximg = !ximg;
1202#ifdef HAVE_NTGUI 1182#ifdef HAVE_NTGUI
1203 HGDIOBJ prev; 1183 HGDIOBJ prev;
1204#endif /* HAVE_NTGUI */ 1184#endif /* HAVE_NTGUI */
@@ -1239,7 +1219,7 @@ image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_D
1239 { 1219 {
1240 if (img->mask) 1220 if (img->mask)
1241 { 1221 {
1242 int free_mask = !mask; 1222 bool free_mask = !mask;
1243#ifdef HAVE_NTGUI 1223#ifdef HAVE_NTGUI
1244 HGDIOBJ prev; 1224 HGDIOBJ prev;
1245#endif /* HAVE_NTGUI */ 1225#endif /* HAVE_NTGUI */
@@ -1277,23 +1257,13 @@ image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_D
1277 Helper functions for X image types 1257 Helper functions for X image types
1278 ***********************************************************************/ 1258 ***********************************************************************/
1279 1259
1280static void x_clear_image_1 (struct frame *, struct image *, int, 1260/* Clear X resources of image IMG on frame F. PIXMAP_P means free the
1281 int, int); 1261 pixmap if any. MASK_P means clear the mask pixmap if any.
1282static void x_clear_image (struct frame *f, struct image *img); 1262 COLORS_P means free colors allocated for the image, if any. */
1283static unsigned long x_alloc_image_color (struct frame *f,
1284 struct image *img,
1285 Lisp_Object color_name,
1286 unsigned long dflt);
1287
1288
1289/* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
1290 free the pixmap if any. MASK_P non-zero means clear the mask
1291 pixmap if any. COLORS_P non-zero means free colors allocated for
1292 the image, if any. */
1293 1263
1294static void 1264static void
1295x_clear_image_1 (struct frame *f, struct image *img, int pixmap_p, int mask_p, 1265x_clear_image_1 (struct frame *f, struct image *img, bool pixmap_p,
1296 int colors_p) 1266 bool mask_p, bool colors_p)
1297{ 1267{
1298 if (pixmap_p && img->pixmap) 1268 if (pixmap_p && img->pixmap)
1299 { 1269 {
@@ -1328,9 +1298,9 @@ x_clear_image_1 (struct frame *f, struct image *img, int pixmap_p, int mask_p,
1328static void 1298static void
1329x_clear_image (struct frame *f, struct image *img) 1299x_clear_image (struct frame *f, struct image *img)
1330{ 1300{
1331 BLOCK_INPUT; 1301 block_input ();
1332 x_clear_image_1 (f, img, 1, 1, 1); 1302 x_clear_image_1 (f, img, 1, 1, 1);
1333 UNBLOCK_INPUT; 1303 unblock_input ();
1334} 1304}
1335 1305
1336 1306
@@ -1373,7 +1343,6 @@ x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name,
1373 ***********************************************************************/ 1343 ***********************************************************************/
1374 1344
1375static void cache_image (struct frame *f, struct image *img); 1345static void cache_image (struct frame *f, struct image *img);
1376static void postprocess_image (struct frame *, struct image *);
1377 1346
1378/* Return a new, initialized image cache that is allocated from the 1347/* Return a new, initialized image cache that is allocated from the
1379 heap. Call free_image_cache to free an image cache. */ 1348 heap. Call free_image_cache to free an image cache. */
@@ -1485,7 +1454,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
1485 1454
1486 /* Block input so that we won't be interrupted by a SIGIO 1455 /* Block input so that we won't be interrupted by a SIGIO
1487 while being in an inconsistent state. */ 1456 while being in an inconsistent state. */
1488 BLOCK_INPUT; 1457 block_input ();
1489 1458
1490 if (!NILP (filter)) 1459 if (!NILP (filter))
1491 { 1460 {
@@ -1551,7 +1520,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
1551 ++windows_or_buffers_changed; 1520 ++windows_or_buffers_changed;
1552 } 1521 }
1553 1522
1554 UNBLOCK_INPUT; 1523 unblock_input ();
1555 } 1524 }
1556} 1525}
1557 1526
@@ -1646,7 +1615,7 @@ postprocess_image (struct frame *f, struct image *img)
1646 x_build_heuristic_mask (f, img, mask); 1615 x_build_heuristic_mask (f, img, mask);
1647 else 1616 else
1648 { 1617 {
1649 int found_p; 1618 bool found_p;
1650 1619
1651 mask = image_spec_value (spec, QCmask, &found_p); 1620 mask = image_spec_value (spec, QCmask, &found_p);
1652 1621
@@ -1716,10 +1685,10 @@ lookup_image (struct frame *f, Lisp_Object spec)
1716 /* If not found, create a new image and cache it. */ 1685 /* If not found, create a new image and cache it. */
1717 if (img == NULL) 1686 if (img == NULL)
1718 { 1687 {
1719 BLOCK_INPUT; 1688 block_input ();
1720 img = make_image (spec, hash); 1689 img = make_image (spec, hash);
1721 cache_image (f, img); 1690 cache_image (f, img);
1722 img->load_failed_p = img->type->load (f, img) == 0; 1691 img->load_failed_p = ! img->type->load (f, img);
1723 img->frame_foreground = FRAME_FOREGROUND_PIXEL (f); 1692 img->frame_foreground = FRAME_FOREGROUND_PIXEL (f);
1724 img->frame_background = FRAME_BACKGROUND_PIXEL (f); 1693 img->frame_background = FRAME_BACKGROUND_PIXEL (f);
1725 1694
@@ -1787,7 +1756,7 @@ lookup_image (struct frame *f, Lisp_Object spec)
1787 postprocess_image (f, img); 1756 postprocess_image (f, img);
1788 } 1757 }
1789 1758
1790 UNBLOCK_INPUT; 1759 unblock_input ();
1791 } 1760 }
1792 1761
1793 /* We're using IMG, so set its timestamp to `now'. */ 1762 /* We're using IMG, so set its timestamp to `now'. */
@@ -1878,16 +1847,11 @@ mark_image_cache (struct image_cache *c)
1878 1847
1879#endif /* HAVE_NTGUI */ 1848#endif /* HAVE_NTGUI */
1880 1849
1881static int x_create_x_image_and_pixmap (struct frame *, int, int, int, 1850/* Return true if XIMG's size WIDTH x HEIGHT doesn't break the
1882 XImagePtr *, Pixmap *);
1883static void x_destroy_x_image (XImagePtr);
1884static void x_put_x_image (struct frame *, XImagePtr, Pixmap, int, int);
1885
1886/* Return nonzero if XIMG's size WIDTH x HEIGHT doesn't break the
1887 windowing system. 1851 windowing system.
1888 WIDTH and HEIGHT must both be positive. 1852 WIDTH and HEIGHT must both be positive.
1889 If XIMG is null, assume it is a bitmap. */ 1853 If XIMG is null, assume it is a bitmap. */
1890static int 1854static bool
1891x_check_image_size (XImagePtr ximg, int width, int height) 1855x_check_image_size (XImagePtr ximg, int width, int height)
1892{ 1856{
1893#ifdef HAVE_X_WINDOWS 1857#ifdef HAVE_X_WINDOWS
@@ -1926,12 +1890,12 @@ x_check_image_size (XImagePtr ximg, int width, int height)
1926 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created. 1890 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
1927 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated 1891 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
1928 via xmalloc. Print error messages via image_error if an error 1892 via xmalloc. Print error messages via image_error if an error
1929 occurs. Value is non-zero if successful. 1893 occurs. Value is true if successful.
1930 1894
1931 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH 1895 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH
1932 should indicate the bit depth of the image. */ 1896 should indicate the bit depth of the image. */
1933 1897
1934static int 1898static bool
1935x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, 1899x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
1936 XImagePtr *ximg, Pixmap *pixmap) 1900 XImagePtr *ximg, Pixmap *pixmap)
1937{ 1901{
@@ -1940,7 +1904,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
1940 Window window = FRAME_X_WINDOW (f); 1904 Window window = FRAME_X_WINDOW (f);
1941 Screen *screen = FRAME_X_SCREEN (f); 1905 Screen *screen = FRAME_X_SCREEN (f);
1942 1906
1943 eassert (interrupt_input_blocked); 1907 eassert (input_blocked_p ());
1944 1908
1945 if (depth <= 0) 1909 if (depth <= 0)
1946 depth = DefaultDepthOfScreen (screen); 1910 depth = DefaultDepthOfScreen (screen);
@@ -2078,7 +2042,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
2078static void 2042static void
2079x_destroy_x_image (XImagePtr ximg) 2043x_destroy_x_image (XImagePtr ximg)
2080{ 2044{
2081 eassert (interrupt_input_blocked); 2045 eassert (input_blocked_p ());
2082 if (ximg) 2046 if (ximg)
2083 { 2047 {
2084#ifdef HAVE_X_WINDOWS 2048#ifdef HAVE_X_WINDOWS
@@ -2107,7 +2071,7 @@ x_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int he
2107#ifdef HAVE_X_WINDOWS 2071#ifdef HAVE_X_WINDOWS
2108 GC gc; 2072 GC gc;
2109 2073
2110 eassert (interrupt_input_blocked); 2074 eassert (input_blocked_p ());
2111 gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL); 2075 gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL);
2112 XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, width, height); 2076 XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, width, height);
2113 XFreeGC (FRAME_X_DISPLAY (f), gc); 2077 XFreeGC (FRAME_X_DISPLAY (f), gc);
@@ -2203,15 +2167,9 @@ slurp_file (char *file, ptrdiff_t *size)
2203 XBM images 2167 XBM images
2204 ***********************************************************************/ 2168 ***********************************************************************/
2205 2169
2206static int xbm_scan (unsigned char **, unsigned char *, char *, int *); 2170static bool xbm_load (struct frame *f, struct image *img);
2207static int xbm_load (struct frame *f, struct image *img); 2171static bool xbm_image_p (Lisp_Object object);
2208static int xbm_load_image (struct frame *f, struct image *img, 2172static bool xbm_file_p (Lisp_Object);
2209 unsigned char *, unsigned char *);
2210static int xbm_image_p (Lisp_Object object);
2211static int xbm_read_bitmap_data (struct frame *f,
2212 unsigned char *, unsigned char *,
2213 int *, int *, char **, int);
2214static int xbm_file_p (Lisp_Object);
2215 2173
2216 2174
2217/* Indices of image specification fields in xbm_format, below. */ 2175/* Indices of image specification fields in xbm_format, below. */
@@ -2275,10 +2233,10 @@ enum xbm_token
2275}; 2233};
2276 2234
2277 2235
2278/* Return non-zero if OBJECT is a valid XBM-type image specification. 2236/* Return true if OBJECT is a valid XBM-type image specification.
2279 A valid specification is a list starting with the symbol `image' 2237 A valid specification is a list starting with the symbol `image'
2280 The rest of the list is a property list which must contain an 2238 The rest of the list is a property list which must contain an
2281 entry `:type xbm.. 2239 entry `:type xbm'.
2282 2240
2283 If the specification specifies a file to load, it must contain 2241 If the specification specifies a file to load, it must contain
2284 an entry `:file FILENAME' where FILENAME is a string. 2242 an entry `:file FILENAME' where FILENAME is a string.
@@ -2304,7 +2262,7 @@ enum xbm_token
2304 foreground and background of the frame on which the image is 2262 foreground and background of the frame on which the image is
2305 displayed is used. */ 2263 displayed is used. */
2306 2264
2307static int 2265static bool
2308xbm_image_p (Lisp_Object object) 2266xbm_image_p (Lisp_Object object)
2309{ 2267{
2310 struct image_keyword kw[XBM_LAST]; 2268 struct image_keyword kw[XBM_LAST];
@@ -2562,7 +2520,7 @@ convert_mono_to_color_image (struct frame *f, struct image *img,
2562static void 2520static void
2563Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data, 2521Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
2564 RGB_PIXEL_COLOR fg, RGB_PIXEL_COLOR bg, 2522 RGB_PIXEL_COLOR fg, RGB_PIXEL_COLOR bg,
2565 int non_default_colors) 2523 bool non_default_colors)
2566{ 2524{
2567#ifdef HAVE_NTGUI 2525#ifdef HAVE_NTGUI
2568 img->pixmap 2526 img->pixmap
@@ -2594,20 +2552,20 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
2594 X versions. CONTENTS is a pointer to a buffer to parse; END is the 2552 X versions. CONTENTS is a pointer to a buffer to parse; END is the
2595 buffer's end. Set *WIDTH and *HEIGHT to the width and height of 2553 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
2596 the image. Return in *DATA the bitmap data allocated with xmalloc. 2554 the image. Return in *DATA the bitmap data allocated with xmalloc.
2597 Value is non-zero if successful. DATA null means just test if 2555 Value is true if successful. DATA null means just test if
2598 CONTENTS looks like an in-memory XBM file. If INHIBIT_IMAGE_ERROR 2556 CONTENTS looks like an in-memory XBM file. If INHIBIT_IMAGE_ERROR,
2599 is non-zero, inhibit the call to image_error when the image size is 2557 inhibit the call to image_error when the image size is invalid (the
2600 invalid (the bitmap remains unread). */ 2558 bitmap remains unread). */
2601 2559
2602static int 2560static bool
2603xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *end, 2561xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *end,
2604 int *width, int *height, char **data, 2562 int *width, int *height, char **data,
2605 int inhibit_image_error) 2563 bool inhibit_image_error)
2606{ 2564{
2607 unsigned char *s = contents; 2565 unsigned char *s = contents;
2608 char buffer[BUFSIZ]; 2566 char buffer[BUFSIZ];
2609 int padding_p = 0; 2567 bool padding_p = 0;
2610 int v10 = 0; 2568 bool v10 = 0;
2611 int bytes_per_line, i, nbytes; 2569 int bytes_per_line, i, nbytes;
2612 char *p; 2570 char *p;
2613 int value; 2571 int value;
@@ -2754,16 +2712,16 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e
2754 2712
2755 2713
2756/* Load XBM image IMG which will be displayed on frame F from buffer 2714/* Load XBM image IMG which will be displayed on frame F from buffer
2757 CONTENTS. END is the end of the buffer. Value is non-zero if 2715 CONTENTS. END is the end of the buffer. Value is true if
2758 successful. */ 2716 successful. */
2759 2717
2760static int 2718static bool
2761xbm_load_image (struct frame *f, struct image *img, unsigned char *contents, 2719xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2762 unsigned char *end) 2720 unsigned char *end)
2763{ 2721{
2764 int rc; 2722 bool rc;
2765 char *data; 2723 char *data;
2766 int success_p = 0; 2724 bool success_p = 0;
2767 2725
2768 rc = xbm_read_bitmap_data (f, contents, end, &img->width, &img->height, 2726 rc = xbm_read_bitmap_data (f, contents, end, &img->width, &img->height,
2769 &data, 0); 2727 &data, 0);
@@ -2771,7 +2729,7 @@ xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2771 { 2729 {
2772 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); 2730 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
2773 unsigned long background = FRAME_BACKGROUND_PIXEL (f); 2731 unsigned long background = FRAME_BACKGROUND_PIXEL (f);
2774 int non_default_colors = 0; 2732 bool non_default_colors = 0;
2775 Lisp_Object value; 2733 Lisp_Object value;
2776 2734
2777 eassert (img->width > 0 && img->height > 0); 2735 eassert (img->width > 0 && img->height > 0);
@@ -2812,9 +2770,9 @@ xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2812} 2770}
2813 2771
2814 2772
2815/* Value is non-zero if DATA looks like an in-memory XBM file. */ 2773/* Value is true if DATA looks like an in-memory XBM file. */
2816 2774
2817static int 2775static bool
2818xbm_file_p (Lisp_Object data) 2776xbm_file_p (Lisp_Object data)
2819{ 2777{
2820 int w, h; 2778 int w, h;
@@ -2826,12 +2784,12 @@ xbm_file_p (Lisp_Object data)
2826 2784
2827 2785
2828/* Fill image IMG which is used on frame F with pixmap data. Value is 2786/* Fill image IMG which is used on frame F with pixmap data. Value is
2829 non-zero if successful. */ 2787 true if successful. */
2830 2788
2831static int 2789static bool
2832xbm_load (struct frame *f, struct image *img) 2790xbm_load (struct frame *f, struct image *img)
2833{ 2791{
2834 int success_p = 0; 2792 bool success_p = 0;
2835 Lisp_Object file_name; 2793 Lisp_Object file_name;
2836 2794
2837 eassert (xbm_image_p (img->spec)); 2795 eassert (xbm_image_p (img->spec));
@@ -2867,10 +2825,10 @@ xbm_load (struct frame *f, struct image *img)
2867 Lisp_Object data; 2825 Lisp_Object data;
2868 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); 2826 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
2869 unsigned long background = FRAME_BACKGROUND_PIXEL (f); 2827 unsigned long background = FRAME_BACKGROUND_PIXEL (f);
2870 int non_default_colors = 0; 2828 bool non_default_colors = 0;
2871 char *bits; 2829 char *bits;
2872 int parsed_p; 2830 bool parsed_p;
2873 int in_memory_file_p = 0; 2831 bool in_memory_file_p = 0;
2874 2832
2875 /* See if data looks like an in-memory XBM file. */ 2833 /* See if data looks like an in-memory XBM file. */
2876 data = image_spec_value (img->spec, QCdata, NULL); 2834 data = image_spec_value (img->spec, QCdata, NULL);
@@ -2879,7 +2837,6 @@ xbm_load (struct frame *f, struct image *img)
2879 /* Parse the image specification. */ 2837 /* Parse the image specification. */
2880 memcpy (fmt, xbm_format, sizeof fmt); 2838 memcpy (fmt, xbm_format, sizeof fmt);
2881 parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm); 2839 parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm);
2882 (void) parsed_p;
2883 eassert (parsed_p); 2840 eassert (parsed_p);
2884 2841
2885 /* Get specified width, and height. */ 2842 /* Get specified width, and height. */
@@ -2984,9 +2941,8 @@ xbm_load (struct frame *f, struct image *img)
2984 2941
2985#if defined (HAVE_XPM) || defined (HAVE_NS) 2942#if defined (HAVE_XPM) || defined (HAVE_NS)
2986 2943
2987static int xpm_image_p (Lisp_Object object); 2944static bool xpm_image_p (Lisp_Object object);
2988static int xpm_load (struct frame *f, struct image *img); 2945static bool xpm_load (struct frame *f, struct image *img);
2989static int xpm_valid_color_symbols_p (Lisp_Object);
2990 2946
2991#endif /* HAVE_XPM || HAVE_NS */ 2947#endif /* HAVE_XPM || HAVE_NS */
2992 2948
@@ -3053,7 +3009,7 @@ static const struct image_keyword xpm_format[XPM_LAST] =
3053}; 3009};
3054 3010
3055#ifdef HAVE_NTGUI 3011#ifdef HAVE_NTGUI
3056static int init_xpm_functions (Lisp_Object); 3012static bool init_xpm_functions (void);
3057#else 3013#else
3058#define init_xpm_functions NULL 3014#define init_xpm_functions NULL
3059#endif 3015#endif
@@ -3084,10 +3040,6 @@ static struct image_type xpm_type =
3084 3040
3085#ifdef ALLOC_XPM_COLORS 3041#ifdef ALLOC_XPM_COLORS
3086 3042
3087static void xpm_init_color_cache (struct frame *, XpmAttributes *);
3088static void xpm_free_color_cache (void);
3089static int xpm_lookup_color (struct frame *, char *, XColor *);
3090static int xpm_color_bucket (char *);
3091static struct xpm_cached_color *xpm_cache_color (struct frame *, char *, 3043static struct xpm_cached_color *xpm_cache_color (struct frame *, char *,
3092 XColor *, int); 3044 XColor *, int);
3093 3045
@@ -3194,10 +3146,10 @@ xpm_cache_color (struct frame *f, char *color_name, XColor *color, int bucket)
3194 3146
3195/* Look up color COLOR_NAME for frame F in the color cache. If found, 3147/* Look up color COLOR_NAME for frame F in the color cache. If found,
3196 return the cached definition in *COLOR. Otherwise, make a new 3148 return the cached definition in *COLOR. Otherwise, make a new
3197 entry in the cache and allocate the color. Value is zero if color 3149 entry in the cache and allocate the color. Value is false if color
3198 allocation failed. */ 3150 allocation failed. */
3199 3151
3200static int 3152static bool
3201xpm_lookup_color (struct frame *f, char *color_name, XColor *color) 3153xpm_lookup_color (struct frame *f, char *color_name, XColor *color)
3202{ 3154{
3203 struct xpm_cached_color *p; 3155 struct xpm_cached_color *p;
@@ -3266,12 +3218,12 @@ DEF_IMGLIB_FN (int, XpmReadFileToImage, (Display *, char *, xpm_XImage **,
3266 xpm_XImage **, XpmAttributes *)); 3218 xpm_XImage **, XpmAttributes *));
3267DEF_IMGLIB_FN (void, XImageFree, (xpm_XImage *)); 3219DEF_IMGLIB_FN (void, XImageFree, (xpm_XImage *));
3268 3220
3269static int 3221static bool
3270init_xpm_functions (Lisp_Object libraries) 3222init_xpm_functions (void)
3271{ 3223{
3272 HMODULE library; 3224 HMODULE library;
3273 3225
3274 if (!(library = w32_delayed_load (libraries, Qxpm))) 3226 if (!(library = w32_delayed_load (Qxpm)))
3275 return 0; 3227 return 0;
3276 3228
3277 LOAD_IMGLIB_FN (library, XpmFreeAttributes); 3229 LOAD_IMGLIB_FN (library, XpmFreeAttributes);
@@ -3284,11 +3236,11 @@ init_xpm_functions (Lisp_Object libraries)
3284#endif /* HAVE_NTGUI */ 3236#endif /* HAVE_NTGUI */
3285 3237
3286 3238
3287/* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list 3239/* Value is true if COLOR_SYMBOLS is a valid color symbols list
3288 for XPM images. Such a list must consist of conses whose car and 3240 for XPM images. Such a list must consist of conses whose car and
3289 cdr are strings. */ 3241 cdr are strings. */
3290 3242
3291static int 3243static bool
3292xpm_valid_color_symbols_p (Lisp_Object color_symbols) 3244xpm_valid_color_symbols_p (Lisp_Object color_symbols)
3293{ 3245{
3294 while (CONSP (color_symbols)) 3246 while (CONSP (color_symbols))
@@ -3305,9 +3257,9 @@ xpm_valid_color_symbols_p (Lisp_Object color_symbols)
3305} 3257}
3306 3258
3307 3259
3308/* Value is non-zero if OBJECT is a valid XPM image specification. */ 3260/* Value is true if OBJECT is a valid XPM image specification. */
3309 3261
3310static int 3262static bool
3311xpm_image_p (Lisp_Object object) 3263xpm_image_p (Lisp_Object object)
3312{ 3264{
3313 struct image_keyword fmt[XPM_LAST]; 3265 struct image_keyword fmt[XPM_LAST];
@@ -3364,11 +3316,11 @@ x_create_bitmap_from_xpm_data (struct frame *f, const char **bits)
3364#endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */ 3316#endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
3365 3317
3366/* Load image IMG which will be displayed on frame F. Value is 3318/* Load image IMG which will be displayed on frame F. Value is
3367 non-zero if successful. */ 3319 true if successful. */
3368 3320
3369#ifdef HAVE_XPM 3321#ifdef HAVE_XPM
3370 3322
3371static int 3323static bool
3372xpm_load (struct frame *f, struct image *img) 3324xpm_load (struct frame *f, struct image *img)
3373{ 3325{
3374 int rc; 3326 int rc;
@@ -3822,7 +3774,7 @@ xpm_str_to_color_key (const char *s)
3822 return -1; 3774 return -1;
3823} 3775}
3824 3776
3825static int 3777static bool
3826xpm_load_image (struct frame *f, 3778xpm_load_image (struct frame *f,
3827 struct image *img, 3779 struct image *img,
3828 const unsigned char *contents, 3780 const unsigned char *contents,
@@ -3837,7 +3789,8 @@ xpm_load_image (struct frame *f,
3837 void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object); 3789 void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object);
3838 Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int); 3790 Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int);
3839 Lisp_Object frame, color_symbols, color_table; 3791 Lisp_Object frame, color_symbols, color_table;
3840 int best_key, have_mask = 0; 3792 int best_key;
3793 bool have_mask = 0;
3841 XImagePtr ximg = NULL, mask_img = NULL; 3794 XImagePtr ximg = NULL, mask_img = NULL;
3842 3795
3843#define match() \ 3796#define match() \
@@ -4057,11 +4010,11 @@ xpm_load_image (struct frame *f,
4057#undef expect_ident 4010#undef expect_ident
4058} 4011}
4059 4012
4060static int 4013static bool
4061xpm_load (struct frame *f, 4014xpm_load (struct frame *f,
4062 struct image *img) 4015 struct image *img)
4063{ 4016{
4064 int success_p = 0; 4017 bool success_p = 0;
4065 Lisp_Object file_name; 4018 Lisp_Object file_name;
4066 4019
4067 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 4020 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -4232,7 +4185,7 @@ lookup_rgb_color (struct frame *f, int r, int g, int b)
4232#ifdef HAVE_X_WINDOWS 4185#ifdef HAVE_X_WINDOWS
4233 XColor color; 4186 XColor color;
4234 Colormap cmap; 4187 Colormap cmap;
4235 int rc; 4188 bool rc;
4236#else 4189#else
4237 COLORREF color; 4190 COLORREF color;
4238#endif 4191#endif
@@ -4300,7 +4253,7 @@ lookup_pixel_color (struct frame *f, unsigned long pixel)
4300 { 4253 {
4301 XColor color; 4254 XColor color;
4302 Colormap cmap; 4255 Colormap cmap;
4303 int rc; 4256 bool rc;
4304 4257
4305 if (ct_colors_allocated_max <= ct_colors_allocated) 4258 if (ct_colors_allocated_max <= ct_colors_allocated)
4306 return FRAME_FOREGROUND_PIXEL (f); 4259 return FRAME_FOREGROUND_PIXEL (f);
@@ -4311,12 +4264,12 @@ lookup_pixel_color (struct frame *f, unsigned long pixel)
4311 x_query_color (f, &color); 4264 x_query_color (f, &color);
4312 rc = x_alloc_nearest_color (f, cmap, &color); 4265 rc = x_alloc_nearest_color (f, cmap, &color);
4313#else 4266#else
4314 BLOCK_INPUT; 4267 block_input ();
4315 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); 4268 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
4316 color.pixel = pixel; 4269 color.pixel = pixel;
4317 XQueryColor (NULL, cmap, &color); 4270 XQueryColor (NULL, cmap, &color);
4318 rc = x_alloc_nearest_color (f, cmap, &color); 4271 rc = x_alloc_nearest_color (f, cmap, &color);
4319 UNBLOCK_INPUT; 4272 unblock_input ();
4320#endif /* HAVE_X_WINDOWS */ 4273#endif /* HAVE_X_WINDOWS */
4321 4274
4322 if (rc) 4275 if (rc)
@@ -4394,14 +4347,6 @@ init_color_table (void)
4394 Algorithms 4347 Algorithms
4395 ***********************************************************************/ 4348 ***********************************************************************/
4396 4349
4397static XColor *x_to_xcolors (struct frame *, struct image *, int);
4398static void x_from_xcolors (struct frame *, struct image *, XColor *);
4399static void x_detect_edges (struct frame *, struct image *, int[9], int);
4400
4401#ifdef HAVE_NTGUI
4402static void XPutPixel (XImagePtr , int, int, COLORREF);
4403#endif /* HAVE_NTGUI */
4404
4405/* Edge detection matrices for different edge-detection 4350/* Edge detection matrices for different edge-detection
4406 strategies. */ 4351 strategies. */
4407 4352
@@ -4427,12 +4372,12 @@ static int laplace_matrix[9] = {
4427 4372
4428/* On frame F, return an array of XColor structures describing image 4373/* On frame F, return an array of XColor structures describing image
4429 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P 4374 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
4430 non-zero means also fill the red/green/blue members of the XColor 4375 means also fill the red/green/blue members of the XColor
4431 structures. Value is a pointer to the array of XColors structures, 4376 structures. Value is a pointer to the array of XColors structures,
4432 allocated with xmalloc; it must be freed by the caller. */ 4377 allocated with xmalloc; it must be freed by the caller. */
4433 4378
4434static XColor * 4379static XColor *
4435x_to_xcolors (struct frame *f, struct image *img, int rgb_p) 4380x_to_xcolors (struct frame *f, struct image *img, bool rgb_p)
4436{ 4381{
4437 int x, y; 4382 int x, y;
4438 XColor *colors, *p; 4383 XColor *colors, *p;
@@ -4808,9 +4753,9 @@ x_disable_image (struct frame *f, struct image *img)
4808 determine the background color of IMG. If it is a list '(R G B)', 4753 determine the background color of IMG. If it is a list '(R G B)',
4809 with R, G, and B being integers >= 0, take that as the color of the 4754 with R, G, and B being integers >= 0, take that as the color of the
4810 background. Otherwise, determine the background color of IMG 4755 background. Otherwise, determine the background color of IMG
4811 heuristically. Value is non-zero if successful. */ 4756 heuristically. */
4812 4757
4813static int 4758static void
4814x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how) 4759x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4815{ 4760{
4816 XImagePtr_or_DC ximg; 4761 XImagePtr_or_DC ximg;
@@ -4822,7 +4767,8 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4822 char *mask_img; 4767 char *mask_img;
4823 int row_width; 4768 int row_width;
4824#endif /* HAVE_NTGUI */ 4769#endif /* HAVE_NTGUI */
4825 int x, y, rc, use_img_background; 4770 int x, y;
4771 bool rc, use_img_background;
4826 unsigned long bg = 0; 4772 unsigned long bg = 0;
4827 4773
4828 if (img->mask) 4774 if (img->mask)
@@ -4838,7 +4784,7 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4838 rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1, 4784 rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1,
4839 &mask_img, &img->mask); 4785 &mask_img, &img->mask);
4840 if (!rc) 4786 if (!rc)
4841 return 0; 4787 return;
4842#endif /* !HAVE_NS */ 4788#endif /* !HAVE_NS */
4843 4789
4844 /* Get the X image of IMG->pixmap. */ 4790 /* Get the X image of IMG->pixmap. */
@@ -4928,8 +4874,6 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4928#endif /* HAVE_NTGUI */ 4874#endif /* HAVE_NTGUI */
4929 4875
4930 Destroy_Image (ximg, prev); 4876 Destroy_Image (ximg, prev);
4931
4932 return 1;
4933} 4877}
4934 4878
4935 4879
@@ -4937,9 +4881,8 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4937 PBM (mono, gray, color) 4881 PBM (mono, gray, color)
4938 ***********************************************************************/ 4882 ***********************************************************************/
4939 4883
4940static int pbm_image_p (Lisp_Object object); 4884static bool pbm_image_p (Lisp_Object object);
4941static int pbm_load (struct frame *f, struct image *img); 4885static bool pbm_load (struct frame *f, struct image *img);
4942static int pbm_scan_number (unsigned char **, unsigned char *);
4943 4886
4944/* The symbol `pbm' identifying images of this type. */ 4887/* The symbol `pbm' identifying images of this type. */
4945 4888
@@ -4994,9 +4937,9 @@ static struct image_type pbm_type =
4994}; 4937};
4995 4938
4996 4939
4997/* Return non-zero if OBJECT is a valid PBM image specification. */ 4940/* Return true if OBJECT is a valid PBM image specification. */
4998 4941
4999static int 4942static bool
5000pbm_image_p (Lisp_Object object) 4943pbm_image_p (Lisp_Object object)
5001{ 4944{
5002 struct image_keyword fmt[PBM_LAST]; 4945 struct image_keyword fmt[PBM_LAST];
@@ -5089,10 +5032,11 @@ pbm_read_file (Lisp_Object file, int *size)
5089 5032
5090/* Load PBM image IMG for use on frame F. */ 5033/* Load PBM image IMG for use on frame F. */
5091 5034
5092static int 5035static bool
5093pbm_load (struct frame *f, struct image *img) 5036pbm_load (struct frame *f, struct image *img)
5094{ 5037{
5095 int raw_p, x, y; 5038 bool raw_p;
5039 int x, y;
5096 int width, height, max_color_idx = 0; 5040 int width, height, max_color_idx = 0;
5097 XImagePtr ximg; 5041 XImagePtr ximg;
5098 Lisp_Object file, specified_file; 5042 Lisp_Object file, specified_file;
@@ -5355,8 +5299,8 @@ pbm_load (struct frame *f, struct image *img)
5355 5299
5356/* Function prototypes. */ 5300/* Function prototypes. */
5357 5301
5358static int png_image_p (Lisp_Object object); 5302static bool png_image_p (Lisp_Object object);
5359static int png_load (struct frame *f, struct image *img); 5303static bool png_load (struct frame *f, struct image *img);
5360 5304
5361/* The symbol `png' identifying images of this type. */ 5305/* The symbol `png' identifying images of this type. */
5362 5306
@@ -5397,7 +5341,7 @@ static const struct image_keyword png_format[PNG_LAST] =
5397}; 5341};
5398 5342
5399#ifdef HAVE_NTGUI 5343#ifdef HAVE_NTGUI
5400static int init_png_functions (Lisp_Object); 5344static bool init_png_functions (void);
5401#else 5345#else
5402#define init_png_functions NULL 5346#define init_png_functions NULL
5403#endif 5347#endif
@@ -5414,9 +5358,9 @@ static struct image_type png_type =
5414 NULL 5358 NULL
5415}; 5359};
5416 5360
5417/* Return non-zero if OBJECT is a valid PNG image specification. */ 5361/* Return true if OBJECT is a valid PNG image specification. */
5418 5362
5419static int 5363static bool
5420png_image_p (Lisp_Object object) 5364png_image_p (Lisp_Object object)
5421{ 5365{
5422 struct image_keyword fmt[PNG_LAST]; 5366 struct image_keyword fmt[PNG_LAST];
@@ -5468,12 +5412,12 @@ DEF_IMGLIB_FN (void, png_longjmp, (png_structp, int));
5468DEF_IMGLIB_FN (jmp_buf *, png_set_longjmp_fn, (png_structp, png_longjmp_ptr, size_t)); 5412DEF_IMGLIB_FN (jmp_buf *, png_set_longjmp_fn, (png_structp, png_longjmp_ptr, size_t));
5469#endif /* libpng version >= 1.5 */ 5413#endif /* libpng version >= 1.5 */
5470 5414
5471static int 5415static bool
5472init_png_functions (Lisp_Object libraries) 5416init_png_functions (void)
5473{ 5417{
5474 HMODULE library; 5418 HMODULE library;
5475 5419
5476 if (!(library = w32_delayed_load (libraries, Qpng))) 5420 if (!(library = w32_delayed_load (Qpng)))
5477 return 0; 5421 return 0;
5478 5422
5479 LOAD_IMGLIB_FN (library, png_get_io_ptr); 5423 LOAD_IMGLIB_FN (library, png_get_io_ptr);
@@ -5619,7 +5563,7 @@ png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length)
5619} 5563}
5620 5564
5621 5565
5622/* Load PNG image IMG for use on frame F. Value is non-zero if 5566/* Load PNG image IMG for use on frame F. Value is true if
5623 successful. */ 5567 successful. */
5624 5568
5625struct png_load_context 5569struct png_load_context
@@ -5633,7 +5577,7 @@ struct png_load_context
5633 png_byte **rows; 5577 png_byte **rows;
5634}; 5578};
5635 5579
5636static int 5580static bool
5637png_load_body (struct frame *f, struct image *img, struct png_load_context *c) 5581png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5638{ 5582{
5639 Lisp_Object file, specified_file; 5583 Lisp_Object file, specified_file;
@@ -5651,7 +5595,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5651 int bit_depth, color_type, interlace_type; 5595 int bit_depth, color_type, interlace_type;
5652 png_byte channels; 5596 png_byte channels;
5653 png_uint_32 row_bytes; 5597 png_uint_32 row_bytes;
5654 int transparent_p; 5598 bool transparent_p;
5655 struct png_memory_storage tbr; /* Data to be read */ 5599 struct png_memory_storage tbr; /* Data to be read */
5656 5600
5657 /* Find out what file to load. */ 5601 /* Find out what file to load. */
@@ -5984,7 +5928,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5984 return 1; 5928 return 1;
5985} 5929}
5986 5930
5987static int 5931static bool
5988png_load (struct frame *f, struct image *img) 5932png_load (struct frame *f, struct image *img)
5989{ 5933{
5990 struct png_load_context c; 5934 struct png_load_context c;
@@ -5994,7 +5938,7 @@ png_load (struct frame *f, struct image *img)
5994#else /* HAVE_PNG */ 5938#else /* HAVE_PNG */
5995 5939
5996#ifdef HAVE_NS 5940#ifdef HAVE_NS
5997static int 5941static bool
5998png_load (struct frame *f, struct image *img) 5942png_load (struct frame *f, struct image *img)
5999{ 5943{
6000 return ns_load_image (f, img, 5944 return ns_load_image (f, img,
@@ -6014,8 +5958,8 @@ png_load (struct frame *f, struct image *img)
6014 5958
6015#if defined (HAVE_JPEG) || defined (HAVE_NS) 5959#if defined (HAVE_JPEG) || defined (HAVE_NS)
6016 5960
6017static int jpeg_image_p (Lisp_Object object); 5961static bool jpeg_image_p (Lisp_Object object);
6018static int jpeg_load (struct frame *f, struct image *img); 5962static bool jpeg_load (struct frame *f, struct image *img);
6019 5963
6020/* The symbol `jpeg' identifying images of this type. */ 5964/* The symbol `jpeg' identifying images of this type. */
6021 5965
@@ -6056,7 +6000,7 @@ static const struct image_keyword jpeg_format[JPEG_LAST] =
6056}; 6000};
6057 6001
6058#ifdef HAVE_NTGUI 6002#ifdef HAVE_NTGUI
6059static int init_jpeg_functions (Lisp_Object); 6003static bool init_jpeg_functions (void);
6060#else 6004#else
6061#define init_jpeg_functions NULL 6005#define init_jpeg_functions NULL
6062#endif 6006#endif
@@ -6073,9 +6017,9 @@ static struct image_type jpeg_type =
6073 NULL 6017 NULL
6074}; 6018};
6075 6019
6076/* Return non-zero if OBJECT is a valid JPEG image specification. */ 6020/* Return true if OBJECT is a valid JPEG image specification. */
6077 6021
6078static int 6022static bool
6079jpeg_image_p (Lisp_Object object) 6023jpeg_image_p (Lisp_Object object)
6080{ 6024{
6081 struct image_keyword fmt[JPEG_LAST]; 6025 struct image_keyword fmt[JPEG_LAST];
@@ -6124,12 +6068,12 @@ DEF_IMGLIB_FN (JDIMENSION, jpeg_read_scanlines, (j_decompress_ptr, JSAMPARRAY, J
6124DEF_IMGLIB_FN (struct jpeg_error_mgr *, jpeg_std_error, (struct jpeg_error_mgr *)); 6068DEF_IMGLIB_FN (struct jpeg_error_mgr *, jpeg_std_error, (struct jpeg_error_mgr *));
6125DEF_IMGLIB_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int)); 6069DEF_IMGLIB_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int));
6126 6070
6127static int 6071static bool
6128init_jpeg_functions (Lisp_Object libraries) 6072init_jpeg_functions (void)
6129{ 6073{
6130 HMODULE library; 6074 HMODULE library;
6131 6075
6132 if (!(library = w32_delayed_load (libraries, Qjpeg))) 6076 if (!(library = w32_delayed_load (Qjpeg)))
6133 return 0; 6077 return 0;
6134 6078
6135 LOAD_IMGLIB_FN (library, jpeg_finish_decompress); 6079 LOAD_IMGLIB_FN (library, jpeg_finish_decompress);
@@ -6394,7 +6338,7 @@ jpeg_file_src (j_decompress_ptr cinfo, FILE *fp)
6394/* Load image IMG for use on frame F. Patterned after example.c 6338/* Load image IMG for use on frame F. Patterned after example.c
6395 from the JPEG lib. */ 6339 from the JPEG lib. */
6396 6340
6397static int 6341static bool
6398jpeg_load_body (struct frame *f, struct image *img, 6342jpeg_load_body (struct frame *f, struct image *img,
6399 struct my_jpeg_error_mgr *mgr) 6343 struct my_jpeg_error_mgr *mgr)
6400{ 6344{
@@ -6575,7 +6519,7 @@ jpeg_load_body (struct frame *f, struct image *img,
6575 return 1; 6519 return 1;
6576} 6520}
6577 6521
6578static int 6522static bool
6579jpeg_load (struct frame *f, struct image *img) 6523jpeg_load (struct frame *f, struct image *img)
6580{ 6524{
6581 struct my_jpeg_error_mgr mgr; 6525 struct my_jpeg_error_mgr mgr;
@@ -6585,7 +6529,7 @@ jpeg_load (struct frame *f, struct image *img)
6585#else /* HAVE_JPEG */ 6529#else /* HAVE_JPEG */
6586 6530
6587#ifdef HAVE_NS 6531#ifdef HAVE_NS
6588static int 6532static bool
6589jpeg_load (struct frame *f, struct image *img) 6533jpeg_load (struct frame *f, struct image *img)
6590{ 6534{
6591 return ns_load_image (f, img, 6535 return ns_load_image (f, img,
@@ -6604,8 +6548,8 @@ jpeg_load (struct frame *f, struct image *img)
6604 6548
6605#if defined (HAVE_TIFF) || defined (HAVE_NS) 6549#if defined (HAVE_TIFF) || defined (HAVE_NS)
6606 6550
6607static int tiff_image_p (Lisp_Object object); 6551static bool tiff_image_p (Lisp_Object object);
6608static int tiff_load (struct frame *f, struct image *img); 6552static bool tiff_load (struct frame *f, struct image *img);
6609 6553
6610/* The symbol `tiff' identifying images of this type. */ 6554/* The symbol `tiff' identifying images of this type. */
6611 6555
@@ -6648,7 +6592,7 @@ static const struct image_keyword tiff_format[TIFF_LAST] =
6648}; 6592};
6649 6593
6650#ifdef HAVE_NTGUI 6594#ifdef HAVE_NTGUI
6651static int init_tiff_functions (Lisp_Object); 6595static bool init_tiff_functions (void);
6652#else 6596#else
6653#define init_tiff_functions NULL 6597#define init_tiff_functions NULL
6654#endif 6598#endif
@@ -6665,9 +6609,9 @@ static struct image_type tiff_type =
6665 NULL 6609 NULL
6666}; 6610};
6667 6611
6668/* Return non-zero if OBJECT is a valid TIFF image specification. */ 6612/* Return true if OBJECT is a valid TIFF image specification. */
6669 6613
6670static int 6614static bool
6671tiff_image_p (Lisp_Object object) 6615tiff_image_p (Lisp_Object object)
6672{ 6616{
6673 struct image_keyword fmt[TIFF_LAST]; 6617 struct image_keyword fmt[TIFF_LAST];
@@ -6701,12 +6645,12 @@ DEF_IMGLIB_FN (int, TIFFReadRGBAImage, (TIFF *, uint32, uint32, uint32 *, int));
6701DEF_IMGLIB_FN (void, TIFFClose, (TIFF *)); 6645DEF_IMGLIB_FN (void, TIFFClose, (TIFF *));
6702DEF_IMGLIB_FN (int, TIFFSetDirectory, (TIFF *, tdir_t)); 6646DEF_IMGLIB_FN (int, TIFFSetDirectory, (TIFF *, tdir_t));
6703 6647
6704static int 6648static bool
6705init_tiff_functions (Lisp_Object libraries) 6649init_tiff_functions (void)
6706{ 6650{
6707 HMODULE library; 6651 HMODULE library;
6708 6652
6709 if (!(library = w32_delayed_load (libraries, Qtiff))) 6653 if (!(library = w32_delayed_load (Qtiff)))
6710 return 0; 6654 return 0;
6711 6655
6712 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler); 6656 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler);
@@ -6871,10 +6815,10 @@ tiff_warning_handler (const char *title, const char *format, va_list ap)
6871} 6815}
6872 6816
6873 6817
6874/* Load TIFF image IMG for use on frame F. Value is non-zero if 6818/* Load TIFF image IMG for use on frame F. Value is true if
6875 successful. */ 6819 successful. */
6876 6820
6877static int 6821static bool
6878tiff_load (struct frame *f, struct image *img) 6822tiff_load (struct frame *f, struct image *img)
6879{ 6823{
6880 Lisp_Object file, specified_file; 6824 Lisp_Object file, specified_file;
@@ -7039,7 +6983,7 @@ tiff_load (struct frame *f, struct image *img)
7039#else /* HAVE_TIFF */ 6983#else /* HAVE_TIFF */
7040 6984
7041#ifdef HAVE_NS 6985#ifdef HAVE_NS
7042static int 6986static bool
7043tiff_load (struct frame *f, struct image *img) 6987tiff_load (struct frame *f, struct image *img)
7044{ 6988{
7045 return ns_load_image (f, img, 6989 return ns_load_image (f, img,
@@ -7058,8 +7002,8 @@ tiff_load (struct frame *f, struct image *img)
7058 7002
7059#if defined (HAVE_GIF) || defined (HAVE_NS) 7003#if defined (HAVE_GIF) || defined (HAVE_NS)
7060 7004
7061static int gif_image_p (Lisp_Object object); 7005static bool gif_image_p (Lisp_Object object);
7062static int gif_load (struct frame *f, struct image *img); 7006static bool gif_load (struct frame *f, struct image *img);
7063static void gif_clear_image (struct frame *f, struct image *img); 7007static void gif_clear_image (struct frame *f, struct image *img);
7064 7008
7065/* The symbol `gif' identifying images of this type. */ 7009/* The symbol `gif' identifying images of this type. */
@@ -7103,7 +7047,7 @@ static const struct image_keyword gif_format[GIF_LAST] =
7103}; 7047};
7104 7048
7105#ifdef HAVE_NTGUI 7049#ifdef HAVE_NTGUI
7106static int init_gif_functions (Lisp_Object); 7050static bool init_gif_functions (void);
7107#else 7051#else
7108#define init_gif_functions NULL 7052#define init_gif_functions NULL
7109#endif 7053#endif
@@ -7129,9 +7073,9 @@ gif_clear_image (struct frame *f, struct image *img)
7129 x_clear_image (f, img); 7073 x_clear_image (f, img);
7130} 7074}
7131 7075
7132/* Return non-zero if OBJECT is a valid GIF image specification. */ 7076/* Return true if OBJECT is a valid GIF image specification. */
7133 7077
7134static int 7078static bool
7135gif_image_p (Lisp_Object object) 7079gif_image_p (Lisp_Object object)
7136{ 7080{
7137 struct image_keyword fmt[GIF_LAST]; 7081 struct image_keyword fmt[GIF_LAST];
@@ -7174,12 +7118,12 @@ DEF_IMGLIB_FN (int, DGifSlurp, (GifFileType *));
7174DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc)); 7118DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc));
7175DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *)); 7119DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *));
7176 7120
7177static int 7121static bool
7178init_gif_functions (Lisp_Object libraries) 7122init_gif_functions (void)
7179{ 7123{
7180 HMODULE library; 7124 HMODULE library;
7181 7125
7182 if (!(library = w32_delayed_load (libraries, Qgif))) 7126 if (!(library = w32_delayed_load (Qgif)))
7183 return 0; 7127 return 0;
7184 7128
7185 LOAD_IMGLIB_FN (library, DGifCloseFile); 7129 LOAD_IMGLIB_FN (library, DGifCloseFile);
@@ -7228,7 +7172,7 @@ gif_read_from_memory (GifFileType *file, GifByteType *buf, int len)
7228} 7172}
7229 7173
7230 7174
7231/* Load GIF image IMG for use on frame F. Value is non-zero if 7175/* Load GIF image IMG for use on frame F. Value is true if
7232 successful. */ 7176 successful. */
7233 7177
7234static const int interlace_start[] = {0, 4, 2, 1}; 7178static const int interlace_start[] = {0, 4, 2, 1};
@@ -7236,7 +7180,7 @@ static const int interlace_increment[] = {8, 8, 4, 2};
7236 7180
7237#define GIF_LOCAL_DESCRIPTOR_EXTENSION 249 7181#define GIF_LOCAL_DESCRIPTOR_EXTENSION 249
7238 7182
7239static int 7183static bool
7240gif_load (struct frame *f, struct image *img) 7184gif_load (struct frame *f, struct image *img)
7241{ 7185{
7242 Lisp_Object file; 7186 Lisp_Object file;
@@ -7534,7 +7478,7 @@ gif_load (struct frame *f, struct image *img)
7534#else /* !HAVE_GIF */ 7478#else /* !HAVE_GIF */
7535 7479
7536#ifdef HAVE_NS 7480#ifdef HAVE_NS
7537static int 7481static bool
7538gif_load (struct frame *f, struct image *img) 7482gif_load (struct frame *f, struct image *img)
7539{ 7483{
7540 return ns_load_image (f, img, 7484 return ns_load_image (f, img,
@@ -7553,8 +7497,8 @@ gif_load (struct frame *f, struct image *img)
7553 7497
7554static Lisp_Object Qimagemagick; 7498static Lisp_Object Qimagemagick;
7555 7499
7556static int imagemagick_image_p (Lisp_Object); 7500static bool imagemagick_image_p (Lisp_Object);
7557static int imagemagick_load (struct frame *, struct image *); 7501static bool imagemagick_load (struct frame *, struct image *);
7558static void imagemagick_clear_image (struct frame *, struct image *); 7502static void imagemagick_clear_image (struct frame *, struct image *);
7559 7503
7560/* Indices of image specification fields in imagemagick_format. */ 7504/* Indices of image specification fields in imagemagick_format. */
@@ -7600,7 +7544,7 @@ static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] =
7600 }; 7544 };
7601 7545
7602#ifdef HAVE_NTGUI 7546#ifdef HAVE_NTGUI
7603static int init_imagemagick_functions (Lisp_Object); 7547static bool init_imagemagick_functions (void);
7604#else 7548#else
7605#define init_imagemagick_functions NULL 7549#define init_imagemagick_functions NULL
7606#endif 7550#endif
@@ -7627,11 +7571,11 @@ imagemagick_clear_image (struct frame *f,
7627 x_clear_image (f, img); 7571 x_clear_image (f, img);
7628} 7572}
7629 7573
7630/* Return non-zero if OBJECT is a valid IMAGEMAGICK image specification. Do 7574/* Return true if OBJECT is a valid IMAGEMAGICK image specification. Do
7631 this by calling parse_image_spec and supplying the keywords that 7575 this by calling parse_image_spec and supplying the keywords that
7632 identify the IMAGEMAGICK format. */ 7576 identify the IMAGEMAGICK format. */
7633 7577
7634static int 7578static bool
7635imagemagick_image_p (Lisp_Object object) 7579imagemagick_image_p (Lisp_Object object)
7636{ 7580{
7637 struct image_keyword fmt[IMAGEMAGICK_LAST]; 7581 struct image_keyword fmt[IMAGEMAGICK_LAST];
@@ -7683,9 +7627,9 @@ imagemagick_error (MagickWand *wand)
7683 be parsed; SIZE is the number of bytes of data; and FILENAME is 7627 be parsed; SIZE is the number of bytes of data; and FILENAME is
7684 either the file name or the image data. 7628 either the file name or the image data.
7685 7629
7686 Return non-zero if successful. */ 7630 Return true if successful. */
7687 7631
7688static int 7632static bool
7689imagemagick_load_image (struct frame *f, struct image *img, 7633imagemagick_load_image (struct frame *f, struct image *img,
7690 unsigned char *contents, unsigned int size, 7634 unsigned char *contents, unsigned int size,
7691 char *filename) 7635 char *filename)
@@ -8023,14 +7967,14 @@ imagemagick_load_image (struct frame *f, struct image *img,
8023} 7967}
8024 7968
8025 7969
8026/* Load IMAGEMAGICK image IMG for use on frame F. Value is non-zero if 7970/* Load IMAGEMAGICK image IMG for use on frame F. Value is true if
8027 successful. this function will go into the imagemagick_type structure, and 7971 successful. this function will go into the imagemagick_type structure, and
8028 the prototype thus needs to be compatible with that structure. */ 7972 the prototype thus needs to be compatible with that structure. */
8029 7973
8030static int 7974static bool
8031imagemagick_load (struct frame *f, struct image *img) 7975imagemagick_load (struct frame *f, struct image *img)
8032{ 7976{
8033 int success_p = 0; 7977 bool success_p = 0;
8034 Lisp_Object file_name; 7978 Lisp_Object file_name;
8035 7979
8036 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 7980 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -8109,11 +8053,11 @@ and `imagemagick-types-inhibit'. */)
8109 8053
8110/* Function prototypes. */ 8054/* Function prototypes. */
8111 8055
8112static int svg_image_p (Lisp_Object object); 8056static bool svg_image_p (Lisp_Object object);
8113static int svg_load (struct frame *f, struct image *img); 8057static bool svg_load (struct frame *f, struct image *img);
8114 8058
8115static int svg_load_image (struct frame *, struct image *, 8059static bool svg_load_image (struct frame *, struct image *,
8116 unsigned char *, ptrdiff_t); 8060 unsigned char *, ptrdiff_t);
8117 8061
8118/* The symbol `svg' identifying images of this type. */ 8062/* The symbol `svg' identifying images of this type. */
8119 8063
@@ -8154,7 +8098,7 @@ static const struct image_keyword svg_format[SVG_LAST] =
8154}; 8098};
8155 8099
8156#ifdef HAVE_NTGUI 8100#ifdef HAVE_NTGUI
8157static int init_svg_functions (Lisp_Object); 8101static bool init_svg_functions (void);
8158#else 8102#else
8159#define init_svg_functions NULL 8103#define init_svg_functions NULL
8160#endif 8104#endif
@@ -8174,11 +8118,11 @@ static struct image_type svg_type =
8174}; 8118};
8175 8119
8176 8120
8177/* Return non-zero if OBJECT is a valid SVG image specification. Do 8121/* Return true if OBJECT is a valid SVG image specification. Do
8178 this by calling parse_image_spec and supplying the keywords that 8122 this by calling parse_image_spec and supplying the keywords that
8179 identify the SVG format. */ 8123 identify the SVG format. */
8180 8124
8181static int 8125static bool
8182svg_image_p (Lisp_Object object) 8126svg_image_p (Lisp_Object object)
8183{ 8127{
8184 struct image_keyword fmt[SVG_LAST]; 8128 struct image_keyword fmt[SVG_LAST];
@@ -8217,15 +8161,15 @@ DEF_IMGLIB_FN (void, g_error_free);
8217 8161
8218Lisp_Object Qgdk_pixbuf, Qglib, Qgobject; 8162Lisp_Object Qgdk_pixbuf, Qglib, Qgobject;
8219 8163
8220static int 8164static bool
8221init_svg_functions (Lisp_Object libraries) 8165init_svg_functions (void)
8222{ 8166{
8223 HMODULE library, gdklib, glib, gobject; 8167 HMODULE library, gdklib, glib, gobject;
8224 8168
8225 if (!(glib = w32_delayed_load (libraries, Qglib)) 8169 if (!(glib = w32_delayed_load (Qglib))
8226 || !(gobject = w32_delayed_load (libraries, Qgobject)) 8170 || !(gobject = w32_delayed_load (Qgobject))
8227 || !(gdklib = w32_delayed_load (libraries, Qgdk_pixbuf)) 8171 || !(gdklib = w32_delayed_load (Qgdk_pixbuf))
8228 || !(library = w32_delayed_load (libraries, Qsvg))) 8172 || !(library = w32_delayed_load (Qsvg)))
8229 return 0; 8173 return 0;
8230 8174
8231 LOAD_IMGLIB_FN (library, rsvg_handle_new); 8175 LOAD_IMGLIB_FN (library, rsvg_handle_new);
@@ -8273,14 +8217,13 @@ init_svg_functions (Lisp_Object libraries)
8273#define fn_g_error_free g_error_free 8217#define fn_g_error_free g_error_free
8274#endif /* !HAVE_NTGUI */ 8218#endif /* !HAVE_NTGUI */
8275 8219
8276/* Load SVG image IMG for use on frame F. Value is non-zero if 8220/* Load SVG image IMG for use on frame F. Value is true if
8277 successful. this function will go into the svg_type structure, and 8221 successful. */
8278 the prototype thus needs to be compatible with that structure. */
8279 8222
8280static int 8223static bool
8281svg_load (struct frame *f, struct image *img) 8224svg_load (struct frame *f, struct image *img)
8282{ 8225{
8283 int success_p = 0; 8226 bool success_p = 0;
8284 Lisp_Object file_name; 8227 Lisp_Object file_name;
8285 8228
8286 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 8229 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -8333,8 +8276,8 @@ svg_load (struct frame *f, struct image *img)
8333 8276
8334 Uses librsvg to do most of the image processing. 8277 Uses librsvg to do most of the image processing.
8335 8278
8336 Returns non-zero when successful. */ 8279 Returns true when successful. */
8337static int 8280static bool
8338svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */ 8281svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */
8339 struct image *img, /* Pointer to emacs image structure. */ 8282 struct image *img, /* Pointer to emacs image structure. */
8340 unsigned char *contents, /* String containing the SVG XML data to be parsed. */ 8283 unsigned char *contents, /* String containing the SVG XML data to be parsed. */
@@ -8501,8 +8444,8 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
8501 8444
8502#ifdef HAVE_GHOSTSCRIPT 8445#ifdef HAVE_GHOSTSCRIPT
8503 8446
8504static int gs_image_p (Lisp_Object object); 8447static bool gs_image_p (Lisp_Object object);
8505static int gs_load (struct frame *f, struct image *img); 8448static bool gs_load (struct frame *f, struct image *img);
8506static void gs_clear_image (struct frame *f, struct image *img); 8449static void gs_clear_image (struct frame *f, struct image *img);
8507 8450
8508/* Keyword symbols. */ 8451/* Keyword symbols. */
@@ -8549,12 +8492,6 @@ static const struct image_keyword gs_format[GS_LAST] =
8549 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 8492 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
8550}; 8493};
8551 8494
8552#ifdef HAVE_NTGUI
8553static int init_gs_functions (Lisp_Object);
8554#else
8555#define init_gs_functions NULL
8556#endif
8557
8558/* Structure describing the image type `ghostscript'. */ 8495/* Structure describing the image type `ghostscript'. */
8559 8496
8560static struct image_type gs_type = 8497static struct image_type gs_type =
@@ -8563,7 +8500,7 @@ static struct image_type gs_type =
8563 gs_image_p, 8500 gs_image_p,
8564 gs_load, 8501 gs_load,
8565 gs_clear_image, 8502 gs_clear_image,
8566 init_gs_functions, 8503 NULL,
8567 NULL 8504 NULL
8568}; 8505};
8569 8506
@@ -8577,10 +8514,10 @@ gs_clear_image (struct frame *f, struct image *img)
8577} 8514}
8578 8515
8579 8516
8580/* Return non-zero if OBJECT is a valid Ghostscript image 8517/* Return true if OBJECT is a valid Ghostscript image
8581 specification. */ 8518 specification. */
8582 8519
8583static int 8520static bool
8584gs_image_p (Lisp_Object object) 8521gs_image_p (Lisp_Object object)
8585{ 8522{
8586 struct image_keyword fmt[GS_LAST]; 8523 struct image_keyword fmt[GS_LAST];
@@ -8617,10 +8554,10 @@ gs_image_p (Lisp_Object object)
8617} 8554}
8618 8555
8619 8556
8620/* Load Ghostscript image IMG for use on frame F. Value is non-zero 8557/* Load Ghostscript image IMG for use on frame F. Value is true
8621 if successful. */ 8558 if successful. */
8622 8559
8623static int 8560static bool
8624gs_load (struct frame *f, struct image *img) 8561gs_load (struct frame *f, struct image *img)
8625{ 8562{
8626 uprintmax_t printnum1, printnum2; 8563 uprintmax_t printnum1, printnum2;
@@ -8656,11 +8593,11 @@ gs_load (struct frame *f, struct image *img)
8656 if (x_check_image_size (0, img->width, img->height)) 8593 if (x_check_image_size (0, img->width, img->height))
8657 { 8594 {
8658 /* Only W32 version did BLOCK_INPUT here. ++kfs */ 8595 /* Only W32 version did BLOCK_INPUT here. ++kfs */
8659 BLOCK_INPUT; 8596 block_input ();
8660 img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 8597 img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
8661 img->width, img->height, 8598 img->width, img->height,
8662 DefaultDepthOfScreen (FRAME_X_SCREEN (f))); 8599 DefaultDepthOfScreen (FRAME_X_SCREEN (f)));
8663 UNBLOCK_INPUT; 8600 unblock_input ();
8664 } 8601 }
8665 8602
8666 if (!img->pixmap) 8603 if (!img->pixmap)
@@ -8736,7 +8673,7 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f)
8736 { 8673 {
8737 XImagePtr ximg; 8674 XImagePtr ximg;
8738 8675
8739 BLOCK_INPUT; 8676 block_input ();
8740 8677
8741 /* Try to get an XImage for img->pixmep. */ 8678 /* Try to get an XImage for img->pixmep. */
8742 ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, 8679 ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap,
@@ -8779,15 +8716,15 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f)
8779 image_error ("Cannot get X image of `%s'; colors will not be freed", 8716 image_error ("Cannot get X image of `%s'; colors will not be freed",
8780 img->spec, Qnil); 8717 img->spec, Qnil);
8781 8718
8782 UNBLOCK_INPUT; 8719 unblock_input ();
8783 } 8720 }
8784#endif /* HAVE_X_WINDOWS */ 8721#endif /* HAVE_X_WINDOWS */
8785 8722
8786 /* Now that we have the pixmap, compute mask and transform the 8723 /* Now that we have the pixmap, compute mask and transform the
8787 image if requested. */ 8724 image if requested. */
8788 BLOCK_INPUT; 8725 block_input ();
8789 postprocess_image (f, img); 8726 postprocess_image (f, img);
8790 UNBLOCK_INPUT; 8727 unblock_input ();
8791} 8728}
8792 8729
8793#endif /* HAVE_GHOSTSCRIPT */ 8730#endif /* HAVE_GHOSTSCRIPT */
@@ -8826,88 +8763,92 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "")
8826 Initialization 8763 Initialization
8827 ***********************************************************************/ 8764 ***********************************************************************/
8828 8765
8829DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0, 8766DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 1, 1, 0,
8830 doc: /* Initialize image library implementing image type TYPE. 8767 doc: /* Initialize image library implementing image type TYPE.
8831Return non-nil if TYPE is a supported image type. 8768Return non-nil if TYPE is a supported image type.
8832 8769
8833Image types pbm and xbm are prebuilt; other types are loaded here. 8770If image libraries are loaded dynamically (currently only the case on
8834Libraries to load are specified in alist LIBRARIES (usually, the value 8771MS-Windows), load the library for TYPE if it is not yet loaded, using
8835of `dynamic-library-alist', which see). */) 8772the library file(s) specified by `dynamic-library-alist'. */)
8836 (Lisp_Object type, Lisp_Object libraries) 8773 (Lisp_Object type)
8837{ 8774{
8838 return lookup_image_type (type, libraries) ? Qt : Qnil; 8775 return lookup_image_type (type) ? Qt : Qnil;
8839} 8776}
8840 8777
8841/* Look up image type TYPE, and return a pointer to its image_type 8778/* Look up image type TYPE, and return a pointer to its image_type
8842 structure. Return 0 if TYPE is not a known image type. 8779 structure. Return 0 if TYPE is not a known image type. */
8843
8844 LIBRARIES is an alist associating dynamic libraries to external
8845 files implementing them, which is passed to the image library
8846 initialization function if necessary. A nil value defaults to
8847 Vdynamic_library_alist. */
8848 8780
8849static struct image_type * 8781static struct image_type *
8850lookup_image_type (Lisp_Object type, Lisp_Object libraries) 8782lookup_image_type (Lisp_Object type)
8851{ 8783{
8852 if (NILP (libraries))
8853 libraries = Vdynamic_library_alist;
8854
8855 /* Types pbm and xbm are built-in and always available. */ 8784 /* Types pbm and xbm are built-in and always available. */
8856 if (EQ (type, Qpbm)) 8785 if (EQ (type, Qpbm))
8857 return define_image_type (&pbm_type, libraries); 8786 return define_image_type (&pbm_type);
8858 8787
8859 if (EQ (type, Qxbm)) 8788 if (EQ (type, Qxbm))
8860 return define_image_type (&xbm_type, libraries); 8789 return define_image_type (&xbm_type);
8861 8790
8862#if defined (HAVE_XPM) || defined (HAVE_NS) 8791#if defined (HAVE_XPM) || defined (HAVE_NS)
8863 if (EQ (type, Qxpm)) 8792 if (EQ (type, Qxpm))
8864 return define_image_type (&xpm_type, libraries); 8793 return define_image_type (&xpm_type);
8865#endif 8794#endif
8866 8795
8867#if defined (HAVE_JPEG) || defined (HAVE_NS) 8796#if defined (HAVE_JPEG) || defined (HAVE_NS)
8868 if (EQ (type, Qjpeg)) 8797 if (EQ (type, Qjpeg))
8869 return define_image_type (&jpeg_type, libraries); 8798 return define_image_type (&jpeg_type);
8870#endif 8799#endif
8871 8800
8872#if defined (HAVE_TIFF) || defined (HAVE_NS) 8801#if defined (HAVE_TIFF) || defined (HAVE_NS)
8873 if (EQ (type, Qtiff)) 8802 if (EQ (type, Qtiff))
8874 return define_image_type (&tiff_type, libraries); 8803 return define_image_type (&tiff_type);
8875#endif 8804#endif
8876 8805
8877#if defined (HAVE_GIF) || defined (HAVE_NS) 8806#if defined (HAVE_GIF) || defined (HAVE_NS)
8878 if (EQ (type, Qgif)) 8807 if (EQ (type, Qgif))
8879 return define_image_type (&gif_type, libraries); 8808 return define_image_type (&gif_type);
8880#endif 8809#endif
8881 8810
8882#if defined (HAVE_PNG) || defined (HAVE_NS) 8811#if defined (HAVE_PNG) || defined (HAVE_NS)
8883 if (EQ (type, Qpng)) 8812 if (EQ (type, Qpng))
8884 return define_image_type (&png_type, libraries); 8813 return define_image_type (&png_type);
8885#endif 8814#endif
8886 8815
8887#if defined (HAVE_RSVG) 8816#if defined (HAVE_RSVG)
8888 if (EQ (type, Qsvg)) 8817 if (EQ (type, Qsvg))
8889 return define_image_type (&svg_type, libraries); 8818 return define_image_type (&svg_type);
8890#endif 8819#endif
8891 8820
8892#if defined (HAVE_IMAGEMAGICK) 8821#if defined (HAVE_IMAGEMAGICK)
8893 if (EQ (type, Qimagemagick)) 8822 if (EQ (type, Qimagemagick))
8894 return define_image_type (&imagemagick_type, libraries); 8823 return define_image_type (&imagemagick_type);
8895#endif 8824#endif
8896 8825
8897#ifdef HAVE_GHOSTSCRIPT 8826#ifdef HAVE_GHOSTSCRIPT
8898 if (EQ (type, Qpostscript)) 8827 if (EQ (type, Qpostscript))
8899 return define_image_type (&gs_type, libraries); 8828 return define_image_type (&gs_type);
8900#endif 8829#endif
8901 8830
8902 return NULL; 8831 return NULL;
8903} 8832}
8904 8833
8834/* Reset image_types before dumping.
8835 Called from Fdump_emacs. */
8836
8837void
8838reset_image_types (void)
8839{
8840 while (image_types)
8841 {
8842 struct image_type *next = image_types->next;
8843 xfree (image_types);
8844 image_types = next;
8845 }
8846}
8847
8905void 8848void
8906syms_of_image (void) 8849syms_of_image (void)
8907{ 8850{
8908 /* Initialize this only once, since that's what we do with Vimage_types 8851 /* Initialize this only once; it will be reset before dumping. */
8909 and they are supposed to be in sync. Initializing here gives correct
8910 operation on GNU/Linux of calling dump-emacs after loading some images. */
8911 image_types = NULL; 8852 image_types = NULL;
8912 8853
8913 /* Must be defined now because we're going to update it below, while 8854 /* Must be defined now because we're going to update it below, while