comparison src/image.c @ 109871:3226ac2da7f7

merge from trunk
author Joakim <joakim@localhost.localdomain>
date Tue, 17 Aug 2010 23:19:11 +0200
parents c1ae0a9b14a1 8949aad5e992
children 45bb792f536e
comparison
equal deleted inserted replaced
109870:2ea89e2c498f 109871:3226ac2da7f7
124 124
125 /* Search path for bitmap files. */ 125 /* Search path for bitmap files. */
126 126
127 Lisp_Object Vx_bitmap_file_path; 127 Lisp_Object Vx_bitmap_file_path;
128 128
129 129 /* The symbol `postscript' identifying images of this type. */
130 static void x_disable_image P_ ((struct frame *, struct image *)); 130
131 static void x_edge_detection P_ ((struct frame *, struct image *, Lisp_Object, 131 Lisp_Object Qpostscript;
132 Lisp_Object)); 132
133 133 static void x_disable_image (struct frame *, struct image *);
134 static void init_color_table P_ ((void)); 134 static void x_edge_detection (struct frame *, struct image *, Lisp_Object,
135 static unsigned long lookup_rgb_color P_ ((struct frame *f, int r, int g, int b)); 135 Lisp_Object);
136
137 static void init_color_table (void);
138 static unsigned long lookup_rgb_color (struct frame *f, int r, int g, int b);
136 #ifdef COLOR_TABLE_SUPPORT 139 #ifdef COLOR_TABLE_SUPPORT
137 static void free_color_table P_ ((void)); 140 static void free_color_table (void);
138 static unsigned long *colors_in_color_table P_ ((int *n)); 141 static unsigned long *colors_in_color_table (int *n);
139 static unsigned long lookup_pixel_color P_ ((struct frame *f, unsigned long p)); 142 static unsigned long lookup_pixel_color (struct frame *f, unsigned long p);
140 #endif 143 #endif
141 144
142 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap 145 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
143 id, which is just an int that this section returns. Bitmaps are 146 id, which is just an int that this section returns. Bitmaps are
144 reference counted so they can be shared among frames. 147 reference counted so they can be shared among frames.
155 XGetImage (Display *display, Pixmap pixmap, int x, int y, 158 XGetImage (Display *display, Pixmap pixmap, int x, int y,
156 unsigned int width, unsigned int height, 159 unsigned int width, unsigned int height,
157 unsigned long plane_mask, int format) 160 unsigned long plane_mask, int format)
158 { 161 {
159 /* TODO: not sure what this function is supposed to do.. */ 162 /* TODO: not sure what this function is supposed to do.. */
160 ns_retain_object(pixmap); 163 ns_retain_object (pixmap);
161 return pixmap; 164 return pixmap;
162 } 165 }
163 166
164 /* use with imgs created by ns_image_for_XPM */ 167 /* use with imgs created by ns_image_for_XPM */
165 unsigned long 168 unsigned long
166 XGetPixel (XImagePtr ximage, int x, int y) 169 XGetPixel (XImagePtr ximage, int x, int y)
167 { 170 {
168 return ns_get_pixel(ximage, x, y); 171 return ns_get_pixel (ximage, x, y);
169 } 172 }
170 173
171 /* use with imgs created by ns_image_for_XPM; alpha set to 1; 174 /* use with imgs created by ns_image_for_XPM; alpha set to 1;
172 pixel is assumed to be in form RGB */ 175 pixel is assumed to be in form RGB */
173 void 176 void
174 XPutPixel (XImagePtr ximage, int x, int y, unsigned long pixel) 177 XPutPixel (XImagePtr ximage, int x, int y, unsigned long pixel)
175 { 178 {
176 ns_put_pixel(ximage, x, y, pixel); 179 ns_put_pixel (ximage, x, y, pixel);
177 } 180 }
178 #endif /* HAVE_NS */ 181 #endif /* HAVE_NS */
179 182
180 183
181 /* Functions to access the contents of a bitmap, given an id. */ 184 /* Functions to access the contents of a bitmap, given an id. */
182 185
183 int 186 int
184 x_bitmap_height (f, id) 187 x_bitmap_height (FRAME_PTR f, int id)
185 FRAME_PTR f;
186 int id;
187 { 188 {
188 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height; 189 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height;
189 } 190 }
190 191
191 int 192 int
192 x_bitmap_width (f, id) 193 x_bitmap_width (FRAME_PTR f, int id)
193 FRAME_PTR f;
194 int id;
195 { 194 {
196 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width; 195 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width;
197 } 196 }
198 197
199 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) 198 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
200 int 199 int
201 x_bitmap_pixmap (f, id) 200 x_bitmap_pixmap (FRAME_PTR f, int id)
202 FRAME_PTR f;
203 int id;
204 { 201 {
205 return (int) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap; 202 return (int) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap;
206 } 203 }
207 #endif 204 #endif
208 205
209 #ifdef HAVE_X_WINDOWS 206 #ifdef HAVE_X_WINDOWS
210 int 207 int
211 x_bitmap_mask (f, id) 208 x_bitmap_mask (FRAME_PTR f, int id)
212 FRAME_PTR f;
213 int id;
214 { 209 {
215 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask; 210 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask;
216 } 211 }
217 #endif 212 #endif
218 213
219 /* Allocate a new bitmap record. Returns index of new record. */ 214 /* Allocate a new bitmap record. Returns index of new record. */
220 215
221 static int 216 static int
222 x_allocate_bitmap_record (f) 217 x_allocate_bitmap_record (FRAME_PTR f)
223 FRAME_PTR f;
224 { 218 {
225 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 219 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
226 int i; 220 int i;
227 221
228 if (dpyinfo->bitmaps == NULL) 222 if (dpyinfo->bitmaps == NULL)
249 } 243 }
250 244
251 /* Add one reference to the reference count of the bitmap with id ID. */ 245 /* Add one reference to the reference count of the bitmap with id ID. */
252 246
253 void 247 void
254 x_reference_bitmap (f, id) 248 x_reference_bitmap (FRAME_PTR f, int id)
255 FRAME_PTR f;
256 int id;
257 { 249 {
258 ++FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].refcount; 250 ++FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].refcount;
259 } 251 }
260 252
261 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */ 253 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
262 254
263 int 255 int
264 x_create_bitmap_from_data (f, bits, width, height) 256 x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsigned int height)
265 struct frame *f;
266 char *bits;
267 unsigned int width, height;
268 { 257 {
269 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 258 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
270 int id; 259 int id;
271 260
272 #ifdef HAVE_X_WINDOWS 261 #ifdef HAVE_X_WINDOWS
286 if (! bitmap) 275 if (! bitmap)
287 return -1; 276 return -1;
288 #endif /* HAVE_NTGUI */ 277 #endif /* HAVE_NTGUI */
289 278
290 #ifdef HAVE_NS 279 #ifdef HAVE_NS
291 void *bitmap = ns_image_from_XBM(bits, width, height); 280 void *bitmap = ns_image_from_XBM (bits, width, height);
292 if (!bitmap) 281 if (!bitmap)
293 return -1; 282 return -1;
294 #endif 283 #endif
295 284
296 id = x_allocate_bitmap_record (f); 285 id = x_allocate_bitmap_record (f);
321 } 310 }
322 311
323 /* Create bitmap from file FILE for frame F. */ 312 /* Create bitmap from file FILE for frame F. */
324 313
325 int 314 int
326 x_create_bitmap_from_file (f, file) 315 x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
327 struct frame *f;
328 Lisp_Object file;
329 { 316 {
330 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 317 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
331 318
332 #ifdef HAVE_NTGUI 319 #ifdef HAVE_NTGUI
333 return -1; /* W32_TODO : bitmap support */ 320 return -1; /* W32_TODO : bitmap support */
334 #endif /* HAVE_NTGUI */ 321 #endif /* HAVE_NTGUI */
335 322
336 #ifdef HAVE_NS 323 #ifdef HAVE_NS
337 int id; 324 int id;
338 void *bitmap = ns_image_from_file(file); 325 void *bitmap = ns_image_from_file (file);
339 326
340 if (!bitmap) 327 if (!bitmap)
341 return -1; 328 return -1;
342 329
343 330
344 id = x_allocate_bitmap_record (f); 331 id = x_allocate_bitmap_record (f);
345 dpyinfo->bitmaps[id - 1].img = bitmap; 332 dpyinfo->bitmaps[id - 1].img = bitmap;
346 dpyinfo->bitmaps[id - 1].refcount = 1; 333 dpyinfo->bitmaps[id - 1].refcount = 1;
347 dpyinfo->bitmaps[id - 1].file = (char *) xmalloc (SBYTES (file) + 1); 334 dpyinfo->bitmaps[id - 1].file = (char *) xmalloc (SBYTES (file) + 1);
348 dpyinfo->bitmaps[id - 1].depth = 1; 335 dpyinfo->bitmaps[id - 1].depth = 1;
349 dpyinfo->bitmaps[id - 1].height = ns_image_width(bitmap); 336 dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap);
350 dpyinfo->bitmaps[id - 1].width = ns_image_height(bitmap); 337 dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap);
351 strcpy (dpyinfo->bitmaps[id - 1].file, SDATA (file)); 338 strcpy (dpyinfo->bitmaps[id - 1].file, SDATA (file));
352 return id; 339 return id;
353 #endif 340 #endif
354 341
355 #ifdef HAVE_X_WINDOWS 342 #ifdef HAVE_X_WINDOWS
400 } 387 }
401 388
402 /* Free bitmap B. */ 389 /* Free bitmap B. */
403 390
404 static void 391 static void
405 free_bitmap_record (dpyinfo, bm) 392 free_bitmap_record (Display_Info *dpyinfo, Bitmap_Record *bm)
406 Display_Info *dpyinfo;
407 Bitmap_Record *bm;
408 { 393 {
409 #ifdef HAVE_X_WINDOWS 394 #ifdef HAVE_X_WINDOWS
410 XFreePixmap (dpyinfo->display, bm->pixmap); 395 XFreePixmap (dpyinfo->display, bm->pixmap);
411 if (bm->have_mask) 396 if (bm->have_mask)
412 XFreePixmap (dpyinfo->display, bm->mask); 397 XFreePixmap (dpyinfo->display, bm->mask);
415 #ifdef HAVE_NTGUI 400 #ifdef HAVE_NTGUI
416 DeleteObject (bm->pixmap); 401 DeleteObject (bm->pixmap);
417 #endif /* HAVE_NTGUI */ 402 #endif /* HAVE_NTGUI */
418 403
419 #ifdef HAVE_NS 404 #ifdef HAVE_NS
420 ns_release_object(bm->img); 405 ns_release_object (bm->img);
421 #endif 406 #endif
422 407
423 if (bm->file) 408 if (bm->file)
424 { 409 {
425 xfree (bm->file); 410 xfree (bm->file);
428 } 413 }
429 414
430 /* Remove reference to bitmap with id number ID. */ 415 /* Remove reference to bitmap with id number ID. */
431 416
432 void 417 void
433 x_destroy_bitmap (f, id) 418 x_destroy_bitmap (FRAME_PTR f, int id)
434 FRAME_PTR f;
435 int id;
436 { 419 {
437 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 420 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
438 421
439 if (id > 0) 422 if (id > 0)
440 { 423 {
450 } 433 }
451 434
452 /* Free all the bitmaps for the display specified by DPYINFO. */ 435 /* Free all the bitmaps for the display specified by DPYINFO. */
453 436
454 void 437 void
455 x_destroy_all_bitmaps (dpyinfo) 438 x_destroy_all_bitmaps (Display_Info *dpyinfo)
456 Display_Info *dpyinfo;
457 { 439 {
458 int i; 440 int i;
459 Bitmap_Record *bm = dpyinfo->bitmaps; 441 Bitmap_Record *bm = dpyinfo->bitmaps;
460 442
461 for (i = 0; i < dpyinfo->bitmaps_last; i++, bm++) 443 for (i = 0; i < dpyinfo->bitmaps_last; i++, bm++)
469 #ifdef HAVE_X_WINDOWS 451 #ifdef HAVE_X_WINDOWS
470 452
471 /* Useful functions defined in the section 453 /* Useful functions defined in the section
472 `Image type independent image structures' below. */ 454 `Image type independent image structures' below. */
473 455
474 static unsigned long four_corners_best P_ ((XImagePtr ximg, 456 static unsigned long four_corners_best (XImagePtr ximg,
475 int *corners, 457 int *corners,
476 unsigned long width, 458 unsigned long width,
477 unsigned long height)); 459 unsigned long height);
478 460
479 static int x_create_x_image_and_pixmap P_ ((struct frame *f, int width, int height, 461 static int x_create_x_image_and_pixmap (struct frame *f, int width, int height,
480 int depth, XImagePtr *ximg, 462 int depth, XImagePtr *ximg,
481 Pixmap *pixmap)); 463 Pixmap *pixmap);
482 464
483 static void x_destroy_x_image P_ ((XImagePtr ximg)); 465 static void x_destroy_x_image (XImagePtr ximg);
484 466
485 467
486 /* Create a mask of a bitmap. Note is this not a perfect mask. 468 /* Create a mask of a bitmap. Note is this not a perfect mask.
487 It's nicer with some borders in this context */ 469 It's nicer with some borders in this context */
488 470
489 int 471 int
490 x_create_bitmap_mask (f, id) 472 x_create_bitmap_mask (struct frame *f, int id)
491 struct frame *f;
492 int id;
493 { 473 {
494 Pixmap pixmap, mask; 474 Pixmap pixmap, mask;
495 XImagePtr ximg, mask_img; 475 XImagePtr ximg, mask_img;
496 unsigned long width, height; 476 unsigned long width, height;
497 int result; 477 int result;
599 579
600 Lisp_Object Qxbm; 580 Lisp_Object Qxbm;
601 581
602 /* Keywords. */ 582 /* Keywords. */
603 583
604 extern Lisp_Object QCwidth, QCheight, QCforeground, QCbackground, QCfile;
605 extern Lisp_Object QCdata, QCtype;
606 extern Lisp_Object Qcenter;
607 Lisp_Object QCascent, QCmargin, QCrelief, Qcount, Qextension_data; 584 Lisp_Object QCascent, QCmargin, QCrelief, Qcount, Qextension_data;
608 Lisp_Object QCconversion, QCcolor_symbols, QCheuristic_mask; 585 Lisp_Object QCconversion, QCcolor_symbols, QCheuristic_mask;
609 Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask, QCgeometry, QCcrop, QCrotation; 586 Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask, QCgeometry, QCcrop, QCrotation;
610 587
611 /* Other symbols. */ 588 /* Other symbols. */
617 594
618 Lisp_Object Vimage_cache_eviction_delay; 595 Lisp_Object Vimage_cache_eviction_delay;
619 596
620 /* Function prototypes. */ 597 /* Function prototypes. */
621 598
622 static Lisp_Object define_image_type P_ ((struct image_type *type, int loaded)); 599 static Lisp_Object define_image_type (struct image_type *type, int loaded);
623 static struct image_type *lookup_image_type P_ ((Lisp_Object symbol)); 600 static struct image_type *lookup_image_type (Lisp_Object symbol);
624 static void image_error P_ ((char *format, Lisp_Object, Lisp_Object)); 601 static void image_error (const char *format, Lisp_Object, Lisp_Object);
625 static void x_laplace P_ ((struct frame *, struct image *)); 602 static void x_laplace (struct frame *, struct image *);
626 static void x_emboss P_ ((struct frame *, struct image *)); 603 static void x_emboss (struct frame *, struct image *);
627 static int x_build_heuristic_mask P_ ((struct frame *, struct image *, 604 static int x_build_heuristic_mask (struct frame *, struct image *,
628 Lisp_Object)); 605 Lisp_Object);
629 606
630 #define CACHE_IMAGE_TYPE(type, status) \ 607 #define CACHE_IMAGE_TYPE(type, status) \
631 do { Vimage_type_cache = Fcons (Fcons (type, status), Vimage_type_cache); } while (0) 608 do { Vimage_type_cache = Fcons (Fcons (type, status), Vimage_type_cache); } while (0)
632 609
633 #define ADD_IMAGE_TYPE(type) \ 610 #define ADD_IMAGE_TYPE(type) \
635 612
636 /* Define a new image type from TYPE. This adds a copy of TYPE to 613 /* Define a new image type from TYPE. This adds a copy of TYPE to
637 image_types and caches the loading status of TYPE. */ 614 image_types and caches the loading status of TYPE. */
638 615
639 static Lisp_Object 616 static Lisp_Object
640 define_image_type (type, loaded) 617 define_image_type (struct image_type *type, int loaded)
641 struct image_type *type;
642 int loaded;
643 { 618 {
644 Lisp_Object success; 619 Lisp_Object success;
645 620
646 if (!loaded) 621 if (!loaded)
647 success = Qnil; 622 success = Qnil;
648 else 623 else
649 { 624 {
650 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs. 625 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
651 The initialized data segment is read-only. */ 626 The initialized data segment is read-only. */
652 struct image_type *p = (struct image_type *) xmalloc (sizeof *p); 627 struct image_type *p = (struct image_type *) xmalloc (sizeof *p);
653 bcopy (type, p, sizeof *p); 628 memcpy (p, type, sizeof *p);
654 p->next = image_types; 629 p->next = image_types;
655 image_types = p; 630 image_types = p;
656 success = Qt; 631 success = Qt;
657 } 632 }
658 633
663 638
664 /* Look up image type SYMBOL, and return a pointer to its image_type 639 /* Look up image type SYMBOL, and return a pointer to its image_type
665 structure. Value is null if SYMBOL is not a known image type. */ 640 structure. Value is null if SYMBOL is not a known image type. */
666 641
667 static INLINE struct image_type * 642 static INLINE struct image_type *
668 lookup_image_type (symbol) 643 lookup_image_type (Lisp_Object symbol)
669 Lisp_Object symbol;
670 { 644 {
671 struct image_type *type; 645 struct image_type *type;
672 646
673 /* We must initialize the image-type if it hasn't been already. */ 647 /* We must initialize the image-type if it hasn't been already. */
674 if (NILP (Finit_image_library (symbol, Vimage_library_alist))) 648 if (NILP (Finit_image_library (symbol, Vimage_library_alist)))
688 contain a value for key `:type'. That value must be the name of a 662 contain a value for key `:type'. That value must be the name of a
689 supported image type. The rest of the property list depends on the 663 supported image type. The rest of the property list depends on the
690 image type. */ 664 image type. */
691 665
692 int 666 int
693 valid_image_p (object) 667 valid_image_p (Lisp_Object object)
694 Lisp_Object object;
695 { 668 {
696 int valid_p = 0; 669 int valid_p = 0;
697 670
698 if (IMAGEP (object)) 671 if (IMAGEP (object))
699 { 672 {
724 good idea because this would interrupt redisplay, and the error 697 good idea because this would interrupt redisplay, and the error
725 message display would lead to another redisplay. This function 698 message display would lead to another redisplay. This function
726 therefore simply displays a message. */ 699 therefore simply displays a message. */
727 700
728 static void 701 static void
729 image_error (format, arg1, arg2) 702 image_error (const char *format, Lisp_Object arg1, Lisp_Object arg2)
730 char *format;
731 Lisp_Object arg1, arg2;
732 { 703 {
733 add_to_log (format, arg1, arg2); 704 add_to_log (format, arg1, arg2);
734 } 705 }
735 706
736 707
758 /* Structure used when parsing image specifications. */ 729 /* Structure used when parsing image specifications. */
759 730
760 struct image_keyword 731 struct image_keyword
761 { 732 {
762 /* Name of keyword. */ 733 /* Name of keyword. */
763 char *name; 734 const char *name;
764 735
765 /* The type of value allowed. */ 736 /* The type of value allowed. */
766 enum image_value_type type; 737 enum image_value_type type;
767 738
768 /* Non-zero means key must be present. */ 739 /* Non-zero means key must be present. */
774 /* The value that was found. */ 745 /* The value that was found. */
775 Lisp_Object value; 746 Lisp_Object value;
776 }; 747 };
777 748
778 749
779 static int parse_image_spec P_ ((Lisp_Object, struct image_keyword *, 750 static int parse_image_spec (Lisp_Object, struct image_keyword *,
780 int, Lisp_Object)); 751 int, Lisp_Object);
781 static Lisp_Object image_spec_value P_ ((Lisp_Object, Lisp_Object, int *)); 752 static Lisp_Object image_spec_value (Lisp_Object, Lisp_Object, int *);
782 753
783 754
784 /* Parse image spec SPEC according to KEYWORDS. A valid image spec 755 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
785 has the format (image KEYWORD VALUE ...). One of the keyword/ 756 has the format (image KEYWORD VALUE ...). One of the keyword/
786 value pairs must be `:type TYPE'. KEYWORDS is a vector of 757 value pairs must be `:type TYPE'. KEYWORDS is a vector of
787 image_keywords structures of size NKEYWORDS describing other 758 image_keywords structures of size NKEYWORDS describing other
788 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */ 759 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
789 760
790 static int 761 static int
791 parse_image_spec (spec, keywords, nkeywords, type) 762 parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
792 Lisp_Object spec; 763 int nkeywords, Lisp_Object type)
793 struct image_keyword *keywords;
794 int nkeywords;
795 Lisp_Object type;
796 { 764 {
797 int i; 765 int i;
798 Lisp_Object plist; 766 Lisp_Object plist;
799 767
800 if (!IMAGEP (spec)) 768 if (!IMAGEP (spec))
926 /* Return the value of KEY in image specification SPEC. Value is nil 894 /* Return the value of KEY in image specification SPEC. Value is nil
927 if KEY is not present in SPEC. if FOUND is not null, set *FOUND 895 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
928 to 1 if KEY was found in SPEC, set it to 0 otherwise. */ 896 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
929 897
930 static Lisp_Object 898 static Lisp_Object
931 image_spec_value (spec, key, found) 899 image_spec_value (Lisp_Object spec, Lisp_Object key, int *found)
932 Lisp_Object spec, key;
933 int *found;
934 { 900 {
935 Lisp_Object tail; 901 Lisp_Object tail;
936 902
937 xassert (valid_image_p (spec)); 903 xassert (valid_image_p (spec));
938 904
954 } 920 }
955 921
956 922
957 DEFUN ("image-size", Fimage_size, Simage_size, 1, 3, 0, 923 DEFUN ("image-size", Fimage_size, Simage_size, 1, 3, 0,
958 doc: /* Return the size of image SPEC as pair (WIDTH . HEIGHT). 924 doc: /* Return the size of image SPEC as pair (WIDTH . HEIGHT).
959 PIXELS non-nil means return the size in pixels, otherwise return the 925 PIXELS non-nil means return the size in pixels, otherwise return the
960 size in canonical character units. 926 size in canonical character units.
961 FRAME is the frame on which the image will be displayed. FRAME nil 927 FRAME is the frame on which the image will be displayed. FRAME nil
962 or omitted means use the selected frame. */) 928 or omitted means use the selected frame. */)
963 (spec, pixels, frame) 929 (Lisp_Object spec, Lisp_Object pixels, Lisp_Object frame)
964 Lisp_Object spec, pixels, frame;
965 { 930 {
966 Lisp_Object size; 931 Lisp_Object size;
967 932
968 size = Qnil; 933 size = Qnil;
969 if (valid_image_p (spec)) 934 if (valid_image_p (spec))
987 } 952 }
988 953
989 954
990 DEFUN ("image-mask-p", Fimage_mask_p, Simage_mask_p, 1, 2, 0, 955 DEFUN ("image-mask-p", Fimage_mask_p, Simage_mask_p, 1, 2, 0,
991 doc: /* Return t if image SPEC has a mask bitmap. 956 doc: /* Return t if image SPEC has a mask bitmap.
992 FRAME is the frame on which the image will be displayed. FRAME nil 957 FRAME is the frame on which the image will be displayed. FRAME nil
993 or omitted means use the selected frame. */) 958 or omitted means use the selected frame. */)
994 (spec, frame) 959 (Lisp_Object spec, Lisp_Object frame)
995 Lisp_Object spec, frame;
996 { 960 {
997 Lisp_Object mask; 961 Lisp_Object mask;
998 962
999 mask = Qnil; 963 mask = Qnil;
1000 if (valid_image_p (spec)) 964 if (valid_image_p (spec))
1011 return mask; 975 return mask;
1012 } 976 }
1013 977
1014 DEFUN ("image-metadata", Fimage_metadata, Simage_metadata, 1, 2, 0, 978 DEFUN ("image-metadata", Fimage_metadata, Simage_metadata, 1, 2, 0,
1015 doc: /* Return metadata for image SPEC. 979 doc: /* Return metadata for image SPEC.
1016 FRAME is the frame on which the image will be displayed. FRAME nil 980 FRAME is the frame on which the image will be displayed. FRAME nil
1017 or omitted means use the selected frame. */) 981 or omitted means use the selected frame. */)
1018 (spec, frame) 982 (Lisp_Object spec, Lisp_Object frame)
1019 Lisp_Object spec, frame;
1020 { 983 {
1021 Lisp_Object ext; 984 Lisp_Object ext;
1022 985
1023 ext = Qnil; 986 ext = Qnil;
1024 if (valid_image_p (spec)) 987 if (valid_image_p (spec))
1035 998
1036 /*********************************************************************** 999 /***********************************************************************
1037 Image type independent image structures 1000 Image type independent image structures
1038 ***********************************************************************/ 1001 ***********************************************************************/
1039 1002
1040 static struct image *make_image P_ ((Lisp_Object spec, unsigned hash)); 1003 static struct image *make_image (Lisp_Object spec, unsigned hash);
1041 static void free_image P_ ((struct frame *f, struct image *img)); 1004 static void free_image (struct frame *f, struct image *img);
1042 static int check_image_size P_ ((struct frame *f, int width, int height)); 1005 static int check_image_size (struct frame *f, int width, int height);
1043 1006
1044 #define MAX_IMAGE_SIZE 6.0 1007 #define MAX_IMAGE_SIZE 6.0
1045 Lisp_Object Vmax_image_size; 1008 Lisp_Object Vmax_image_size;
1046 1009
1047 /* Allocate and return a new image structure for image specification 1010 /* Allocate and return a new image structure for image specification
1048 SPEC. SPEC has a hash value of HASH. */ 1011 SPEC. SPEC has a hash value of HASH. */
1049 1012
1050 static struct image * 1013 static struct image *
1051 make_image (spec, hash) 1014 make_image (Lisp_Object spec, unsigned int hash)
1052 Lisp_Object spec;
1053 unsigned hash;
1054 { 1015 {
1055 struct image *img = (struct image *) xmalloc (sizeof *img); 1016 struct image *img = (struct image *) xmalloc (sizeof *img);
1056 Lisp_Object file = image_spec_value (spec, QCfile, NULL); 1017 Lisp_Object file = image_spec_value (spec, QCfile, NULL);
1057 1018
1058 xassert (valid_image_p (spec)); 1019 xassert (valid_image_p (spec));
1059 bzero (img, sizeof *img); 1020 memset (img, 0, sizeof *img);
1060 img->dependencies = NILP (file) ? Qnil : list1 (file); 1021 img->dependencies = NILP (file) ? Qnil : list1 (file);
1061 img->type = lookup_image_type (image_spec_value (spec, QCtype, NULL)); 1022 img->type = lookup_image_type (image_spec_value (spec, QCtype, NULL));
1062 xassert (img->type != NULL); 1023 xassert (img->type != NULL);
1063 img->spec = spec; 1024 img->spec = spec;
1064 img->data.lisp_val = Qnil; 1025 img->data.lisp_val = Qnil;
1070 1031
1071 1032
1072 /* Free image IMG which was used on frame F, including its resources. */ 1033 /* Free image IMG which was used on frame F, including its resources. */
1073 1034
1074 static void 1035 static void
1075 free_image (f, img) 1036 free_image (struct frame *f, struct image *img)
1076 struct frame *f;
1077 struct image *img;
1078 { 1037 {
1079 if (img) 1038 if (img)
1080 { 1039 {
1081 struct image_cache *c = FRAME_IMAGE_CACHE (f); 1040 struct image_cache *c = FRAME_IMAGE_CACHE (f);
1082 1041
1092 c->images[img->id] = NULL; 1051 c->images[img->id] = NULL;
1093 1052
1094 /* Free resources, then free IMG. */ 1053 /* Free resources, then free IMG. */
1095 img->type->free (f, img); 1054 img->type->free (f, img);
1096 xfree (img); 1055 xfree (img);
1056
1057 /* As display glyphs may still be referring to the image ID, we
1058 must garbage the frame (Bug#6426). */
1059 SET_FRAME_GARBAGED (f);
1097 } 1060 }
1098 } 1061 }
1099 1062
1100 /* Return 1 if the given widths and heights are valid for display; 1063 /* Return 1 if the given widths and heights are valid for display;
1101 otherwise, return 0. */ 1064 otherwise, return 0. */
1102 1065
1103 int 1066 int
1104 check_image_size (f, width, height) 1067 check_image_size (struct frame *f, int width, int height)
1105 struct frame *f;
1106 int width;
1107 int height;
1108 { 1068 {
1109 int w, h; 1069 int w, h;
1110 1070
1111 if (width <= 0 || height <= 0) 1071 if (width <= 0 || height <= 0)
1112 return 0; 1072 return 0;
1133 1093
1134 /* Prepare image IMG for display on frame F. Must be called before 1094 /* Prepare image IMG for display on frame F. Must be called before
1135 drawing an image. */ 1095 drawing an image. */
1136 1096
1137 void 1097 void
1138 prepare_image_for_display (f, img) 1098 prepare_image_for_display (struct frame *f, struct image *img)
1139 struct frame *f;
1140 struct image *img;
1141 { 1099 {
1142 EMACS_TIME t; 1100 EMACS_TIME t;
1143 1101
1144 /* We're about to display IMG, so set its timestamp to `now'. */ 1102 /* We're about to display IMG, so set its timestamp to `now'. */
1145 EMACS_GET_TIME (t); 1103 EMACS_GET_TIME (t);
1155 1113
1156 /* Value is the number of pixels for the ascent of image IMG when 1114 /* Value is the number of pixels for the ascent of image IMG when
1157 drawn in face FACE. */ 1115 drawn in face FACE. */
1158 1116
1159 int 1117 int
1160 image_ascent (img, face, slice) 1118 image_ascent (struct image *img, struct face *face, struct glyph_slice *slice)
1161 struct image *img;
1162 struct face *face;
1163 struct glyph_slice *slice;
1164 { 1119 {
1165 int height; 1120 int height;
1166 int ascent; 1121 int ascent;
1167 1122
1168 if (slice->height == img->height) 1123 if (slice->height == img->height)
1204 1159
1205 /* Find the "best" corner color of a bitmap. 1160 /* Find the "best" corner color of a bitmap.
1206 On W32, XIMG is assumed to a device context with the bitmap selected. */ 1161 On W32, XIMG is assumed to a device context with the bitmap selected. */
1207 1162
1208 static RGB_PIXEL_COLOR 1163 static RGB_PIXEL_COLOR
1209 four_corners_best (ximg, corners, width, height) 1164 four_corners_best (XImagePtr_or_DC ximg, int *corners,
1210 XImagePtr_or_DC ximg; 1165 unsigned long width, unsigned long height)
1211 int *corners;
1212 unsigned long width, height;
1213 { 1166 {
1214 RGB_PIXEL_COLOR corner_pixels[4], best; 1167 RGB_PIXEL_COLOR corner_pixels[4], best;
1215 int i, best_count; 1168 int i, best_count;
1216 1169
1217 if (corners && corners[BOT_CORNER] >= 0) 1170 if (corners && corners[BOT_CORNER] >= 0)
1256 #define Free_Pixmap(display, pixmap) \ 1209 #define Free_Pixmap(display, pixmap) \
1257 DeleteObject (pixmap) 1210 DeleteObject (pixmap)
1258 1211
1259 #elif defined (HAVE_NS) 1212 #elif defined (HAVE_NS)
1260 1213
1261 #define Destroy_Image(ximg, dummy) \ 1214 #define Destroy_Image(ximg, dummy) \
1262 ns_release_object(ximg) 1215 ns_release_object (ximg)
1263 1216
1264 #define Free_Pixmap(display, pixmap) \ 1217 #define Free_Pixmap(display, pixmap) \
1265 ns_release_object(pixmap) 1218 ns_release_object (pixmap)
1266 1219
1267 #else 1220 #else
1268 1221
1269 #define Destroy_Image(ximg, dummy) \ 1222 #define Destroy_Image(ximg, dummy) \
1270 XDestroyImage (ximg) 1223 XDestroyImage (ximg)
1279 it is guessed heuristically. If non-zero, XIMG is an existing 1232 it is guessed heuristically. If non-zero, XIMG is an existing
1280 XImage object (or device context with the image selected on W32) to 1233 XImage object (or device context with the image selected on W32) to
1281 use for the heuristic. */ 1234 use for the heuristic. */
1282 1235
1283 RGB_PIXEL_COLOR 1236 RGB_PIXEL_COLOR
1284 image_background (img, f, ximg) 1237 image_background (struct image *img, struct frame *f, XImagePtr_or_DC ximg)
1285 struct image *img;
1286 struct frame *f;
1287 XImagePtr_or_DC ximg;
1288 { 1238 {
1289 if (! img->background_valid) 1239 if (! img->background_valid)
1290 /* IMG doesn't have a background yet, try to guess a reasonable value. */ 1240 /* IMG doesn't have a background yet, try to guess a reasonable value. */
1291 { 1241 {
1292 int free_ximg = !ximg; 1242 int free_ximg = !ximg;
1321 /* Return the `background_transparent' field of IMG. If IMG doesn't 1271 /* Return the `background_transparent' field of IMG. If IMG doesn't
1322 have one yet, it is guessed heuristically. If non-zero, MASK is an 1272 have one yet, it is guessed heuristically. If non-zero, MASK is an
1323 existing XImage object to use for the heuristic. */ 1273 existing XImage object to use for the heuristic. */
1324 1274
1325 int 1275 int
1326 image_background_transparent (img, f, mask) 1276 image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_DC mask)
1327 struct image *img;
1328 struct frame *f;
1329 XImagePtr_or_DC mask;
1330 { 1277 {
1331 if (! img->background_transparent_valid) 1278 if (! img->background_transparent_valid)
1332 /* IMG doesn't have a background yet, try to guess a reasonable value. */ 1279 /* IMG doesn't have a background yet, try to guess a reasonable value. */
1333 { 1280 {
1334 if (img->mask) 1281 if (img->mask)
1369 1316
1370 /*********************************************************************** 1317 /***********************************************************************
1371 Helper functions for X image types 1318 Helper functions for X image types
1372 ***********************************************************************/ 1319 ***********************************************************************/
1373 1320
1374 static void x_clear_image_1 P_ ((struct frame *, struct image *, int, 1321 static void x_clear_image_1 (struct frame *, struct image *, int,
1375 int, int)); 1322 int, int);
1376 static void x_clear_image P_ ((struct frame *f, struct image *img)); 1323 static void x_clear_image (struct frame *f, struct image *img);
1377 static unsigned long x_alloc_image_color P_ ((struct frame *f, 1324 static unsigned long x_alloc_image_color (struct frame *f,
1378 struct image *img, 1325 struct image *img,
1379 Lisp_Object color_name, 1326 Lisp_Object color_name,
1380 unsigned long dflt)); 1327 unsigned long dflt);
1381 1328
1382 1329
1383 /* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means 1330 /* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
1384 free the pixmap if any. MASK_P non-zero means clear the mask 1331 free the pixmap if any. MASK_P non-zero means clear the mask
1385 pixmap if any. COLORS_P non-zero means free colors allocated for 1332 pixmap if any. COLORS_P non-zero means free colors allocated for
1386 the image, if any. */ 1333 the image, if any. */
1387 1334
1388 static void 1335 static void
1389 x_clear_image_1 (f, img, pixmap_p, mask_p, colors_p) 1336 x_clear_image_1 (struct frame *f, struct image *img, int pixmap_p, int mask_p,
1390 struct frame *f; 1337 int colors_p)
1391 struct image *img;
1392 int pixmap_p, mask_p, colors_p;
1393 { 1338 {
1394 if (pixmap_p && img->pixmap) 1339 if (pixmap_p && img->pixmap)
1395 { 1340 {
1396 Free_Pixmap (FRAME_X_DISPLAY (f), img->pixmap); 1341 Free_Pixmap (FRAME_X_DISPLAY (f), img->pixmap);
1397 img->pixmap = NO_PIXMAP; 1342 img->pixmap = NO_PIXMAP;
1420 } 1365 }
1421 1366
1422 /* Free X resources of image IMG which is used on frame F. */ 1367 /* Free X resources of image IMG which is used on frame F. */
1423 1368
1424 static void 1369 static void
1425 x_clear_image (f, img) 1370 x_clear_image (struct frame *f, struct image *img)
1426 struct frame *f;
1427 struct image *img;
1428 { 1371 {
1429 BLOCK_INPUT; 1372 BLOCK_INPUT;
1430 x_clear_image_1 (f, img, 1, 1, 1); 1373 x_clear_image_1 (f, img, 1, 1, 1);
1431 UNBLOCK_INPUT; 1374 UNBLOCK_INPUT;
1432 } 1375 }
1436 cannot be allocated, use DFLT. Add a newly allocated color to 1379 cannot be allocated, use DFLT. Add a newly allocated color to
1437 IMG->colors, so that it can be freed again. Value is the pixel 1380 IMG->colors, so that it can be freed again. Value is the pixel
1438 color. */ 1381 color. */
1439 1382
1440 static unsigned long 1383 static unsigned long
1441 x_alloc_image_color (f, img, color_name, dflt) 1384 x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name,
1442 struct frame *f; 1385 unsigned long dflt)
1443 struct image *img;
1444 Lisp_Object color_name;
1445 unsigned long dflt;
1446 { 1386 {
1447 XColor color; 1387 XColor color;
1448 unsigned long result; 1388 unsigned long result;
1449 1389
1450 xassert (STRINGP (color_name)); 1390 xassert (STRINGP (color_name));
1470 1410
1471 /*********************************************************************** 1411 /***********************************************************************
1472 Image Cache 1412 Image Cache
1473 ***********************************************************************/ 1413 ***********************************************************************/
1474 1414
1475 static struct image *search_image_cache P_ ((struct frame *, Lisp_Object, unsigned)); 1415 static struct image *search_image_cache (struct frame *, Lisp_Object, unsigned);
1476 static void cache_image P_ ((struct frame *f, struct image *img)); 1416 static void cache_image (struct frame *f, struct image *img);
1477 static void postprocess_image P_ ((struct frame *, struct image *)); 1417 static void postprocess_image (struct frame *, struct image *);
1478 1418
1479 /* Return a new, initialized image cache that is allocated from the 1419 /* Return a new, initialized image cache that is allocated from the
1480 heap. Call free_image_cache to free an image cache. */ 1420 heap. Call free_image_cache to free an image cache. */
1481 1421
1482 struct image_cache * 1422 struct image_cache *
1483 make_image_cache () 1423 make_image_cache (void)
1484 { 1424 {
1485 struct image_cache *c = (struct image_cache *) xmalloc (sizeof *c); 1425 struct image_cache *c = (struct image_cache *) xmalloc (sizeof *c);
1486 int size; 1426 int size;
1487 1427
1488 bzero (c, sizeof *c); 1428 memset (c, 0, sizeof *c);
1489 c->size = 50; 1429 c->size = 50;
1490 c->images = (struct image **) xmalloc (c->size * sizeof *c->images); 1430 c->images = (struct image **) xmalloc (c->size * sizeof *c->images);
1491 size = IMAGE_CACHE_BUCKETS_SIZE * sizeof *c->buckets; 1431 size = IMAGE_CACHE_BUCKETS_SIZE * sizeof *c->buckets;
1492 c->buckets = (struct image **) xmalloc (size); 1432 c->buckets = (struct image **) xmalloc (size);
1493 bzero (c->buckets, size); 1433 memset (c->buckets, 0, size);
1494 return c; 1434 return c;
1495 } 1435 }
1496 1436
1497 1437
1498 /* Find an image matching SPEC in the cache, and return it. If no 1438 /* Find an image matching SPEC in the cache, and return it. If no
1499 image is found, return NULL. */ 1439 image is found, return NULL. */
1500 static struct image * 1440 static struct image *
1501 search_image_cache (f, spec, hash) 1441 search_image_cache (struct frame *f, Lisp_Object spec, unsigned int hash)
1502 struct frame *f;
1503 Lisp_Object spec;
1504 unsigned hash;
1505 { 1442 {
1506 struct image *img; 1443 struct image *img;
1507 struct image_cache *c = FRAME_IMAGE_CACHE (f); 1444 struct image_cache *c = FRAME_IMAGE_CACHE (f);
1508 int i = hash % IMAGE_CACHE_BUCKETS_SIZE; 1445 int i = hash % IMAGE_CACHE_BUCKETS_SIZE;
1509 1446
1532 1469
1533 1470
1534 /* Search frame F for an image with spec SPEC, and free it. */ 1471 /* Search frame F for an image with spec SPEC, and free it. */
1535 1472
1536 static void 1473 static void
1537 uncache_image (f, spec) 1474 uncache_image (struct frame *f, Lisp_Object spec)
1538 struct frame *f;
1539 Lisp_Object spec;
1540 { 1475 {
1541 struct image *img = search_image_cache (f, spec, sxhash (spec, 0)); 1476 struct image *img = search_image_cache (f, spec, sxhash (spec, 0));
1542 if (img) 1477 if (img)
1543 free_image (f, img); 1478 free_image (f, img);
1544 } 1479 }
1546 1481
1547 /* Free image cache of frame F. Be aware that X frames share images 1482 /* Free image cache of frame F. Be aware that X frames share images
1548 caches. */ 1483 caches. */
1549 1484
1550 void 1485 void
1551 free_image_cache (f) 1486 free_image_cache (struct frame *f)
1552 struct frame *f;
1553 { 1487 {
1554 struct image_cache *c = FRAME_IMAGE_CACHE (f); 1488 struct image_cache *c = FRAME_IMAGE_CACHE (f);
1555 if (c) 1489 if (c)
1556 { 1490 {
1557 int i; 1491 int i;
1671 } 1605 }
1672 1606
1673 DEFUN ("clear-image-cache", Fclear_image_cache, Sclear_image_cache, 1607 DEFUN ("clear-image-cache", Fclear_image_cache, Sclear_image_cache,
1674 0, 1, 0, 1608 0, 1, 0,
1675 doc: /* Clear the image cache. 1609 doc: /* Clear the image cache.
1676 FILTER nil or a frame means clear all images in the selected frame. 1610 FILTER nil or a frame means clear all images in the selected frame.
1677 FILTER t means clear the image caches of all frames. 1611 FILTER t means clear the image caches of all frames.
1678 Anything else, means only clear those images which refer to FILTER, 1612 Anything else, means only clear those images which refer to FILTER,
1679 which is then usually a filename. */) 1613 which is then usually a filename. */)
1680 (filter) 1614 (Lisp_Object filter)
1681 Lisp_Object filter;
1682 { 1615 {
1683 if (!(EQ (filter, Qnil) || FRAMEP (filter))) 1616 if (!(EQ (filter, Qnil) || FRAMEP (filter)))
1684 clear_image_caches (filter); 1617 clear_image_caches (filter);
1685 else 1618 else
1686 clear_image_cache (check_x_frame (filter), Qt); 1619 clear_image_cache (check_x_frame (filter), Qt);
1694 doc: /* Fush the image with specification SPEC on frame FRAME. 1627 doc: /* Fush the image with specification SPEC on frame FRAME.
1695 This removes the image from the Emacs image cache. If SPEC specifies 1628 This removes the image from the Emacs image cache. If SPEC specifies
1696 an image file, the next redisplay of this image will read from the 1629 an image file, the next redisplay of this image will read from the
1697 current contents of that file. 1630 current contents of that file.
1698 1631
1699 FRAME nil or omitted means use the selected frame. 1632 FRAME nil or omitted means use the selected frame.
1700 FRAME t means refresh the image on all frames. */) 1633 FRAME t means refresh the image on all frames. */)
1701 (spec, frame) 1634 (Lisp_Object spec, Lisp_Object frame)
1702 Lisp_Object spec, frame;
1703 { 1635 {
1704 if (!valid_image_p (spec)) 1636 if (!valid_image_p (spec))
1705 error ("Invalid image specification"); 1637 error ("Invalid image specification");
1706 1638
1707 if (EQ (frame, Qt)) 1639 if (EQ (frame, Qt))
1723 1655
1724 /* Compute masks and transform image IMG on frame F, as specified 1656 /* Compute masks and transform image IMG on frame F, as specified
1725 by the image's specification, */ 1657 by the image's specification, */
1726 1658
1727 static void 1659 static void
1728 postprocess_image (f, img) 1660 postprocess_image (struct frame *f, struct image *img)
1729 struct frame *f;
1730 struct image *img;
1731 { 1661 {
1732 /* Manipulation of the image's mask. */ 1662 /* Manipulation of the image's mask. */
1733 if (img->pixmap) 1663 if (img->pixmap)
1734 { 1664 {
1735 Lisp_Object conversion, spec; 1665 Lisp_Object conversion, spec;
1798 1728
1799 /* Return the id of image with Lisp specification SPEC on frame F. 1729 /* Return the id of image with Lisp specification SPEC on frame F.
1800 SPEC must be a valid Lisp image specification (see valid_image_p). */ 1730 SPEC must be a valid Lisp image specification (see valid_image_p). */
1801 1731
1802 int 1732 int
1803 lookup_image (f, spec) 1733 lookup_image (struct frame *f, Lisp_Object spec)
1804 struct frame *f;
1805 Lisp_Object spec;
1806 { 1734 {
1807 struct image_cache *c; 1735 struct image_cache *c;
1808 struct image *img; 1736 struct image *img;
1809 unsigned hash; 1737 unsigned hash;
1810 struct gcpro gcpro1; 1738 struct gcpro gcpro1;
1829 } 1757 }
1830 1758
1831 /* If not found, create a new image and cache it. */ 1759 /* If not found, create a new image and cache it. */
1832 if (img == NULL) 1760 if (img == NULL)
1833 { 1761 {
1834 extern Lisp_Object Qpostscript;
1835
1836 BLOCK_INPUT; 1762 BLOCK_INPUT;
1837 img = make_image (spec, hash); 1763 img = make_image (spec, hash);
1838 cache_image (f, img); 1764 cache_image (f, img);
1839 img->load_failed_p = img->type->load (f, img) == 0; 1765 img->load_failed_p = img->type->load (f, img) == 0;
1840 img->frame_foreground = FRAME_FOREGROUND_PIXEL (f); 1766 img->frame_foreground = FRAME_FOREGROUND_PIXEL (f);
1920 1846
1921 1847
1922 /* Cache image IMG in the image cache of frame F. */ 1848 /* Cache image IMG in the image cache of frame F. */
1923 1849
1924 static void 1850 static void
1925 cache_image (f, img) 1851 cache_image (struct frame *f, struct image *img)
1926 struct frame *f;
1927 struct image *img;
1928 { 1852 {
1929 struct image_cache *c = FRAME_IMAGE_CACHE (f); 1853 struct image_cache *c = FRAME_IMAGE_CACHE (f);
1930 int i; 1854 int i;
1931 1855
1932 /* Find a free slot in c->images. */ 1856 /* Find a free slot in c->images. */
1962 Lisp Objects in the image cache. */ 1886 Lisp Objects in the image cache. */
1963 1887
1964 /* Mark Lisp objects in image IMG. */ 1888 /* Mark Lisp objects in image IMG. */
1965 1889
1966 static void 1890 static void
1967 mark_image (img) 1891 mark_image (struct image *img)
1968 struct image *img;
1969 { 1892 {
1970 mark_object (img->spec); 1893 mark_object (img->spec);
1971 mark_object (img->dependencies); 1894 mark_object (img->dependencies);
1972 1895
1973 if (!NILP (img->data.lisp_val)) 1896 if (!NILP (img->data.lisp_val))
2031 return library; 1954 return library;
2032 } 1955 }
2033 1956
2034 #endif /* HAVE_NTGUI */ 1957 #endif /* HAVE_NTGUI */
2035 1958
2036 static int x_create_x_image_and_pixmap P_ ((struct frame *, int, int, int, 1959 static int x_create_x_image_and_pixmap (struct frame *, int, int, int,
2037 XImagePtr *, Pixmap *)); 1960 XImagePtr *, Pixmap *);
2038 static void x_destroy_x_image P_ ((XImagePtr)); 1961 static void x_destroy_x_image (XImagePtr);
2039 static void x_put_x_image P_ ((struct frame *, XImagePtr, Pixmap, int, int)); 1962 static void x_put_x_image (struct frame *, XImagePtr, Pixmap, int, int);
2040 1963
2041 1964
2042 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on 1965 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
2043 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created. 1966 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
2044 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated 1967 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
2047 1970
2048 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH 1971 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH
2049 should indicate the bit depth of the image. */ 1972 should indicate the bit depth of the image. */
2050 1973
2051 static int 1974 static int
2052 x_create_x_image_and_pixmap (f, width, height, depth, ximg, pixmap) 1975 x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
2053 struct frame *f; 1976 XImagePtr *ximg, Pixmap *pixmap)
2054 int width, height, depth;
2055 XImagePtr *ximg;
2056 Pixmap *pixmap;
2057 { 1977 {
2058 #ifdef HAVE_X_WINDOWS 1978 #ifdef HAVE_X_WINDOWS
2059 Display *display = FRAME_X_DISPLAY (f); 1979 Display *display = FRAME_X_DISPLAY (f);
2060 Window window = FRAME_X_WINDOW (f); 1980 Window window = FRAME_X_WINDOW (f);
2061 Screen *screen = FRAME_X_SCREEN (f); 1981 Screen *screen = FRAME_X_SCREEN (f);
2123 { 2043 {
2124 image_error ("Unable to allocate memory for XImage", Qnil, Qnil); 2044 image_error ("Unable to allocate memory for XImage", Qnil, Qnil);
2125 return 0; 2045 return 0;
2126 } 2046 }
2127 2047
2128 header = &((*ximg)->info.bmiHeader); 2048 header = &(*ximg)->info.bmiHeader;
2129 bzero (&((*ximg)->info), sizeof (BITMAPINFO)); 2049 memset (&(*ximg)->info, 0, sizeof (BITMAPINFO));
2130 header->biSize = sizeof (*header); 2050 header->biSize = sizeof (*header);
2131 header->biWidth = width; 2051 header->biWidth = width;
2132 header->biHeight = -height; /* negative indicates a top-down bitmap. */ 2052 header->biHeight = -height; /* negative indicates a top-down bitmap. */
2133 header->biPlanes = 1; 2053 header->biPlanes = 1;
2134 header->biBitCount = depth; 2054 header->biBitCount = depth;
2174 return 1; 2094 return 1;
2175 2095
2176 #endif /* HAVE_NTGUI */ 2096 #endif /* HAVE_NTGUI */
2177 2097
2178 #ifdef HAVE_NS 2098 #ifdef HAVE_NS
2179 *pixmap = ns_image_for_XPM(width, height, depth); 2099 *pixmap = ns_image_for_XPM (width, height, depth);
2180 if (*pixmap == 0) 2100 if (*pixmap == 0)
2181 { 2101 {
2182 *ximg = NULL; 2102 *ximg = NULL;
2183 image_error ("Unable to allocate NSImage for XPM pixmap", Qnil, Qnil); 2103 image_error ("Unable to allocate NSImage for XPM pixmap", Qnil, Qnil);
2184 return 0; 2104 return 0;
2190 2110
2191 2111
2192 /* Destroy XImage XIMG. Free XIMG->data. */ 2112 /* Destroy XImage XIMG. Free XIMG->data. */
2193 2113
2194 static void 2114 static void
2195 x_destroy_x_image (ximg) 2115 x_destroy_x_image (XImagePtr ximg)
2196 XImagePtr ximg;
2197 { 2116 {
2198 xassert (interrupt_input_blocked); 2117 xassert (interrupt_input_blocked);
2199 if (ximg) 2118 if (ximg)
2200 { 2119 {
2201 #ifdef HAVE_X_WINDOWS 2120 #ifdef HAVE_X_WINDOWS
2207 /* Data will be freed by DestroyObject. */ 2126 /* Data will be freed by DestroyObject. */
2208 ximg->data = NULL; 2127 ximg->data = NULL;
2209 xfree (ximg); 2128 xfree (ximg);
2210 #endif /* HAVE_NTGUI */ 2129 #endif /* HAVE_NTGUI */
2211 #ifdef HAVE_NS 2130 #ifdef HAVE_NS
2212 ns_release_object(ximg); 2131 ns_release_object (ximg);
2213 #endif /* HAVE_NS */ 2132 #endif /* HAVE_NS */
2214 } 2133 }
2215 } 2134 }
2216 2135
2217 2136
2218 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT 2137 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
2219 are width and height of both the image and pixmap. */ 2138 are width and height of both the image and pixmap. */
2220 2139
2221 static void 2140 static void
2222 x_put_x_image (f, ximg, pixmap, width, height) 2141 x_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int height)
2223 struct frame *f;
2224 XImagePtr ximg;
2225 Pixmap pixmap;
2226 int width, height;
2227 { 2142 {
2228 #ifdef HAVE_X_WINDOWS 2143 #ifdef HAVE_X_WINDOWS
2229 GC gc; 2144 GC gc;
2230 2145
2231 xassert (interrupt_input_blocked); 2146 xassert (interrupt_input_blocked);
2242 #endif 2157 #endif
2243 #endif /* HAVE_NTGUI */ 2158 #endif /* HAVE_NTGUI */
2244 2159
2245 #ifdef HAVE_NS 2160 #ifdef HAVE_NS
2246 xassert (ximg == pixmap); 2161 xassert (ximg == pixmap);
2247 ns_retain_object(ximg); 2162 ns_retain_object (ximg);
2248 #endif 2163 #endif
2249 } 2164 }
2250 2165
2251 2166
2252 /*********************************************************************** 2167 /***********************************************************************
2253 File Handling 2168 File Handling
2254 ***********************************************************************/ 2169 ***********************************************************************/
2255 2170
2256 static unsigned char *slurp_file P_ ((char *, int *)); 2171 static unsigned char *slurp_file (char *, int *);
2257 2172
2258 2173
2259 /* Find image file FILE. Look in data-directory/images, then 2174 /* Find image file FILE. Look in data-directory/images, then
2260 x-bitmap-file-path. Value is the encoded full name of the file 2175 x-bitmap-file-path. Value is the encoded full name of the file
2261 found, or nil if not found. */ 2176 found, or nil if not found. */
2262 2177
2263 Lisp_Object 2178 Lisp_Object
2264 x_find_image_file (file) 2179 x_find_image_file (Lisp_Object file)
2265 Lisp_Object file;
2266 { 2180 {
2267 Lisp_Object file_found, search_path; 2181 Lisp_Object file_found, search_path;
2268 struct gcpro gcpro1, gcpro2; 2182 struct gcpro gcpro1, gcpro2;
2269 int fd; 2183 int fd;
2270 2184
2295 /* Read FILE into memory. Value is a pointer to a buffer allocated 2209 /* Read FILE into memory. Value is a pointer to a buffer allocated
2296 with xmalloc holding FILE's contents. Value is null if an error 2210 with xmalloc holding FILE's contents. Value is null if an error
2297 occurred. *SIZE is set to the size of the file. */ 2211 occurred. *SIZE is set to the size of the file. */
2298 2212
2299 static unsigned char * 2213 static unsigned char *
2300 slurp_file (file, size) 2214 slurp_file (char *file, int *size)
2301 char *file;
2302 int *size;
2303 { 2215 {
2304 FILE *fp = NULL; 2216 FILE *fp = NULL;
2305 unsigned char *buf = NULL; 2217 unsigned char *buf = NULL;
2306 struct stat st; 2218 struct stat st;
2307 2219
2331 2243
2332 /*********************************************************************** 2244 /***********************************************************************
2333 XBM images 2245 XBM images
2334 ***********************************************************************/ 2246 ***********************************************************************/
2335 2247
2336 static int xbm_scan P_ ((unsigned char **, unsigned char *, char *, int *)); 2248 static int xbm_scan (unsigned char **, unsigned char *, char *, int *);
2337 static int xbm_load P_ ((struct frame *f, struct image *img)); 2249 static int xbm_load (struct frame *f, struct image *img);
2338 static int xbm_load_image P_ ((struct frame *f, struct image *img, 2250 static int xbm_load_image (struct frame *f, struct image *img,
2339 unsigned char *, unsigned char *)); 2251 unsigned char *, unsigned char *);
2340 static int xbm_image_p P_ ((Lisp_Object object)); 2252 static int xbm_image_p (Lisp_Object object);
2341 static int xbm_read_bitmap_data P_ ((struct frame *f, 2253 static int xbm_read_bitmap_data (struct frame *f,
2342 unsigned char *, unsigned char *, 2254 unsigned char *, unsigned char *,
2343 int *, int *, unsigned char **, int)); 2255 int *, int *, unsigned char **, int);
2344 static int xbm_file_p P_ ((Lisp_Object)); 2256 static int xbm_file_p (Lisp_Object);
2345 2257
2346 2258
2347 /* Indices of image specification fields in xbm_format, below. */ 2259 /* Indices of image specification fields in xbm_format, below. */
2348 2260
2349 enum xbm_keyword_index 2261 enum xbm_keyword_index
2432 `:background COLOR' and `:foreground COLOR'. If not present, 2344 `:background COLOR' and `:foreground COLOR'. If not present,
2433 foreground and background of the frame on which the image is 2345 foreground and background of the frame on which the image is
2434 displayed is used. */ 2346 displayed is used. */
2435 2347
2436 static int 2348 static int
2437 xbm_image_p (object) 2349 xbm_image_p (Lisp_Object object)
2438 Lisp_Object object;
2439 { 2350 {
2440 struct image_keyword kw[XBM_LAST]; 2351 struct image_keyword kw[XBM_LAST];
2441 2352
2442 bcopy (xbm_format, kw, sizeof kw); 2353 memcpy (kw, xbm_format, sizeof kw);
2443 if (!parse_image_spec (object, kw, XBM_LAST, Qxbm)) 2354 if (!parse_image_spec (object, kw, XBM_LAST, Qxbm))
2444 return 0; 2355 return 0;
2445 2356
2446 xassert (EQ (kw[XBM_TYPE].value, Qxbm)); 2357 xassert (EQ (kw[XBM_TYPE].value, Qxbm));
2447 2358
2526 single-character token, or 0 at end of file. If scanning an 2437 single-character token, or 0 at end of file. If scanning an
2527 identifier, store the lexeme of the identifier in SVAL. If 2438 identifier, store the lexeme of the identifier in SVAL. If
2528 scanning a number, store its value in *IVAL. */ 2439 scanning a number, store its value in *IVAL. */
2529 2440
2530 static int 2441 static int
2531 xbm_scan (s, end, sval, ival) 2442 xbm_scan (unsigned char **s, unsigned char *end, char *sval, int *ival)
2532 unsigned char **s, *end;
2533 char *sval;
2534 int *ival;
2535 { 2443 {
2536 unsigned int c; 2444 unsigned int c;
2537 2445
2538 loop: 2446 loop:
2539 2447
2630 HBITMAP bmp; 2538 HBITMAP bmp;
2631 2539
2632 w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */ 2540 w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */
2633 w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */ 2541 w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */
2634 bits = (unsigned char *) alloca (height * w2); 2542 bits = (unsigned char *) alloca (height * w2);
2635 bzero (bits, height * w2); 2543 memset (bits, 0, height * w2);
2636 for (i = 0; i < height; i++) 2544 for (i = 0; i < height; i++)
2637 { 2545 {
2638 p = bits + i*w2; 2546 p = bits + i*w2;
2639 for (j = 0; j < w1; j++) 2547 for (j = 0; j < w1; j++)
2640 { 2548 {
2648 2556
2649 return bmp; 2557 return bmp;
2650 } 2558 }
2651 2559
2652 static void 2560 static void
2653 convert_mono_to_color_image (f, img, foreground, background) 2561 convert_mono_to_color_image (struct frame *f, struct image *img,
2654 struct frame *f; 2562 COLORREF foreground, COLORREF background)
2655 struct image *img;
2656 COLORREF foreground, background;
2657 { 2563 {
2658 HDC hdc, old_img_dc, new_img_dc; 2564 HDC hdc, old_img_dc, new_img_dc;
2659 HGDIOBJ old_prev, new_prev; 2565 HGDIOBJ old_prev, new_prev;
2660 HBITMAP new_pixmap; 2566 HBITMAP new_pixmap;
2661 2567
2693 2599
2694 #endif /* HAVE_NTGUI */ 2600 #endif /* HAVE_NTGUI */
2695 2601
2696 2602
2697 static void 2603 static void
2698 Create_Pixmap_From_Bitmap_Data (f, img, data, fg, bg, non_default_colors) 2604 Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
2699 struct frame *f; 2605 RGB_PIXEL_COLOR fg, RGB_PIXEL_COLOR bg,
2700 struct image *img; 2606 int non_default_colors)
2701 char *data;
2702 RGB_PIXEL_COLOR fg, bg;
2703 int non_default_colors;
2704 { 2607 {
2705 #ifdef HAVE_NTGUI 2608 #ifdef HAVE_NTGUI
2706 img->pixmap 2609 img->pixmap
2707 = w32_create_pixmap_from_bitmap_data (img->width, img->height, data); 2610 = w32_create_pixmap_from_bitmap_data (img->width, img->height, data);
2708 2611
2709 /* If colors were specified, transfer the bitmap to a color one. */ 2612 /* If colors were specified, transfer the bitmap to a color one. */
2710 if (non_default_colors) 2613 if (non_default_colors)
2711 convert_mono_to_color_image (f, img, fg, bg); 2614 convert_mono_to_color_image (f, img, fg, bg);
2712 2615
2713 #elif defined (HAVE_NS) 2616 #elif defined (HAVE_NS)
2714 img->pixmap = ns_image_from_XBM(data, img->width, img->height); 2617 img->pixmap = ns_image_from_XBM (data, img->width, img->height);
2715 2618
2716 #else 2619 #else
2717 img->pixmap 2620 img->pixmap
2718 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), 2621 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f),
2719 FRAME_X_WINDOW (f), 2622 FRAME_X_WINDOW (f),
2734 CONTENTS looks like an in-memory XBM file. If INHIBIT_IMAGE_ERROR 2637 CONTENTS looks like an in-memory XBM file. If INHIBIT_IMAGE_ERROR
2735 is non-zero, inhibit the call to image_error when the image size is 2638 is non-zero, inhibit the call to image_error when the image size is
2736 invalid (the bitmap remains unread). */ 2639 invalid (the bitmap remains unread). */
2737 2640
2738 static int 2641 static int
2739 xbm_read_bitmap_data (f, contents, end, width, height, data, inhibit_image_error) 2642 xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *end,
2740 struct frame *f; 2643 int *width, int *height, unsigned char **data,
2741 unsigned char *contents, *end; 2644 int inhibit_image_error)
2742 int *width, *height;
2743 unsigned char **data;
2744 int inhibit_image_error;
2745 { 2645 {
2746 unsigned char *s = contents; 2646 unsigned char *s = contents;
2747 char buffer[BUFSIZ]; 2647 char buffer[BUFSIZ];
2748 int padding_p = 0; 2648 int padding_p = 0;
2749 int v10 = 0; 2649 int v10 = 0;
2888 /* Load XBM image IMG which will be displayed on frame F from buffer 2788 /* Load XBM image IMG which will be displayed on frame F from buffer
2889 CONTENTS. END is the end of the buffer. Value is non-zero if 2789 CONTENTS. END is the end of the buffer. Value is non-zero if
2890 successful. */ 2790 successful. */
2891 2791
2892 static int 2792 static int
2893 xbm_load_image (f, img, contents, end) 2793 xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2894 struct frame *f; 2794 unsigned char *end)
2895 struct image *img;
2896 unsigned char *contents, *end;
2897 { 2795 {
2898 int rc; 2796 int rc;
2899 unsigned char *data; 2797 unsigned char *data;
2900 int success_p = 0; 2798 int success_p = 0;
2901 2799
2947 2845
2948 2846
2949 /* Value is non-zero if DATA looks like an in-memory XBM file. */ 2847 /* Value is non-zero if DATA looks like an in-memory XBM file. */
2950 2848
2951 static int 2849 static int
2952 xbm_file_p (data) 2850 xbm_file_p (Lisp_Object data)
2953 Lisp_Object data;
2954 { 2851 {
2955 int w, h; 2852 int w, h;
2956 return (STRINGP (data) 2853 return (STRINGP (data)
2957 && xbm_read_bitmap_data (NULL, SDATA (data), 2854 && xbm_read_bitmap_data (NULL, SDATA (data),
2958 (SDATA (data) + SBYTES (data)), 2855 (SDATA (data) + SBYTES (data)),
2962 2859
2963 /* Fill image IMG which is used on frame F with pixmap data. Value is 2860 /* Fill image IMG which is used on frame F with pixmap data. Value is
2964 non-zero if successful. */ 2861 non-zero if successful. */
2965 2862
2966 static int 2863 static int
2967 xbm_load (f, img) 2864 xbm_load (struct frame *f, struct image *img)
2968 struct frame *f;
2969 struct image *img;
2970 { 2865 {
2971 int success_p = 0; 2866 int success_p = 0;
2972 Lisp_Object file_name; 2867 Lisp_Object file_name;
2973 2868
2974 xassert (xbm_image_p (img->spec)); 2869 xassert (xbm_image_p (img->spec));
3016 /* See if data looks like an in-memory XBM file. */ 2911 /* See if data looks like an in-memory XBM file. */
3017 data = image_spec_value (img->spec, QCdata, NULL); 2912 data = image_spec_value (img->spec, QCdata, NULL);
3018 in_memory_file_p = xbm_file_p (data); 2913 in_memory_file_p = xbm_file_p (data);
3019 2914
3020 /* Parse the image specification. */ 2915 /* Parse the image specification. */
3021 bcopy (xbm_format, fmt, sizeof fmt); 2916 memcpy (fmt, xbm_format, sizeof fmt);
3022 parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm); 2917 parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm);
3023 xassert (parsed_p); 2918 xassert (parsed_p);
3024 2919
3025 /* Get specified width, and height. */ 2920 /* Get specified width, and height. */
3026 if (!in_memory_file_p) 2921 if (!in_memory_file_p)
3062 p = bits = (char *) alloca (nbytes * img->height); 2957 p = bits = (char *) alloca (nbytes * img->height);
3063 for (i = 0; i < img->height; ++i, p += nbytes) 2958 for (i = 0; i < img->height; ++i, p += nbytes)
3064 { 2959 {
3065 Lisp_Object line = XVECTOR (data)->contents[i]; 2960 Lisp_Object line = XVECTOR (data)->contents[i];
3066 if (STRINGP (line)) 2961 if (STRINGP (line))
3067 bcopy (SDATA (line), p, nbytes); 2962 memcpy (p, SDATA (line), nbytes);
3068 else 2963 else
3069 bcopy (XBOOL_VECTOR (line)->data, p, nbytes); 2964 memcpy (p, XBOOL_VECTOR (line)->data, nbytes);
3070 } 2965 }
3071 } 2966 }
3072 else if (STRINGP (data)) 2967 else if (STRINGP (data))
3073 bits = SDATA (data); 2968 bits = SDATA (data);
3074 else 2969 else
3080 int nbytes, i; 2975 int nbytes, i;
3081 /* Windows mono bitmaps are reversed compared with X. */ 2976 /* Windows mono bitmaps are reversed compared with X. */
3082 invertedBits = bits; 2977 invertedBits = bits;
3083 nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR 2978 nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR
3084 * img->height; 2979 * img->height;
3085 bits = (char *) alloca(nbytes); 2980 bits = (char *) alloca (nbytes);
3086 for (i = 0; i < nbytes; i++) 2981 for (i = 0; i < nbytes; i++)
3087 bits[i] = XBM_BIT_SHUFFLE (invertedBits[i]); 2982 bits[i] = XBM_BIT_SHUFFLE (invertedBits[i]);
3088 } 2983 }
3089 #endif 2984 #endif
3090 /* Create the pixmap. */ 2985 /* Create the pixmap. */
3112 XPM images 3007 XPM images
3113 ***********************************************************************/ 3008 ***********************************************************************/
3114 3009
3115 #if defined (HAVE_XPM) || defined (HAVE_NS) 3010 #if defined (HAVE_XPM) || defined (HAVE_NS)
3116 3011
3117 static int xpm_image_p P_ ((Lisp_Object object)); 3012 static int xpm_image_p (Lisp_Object object);
3118 static int xpm_load P_ ((struct frame *f, struct image *img)); 3013 static int xpm_load (struct frame *f, struct image *img);
3119 static int xpm_valid_color_symbols_p P_ ((Lisp_Object)); 3014 static int xpm_valid_color_symbols_p (Lisp_Object);
3120 3015
3121 #endif /* HAVE_XPM || HAVE_NS */ 3016 #endif /* HAVE_XPM || HAVE_NS */
3122 3017
3123 #ifdef HAVE_XPM 3018 #ifdef HAVE_XPM
3124 #ifdef HAVE_NTGUI 3019 #ifdef HAVE_NTGUI
3205 #endif 3100 #endif
3206 #endif /* HAVE_X_WINDOWS */ 3101 #endif /* HAVE_X_WINDOWS */
3207 3102
3208 #ifdef ALLOC_XPM_COLORS 3103 #ifdef ALLOC_XPM_COLORS
3209 3104
3210 static void xpm_init_color_cache P_ ((struct frame *, XpmAttributes *)); 3105 static void xpm_init_color_cache (struct frame *, XpmAttributes *);
3211 static void xpm_free_color_cache P_ ((void)); 3106 static void xpm_free_color_cache (void);
3212 static int xpm_lookup_color P_ ((struct frame *, char *, XColor *)); 3107 static int xpm_lookup_color (struct frame *, char *, XColor *);
3213 static int xpm_color_bucket P_ ((char *)); 3108 static int xpm_color_bucket (char *);
3214 static struct xpm_cached_color *xpm_cache_color P_ ((struct frame *, char *, 3109 static struct xpm_cached_color *xpm_cache_color (struct frame *, char *,
3215 XColor *, int)); 3110 XColor *, int);
3216 3111
3217 /* An entry in a hash table used to cache color definitions of named 3112 /* An entry in a hash table used to cache color definitions of named
3218 colors. This cache is necessary to speed up XPM image loading in 3113 colors. This cache is necessary to speed up XPM image loading in
3219 case we do color allocations ourselves. Without it, we would need 3114 case we do color allocations ourselves. Without it, we would need
3220 a call to XParseColor per pixel in the image. */ 3115 a call to XParseColor per pixel in the image. */
3238 struct xpm_cached_color **xpm_color_cache; 3133 struct xpm_cached_color **xpm_color_cache;
3239 3134
3240 /* Initialize the color cache. */ 3135 /* Initialize the color cache. */
3241 3136
3242 static void 3137 static void
3243 xpm_init_color_cache (f, attrs) 3138 xpm_init_color_cache (struct frame *f, XpmAttributes *attrs)
3244 struct frame *f;
3245 XpmAttributes *attrs;
3246 { 3139 {
3247 size_t nbytes = XPM_COLOR_CACHE_BUCKETS * sizeof *xpm_color_cache; 3140 size_t nbytes = XPM_COLOR_CACHE_BUCKETS * sizeof *xpm_color_cache;
3248 xpm_color_cache = (struct xpm_cached_color **) xmalloc (nbytes); 3141 xpm_color_cache = (struct xpm_cached_color **) xmalloc (nbytes);
3249 memset (xpm_color_cache, 0, nbytes); 3142 memset (xpm_color_cache, 0, nbytes);
3250 init_color_table (); 3143 init_color_table ();
3266 } 3159 }
3267 3160
3268 /* Free the color cache. */ 3161 /* Free the color cache. */
3269 3162
3270 static void 3163 static void
3271 xpm_free_color_cache () 3164 xpm_free_color_cache (void)
3272 { 3165 {
3273 struct xpm_cached_color *p, *next; 3166 struct xpm_cached_color *p, *next;
3274 int i; 3167 int i;
3275 3168
3276 for (i = 0; i < XPM_COLOR_CACHE_BUCKETS; ++i) 3169 for (i = 0; i < XPM_COLOR_CACHE_BUCKETS; ++i)
3287 3180
3288 /* Return the bucket index for color named COLOR_NAME in the color 3181 /* Return the bucket index for color named COLOR_NAME in the color
3289 cache. */ 3182 cache. */
3290 3183
3291 static int 3184 static int
3292 xpm_color_bucket (color_name) 3185 xpm_color_bucket (char *color_name)
3293 char *color_name;
3294 { 3186 {
3295 unsigned h = 0; 3187 unsigned h = 0;
3296 char *s; 3188 char *s;
3297 3189
3298 for (s = color_name; *s; ++s) 3190 for (s = color_name; *s; ++s)
3304 /* On frame F, cache values COLOR for color with name COLOR_NAME. 3196 /* On frame F, cache values COLOR for color with name COLOR_NAME.
3305 BUCKET, if >= 0, is a precomputed bucket index. Value is the cache 3197 BUCKET, if >= 0, is a precomputed bucket index. Value is the cache
3306 entry added. */ 3198 entry added. */
3307 3199
3308 static struct xpm_cached_color * 3200 static struct xpm_cached_color *
3309 xpm_cache_color (f, color_name, color, bucket) 3201 xpm_cache_color (struct frame *f, char *color_name, XColor *color, int bucket)
3310 struct frame *f;
3311 char *color_name;
3312 XColor *color;
3313 int bucket;
3314 { 3202 {
3315 size_t nbytes; 3203 size_t nbytes;
3316 struct xpm_cached_color *p; 3204 struct xpm_cached_color *p;
3317 3205
3318 if (bucket < 0) 3206 if (bucket < 0)
3331 return the cached definition in *COLOR. Otherwise, make a new 3219 return the cached definition in *COLOR. Otherwise, make a new
3332 entry in the cache and allocate the color. Value is zero if color 3220 entry in the cache and allocate the color. Value is zero if color
3333 allocation failed. */ 3221 allocation failed. */
3334 3222
3335 static int 3223 static int
3336 xpm_lookup_color (f, color_name, color) 3224 xpm_lookup_color (struct frame *f, char *color_name, XColor *color)
3337 struct frame *f;
3338 char *color_name;
3339 XColor *color;
3340 { 3225 {
3341 struct xpm_cached_color *p; 3226 struct xpm_cached_color *p;
3342 int h = xpm_color_bucket (color_name); 3227 int h = xpm_color_bucket (color_name);
3343 3228
3344 for (p = xpm_color_cache[h]; p; p = p->next) 3229 for (p = xpm_color_cache[h]; p; p = p->next)
3356 } 3241 }
3357 /* You get `opaque' at least from ImageMagick converting pbm to xpm 3242 /* You get `opaque' at least from ImageMagick converting pbm to xpm
3358 with transparency, and it's useful. */ 3243 with transparency, and it's useful. */
3359 else if (strcmp ("opaque", color_name) == 0) 3244 else if (strcmp ("opaque", color_name) == 0)
3360 { 3245 {
3361 bzero (color, sizeof (XColor)); /* Is this necessary/correct? */ 3246 memset (color, 0, sizeof (XColor)); /* Is this necessary/correct? */
3362 color->pixel = FRAME_FOREGROUND_PIXEL (f); 3247 color->pixel = FRAME_FOREGROUND_PIXEL (f);
3363 p = xpm_cache_color (f, color_name, color, h); 3248 p = xpm_cache_color (f, color_name, color, h);
3364 } 3249 }
3365 3250
3366 return p != NULL; 3251 return p != NULL;
3371 CLOSURE is a pointer to the frame on which we allocate the 3256 CLOSURE is a pointer to the frame on which we allocate the
3372 color. Return in *COLOR the allocated color. Value is non-zero 3257 color. Return in *COLOR the allocated color. Value is non-zero
3373 if successful. */ 3258 if successful. */
3374 3259
3375 static int 3260 static int
3376 xpm_alloc_color (dpy, cmap, color_name, color, closure) 3261 xpm_alloc_color (Display *dpy, Colormap cmap, char *color_name, XColor *color,
3377 Display *dpy; 3262 void *closure)
3378 Colormap cmap;
3379 char *color_name;
3380 XColor *color;
3381 void *closure;
3382 { 3263 {
3383 return xpm_lookup_color ((struct frame *) closure, color_name, color); 3264 return xpm_lookup_color ((struct frame *) closure, color_name, color);
3384 } 3265 }
3385 3266
3386 3267
3387 /* Callback for freeing NPIXELS colors contained in PIXELS. CLOSURE 3268 /* Callback for freeing NPIXELS colors contained in PIXELS. CLOSURE
3388 is a pointer to the frame on which we allocate the color. Value is 3269 is a pointer to the frame on which we allocate the color. Value is
3389 non-zero if successful. */ 3270 non-zero if successful. */
3390 3271
3391 static int 3272 static int
3392 xpm_free_colors (dpy, cmap, pixels, npixels, closure) 3273 xpm_free_colors (Display *dpy, Colormap cmap, Pixel *pixels, int npixels, void *closure)
3393 Display *dpy;
3394 Colormap cmap;
3395 Pixel *pixels;
3396 int npixels;
3397 void *closure;
3398 { 3274 {
3399 return 1; 3275 return 1;
3400 } 3276 }
3401 3277
3402 #endif /* ALLOC_XPM_COLORS */ 3278 #endif /* ALLOC_XPM_COLORS */
3432 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list 3308 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
3433 for XPM images. Such a list must consist of conses whose car and 3309 for XPM images. Such a list must consist of conses whose car and
3434 cdr are strings. */ 3310 cdr are strings. */
3435 3311
3436 static int 3312 static int
3437 xpm_valid_color_symbols_p (color_symbols) 3313 xpm_valid_color_symbols_p (Lisp_Object color_symbols)
3438 Lisp_Object color_symbols;
3439 { 3314 {
3440 while (CONSP (color_symbols)) 3315 while (CONSP (color_symbols))
3441 { 3316 {
3442 Lisp_Object sym = XCAR (color_symbols); 3317 Lisp_Object sym = XCAR (color_symbols);
3443 if (!CONSP (sym) 3318 if (!CONSP (sym)
3452 3327
3453 3328
3454 /* Value is non-zero if OBJECT is a valid XPM image specification. */ 3329 /* Value is non-zero if OBJECT is a valid XPM image specification. */
3455 3330
3456 static int 3331 static int
3457 xpm_image_p (object) 3332 xpm_image_p (Lisp_Object object)
3458 Lisp_Object object;
3459 { 3333 {
3460 struct image_keyword fmt[XPM_LAST]; 3334 struct image_keyword fmt[XPM_LAST];
3461 bcopy (xpm_format, fmt, sizeof fmt); 3335 memcpy (fmt, xpm_format, sizeof fmt);
3462 return (parse_image_spec (object, fmt, XPM_LAST, Qxpm) 3336 return (parse_image_spec (object, fmt, XPM_LAST, Qxpm)
3463 /* Either `:file' or `:data' must be present. */ 3337 /* Either `:file' or `:data' must be present. */
3464 && fmt[XPM_FILE].count + fmt[XPM_DATA].count == 1 3338 && fmt[XPM_FILE].count + fmt[XPM_DATA].count == 1
3465 /* Either no `:color-symbols' or it's a list of conses 3339 /* Either no `:color-symbols' or it's a list of conses
3466 whose car and cdr are strings. */ 3340 whose car and cdr are strings. */
3470 3344
3471 #endif /* HAVE_XPM || HAVE_NS */ 3345 #endif /* HAVE_XPM || HAVE_NS */
3472 3346
3473 #if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) 3347 #if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
3474 int 3348 int
3475 x_create_bitmap_from_xpm_data (f, bits) 3349 x_create_bitmap_from_xpm_data (struct frame *f, char **bits)
3476 struct frame *f;
3477 char **bits;
3478 { 3350 {
3479 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 3351 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3480 int id, rc; 3352 int id, rc;
3481 XpmAttributes attrs; 3353 XpmAttributes attrs;
3482 Pixmap bitmap, mask; 3354 Pixmap bitmap, mask;
3483 3355
3484 bzero (&attrs, sizeof attrs); 3356 memset (&attrs, 0, sizeof attrs);
3485 3357
3486 attrs.visual = FRAME_X_VISUAL (f); 3358 attrs.visual = FRAME_X_VISUAL (f);
3487 attrs.colormap = FRAME_X_COLORMAP (f); 3359 attrs.colormap = FRAME_X_COLORMAP (f);
3488 attrs.valuemask |= XpmVisual; 3360 attrs.valuemask |= XpmVisual;
3489 attrs.valuemask |= XpmColormap; 3361 attrs.valuemask |= XpmColormap;
3515 non-zero if successful. */ 3387 non-zero if successful. */
3516 3388
3517 #ifdef HAVE_XPM 3389 #ifdef HAVE_XPM
3518 3390
3519 static int 3391 static int
3520 xpm_load (f, img) 3392 xpm_load (struct frame *f, struct image *img)
3521 struct frame *f;
3522 struct image *img;
3523 { 3393 {
3524 int rc; 3394 int rc;
3525 XpmAttributes attrs; 3395 XpmAttributes attrs;
3526 Lisp_Object specified_file, color_symbols; 3396 Lisp_Object specified_file, color_symbols;
3527 #ifdef HAVE_NTGUI 3397 #ifdef HAVE_NTGUI
3529 xpm_XImage * xpm_image = NULL, * xpm_mask = NULL; 3399 xpm_XImage * xpm_image = NULL, * xpm_mask = NULL;
3530 #endif /* HAVE_NTGUI */ 3400 #endif /* HAVE_NTGUI */
3531 3401
3532 /* Configure the XPM lib. Use the visual of frame F. Allocate 3402 /* Configure the XPM lib. Use the visual of frame F. Allocate
3533 close colors. Return colors allocated. */ 3403 close colors. Return colors allocated. */
3534 bzero (&attrs, sizeof attrs); 3404 memset (&attrs, 0, sizeof attrs);
3535 3405
3536 #ifndef HAVE_NTGUI 3406 #ifndef HAVE_NTGUI
3537 attrs.visual = FRAME_X_VISUAL (f); 3407 attrs.visual = FRAME_X_VISUAL (f);
3538 attrs.colormap = FRAME_X_COLORMAP (f); 3408 attrs.colormap = FRAME_X_COLORMAP (f);
3539 attrs.valuemask |= XpmVisual; 3409 attrs.valuemask |= XpmVisual;
3576 ++attrs.numsymbols; 3446 ++attrs.numsymbols;
3577 3447
3578 /* Allocate an XpmColorSymbol array. */ 3448 /* Allocate an XpmColorSymbol array. */
3579 size = attrs.numsymbols * sizeof *xpm_syms; 3449 size = attrs.numsymbols * sizeof *xpm_syms;
3580 xpm_syms = (XpmColorSymbol *) alloca (size); 3450 xpm_syms = (XpmColorSymbol *) alloca (size);
3581 bzero (xpm_syms, size); 3451 memset (xpm_syms, 0, size);
3582 attrs.colorsymbols = xpm_syms; 3452 attrs.colorsymbols = xpm_syms;
3583 3453
3584 /* Fill the color symbol array. */ 3454 /* Fill the color symbol array. */
3585 for (tail = color_symbols, i = 0; 3455 for (tail = color_symbols, i = 0;
3586 CONSP (tail); 3456 CONSP (tail);
3750 #if defined (HAVE_NS) && !defined (HAVE_XPM) 3620 #if defined (HAVE_NS) && !defined (HAVE_XPM)
3751 3621
3752 /* XPM support functions for NS where libxpm is not available. 3622 /* XPM support functions for NS where libxpm is not available.
3753 Only XPM version 3 (without any extensions) is supported. */ 3623 Only XPM version 3 (without any extensions) is supported. */
3754 3624
3755 static int xpm_scan P_ ((const unsigned char **, const unsigned char *, 3625 static int xpm_scan (const unsigned char **, const unsigned char *,
3756 const unsigned char **, int *)); 3626 const unsigned char **, int *);
3757 static Lisp_Object xpm_make_color_table_v 3627 static Lisp_Object xpm_make_color_table_v
3758 P_ ((void (**) (Lisp_Object, const unsigned char *, int, Lisp_Object), 3628 (void (**) (Lisp_Object, const unsigned char *, int, Lisp_Object),
3759 Lisp_Object (**) (Lisp_Object, const unsigned char *, int))); 3629 Lisp_Object (**) (Lisp_Object, const unsigned char *, int));
3760 static void xpm_put_color_table_v P_ ((Lisp_Object, const unsigned char *, 3630 static void xpm_put_color_table_v (Lisp_Object, const unsigned char *,
3761 int, Lisp_Object)); 3631 int, Lisp_Object);
3762 static Lisp_Object xpm_get_color_table_v P_ ((Lisp_Object, 3632 static Lisp_Object xpm_get_color_table_v (Lisp_Object,
3763 const unsigned char *, int)); 3633 const unsigned char *, int);
3764 static Lisp_Object xpm_make_color_table_h 3634 static Lisp_Object xpm_make_color_table_h
3765 P_ ((void (**) (Lisp_Object, const unsigned char *, int, Lisp_Object), 3635 (void (**) (Lisp_Object, const unsigned char *, int, Lisp_Object),
3766 Lisp_Object (**) (Lisp_Object, const unsigned char *, int))); 3636 Lisp_Object (**) (Lisp_Object, const unsigned char *, int));
3767 static void xpm_put_color_table_h P_ ((Lisp_Object, const unsigned char *, 3637 static void xpm_put_color_table_h (Lisp_Object, const unsigned char *,
3768 int, Lisp_Object)); 3638 int, Lisp_Object);
3769 static Lisp_Object xpm_get_color_table_h P_ ((Lisp_Object, 3639 static Lisp_Object xpm_get_color_table_h (Lisp_Object,
3770 const unsigned char *, int)); 3640 const unsigned char *, int);
3771 static int xpm_str_to_color_key P_ ((const char *)); 3641 static int xpm_str_to_color_key (const char *);
3772 static int xpm_load_image P_ ((struct frame *, struct image *, 3642 static int xpm_load_image (struct frame *, struct image *,
3773 const unsigned char *, const unsigned char *)); 3643 const unsigned char *, const unsigned char *);
3774 3644
3775 /* Tokens returned from xpm_scan. */ 3645 /* Tokens returned from xpm_scan. */
3776 3646
3777 enum xpm_token 3647 enum xpm_token
3778 { 3648 {
3787 *S while scanning. If token is either XPM_TK_IDENT or 3657 *S while scanning. If token is either XPM_TK_IDENT or
3788 XPM_TK_STRING, *BEG and *LEN are set to the start address and the 3658 XPM_TK_STRING, *BEG and *LEN are set to the start address and the
3789 length of the corresponding token, respectively. */ 3659 length of the corresponding token, respectively. */
3790 3660
3791 static int 3661 static int
3792 xpm_scan (s, end, beg, len) 3662 xpm_scan (const unsigned char **s,
3793 const unsigned char **s, *end, **beg; 3663 const unsigned char *end,
3794 int *len; 3664 const unsigned char **beg,
3665 int *len)
3795 { 3666 {
3796 int c; 3667 int c;
3797 3668
3798 while (*s < end) 3669 while (*s < end)
3799 { 3670 {
3853 transparency, or Qnil for the unspecified color. If the length of 3724 transparency, or Qnil for the unspecified color. If the length of
3854 the key string is one, a vector is used as a table. Otherwise, a 3725 the key string is one, a vector is used as a table. Otherwise, a
3855 hash table is used. */ 3726 hash table is used. */
3856 3727
3857 static Lisp_Object 3728 static Lisp_Object
3858 xpm_make_color_table_v (put_func, get_func) 3729 xpm_make_color_table_v (void (**put_func) (Lisp_Object,
3859 void (**put_func) (Lisp_Object, const unsigned char *, int, Lisp_Object); 3730 const unsigned char *,
3860 Lisp_Object (**get_func) (Lisp_Object, const unsigned char *, int); 3731 int,
3732 Lisp_Object),
3733 Lisp_Object (**get_func) (Lisp_Object,
3734 const unsigned char *,
3735 int))
3861 { 3736 {
3862 *put_func = xpm_put_color_table_v; 3737 *put_func = xpm_put_color_table_v;
3863 *get_func = xpm_get_color_table_v; 3738 *get_func = xpm_get_color_table_v;
3864 return Fmake_vector (make_number (256), Qnil); 3739 return Fmake_vector (make_number (256), Qnil);
3865 } 3740 }
3866 3741
3867 static void 3742 static void
3868 xpm_put_color_table_v (color_table, chars_start, chars_len, color) 3743 xpm_put_color_table_v (Lisp_Object color_table,
3869 Lisp_Object color_table; 3744 const unsigned char *chars_start,
3870 const unsigned char *chars_start; 3745 int chars_len,
3871 int chars_len; 3746 Lisp_Object color)
3872 Lisp_Object color;
3873 { 3747 {
3874 XVECTOR (color_table)->contents[*chars_start] = color; 3748 XVECTOR (color_table)->contents[*chars_start] = color;
3875 } 3749 }
3876 3750
3877 static Lisp_Object 3751 static Lisp_Object
3878 xpm_get_color_table_v (color_table, chars_start, chars_len) 3752 xpm_get_color_table_v (Lisp_Object color_table,
3879 Lisp_Object color_table; 3753 const unsigned char *chars_start,
3880 const unsigned char *chars_start; 3754 int chars_len)
3881 int chars_len;
3882 { 3755 {
3883 return XVECTOR (color_table)->contents[*chars_start]; 3756 return XVECTOR (color_table)->contents[*chars_start];
3884 } 3757 }
3885 3758
3886 static Lisp_Object 3759 static Lisp_Object
3887 xpm_make_color_table_h (put_func, get_func) 3760 xpm_make_color_table_h (void (**put_func) (Lisp_Object,
3888 void (**put_func) (Lisp_Object, const unsigned char *, int, Lisp_Object); 3761 const unsigned char *,
3889 Lisp_Object (**get_func) (Lisp_Object, const unsigned char *, int); 3762 int,
3763 Lisp_Object),
3764 Lisp_Object (**get_func) (Lisp_Object,
3765 const unsigned char *,
3766 int))
3890 { 3767 {
3891 *put_func = xpm_put_color_table_h; 3768 *put_func = xpm_put_color_table_h;
3892 *get_func = xpm_get_color_table_h; 3769 *get_func = xpm_get_color_table_h;
3893 return make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE), 3770 return make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
3894 make_float (DEFAULT_REHASH_SIZE), 3771 make_float (DEFAULT_REHASH_SIZE),
3895 make_float (DEFAULT_REHASH_THRESHOLD), 3772 make_float (DEFAULT_REHASH_THRESHOLD),
3896 Qnil, Qnil, Qnil); 3773 Qnil, Qnil, Qnil);
3897 } 3774 }
3898 3775
3899 static void 3776 static void
3900 xpm_put_color_table_h (color_table, chars_start, chars_len, color) 3777 xpm_put_color_table_h (Lisp_Object color_table,
3901 Lisp_Object color_table; 3778 const unsigned char *chars_start,
3902 const unsigned char *chars_start; 3779 int chars_len,
3903 int chars_len; 3780 Lisp_Object color)
3904 Lisp_Object color;
3905 { 3781 {
3906 struct Lisp_Hash_Table *table = XHASH_TABLE (color_table); 3782 struct Lisp_Hash_Table *table = XHASH_TABLE (color_table);
3907 unsigned hash_code; 3783 unsigned hash_code;
3908 Lisp_Object chars = make_unibyte_string (chars_start, chars_len); 3784 Lisp_Object chars = make_unibyte_string (chars_start, chars_len);
3909 3785
3910 hash_lookup (table, chars, &hash_code); 3786 hash_lookup (table, chars, &hash_code);
3911 hash_put (table, chars, color, hash_code); 3787 hash_put (table, chars, color, hash_code);
3912 } 3788 }
3913 3789
3914 static Lisp_Object 3790 static Lisp_Object
3915 xpm_get_color_table_h (color_table, chars_start, chars_len) 3791 xpm_get_color_table_h (Lisp_Object color_table,
3916 Lisp_Object color_table; 3792 const unsigned char *chars_start,
3917 const unsigned char *chars_start; 3793 int chars_len)
3918 int chars_len;
3919 { 3794 {
3920 struct Lisp_Hash_Table *table = XHASH_TABLE (color_table); 3795 struct Lisp_Hash_Table *table = XHASH_TABLE (color_table);
3921 int i = hash_lookup (table, make_unibyte_string (chars_start, chars_len), 3796 int i = hash_lookup (table, make_unibyte_string (chars_start, chars_len),
3922 NULL); 3797 NULL);
3923 3798
3933 }; 3808 };
3934 3809
3935 static const char xpm_color_key_strings[][4] = {"s", "m", "g4", "g", "c"}; 3810 static const char xpm_color_key_strings[][4] = {"s", "m", "g4", "g", "c"};
3936 3811
3937 static int 3812 static int
3938 xpm_str_to_color_key (s) 3813 xpm_str_to_color_key (const char *s)
3939 const char *s;
3940 { 3814 {
3941 int i; 3815 int i;
3942 3816
3943 for (i = 0; 3817 for (i = 0;
3944 i < sizeof xpm_color_key_strings / sizeof xpm_color_key_strings[0]; 3818 i < sizeof xpm_color_key_strings / sizeof xpm_color_key_strings[0];
3947 return i; 3821 return i;
3948 return -1; 3822 return -1;
3949 } 3823 }
3950 3824
3951 static int 3825 static int
3952 xpm_load_image (f, img, contents, end) 3826 xpm_load_image (struct frame *f,
3953 struct frame *f; 3827 struct image *img,
3954 struct image *img; 3828 const unsigned char *contents,
3955 const unsigned char *contents, *end; 3829 const unsigned char *end)
3956 { 3830 {
3957 const unsigned char *s = contents, *beg, *str; 3831 const unsigned char *s = contents, *beg, *str;
3958 unsigned char buffer[BUFSIZ]; 3832 unsigned char buffer[BUFSIZ];
3959 int width, height, x, y; 3833 int width, height, x, y;
3960 int num_colors, chars_per_pixel; 3834 int num_colors, chars_per_pixel;
3982 goto failure 3856 goto failure
3983 3857
3984 if (!(end - s >= 9 && memcmp (s, "/* XPM */", 9) == 0)) 3858 if (!(end - s >= 9 && memcmp (s, "/* XPM */", 9) == 0))
3985 goto failure; 3859 goto failure;
3986 s += 9; 3860 s += 9;
3987 match(); 3861 match ();
3988 expect_ident ("static"); 3862 expect_ident ("static");
3989 expect_ident ("char"); 3863 expect_ident ("char");
3990 expect ('*'); 3864 expect ('*');
3991 expect (XPM_TK_IDENT); 3865 expect (XPM_TK_IDENT);
3992 expect ('['); 3866 expect ('[');
4132 #ifndef HAVE_NS 4006 #ifndef HAVE_NS
4133 XPutPixel (mask_img, x, y, 4007 XPutPixel (mask_img, x, y,
4134 (!EQ (color_val, Qt) ? PIX_MASK_DRAW 4008 (!EQ (color_val, Qt) ? PIX_MASK_DRAW
4135 : (have_mask = 1, PIX_MASK_RETAIN))); 4009 : (have_mask = 1, PIX_MASK_RETAIN)));
4136 #else 4010 #else
4137 if (EQ(color_val, Qt)) 4011 if (EQ (color_val, Qt))
4138 ns_set_alpha(ximg, x, y, 0); 4012 ns_set_alpha (ximg, x, y, 0);
4139 #endif 4013 #endif
4140 } 4014 }
4141 if (y + 1 < height) 4015 if (y + 1 < height)
4142 expect (','); 4016 expect (',');
4143 } 4017 }
4182 #undef expect 4056 #undef expect
4183 #undef expect_ident 4057 #undef expect_ident
4184 } 4058 }
4185 4059
4186 static int 4060 static int
4187 xpm_load (f, img) 4061 xpm_load (struct frame *f,
4188 struct frame *f; 4062 struct image *img)
4189 struct image *img;
4190 { 4063 {
4191 int success_p = 0; 4064 int success_p = 0;
4192 Lisp_Object file_name; 4065 Lisp_Object file_name;
4193 4066
4194 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 4067 /* If IMG->spec specifies a file name, create a non-file spec from it. */
4271 int ct_colors_allocated; 4144 int ct_colors_allocated;
4272 4145
4273 /* Initialize the color table. */ 4146 /* Initialize the color table. */
4274 4147
4275 static void 4148 static void
4276 init_color_table () 4149 init_color_table (void)
4277 { 4150 {
4278 int size = CT_SIZE * sizeof (*ct_table); 4151 int size = CT_SIZE * sizeof (*ct_table);
4279 ct_table = (struct ct_color **) xmalloc (size); 4152 ct_table = (struct ct_color **) xmalloc (size);
4280 bzero (ct_table, size); 4153 memset (ct_table, 0, size);
4281 ct_colors_allocated = 0; 4154 ct_colors_allocated = 0;
4282 } 4155 }
4283 4156
4284 4157
4285 /* Free memory associated with the color table. */ 4158 /* Free memory associated with the color table. */
4286 4159
4287 static void 4160 static void
4288 free_color_table () 4161 free_color_table (void)
4289 { 4162 {
4290 int i; 4163 int i;
4291 struct ct_color *p, *next; 4164 struct ct_color *p, *next;
4292 4165
4293 for (i = 0; i < CT_SIZE; ++i) 4166 for (i = 0; i < CT_SIZE; ++i)
4306 entry for that color already is in the color table, return the 4179 entry for that color already is in the color table, return the
4307 pixel color of that entry. Otherwise, allocate a new color for R, 4180 pixel color of that entry. Otherwise, allocate a new color for R,
4308 G, B, and make an entry in the color table. */ 4181 G, B, and make an entry in the color table. */
4309 4182
4310 static unsigned long 4183 static unsigned long
4311 lookup_rgb_color (f, r, g, b) 4184 lookup_rgb_color (struct frame *f, int r, int g, int b)
4312 struct frame *f;
4313 int r, g, b;
4314 { 4185 {
4315 unsigned hash = CT_HASH_RGB (r, g, b); 4186 unsigned hash = CT_HASH_RGB (r, g, b);
4316 int i = hash % CT_SIZE; 4187 int i = hash % CT_SIZE;
4317 struct ct_color *p; 4188 struct ct_color *p;
4318 Display_Info *dpyinfo; 4189 Display_Info *dpyinfo;
4403 4274
4404 /* Look up pixel color PIXEL which is used on frame F in the color 4275 /* Look up pixel color PIXEL which is used on frame F in the color
4405 table. If not already present, allocate it. Value is PIXEL. */ 4276 table. If not already present, allocate it. Value is PIXEL. */
4406 4277
4407 static unsigned long 4278 static unsigned long
4408 lookup_pixel_color (f, pixel) 4279 lookup_pixel_color (struct frame *f, unsigned long pixel)
4409 struct frame *f;
4410 unsigned long pixel;
4411 { 4280 {
4412 int i = pixel % CT_SIZE; 4281 int i = pixel % CT_SIZE;
4413 struct ct_color *p; 4282 struct ct_color *p;
4414 4283
4415 for (p = ct_table[i]; p; p = p->next) 4284 for (p = ct_table[i]; p; p = p->next)
4457 4326
4458 /* Value is a vector of all pixel colors contained in the color table, 4327 /* Value is a vector of all pixel colors contained in the color table,
4459 allocated via xmalloc. Set *N to the number of colors. */ 4328 allocated via xmalloc. Set *N to the number of colors. */
4460 4329
4461 static unsigned long * 4330 static unsigned long *
4462 colors_in_color_table (n) 4331 colors_in_color_table (int *n)
4463 int *n;
4464 { 4332 {
4465 int i, j; 4333 int i, j;
4466 struct ct_color *p; 4334 struct ct_color *p;
4467 unsigned long *colors; 4335 unsigned long *colors;
4468 4336
4486 } 4354 }
4487 4355
4488 #else /* COLOR_TABLE_SUPPORT */ 4356 #else /* COLOR_TABLE_SUPPORT */
4489 4357
4490 static unsigned long 4358 static unsigned long
4491 lookup_rgb_color (f, r, g, b) 4359 lookup_rgb_color (struct frame *f, int r, int g, int b)
4492 struct frame *f;
4493 int r, g, b;
4494 { 4360 {
4495 unsigned long pixel; 4361 unsigned long pixel;
4496 4362
4497 #ifdef HAVE_NTGUI 4363 #ifdef HAVE_NTGUI
4498 pixel = PALETTERGB (r >> 8, g >> 8, b >> 8); 4364 pixel = PALETTERGB (r >> 8, g >> 8, b >> 8);
4503 #endif /* HAVE_NS */ 4369 #endif /* HAVE_NS */
4504 return pixel; 4370 return pixel;
4505 } 4371 }
4506 4372
4507 static void 4373 static void
4508 init_color_table () 4374 init_color_table (void)
4509 { 4375 {
4510 } 4376 }
4511 #endif /* COLOR_TABLE_SUPPORT */ 4377 #endif /* COLOR_TABLE_SUPPORT */
4512 4378
4513 4379
4514 /*********************************************************************** 4380 /***********************************************************************
4515 Algorithms 4381 Algorithms
4516 ***********************************************************************/ 4382 ***********************************************************************/
4517 4383
4518 static XColor *x_to_xcolors P_ ((struct frame *, struct image *, int)); 4384 static XColor *x_to_xcolors (struct frame *, struct image *, int);
4519 static void x_from_xcolors P_ ((struct frame *, struct image *, XColor *)); 4385 static void x_from_xcolors (struct frame *, struct image *, XColor *);
4520 static void x_detect_edges P_ ((struct frame *, struct image *, int[9], int)); 4386 static void x_detect_edges (struct frame *, struct image *, int[9], int);
4521 4387
4522 #ifdef HAVE_NTGUI 4388 #ifdef HAVE_NTGUI
4523 static void XPutPixel (XImagePtr , int, int, COLORREF); 4389 static void XPutPixel (XImagePtr , int, int, COLORREF);
4524 #endif /* HAVE_NTGUI */ 4390 #endif /* HAVE_NTGUI */
4525 4391
4556 non-zero means also fill the red/green/blue members of the XColor 4422 non-zero means also fill the red/green/blue members of the XColor
4557 structures. Value is a pointer to the array of XColors structures, 4423 structures. Value is a pointer to the array of XColors structures,
4558 allocated with xmalloc; it must be freed by the caller. */ 4424 allocated with xmalloc; it must be freed by the caller. */
4559 4425
4560 static XColor * 4426 static XColor *
4561 x_to_xcolors (f, img, rgb_p) 4427 x_to_xcolors (struct frame *f, struct image *img, int rgb_p)
4562 struct frame *f;
4563 struct image *img;
4564 int rgb_p;
4565 { 4428 {
4566 int x, y; 4429 int x, y;
4567 XColor *colors, *p; 4430 XColor *colors, *p;
4568 XImagePtr_or_DC ximg; 4431 XImagePtr_or_DC ximg;
4569 #ifdef HAVE_NTGUI 4432 #ifdef HAVE_NTGUI
4624 /* Put a pixel of COLOR at position X, Y in XIMG. XIMG must have been 4487 /* Put a pixel of COLOR at position X, Y in XIMG. XIMG must have been
4625 created with CreateDIBSection, with the pointer to the bit values 4488 created with CreateDIBSection, with the pointer to the bit values
4626 stored in ximg->data. */ 4489 stored in ximg->data. */
4627 4490
4628 static void 4491 static void
4629 XPutPixel (ximg, x, y, color) 4492 XPutPixel (XImagePtr ximg, int x, int y, COLORREF color)
4630 XImagePtr ximg;
4631 int x, y;
4632 COLORREF color;
4633 { 4493 {
4634 int width = ximg->info.bmiHeader.biWidth; 4494 int width = ximg->info.bmiHeader.biWidth;
4635 int height = ximg->info.bmiHeader.biHeight; 4495 int height = ximg->info.bmiHeader.biHeight;
4636 unsigned char * pixel; 4496 unsigned char * pixel;
4637 4497
4672 /* Create IMG->pixmap from an array COLORS of XColor structures, whose 4532 /* Create IMG->pixmap from an array COLORS of XColor structures, whose
4673 RGB members are set. F is the frame on which this all happens. 4533 RGB members are set. F is the frame on which this all happens.
4674 COLORS will be freed; an existing IMG->pixmap will be freed, too. */ 4534 COLORS will be freed; an existing IMG->pixmap will be freed, too. */
4675 4535
4676 static void 4536 static void
4677 x_from_xcolors (f, img, colors) 4537 x_from_xcolors (struct frame *f, struct image *img, XColor *colors)
4678 struct frame *f;
4679 struct image *img;
4680 XColor *colors;
4681 { 4538 {
4682 int x, y; 4539 int x, y;
4683 XImagePtr oimg = NULL; 4540 XImagePtr oimg = NULL;
4684 Pixmap pixmap; 4541 Pixmap pixmap;
4685 XColor *p; 4542 XColor *p;
4717 4574
4718 COLOR_ADJUST is a color adjustment added to each pixel of the 4575 COLOR_ADJUST is a color adjustment added to each pixel of the
4719 outgoing image. */ 4576 outgoing image. */
4720 4577
4721 static void 4578 static void
4722 x_detect_edges (f, img, matrix, color_adjust) 4579 x_detect_edges (struct frame *f, struct image *img, int *matrix, int color_adjust)
4723 struct frame *f;
4724 struct image *img;
4725 int matrix[9], color_adjust;
4726 { 4580 {
4727 XColor *colors = x_to_xcolors (f, img, 1); 4581 XColor *colors = x_to_xcolors (f, img, 1);
4728 XColor *new, *p; 4582 XColor *new, *p;
4729 int x, y, i, sum; 4583 int x, y, i, sum;
4730 4584
4786 4640
4787 /* Perform the pre-defined `emboss' edge-detection on image IMG 4641 /* Perform the pre-defined `emboss' edge-detection on image IMG
4788 on frame F. */ 4642 on frame F. */
4789 4643
4790 static void 4644 static void
4791 x_emboss (f, img) 4645 x_emboss (struct frame *f, struct image *img)
4792 struct frame *f;
4793 struct image *img;
4794 { 4646 {
4795 x_detect_edges (f, img, emboss_matrix, 0xffff / 2); 4647 x_detect_edges (f, img, emboss_matrix, 0xffff / 2);
4796 } 4648 }
4797 4649
4798 4650
4799 /* Transform image IMG which is used on frame F with a Laplace 4651 /* Transform image IMG which is used on frame F with a Laplace
4800 edge-detection algorithm. The result is an image that can be used 4652 edge-detection algorithm. The result is an image that can be used
4801 to draw disabled buttons, for example. */ 4653 to draw disabled buttons, for example. */
4802 4654
4803 static void 4655 static void
4804 x_laplace (f, img) 4656 x_laplace (struct frame *f, struct image *img)
4805 struct frame *f;
4806 struct image *img;
4807 { 4657 {
4808 x_detect_edges (f, img, laplace_matrix, 45000); 4658 x_detect_edges (f, img, laplace_matrix, 45000);
4809 } 4659 }
4810 4660
4811 4661
4819 4669
4820 COLOR_ADJUST nil means use a default; otherwise it must be a 4670 COLOR_ADJUST nil means use a default; otherwise it must be a
4821 number. */ 4671 number. */
4822 4672
4823 static void 4673 static void
4824 x_edge_detection (f, img, matrix, color_adjust) 4674 x_edge_detection (struct frame *f, struct image *img, Lisp_Object matrix,
4825 struct frame *f; 4675 Lisp_Object color_adjust)
4826 struct image *img;
4827 Lisp_Object matrix, color_adjust;
4828 { 4676 {
4829 int i = 0; 4677 int i = 0;
4830 int trans[9]; 4678 int trans[9];
4831 4679
4832 if (CONSP (matrix)) 4680 if (CONSP (matrix))
4851 4699
4852 4700
4853 /* Transform image IMG on frame F so that it looks disabled. */ 4701 /* Transform image IMG on frame F so that it looks disabled. */
4854 4702
4855 static void 4703 static void
4856 x_disable_image (f, img) 4704 x_disable_image (struct frame *f, struct image *img)
4857 struct frame *f;
4858 struct image *img;
4859 { 4705 {
4860 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 4706 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4861 #ifdef HAVE_NTGUI 4707 #ifdef HAVE_NTGUI
4862 int n_planes = dpyinfo->n_planes * dpyinfo->n_cbits; 4708 int n_planes = dpyinfo->n_planes * dpyinfo->n_cbits;
4863 #else 4709 #else
4955 with R, G, and B being integers >= 0, take that as the color of the 4801 with R, G, and B being integers >= 0, take that as the color of the
4956 background. Otherwise, determine the background color of IMG 4802 background. Otherwise, determine the background color of IMG
4957 heuristically. Value is non-zero if successful. */ 4803 heuristically. Value is non-zero if successful. */
4958 4804
4959 static int 4805 static int
4960 x_build_heuristic_mask (f, img, how) 4806 x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4961 struct frame *f;
4962 struct image *img;
4963 Lisp_Object how;
4964 { 4807 {
4965 XImagePtr_or_DC ximg; 4808 XImagePtr_or_DC ximg;
4966 #ifndef HAVE_NTGUI 4809 #ifndef HAVE_NTGUI
4967 XImagePtr mask_img; 4810 XImagePtr mask_img;
4968 #else 4811 #else
4996 ~0, ZPixmap); 4839 ~0, ZPixmap);
4997 #else 4840 #else
4998 /* Create the bit array serving as mask. */ 4841 /* Create the bit array serving as mask. */
4999 row_width = (img->width + 7) / 8; 4842 row_width = (img->width + 7) / 8;
5000 mask_img = xmalloc (row_width * img->height); 4843 mask_img = xmalloc (row_width * img->height);
5001 bzero (mask_img, row_width * img->height); 4844 memset (mask_img, 0, row_width * img->height);
5002 4845
5003 /* Create a memory device context for IMG->pixmap. */ 4846 /* Create a memory device context for IMG->pixmap. */
5004 frame_dc = get_frame_dc (f); 4847 frame_dc = get_frame_dc (f);
5005 ximg = CreateCompatibleDC (frame_dc); 4848 ximg = CreateCompatibleDC (frame_dc);
5006 release_frame_dc (f, frame_dc); 4849 release_frame_dc (f, frame_dc);
5044 for (x = 0; x < img->width; ++x) 4887 for (x = 0; x < img->width; ++x)
5045 #ifndef HAVE_NS 4888 #ifndef HAVE_NS
5046 XPutPixel (mask_img, x, y, (XGetPixel (ximg, x, y) != bg 4889 XPutPixel (mask_img, x, y, (XGetPixel (ximg, x, y) != bg
5047 ? PIX_MASK_DRAW : PIX_MASK_RETAIN)); 4890 ? PIX_MASK_DRAW : PIX_MASK_RETAIN));
5048 #else 4891 #else
5049 if (XGetPixel (ximg, x, y) == bg) 4892 if (XGetPixel (ximg, x, y) == bg)
5050 ns_set_alpha(ximg, x, y, 0); 4893 ns_set_alpha (ximg, x, y, 0);
5051 #endif /* HAVE_NS */ 4894 #endif /* HAVE_NS */
5052 #ifndef HAVE_NS 4895 #ifndef HAVE_NS
5053 /* Fill in the background_transparent field while we have the mask handy. */ 4896 /* Fill in the background_transparent field while we have the mask handy. */
5054 image_background_transparent (img, f, mask_img); 4897 image_background_transparent (img, f, mask_img);
5055 4898
5085 4928
5086 /*********************************************************************** 4929 /***********************************************************************
5087 PBM (mono, gray, color) 4930 PBM (mono, gray, color)
5088 ***********************************************************************/ 4931 ***********************************************************************/
5089 4932
5090 static int pbm_image_p P_ ((Lisp_Object object)); 4933 static int pbm_image_p (Lisp_Object object);
5091 static int pbm_load P_ ((struct frame *f, struct image *img)); 4934 static int pbm_load (struct frame *f, struct image *img);
5092 static int pbm_scan_number P_ ((unsigned char **, unsigned char *)); 4935 static int pbm_scan_number (unsigned char **, unsigned char *);
5093 4936
5094 /* The symbol `pbm' identifying images of this type. */ 4937 /* The symbol `pbm' identifying images of this type. */
5095 4938
5096 Lisp_Object Qpbm; 4939 Lisp_Object Qpbm;
5097 4940
5144 4987
5145 4988
5146 /* Return non-zero if OBJECT is a valid PBM image specification. */ 4989 /* Return non-zero if OBJECT is a valid PBM image specification. */
5147 4990
5148 static int 4991 static int
5149 pbm_image_p (object) 4992 pbm_image_p (Lisp_Object object)
5150 Lisp_Object object;
5151 { 4993 {
5152 struct image_keyword fmt[PBM_LAST]; 4994 struct image_keyword fmt[PBM_LAST];
5153 4995
5154 bcopy (pbm_format, fmt, sizeof fmt); 4996 memcpy (fmt, pbm_format, sizeof fmt);
5155 4997
5156 if (!parse_image_spec (object, fmt, PBM_LAST, Qpbm)) 4998 if (!parse_image_spec (object, fmt, PBM_LAST, Qpbm))
5157 return 0; 4999 return 0;
5158 5000
5159 /* Must specify either :data or :file. */ 5001 /* Must specify either :data or :file. */
5164 /* Scan a decimal number from *S and return it. Advance *S while 5006 /* Scan a decimal number from *S and return it. Advance *S while
5165 reading the number. END is the end of the string. Value is -1 at 5007 reading the number. END is the end of the string. Value is -1 at
5166 end of input. */ 5008 end of input. */
5167 5009
5168 static int 5010 static int
5169 pbm_scan_number (s, end) 5011 pbm_scan_number (unsigned char **s, unsigned char *end)
5170 unsigned char **s, *end;
5171 { 5012 {
5172 int c = 0, val = -1; 5013 int c = 0, val = -1;
5173 5014
5174 while (*s < end) 5015 while (*s < end)
5175 { 5016 {
5240 #endif /* HAVE_NTGUI */ 5081 #endif /* HAVE_NTGUI */
5241 5082
5242 /* Load PBM image IMG for use on frame F. */ 5083 /* Load PBM image IMG for use on frame F. */
5243 5084
5244 static int 5085 static int
5245 pbm_load (f, img) 5086 pbm_load (struct frame *f, struct image *img)
5246 struct frame *f;
5247 struct image *img;
5248 { 5087 {
5249 int raw_p, x, y; 5088 int raw_p, x, y;
5250 int width, height, max_color_idx = 0; 5089 int width, height, max_color_idx = 0;
5251 XImagePtr ximg; 5090 XImagePtr ximg;
5252 Lisp_Object file, specified_file; 5091 Lisp_Object file, specified_file;
5364 struct image_keyword fmt[PBM_LAST]; 5203 struct image_keyword fmt[PBM_LAST];
5365 unsigned long fg = FRAME_FOREGROUND_PIXEL (f); 5204 unsigned long fg = FRAME_FOREGROUND_PIXEL (f);
5366 unsigned long bg = FRAME_BACKGROUND_PIXEL (f); 5205 unsigned long bg = FRAME_BACKGROUND_PIXEL (f);
5367 5206
5368 /* Parse the image specification. */ 5207 /* Parse the image specification. */
5369 bcopy (pbm_format, fmt, sizeof fmt); 5208 memcpy (fmt, pbm_format, sizeof fmt);
5370 parse_image_spec (img->spec, fmt, PBM_LAST, Qpbm); 5209 parse_image_spec (img->spec, fmt, PBM_LAST, Qpbm);
5371 5210
5372 /* Get foreground and background colors, maybe allocate colors. */ 5211 /* Get foreground and background colors, maybe allocate colors. */
5373 if (fmt[PBM_FOREGROUND].count 5212 if (fmt[PBM_FOREGROUND].count
5374 && STRINGP (fmt[PBM_FOREGROUND].value)) 5213 && STRINGP (fmt[PBM_FOREGROUND].value))
5509 5348
5510 #if defined (HAVE_PNG) || defined (HAVE_NS) 5349 #if defined (HAVE_PNG) || defined (HAVE_NS)
5511 5350
5512 /* Function prototypes. */ 5351 /* Function prototypes. */
5513 5352
5514 static int png_image_p P_ ((Lisp_Object object)); 5353 static int png_image_p (Lisp_Object object);
5515 static int png_load P_ ((struct frame *f, struct image *img)); 5354 static int png_load (struct frame *f, struct image *img);
5516 5355
5517 /* The symbol `png' identifying images of this type. */ 5356 /* The symbol `png' identifying images of this type. */
5518 5357
5519 Lisp_Object Qpng; 5358 Lisp_Object Qpng;
5520 5359
5564 }; 5403 };
5565 5404
5566 /* Return non-zero if OBJECT is a valid PNG image specification. */ 5405 /* Return non-zero if OBJECT is a valid PNG image specification. */
5567 5406
5568 static int 5407 static int
5569 png_image_p (object) 5408 png_image_p (Lisp_Object object)
5570 Lisp_Object object;
5571 { 5409 {
5572 struct image_keyword fmt[PNG_LAST]; 5410 struct image_keyword fmt[PNG_LAST];
5573 bcopy (png_format, fmt, sizeof fmt); 5411 memcpy (fmt, png_format, sizeof fmt);
5574 5412
5575 if (!parse_image_spec (object, fmt, PNG_LAST, Qpng)) 5413 if (!parse_image_spec (object, fmt, PNG_LAST, Qpng))
5576 return 0; 5414 return 0;
5577 5415
5578 /* Must specify either the :data or :file keyword. */ 5416 /* Must specify either the :data or :file keyword. */
5669 5507
5670 /* Error and warning handlers installed when the PNG library 5508 /* Error and warning handlers installed when the PNG library
5671 is initialized. */ 5509 is initialized. */
5672 5510
5673 static void 5511 static void
5674 my_png_error (png_ptr, msg) 5512 my_png_error (png_struct *png_ptr, const char *msg)
5675 png_struct *png_ptr;
5676 char *msg;
5677 { 5513 {
5678 xassert (png_ptr != NULL); 5514 xassert (png_ptr != NULL);
5679 image_error ("PNG error: %s", build_string (msg), Qnil); 5515 image_error ("PNG error: %s", build_string (msg), Qnil);
5680 longjmp (png_ptr->jmpbuf, 1); 5516 longjmp (png_ptr->jmpbuf, 1);
5681 } 5517 }
5682 5518
5683 5519
5684 static void 5520 static void
5685 my_png_warning (png_ptr, msg) 5521 my_png_warning (png_struct *png_ptr, const char *msg)
5686 png_struct *png_ptr;
5687 char *msg;
5688 { 5522 {
5689 xassert (png_ptr != NULL); 5523 xassert (png_ptr != NULL);
5690 image_error ("PNG warning: %s", build_string (msg), Qnil); 5524 image_error ("PNG warning: %s", build_string (msg), Qnil);
5691 } 5525 }
5692 5526
5703 /* Function set as reader function when reading PNG image from memory. 5537 /* Function set as reader function when reading PNG image from memory.
5704 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH 5538 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
5705 bytes from the input to DATA. */ 5539 bytes from the input to DATA. */
5706 5540
5707 static void 5541 static void
5708 png_read_from_memory (png_ptr, data, length) 5542 png_read_from_memory (png_structp png_ptr, png_bytep data, png_size_t length)
5709 png_structp png_ptr;
5710 png_bytep data;
5711 png_size_t length;
5712 { 5543 {
5713 struct png_memory_storage *tbr 5544 struct png_memory_storage *tbr
5714 = (struct png_memory_storage *) fn_png_get_io_ptr (png_ptr); 5545 = (struct png_memory_storage *) fn_png_get_io_ptr (png_ptr);
5715 5546
5716 if (length > tbr->len - tbr->index) 5547 if (length > tbr->len - tbr->index)
5717 fn_png_error (png_ptr, "Read error"); 5548 fn_png_error (png_ptr, "Read error");
5718 5549
5719 bcopy (tbr->bytes + tbr->index, data, length); 5550 memcpy (data, tbr->bytes + tbr->index, length);
5720 tbr->index = tbr->index + length; 5551 tbr->index = tbr->index + length;
5721 } 5552 }
5722 5553
5723 5554
5724 /* Function set as reader function when reading PNG image from a file. 5555 /* Function set as reader function when reading PNG image from a file.
5725 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH 5556 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
5726 bytes from the input to DATA. */ 5557 bytes from the input to DATA. */
5727 5558
5728 static void 5559 static void
5729 png_read_from_file (png_ptr, data, length) 5560 png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length)
5730 png_structp png_ptr;
5731 png_bytep data;
5732 png_size_t length;
5733 { 5561 {
5734 FILE *fp = (FILE *) fn_png_get_io_ptr (png_ptr); 5562 FILE *fp = (FILE *) fn_png_get_io_ptr (png_ptr);
5735 5563
5736 if (fread (data, 1, length, fp) < length) 5564 if (fread (data, 1, length, fp) < length)
5737 fn_png_error (png_ptr, "Read error"); 5565 fn_png_error (png_ptr, "Read error");
5740 5568
5741 /* Load PNG image IMG for use on frame F. Value is non-zero if 5569 /* Load PNG image IMG for use on frame F. Value is non-zero if
5742 successful. */ 5570 successful. */
5743 5571
5744 static int 5572 static int
5745 png_load (f, img) 5573 png_load (struct frame *f, struct image *img)
5746 struct frame *f;
5747 struct image *img;
5748 { 5574 {
5749 Lisp_Object file, specified_file; 5575 Lisp_Object file, specified_file;
5750 Lisp_Object specified_data; 5576 Lisp_Object specified_data;
5751 int x, y, i; 5577 int x, y, i;
5752 XImagePtr ximg, mask_img = NULL; 5578 XImagePtr ximg, mask_img = NULL;
5921 XColor color; 5747 XColor color;
5922 if (x_defined_color (f, SDATA (specified_bg), &color, 0)) 5748 if (x_defined_color (f, SDATA (specified_bg), &color, 0))
5923 { 5749 {
5924 png_color_16 user_bg; 5750 png_color_16 user_bg;
5925 5751
5926 bzero (&user_bg, sizeof user_bg); 5752 memset (&user_bg, 0, sizeof user_bg);
5927 user_bg.red = color.red >> shift; 5753 user_bg.red = color.red >> shift;
5928 user_bg.green = color.green >> shift; 5754 user_bg.green = color.green >> shift;
5929 user_bg.blue = color.blue >> shift; 5755 user_bg.blue = color.blue >> shift;
5930 5756
5931 fn_png_set_background (png_ptr, &user_bg, 5757 fn_png_set_background (png_ptr, &user_bg,
5941 png_color_16 frame_background; 5767 png_color_16 frame_background;
5942 5768
5943 color.pixel = FRAME_BACKGROUND_PIXEL (f); 5769 color.pixel = FRAME_BACKGROUND_PIXEL (f);
5944 x_query_color (f, &color); 5770 x_query_color (f, &color);
5945 5771
5946 bzero (&frame_background, sizeof frame_background); 5772 memset (&frame_background, 0, sizeof frame_background);
5947 frame_background.red = color.red >> shift; 5773 frame_background.red = color.red >> shift;
5948 frame_background.green = color.green >> shift; 5774 frame_background.green = color.green >> shift;
5949 frame_background.blue = color.blue >> shift; 5775 frame_background.blue = color.blue >> shift;
5950 #endif /* HAVE_X_WINDOWS */ 5776 #endif /* HAVE_X_WINDOWS */
5951 5777
6111 JPEG 5937 JPEG
6112 ***********************************************************************/ 5938 ***********************************************************************/
6113 5939
6114 #if defined (HAVE_JPEG) || defined (HAVE_NS) 5940 #if defined (HAVE_JPEG) || defined (HAVE_NS)
6115 5941
6116 static int jpeg_image_p P_ ((Lisp_Object object)); 5942 static int jpeg_image_p (Lisp_Object object);
6117 static int jpeg_load P_ ((struct frame *f, struct image *img)); 5943 static int jpeg_load (struct frame *f, struct image *img);
6118 5944
6119 /* The symbol `jpeg' identifying images of this type. */ 5945 /* The symbol `jpeg' identifying images of this type. */
6120 5946
6121 Lisp_Object Qjpeg; 5947 Lisp_Object Qjpeg;
6122 5948
6166 }; 5992 };
6167 5993
6168 /* Return non-zero if OBJECT is a valid JPEG image specification. */ 5994 /* Return non-zero if OBJECT is a valid JPEG image specification. */
6169 5995
6170 static int 5996 static int
6171 jpeg_image_p (object) 5997 jpeg_image_p (Lisp_Object object)
6172 Lisp_Object object;
6173 { 5998 {
6174 struct image_keyword fmt[JPEG_LAST]; 5999 struct image_keyword fmt[JPEG_LAST];
6175 6000
6176 bcopy (jpeg_format, fmt, sizeof fmt); 6001 memcpy (fmt, jpeg_format, sizeof fmt);
6177 6002
6178 if (!parse_image_spec (object, fmt, JPEG_LAST, Qjpeg)) 6003 if (!parse_image_spec (object, fmt, JPEG_LAST, Qjpeg))
6179 return 0; 6004 return 0;
6180 6005
6181 /* Must specify either the :data or :file keyword. */ 6006 /* Must specify either the :data or :file keyword. */
6238 } 6063 }
6239 6064
6240 /* Wrapper since we can't directly assign the function pointer 6065 /* Wrapper since we can't directly assign the function pointer
6241 to another function pointer that was declared more completely easily. */ 6066 to another function pointer that was declared more completely easily. */
6242 static boolean 6067 static boolean
6243 jpeg_resync_to_restart_wrapper (cinfo, desired) 6068 jpeg_resync_to_restart_wrapper (j_decompress_ptr cinfo, int desired)
6244 j_decompress_ptr cinfo;
6245 int desired;
6246 { 6069 {
6247 return fn_jpeg_resync_to_restart (cinfo, desired); 6070 return fn_jpeg_resync_to_restart (cinfo, desired);
6248 } 6071 }
6249 6072
6250 #else 6073 #else
6266 jmp_buf setjmp_buffer; 6089 jmp_buf setjmp_buffer;
6267 }; 6090 };
6268 6091
6269 6092
6270 static void 6093 static void
6271 my_error_exit (cinfo) 6094 my_error_exit (j_common_ptr cinfo)
6272 j_common_ptr cinfo;
6273 { 6095 {
6274 struct my_jpeg_error_mgr *mgr = (struct my_jpeg_error_mgr *) cinfo->err; 6096 struct my_jpeg_error_mgr *mgr = (struct my_jpeg_error_mgr *) cinfo->err;
6275 longjmp (mgr->setjmp_buffer, 1); 6097 longjmp (mgr->setjmp_buffer, 1);
6276 } 6098 }
6277 6099
6279 /* Init source method for JPEG data source manager. Called by 6101 /* Init source method for JPEG data source manager. Called by
6280 jpeg_read_header() before any data is actually read. See 6102 jpeg_read_header() before any data is actually read. See
6281 libjpeg.doc from the JPEG lib distribution. */ 6103 libjpeg.doc from the JPEG lib distribution. */
6282 6104
6283 static void 6105 static void
6284 our_common_init_source (cinfo) 6106 our_common_init_source (j_decompress_ptr cinfo)
6285 j_decompress_ptr cinfo;
6286 { 6107 {
6287 } 6108 }
6288 6109
6289 6110
6290 /* Method to terminate data source. Called by 6111 /* Method to terminate data source. Called by
6291 jpeg_finish_decompress() after all data has been processed. */ 6112 jpeg_finish_decompress() after all data has been processed. */
6292 6113
6293 static void 6114 static void
6294 our_common_term_source (cinfo) 6115 our_common_term_source (j_decompress_ptr cinfo)
6295 j_decompress_ptr cinfo;
6296 { 6116 {
6297 } 6117 }
6298 6118
6299 6119
6300 /* Fill input buffer method for JPEG data source manager. Called 6120 /* Fill input buffer method for JPEG data source manager. Called
6302 so this only adds a fake end of input marker at the end. */ 6122 so this only adds a fake end of input marker at the end. */
6303 6123
6304 static JOCTET our_memory_buffer[2]; 6124 static JOCTET our_memory_buffer[2];
6305 6125
6306 static boolean 6126 static boolean
6307 our_memory_fill_input_buffer (cinfo) 6127 our_memory_fill_input_buffer (j_decompress_ptr cinfo)
6308 j_decompress_ptr cinfo;
6309 { 6128 {
6310 /* Insert a fake EOI marker. */ 6129 /* Insert a fake EOI marker. */
6311 struct jpeg_source_mgr *src = cinfo->src; 6130 struct jpeg_source_mgr *src = cinfo->src;
6312 6131
6313 our_memory_buffer[0] = (JOCTET) 0xFF; 6132 our_memory_buffer[0] = (JOCTET) 0xFF;
6321 6140
6322 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src 6141 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
6323 is the JPEG data source manager. */ 6142 is the JPEG data source manager. */
6324 6143
6325 static void 6144 static void
6326 our_memory_skip_input_data (cinfo, num_bytes) 6145 our_memory_skip_input_data (j_decompress_ptr cinfo, long int num_bytes)
6327 j_decompress_ptr cinfo;
6328 long num_bytes;
6329 { 6146 {
6330 struct jpeg_source_mgr *src = (struct jpeg_source_mgr *) cinfo->src; 6147 struct jpeg_source_mgr *src = (struct jpeg_source_mgr *) cinfo->src;
6331 6148
6332 if (src) 6149 if (src)
6333 { 6150 {
6343 /* Set up the JPEG lib for reading an image from DATA which contains 6160 /* Set up the JPEG lib for reading an image from DATA which contains
6344 LEN bytes. CINFO is the decompression info structure created for 6161 LEN bytes. CINFO is the decompression info structure created for
6345 reading the image. */ 6162 reading the image. */
6346 6163
6347 static void 6164 static void
6348 jpeg_memory_src (cinfo, data, len) 6165 jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, unsigned int len)
6349 j_decompress_ptr cinfo;
6350 JOCTET *data;
6351 unsigned int len;
6352 { 6166 {
6353 struct jpeg_source_mgr *src; 6167 struct jpeg_source_mgr *src;
6354 6168
6355 if (cinfo->src == NULL) 6169 if (cinfo->src == NULL)
6356 { 6170 {
6389 6203
6390 /* Fill input buffer method for JPEG data source manager. Called 6204 /* Fill input buffer method for JPEG data source manager. Called
6391 whenever more data is needed. The data is read from a FILE *. */ 6205 whenever more data is needed. The data is read from a FILE *. */
6392 6206
6393 static boolean 6207 static boolean
6394 our_stdio_fill_input_buffer (cinfo) 6208 our_stdio_fill_input_buffer (j_decompress_ptr cinfo)
6395 j_decompress_ptr cinfo;
6396 { 6209 {
6397 struct jpeg_stdio_mgr *src; 6210 struct jpeg_stdio_mgr *src;
6398 6211
6399 src = (struct jpeg_stdio_mgr *) cinfo->src; 6212 src = (struct jpeg_stdio_mgr *) cinfo->src;
6400 if (!src->finished) 6213 if (!src->finished)
6421 6234
6422 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src 6235 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
6423 is the JPEG data source manager. */ 6236 is the JPEG data source manager. */
6424 6237
6425 static void 6238 static void
6426 our_stdio_skip_input_data (cinfo, num_bytes) 6239 our_stdio_skip_input_data (j_decompress_ptr cinfo, long int num_bytes)
6427 j_decompress_ptr cinfo;
6428 long num_bytes;
6429 { 6240 {
6430 struct jpeg_stdio_mgr *src; 6241 struct jpeg_stdio_mgr *src;
6431 src = (struct jpeg_stdio_mgr *) cinfo->src; 6242 src = (struct jpeg_stdio_mgr *) cinfo->src;
6432 6243
6433 while (num_bytes > 0 && !src->finished) 6244 while (num_bytes > 0 && !src->finished)
6453 /* Set up the JPEG lib for reading an image from a FILE *. 6264 /* Set up the JPEG lib for reading an image from a FILE *.
6454 CINFO is the decompression info structure created for 6265 CINFO is the decompression info structure created for
6455 reading the image. */ 6266 reading the image. */
6456 6267
6457 static void 6268 static void
6458 jpeg_file_src (cinfo, fp) 6269 jpeg_file_src (j_decompress_ptr cinfo, FILE *fp)
6459 j_decompress_ptr cinfo;
6460 FILE *fp;
6461 { 6270 {
6462 struct jpeg_stdio_mgr *src; 6271 struct jpeg_stdio_mgr *src;
6463 6272
6464 if (cinfo->src != NULL) 6273 if (cinfo->src != NULL)
6465 src = (struct jpeg_stdio_mgr *) cinfo->src; 6274 src = (struct jpeg_stdio_mgr *) cinfo->src;
6489 6298
6490 /* Load image IMG for use on frame F. Patterned after example.c 6299 /* Load image IMG for use on frame F. Patterned after example.c
6491 from the JPEG lib. */ 6300 from the JPEG lib. */
6492 6301
6493 static int 6302 static int
6494 jpeg_load (f, img) 6303 jpeg_load (struct frame *f, struct image *img)
6495 struct frame *f;
6496 struct image *img;
6497 { 6304 {
6498 struct jpeg_decompress_struct cinfo; 6305 struct jpeg_decompress_struct cinfo;
6499 struct my_jpeg_error_mgr mgr; 6306 struct my_jpeg_error_mgr mgr;
6500 Lisp_Object file, specified_file; 6307 Lisp_Object file, specified_file;
6501 Lisp_Object specified_data; 6308 Lisp_Object specified_data;
6667 6474
6668 #ifdef HAVE_NS 6475 #ifdef HAVE_NS
6669 static int 6476 static int
6670 jpeg_load (struct frame *f, struct image *img) 6477 jpeg_load (struct frame *f, struct image *img)
6671 { 6478 {
6672 return ns_load_image(f, img, 6479 return ns_load_image (f, img,
6673 image_spec_value (img->spec, QCfile, NULL), 6480 image_spec_value (img->spec, QCfile, NULL),
6674 image_spec_value (img->spec, QCdata, NULL)); 6481 image_spec_value (img->spec, QCdata, NULL));
6675 } 6482 }
6676 #endif /* HAVE_NS */ 6483 #endif /* HAVE_NS */
6677 6484
6678 #endif /* !HAVE_JPEG */ 6485 #endif /* !HAVE_JPEG */
6679 6486
6683 TIFF 6490 TIFF
6684 ***********************************************************************/ 6491 ***********************************************************************/
6685 6492
6686 #if defined (HAVE_TIFF) || defined (HAVE_NS) 6493 #if defined (HAVE_TIFF) || defined (HAVE_NS)
6687 6494
6688 static int tiff_image_p P_ ((Lisp_Object object)); 6495 static int tiff_image_p (Lisp_Object object);
6689 static int tiff_load P_ ((struct frame *f, struct image *img)); 6496 static int tiff_load (struct frame *f, struct image *img);
6690 6497
6691 /* The symbol `tiff' identifying images of this type. */ 6498 /* The symbol `tiff' identifying images of this type. */
6692 6499
6693 Lisp_Object Qtiff; 6500 Lisp_Object Qtiff;
6694 6501
6740 }; 6547 };
6741 6548
6742 /* Return non-zero if OBJECT is a valid TIFF image specification. */ 6549 /* Return non-zero if OBJECT is a valid TIFF image specification. */
6743 6550
6744 static int 6551 static int
6745 tiff_image_p (object) 6552 tiff_image_p (Lisp_Object object)
6746 Lisp_Object object;
6747 { 6553 {
6748 struct image_keyword fmt[TIFF_LAST]; 6554 struct image_keyword fmt[TIFF_LAST];
6749 bcopy (tiff_format, fmt, sizeof fmt); 6555 memcpy (fmt, tiff_format, sizeof fmt);
6750 6556
6751 if (!parse_image_spec (object, fmt, TIFF_LAST, Qtiff)) 6557 if (!parse_image_spec (object, fmt, TIFF_LAST, Qtiff))
6752 return 0; 6558 return 0;
6753 6559
6754 /* Must specify either the :data or :file keyword. */ 6560 /* Must specify either the :data or :file keyword. */
6821 int index; 6627 int index;
6822 } 6628 }
6823 tiff_memory_source; 6629 tiff_memory_source;
6824 6630
6825 static size_t 6631 static size_t
6826 tiff_read_from_memory (data, buf, size) 6632 tiff_read_from_memory (thandle_t data, tdata_t buf, tsize_t size)
6827 thandle_t data;
6828 tdata_t buf;
6829 tsize_t size;
6830 { 6633 {
6831 tiff_memory_source *src = (tiff_memory_source *) data; 6634 tiff_memory_source *src = (tiff_memory_source *) data;
6832 6635
6833 if (size > src->len - src->index) 6636 if (size > src->len - src->index)
6834 return (size_t) -1; 6637 return (size_t) -1;
6835 bcopy (src->bytes + src->index, buf, size); 6638 memcpy (buf, src->bytes + src->index, size);
6836 src->index += size; 6639 src->index += size;
6837 return size; 6640 return size;
6838 } 6641 }
6839 6642
6840 static size_t 6643 static size_t
6841 tiff_write_from_memory (data, buf, size) 6644 tiff_write_from_memory (thandle_t data, tdata_t buf, tsize_t size)
6842 thandle_t data;
6843 tdata_t buf;
6844 tsize_t size;
6845 { 6645 {
6846 return (size_t) -1; 6646 return (size_t) -1;
6847 } 6647 }
6848 6648
6849 static toff_t 6649 static toff_t
6850 tiff_seek_in_memory (data, off, whence) 6650 tiff_seek_in_memory (thandle_t data, toff_t off, int whence)
6851 thandle_t data;
6852 toff_t off;
6853 int whence;
6854 { 6651 {
6855 tiff_memory_source *src = (tiff_memory_source *) data; 6652 tiff_memory_source *src = (tiff_memory_source *) data;
6856 int idx; 6653 int idx;
6857 6654
6858 switch (whence) 6655 switch (whence)
6879 src->index = idx; 6676 src->index = idx;
6880 return src->index; 6677 return src->index;
6881 } 6678 }
6882 6679
6883 static int 6680 static int
6884 tiff_close_memory (data) 6681 tiff_close_memory (thandle_t data)
6885 thandle_t data;
6886 { 6682 {
6887 /* NOOP */ 6683 /* NOOP */
6888 return 0; 6684 return 0;
6889 } 6685 }
6890 6686
6891 static int 6687 static int
6892 tiff_mmap_memory (data, pbase, psize) 6688 tiff_mmap_memory (thandle_t data, tdata_t *pbase, toff_t *psize)
6893 thandle_t data;
6894 tdata_t *pbase;
6895 toff_t *psize;
6896 { 6689 {
6897 /* It is already _IN_ memory. */ 6690 /* It is already _IN_ memory. */
6898 return 0; 6691 return 0;
6899 } 6692 }
6900 6693
6901 static void 6694 static void
6902 tiff_unmap_memory (data, base, size) 6695 tiff_unmap_memory (thandle_t data, tdata_t base, toff_t size)
6903 thandle_t data;
6904 tdata_t base;
6905 toff_t size;
6906 { 6696 {
6907 /* We don't need to do this. */ 6697 /* We don't need to do this. */
6908 } 6698 }
6909 6699
6910 static toff_t 6700 static toff_t
6911 tiff_size_of_memory (data) 6701 tiff_size_of_memory (thandle_t data)
6912 thandle_t data;
6913 { 6702 {
6914 return ((tiff_memory_source *) data)->len; 6703 return ((tiff_memory_source *) data)->len;
6915 } 6704 }
6916 6705
6917 6706
6918 static void 6707 static void
6919 tiff_error_handler (title, format, ap) 6708 tiff_error_handler (const char *title, const char *format, va_list ap)
6920 const char *title, *format;
6921 va_list ap;
6922 { 6709 {
6923 char buf[512]; 6710 char buf[512];
6924 int len; 6711 int len;
6925 6712
6926 len = sprintf (buf, "TIFF error: %s ", title); 6713 len = sprintf (buf, "TIFF error: %s ", title);
6928 add_to_log (buf, Qnil, Qnil); 6715 add_to_log (buf, Qnil, Qnil);
6929 } 6716 }
6930 6717
6931 6718
6932 static void 6719 static void
6933 tiff_warning_handler (title, format, ap) 6720 tiff_warning_handler (const char *title, const char *format, va_list ap)
6934 const char *title, *format;
6935 va_list ap;
6936 { 6721 {
6937 char buf[512]; 6722 char buf[512];
6938 int len; 6723 int len;
6939 6724
6940 len = sprintf (buf, "TIFF warning: %s ", title); 6725 len = sprintf (buf, "TIFF warning: %s ", title);
6945 6730
6946 /* Load TIFF image IMG for use on frame F. Value is non-zero if 6731 /* Load TIFF image IMG for use on frame F. Value is non-zero if
6947 successful. */ 6732 successful. */
6948 6733
6949 static int 6734 static int
6950 tiff_load (f, img) 6735 tiff_load (struct frame *f, struct image *img)
6951 struct frame *f;
6952 struct image *img;
6953 { 6736 {
6954 Lisp_Object file, specified_file; 6737 Lisp_Object file, specified_file;
6955 Lisp_Object specified_data; 6738 Lisp_Object specified_data;
6956 TIFF *tiff; 6739 TIFF *tiff;
6957 int width, height, x, y, count; 6740 int width, height, x, y, count;
7118 6901
7119 #ifdef HAVE_NS 6902 #ifdef HAVE_NS
7120 static int 6903 static int
7121 tiff_load (struct frame *f, struct image *img) 6904 tiff_load (struct frame *f, struct image *img)
7122 { 6905 {
7123 return ns_load_image(f, img, 6906 return ns_load_image (f, img,
7124 image_spec_value (img->spec, QCfile, NULL), 6907 image_spec_value (img->spec, QCfile, NULL),
7125 image_spec_value (img->spec, QCdata, NULL)); 6908 image_spec_value (img->spec, QCdata, NULL));
7126 } 6909 }
7127 #endif /* HAVE_NS */ 6910 #endif /* HAVE_NS */
7128 6911
7129 #endif /* !HAVE_TIFF */ 6912 #endif /* !HAVE_TIFF */
7130 6913
7134 GIF 6917 GIF
7135 ***********************************************************************/ 6918 ***********************************************************************/
7136 6919
7137 #if defined (HAVE_GIF) || defined (HAVE_NS) 6920 #if defined (HAVE_GIF) || defined (HAVE_NS)
7138 6921
7139 static int gif_image_p P_ ((Lisp_Object object)); 6922 static int gif_image_p (Lisp_Object object);
7140 static int gif_load P_ ((struct frame *f, struct image *img)); 6923 static int gif_load (struct frame *f, struct image *img);
7141 static void gif_clear_image P_ ((struct frame *f, struct image *img)); 6924 static void gif_clear_image (struct frame *f, struct image *img);
7142 6925
7143 /* The symbol `gif' identifying images of this type. */ 6926 /* The symbol `gif' identifying images of this type. */
7144 6927
7145 Lisp_Object Qgif; 6928 Lisp_Object Qgif;
7146 6929
7192 }; 6975 };
7193 6976
7194 /* Free X resources of GIF image IMG which is used on frame F. */ 6977 /* Free X resources of GIF image IMG which is used on frame F. */
7195 6978
7196 static void 6979 static void
7197 gif_clear_image (f, img) 6980 gif_clear_image (struct frame *f, struct image *img)
7198 struct frame *f;
7199 struct image *img;
7200 { 6981 {
7201 /* IMG->data.ptr_val may contain metadata with extension data. */ 6982 /* IMG->data.ptr_val may contain metadata with extension data. */
7202 img->data.lisp_val = Qnil; 6983 img->data.lisp_val = Qnil;
7203 x_clear_image (f, img); 6984 x_clear_image (f, img);
7204 } 6985 }
7205 6986
7206 /* Return non-zero if OBJECT is a valid GIF image specification. */ 6987 /* Return non-zero if OBJECT is a valid GIF image specification. */
7207 6988
7208 static int 6989 static int
7209 gif_image_p (object) 6990 gif_image_p (Lisp_Object object)
7210 Lisp_Object object;
7211 { 6991 {
7212 struct image_keyword fmt[GIF_LAST]; 6992 struct image_keyword fmt[GIF_LAST];
7213 bcopy (gif_format, fmt, sizeof fmt); 6993 memcpy (fmt, gif_format, sizeof fmt);
7214 6994
7215 if (!parse_image_spec (object, fmt, GIF_LAST, Qgif)) 6995 if (!parse_image_spec (object, fmt, GIF_LAST, Qgif))
7216 return 0; 6996 return 0;
7217 6997
7218 /* Must specify either the :data or :file keyword. */ 6998 /* Must specify either the :data or :file keyword. */
7288 It's done this way because not all versions of libungif support 7068 It's done this way because not all versions of libungif support
7289 a UserData field in the GifFileType structure. */ 7069 a UserData field in the GifFileType structure. */
7290 static gif_memory_source *current_gif_memory_src; 7070 static gif_memory_source *current_gif_memory_src;
7291 7071
7292 static int 7072 static int
7293 gif_read_from_memory (file, buf, len) 7073 gif_read_from_memory (GifFileType *file, GifByteType *buf, int len)
7294 GifFileType *file;
7295 GifByteType *buf;
7296 int len;
7297 { 7074 {
7298 gif_memory_source *src = current_gif_memory_src; 7075 gif_memory_source *src = current_gif_memory_src;
7299 7076
7300 if (len > src->len - src->index) 7077 if (len > src->len - src->index)
7301 return -1; 7078 return -1;
7302 7079
7303 bcopy (src->bytes + src->index, buf, len); 7080 memcpy (buf, src->bytes + src->index, len);
7304 src->index += len; 7081 src->index += len;
7305 return len; 7082 return len;
7306 } 7083 }
7307 7084
7308 7085
7311 7088
7312 static const int interlace_start[] = {0, 4, 2, 1}; 7089 static const int interlace_start[] = {0, 4, 2, 1};
7313 static const int interlace_increment[] = {8, 8, 4, 2}; 7090 static const int interlace_increment[] = {8, 8, 4, 2};
7314 7091
7315 static int 7092 static int
7316 gif_load (f, img) 7093 gif_load (struct frame *f, struct image *img)
7317 struct frame *f;
7318 struct image *img;
7319 { 7094 {
7320 Lisp_Object file, specified_file; 7095 Lisp_Object file, specified_file;
7321 Lisp_Object specified_data; 7096 Lisp_Object specified_data;
7322 int rc, width, height, x, y, i; 7097 int rc, width, height, x, y, i;
7323 XImagePtr ximg; 7098 XImagePtr ximg;
7436 /* Allocate colors. */ 7211 /* Allocate colors. */
7437 gif_color_map = gif->SavedImages[ino].ImageDesc.ColorMap; 7212 gif_color_map = gif->SavedImages[ino].ImageDesc.ColorMap;
7438 if (!gif_color_map) 7213 if (!gif_color_map)
7439 gif_color_map = gif->SColorMap; 7214 gif_color_map = gif->SColorMap;
7440 init_color_table (); 7215 init_color_table ();
7441 bzero (pixel_colors, sizeof pixel_colors); 7216 memset (pixel_colors, 0, sizeof pixel_colors);
7442 7217
7443 if (gif_color_map) 7218 if (gif_color_map)
7444 for (i = 0; i < gif_color_map->ColorCount; ++i) 7219 for (i = 0; i < gif_color_map->ColorCount; ++i)
7445 { 7220 {
7446 int r = gif_color_map->Colors[i].Red << 8; 7221 int r = gif_color_map->Colors[i].Red << 8;
7556 7331
7557 #ifdef HAVE_NS 7332 #ifdef HAVE_NS
7558 static int 7333 static int
7559 gif_load (struct frame *f, struct image *img) 7334 gif_load (struct frame *f, struct image *img)
7560 { 7335 {
7561 return ns_load_image(f, img, 7336 return ns_load_image (f, img,
7562 image_spec_value (img->spec, QCfile, NULL), 7337 image_spec_value (img->spec, QCfile, NULL),
7563 image_spec_value (img->spec, QCdata, NULL)); 7338 image_spec_value (img->spec, QCdata, NULL));
7564 } 7339 }
7565 #endif /* HAVE_NS */ 7340 #endif /* HAVE_NS */
7566 7341
7567 #endif /* HAVE_GIF */ 7342 #endif /* HAVE_GIF */
7568 7343
7674 unsigned int size, 7449 unsigned int size,
7675 /* Filename, either pass filename or 7450 /* Filename, either pass filename or
7676 contents/size. */ 7451 contents/size. */
7677 unsigned char *filename) 7452 unsigned char *filename)
7678 { 7453 {
7679 long unsigned int width; 7454 size_t width;
7680 long unsigned int height; 7455 size_t height;
7681 7456
7682 MagickBooleanType 7457 MagickBooleanType
7683 status; 7458 status;
7684 7459
7685 XImagePtr ximg; 7460 XImagePtr ximg;
8073 7848
8074 DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, 0, 7849 DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, 0,
8075 doc: /* Return image file types supported by ImageMagick. 7850 doc: /* Return image file types supported by ImageMagick.
8076 Since ImageMagick recognizes a lot of file-types that clash with Emacs, 7851 Since ImageMagick recognizes a lot of file-types that clash with Emacs,
8077 such as .c, we want to be able to alter the list at the lisp level. */) 7852 such as .c, we want to be able to alter the list at the lisp level. */)
8078 () 7853 (void)
8079 { 7854 {
8080 Lisp_Object typelist = Qnil; 7855 Lisp_Object typelist = Qnil;
8081 unsigned long numf; 7856 size_t numf;
8082 ExceptionInfo ex; 7857 ExceptionInfo ex;
8083 char** imtypes = GetMagickList ("*", &numf, &ex); 7858 char** imtypes = GetMagickList ("*", &numf, &ex);
8084 int i; 7859 int i;
8085 Lisp_Object Qimagemagicktype; 7860 Lisp_Object Qimagemagicktype;
8086 for (i = 0; i < numf; i++) 7861 for (i = 0; i < numf; i++)
8101 7876
8102 #if defined (HAVE_RSVG) 7877 #if defined (HAVE_RSVG)
8103 7878
8104 /* Function prototypes. */ 7879 /* Function prototypes. */
8105 7880
8106 static int svg_image_p P_ ((Lisp_Object object)); 7881 static int svg_image_p (Lisp_Object object);
8107 static int svg_load P_ ((struct frame *f, struct image *img)); 7882 static int svg_load (struct frame *f, struct image *img);
8108 7883
8109 static int svg_load_image P_ ((struct frame *, struct image *, 7884 static int svg_load_image (struct frame *, struct image *,
8110 unsigned char *, unsigned int)); 7885 unsigned char *, unsigned int);
8111 7886
8112 /* The symbol `svg' identifying images of this type. */ 7887 /* The symbol `svg' identifying images of this type. */
8113 7888
8114 Lisp_Object Qsvg; 7889 Lisp_Object Qsvg;
8115 7890
8170 /* Return non-zero if OBJECT is a valid SVG image specification. Do 7945 /* Return non-zero if OBJECT is a valid SVG image specification. Do
8171 this by calling parse_image_spec and supplying the keywords that 7946 this by calling parse_image_spec and supplying the keywords that
8172 identify the SVG format. */ 7947 identify the SVG format. */
8173 7948
8174 static int 7949 static int
8175 svg_image_p (object) 7950 svg_image_p (Lisp_Object object)
8176 Lisp_Object object;
8177 { 7951 {
8178 struct image_keyword fmt[SVG_LAST]; 7952 struct image_keyword fmt[SVG_LAST];
8179 bcopy (svg_format, fmt, sizeof fmt); 7953 memcpy (fmt, svg_format, sizeof fmt);
8180 7954
8181 if (!parse_image_spec (object, fmt, SVG_LAST, Qsvg)) 7955 if (!parse_image_spec (object, fmt, SVG_LAST, Qsvg))
8182 return 0; 7956 return 0;
8183 7957
8184 /* Must specify either the :data or :file keyword. */ 7958 /* Must specify either the :data or :file keyword. */
8273 /* Load SVG image IMG for use on frame F. Value is non-zero if 8047 /* Load SVG image IMG for use on frame F. Value is non-zero if
8274 successful. this function will go into the svg_type structure, and 8048 successful. this function will go into the svg_type structure, and
8275 the prototype thus needs to be compatible with that structure. */ 8049 the prototype thus needs to be compatible with that structure. */
8276 8050
8277 static int 8051 static int
8278 svg_load (f, img) 8052 svg_load (struct frame *f, struct image *img)
8279 struct frame *f;
8280 struct image *img;
8281 { 8053 {
8282 int success_p = 0; 8054 int success_p = 0;
8283 Lisp_Object file_name; 8055 Lisp_Object file_name;
8284 8056
8285 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 8057 /* If IMG->spec specifies a file name, create a non-file spec from it. */
8332 8104
8333 Uses librsvg to do most of the image processing. 8105 Uses librsvg to do most of the image processing.
8334 8106
8335 Returns non-zero when successful. */ 8107 Returns non-zero when successful. */
8336 static int 8108 static int
8337 svg_load_image (f, img, contents, size) 8109 svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */
8338 /* Pointer to emacs frame structure. */ 8110 struct image *img, /* Pointer to emacs image structure. */
8339 struct frame *f; 8111 unsigned char *contents, /* String containing the SVG XML data to be parsed. */
8340 /* Pointer to emacs image structure. */ 8112 unsigned int size) /* Size of data in bytes. */
8341 struct image *img;
8342 /* String containing the SVG XML data to be parsed. */
8343 unsigned char *contents;
8344 /* Size of data in bytes. */
8345 unsigned int size;
8346 { 8113 {
8347 RsvgHandle *rsvg_handle; 8114 RsvgHandle *rsvg_handle;
8348 RsvgDimensionData dimension_data; 8115 RsvgDimensionData dimension_data;
8349 GError *error = NULL; 8116 GError *error = NULL;
8350 GdkPixbuf *pixbuf; 8117 GdkPixbuf *pixbuf;
8415 { 8182 {
8416 #ifndef HAVE_NS 8183 #ifndef HAVE_NS
8417 background.pixel = FRAME_BACKGROUND_PIXEL (f); 8184 background.pixel = FRAME_BACKGROUND_PIXEL (f);
8418 x_query_color (f, &background); 8185 x_query_color (f, &background);
8419 #else 8186 #else
8420 ns_query_color(FRAME_BACKGROUND_COLOR (f), &background, 1); 8187 ns_query_color (FRAME_BACKGROUND_COLOR (f), &background, 1);
8421 #endif 8188 #endif
8422 } 8189 }
8423 8190
8424 /* SVG pixmaps specify transparency in the last byte, so right 8191 /* SVG pixmaps specify transparency in the last byte, so right
8425 shift 8 bits to get rid of it, since emacs doesn't support 8192 shift 8 bits to get rid of it, since emacs doesn't support
8501 8268
8502 #ifdef HAVE_X_WINDOWS 8269 #ifdef HAVE_X_WINDOWS
8503 #define HAVE_GHOSTSCRIPT 1 8270 #define HAVE_GHOSTSCRIPT 1
8504 #endif /* HAVE_X_WINDOWS */ 8271 #endif /* HAVE_X_WINDOWS */
8505 8272
8506 /* The symbol `postscript' identifying images of this type. */
8507
8508 Lisp_Object Qpostscript;
8509
8510 #ifdef HAVE_GHOSTSCRIPT 8273 #ifdef HAVE_GHOSTSCRIPT
8511 8274
8512 static int gs_image_p P_ ((Lisp_Object object)); 8275 static int gs_image_p (Lisp_Object object);
8513 static int gs_load P_ ((struct frame *f, struct image *img)); 8276 static int gs_load (struct frame *f, struct image *img);
8514 static void gs_clear_image P_ ((struct frame *f, struct image *img)); 8277 static void gs_clear_image (struct frame *f, struct image *img);
8515 8278
8516 /* Keyword symbols. */ 8279 /* Keyword symbols. */
8517 8280
8518 Lisp_Object QCloader, QCbounding_box, QCpt_width, QCpt_height; 8281 Lisp_Object QCloader, QCbounding_box, QCpt_width, QCpt_height;
8519 8282
8570 8333
8571 8334
8572 /* Free X resources of Ghostscript image IMG which is used on frame F. */ 8335 /* Free X resources of Ghostscript image IMG which is used on frame F. */
8573 8336
8574 static void 8337 static void
8575 gs_clear_image (f, img) 8338 gs_clear_image (struct frame *f, struct image *img)
8576 struct frame *f;
8577 struct image *img;
8578 { 8339 {
8579 /* IMG->data.ptr_val may contain a recorded colormap. */ 8340 /* IMG->data.ptr_val may contain a recorded colormap. */
8580 xfree (img->data.ptr_val); 8341 xfree (img->data.ptr_val);
8581 x_clear_image (f, img); 8342 x_clear_image (f, img);
8582 } 8343 }
8584 8345
8585 /* Return non-zero if OBJECT is a valid Ghostscript image 8346 /* Return non-zero if OBJECT is a valid Ghostscript image
8586 specification. */ 8347 specification. */
8587 8348
8588 static int 8349 static int
8589 gs_image_p (object) 8350 gs_image_p (Lisp_Object object)
8590 Lisp_Object object;
8591 { 8351 {
8592 struct image_keyword fmt[GS_LAST]; 8352 struct image_keyword fmt[GS_LAST];
8593 Lisp_Object tem; 8353 Lisp_Object tem;
8594 int i; 8354 int i;
8595 8355
8596 bcopy (gs_format, fmt, sizeof fmt); 8356 memcpy (fmt, gs_format, sizeof fmt);
8597 8357
8598 if (!parse_image_spec (object, fmt, GS_LAST, Qpostscript)) 8358 if (!parse_image_spec (object, fmt, GS_LAST, Qpostscript))
8599 return 0; 8359 return 0;
8600 8360
8601 /* Bounding box must be a list or vector containing 4 integers. */ 8361 /* Bounding box must be a list or vector containing 4 integers. */
8625 8385
8626 /* Load Ghostscript image IMG for use on frame F. Value is non-zero 8386 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
8627 if successful. */ 8387 if successful. */
8628 8388
8629 static int 8389 static int
8630 gs_load (f, img) 8390 gs_load (struct frame *f, struct image *img)
8631 struct frame *f;
8632 struct image *img;
8633 { 8391 {
8634 char buffer[100]; 8392 char buffer[100];
8635 Lisp_Object window_and_pixmap_id = Qnil, loader, pt_height, pt_width; 8393 Lisp_Object window_and_pixmap_id = Qnil, loader, pt_height, pt_width;
8636 struct gcpro gcpro1, gcpro2; 8394 struct gcpro gcpro1, gcpro2;
8637 Lisp_Object frame; 8395 Lisp_Object frame;
8705 /* Kill the Ghostscript process that was started to fill PIXMAP on 8463 /* Kill the Ghostscript process that was started to fill PIXMAP on
8706 frame F. Called from XTread_socket when receiving an event 8464 frame F. Called from XTread_socket when receiving an event
8707 telling Emacs that Ghostscript has finished drawing. */ 8465 telling Emacs that Ghostscript has finished drawing. */
8708 8466
8709 void 8467 void
8710 x_kill_gs_process (pixmap, f) 8468 x_kill_gs_process (Pixmap pixmap, struct frame *f)
8711 Pixmap pixmap;
8712 struct frame *f;
8713 { 8469 {
8714 struct image_cache *c = FRAME_IMAGE_CACHE (f); 8470 struct image_cache *c = FRAME_IMAGE_CACHE (f);
8715 int class, i; 8471 int class, i;
8716 struct image *img; 8472 struct image *img;
8717 8473
8805 8561
8806 #if GLYPH_DEBUG 8562 #if GLYPH_DEBUG
8807 8563
8808 DEFUN ("imagep", Fimagep, Simagep, 1, 1, 0, 8564 DEFUN ("imagep", Fimagep, Simagep, 1, 1, 0,
8809 doc: /* Value is non-nil if SPEC is a valid image specification. */) 8565 doc: /* Value is non-nil if SPEC is a valid image specification. */)
8810 (spec) 8566 (Lisp_Object spec)
8811 Lisp_Object spec;
8812 { 8567 {
8813 return valid_image_p (spec) ? Qt : Qnil; 8568 return valid_image_p (spec) ? Qt : Qnil;
8814 } 8569 }
8815 8570
8816 8571
8817 DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "") 8572 DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "")
8818 (spec) 8573 (Lisp_Object spec)
8819 Lisp_Object spec;
8820 { 8574 {
8821 int id = -1; 8575 int id = -1;
8822 8576
8823 if (valid_image_p (spec)) 8577 if (valid_image_p (spec))
8824 id = lookup_image (SELECTED_FRAME (), spec); 8578 id = lookup_image (SELECTED_FRAME (), spec);
8846 8600
8847 DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0, 8601 DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0,
8848 doc: /* Initialize image library implementing image type TYPE. 8602 doc: /* Initialize image library implementing image type TYPE.
8849 Return non-nil if TYPE is a supported image type. 8603 Return non-nil if TYPE is a supported image type.
8850 8604
8851 Image types pbm and xbm are prebuilt; other types are loaded here. 8605 Image types pbm and xbm are prebuilt; other types are loaded here.
8852 Libraries to load are specified in alist LIBRARIES (usually, the value 8606 Libraries to load are specified in alist LIBRARIES (usually, the value
8853 of `image-library-alist', which see). */) 8607 of `image-library-alist', which see). */)
8854 (type, libraries) 8608 (Lisp_Object type, Lisp_Object libraries)
8855 Lisp_Object type, libraries;
8856 { 8609 {
8857 Lisp_Object tested; 8610 Lisp_Object tested;
8858 8611
8859 /* Don't try to reload the library. */ 8612 /* Don't try to reload the library. */
8860 tested = Fassq (type, Vimage_type_cache); 8613 tested = Fassq (type, Vimage_type_cache);
8910 return Qnil; 8663 return Qnil;
8911 } 8664 }
8912 8665
8913 8666
8914 void 8667 void
8915 syms_of_image () 8668 syms_of_image (void)
8916 { 8669 {
8917 extern Lisp_Object Qrisky_local_variable; /* Syms_of_xdisp has already run. */
8918
8919 /* Initialize this only once, since that's what we do with Vimage_types 8670 /* Initialize this only once, since that's what we do with Vimage_types
8920 and they are supposed to be in sync. Initializing here gives correct 8671 and they are supposed to be in sync. Initializing here gives correct
8921 operation on GNU/Linux of calling dump-emacs after loading some images. */ 8672 operation on GNU/Linux of calling dump-emacs after loading some images. */
8922 image_types = NULL; 8673 image_types = NULL;
8923 8674
9116 8867
9117 } 8868 }
9118 8869
9119 8870
9120 void 8871 void
9121 init_image () 8872 init_image (void)
9122 { 8873 {
9123 8874
9124 } 8875 }
9125 8876
9126 8877