0
|
1 /* X-specific Lisp objects.
|
|
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995 Tinker Systems
|
|
5 Copyright (C) 1995, 1996 Ben Wing
|
|
6 Copyright (C) 1995 Sun Microsystems
|
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
10 XEmacs is free software; you can redistribute it and/or modify it
|
|
11 under the terms of the GNU General Public License as published by the
|
|
12 Free Software Foundation; either version 2, or (at your option) any
|
|
13 later version.
|
|
14
|
|
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
18 for more details.
|
|
19
|
|
20 You should have received a copy of the GNU General Public License
|
|
21 along with XEmacs; see the file COPYING. If not, write to
|
|
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 Boston, MA 02111-1307, USA. */
|
|
24
|
|
25 /* Synched up with: Not in FSF. */
|
|
26
|
|
27 /* Original author: Jamie Zawinski for 19.8
|
|
28 font-truename stuff added by Jamie Zawinski for 19.10
|
|
29 subwindow support added by Chuck Thompson
|
|
30 additional XPM support added by Chuck Thompson
|
|
31 initial X-Face support added by Stig
|
|
32 rewritten/restructured by Ben Wing for 19.12/19.13
|
|
33 GIF/JPEG support added by Ben Wing for 19.14
|
|
34 PNG support added by Bill Perry for 19.14
|
|
35 Improved GIF/JPEG support added by Bill Perry for 19.14
|
|
36 Cleanup/simplification of error handling by Ben Wing for 19.14
|
|
37 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14
|
|
38
|
|
39 TODO:
|
|
40 TIFF Support
|
|
41 Loadable module support for images
|
|
42 Convert images.el to C and stick it in here?
|
|
43 */
|
|
44
|
|
45 #include <config.h>
|
|
46 #include "lisp.h"
|
|
47
|
|
48 #include "console-x.h"
|
|
49 #include "glyphs-x.h"
|
|
50 #include "objects-x.h"
|
|
51 #include "xmu.h"
|
|
52
|
|
53 #include "buffer.h"
|
|
54 #include "frame.h"
|
|
55 #include "insdel.h"
|
|
56 #include "opaque.h"
|
|
57
|
|
58 #include "sysfile.h"
|
|
59
|
|
60 #include <setjmp.h>
|
|
61
|
36
|
62 /* Set to 1 if you wish to implement this feature */
|
|
63 # define HAVE_SUBWINDOWS 0
|
|
64
|
0
|
65 #define LISP_DEVICE_TO_X_SCREEN(dev) \
|
|
66 XDefaultScreenOfDisplay (DEVICE_X_DISPLAY (XDEVICE (dev)))
|
|
67
|
|
68 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xbm);
|
|
69 Lisp_Object Qxbm;
|
|
70
|
|
71 Lisp_Object Q_mask_file, Q_mask_data, Q_hotspot_x, Q_hotspot_y;
|
|
72 Lisp_Object Q_foreground, Q_background;
|
|
73
|
|
74 #ifdef HAVE_XPM
|
|
75 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm);
|
|
76 Lisp_Object Qxpm;
|
|
77 Lisp_Object Q_color_symbols;
|
|
78 #endif
|
|
79
|
|
80 #ifdef HAVE_XFACE
|
|
81 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xface);
|
|
82 Lisp_Object Qxface;
|
|
83 #endif
|
|
84
|
|
85 #ifdef HAVE_JPEG
|
|
86 DEFINE_IMAGE_INSTANTIATOR_FORMAT (jpeg);
|
|
87 Lisp_Object Qjpeg;
|
|
88 #endif
|
|
89
|
|
90 #ifdef HAVE_PNG
|
|
91 DEFINE_IMAGE_INSTANTIATOR_FORMAT (png);
|
|
92 Lisp_Object Qpng;
|
|
93 #endif
|
|
94
|
|
95 #ifdef HAVE_TIFF
|
|
96 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tiff);
|
|
97 Lisp_Object Qtiff;
|
|
98 #endif
|
|
99
|
|
100 #ifdef HAVE_GIF
|
|
101 DEFINE_IMAGE_INSTANTIATOR_FORMAT (gif);
|
|
102 Lisp_Object Qgif;
|
|
103 #endif
|
|
104
|
|
105 DEFINE_IMAGE_INSTANTIATOR_FORMAT (cursor_font);
|
|
106 Lisp_Object Qcursor_font;
|
|
107
|
|
108 DEFINE_IMAGE_INSTANTIATOR_FORMAT (font);
|
|
109
|
|
110 DEFINE_IMAGE_INSTANTIATOR_FORMAT (autodetect);
|
|
111
|
|
112 static void cursor_font_instantiate (Lisp_Object image_instance,
|
|
113 Lisp_Object instantiator,
|
|
114 Lisp_Object pointer_fg,
|
|
115 Lisp_Object pointer_bg,
|
|
116 int dest_mask);
|
|
117
|
|
118 #include "bitmaps.h"
|
|
119
|
|
120
|
|
121 /************************************************************************/
|
|
122 /* image instance methods */
|
|
123 /************************************************************************/
|
|
124
|
|
125 static void
|
|
126 x_print_image_instance (struct Lisp_Image_Instance *p,
|
|
127 Lisp_Object printcharfun,
|
|
128 int escapeflag)
|
|
129 {
|
|
130 char buf[100];
|
|
131
|
|
132 switch (IMAGE_INSTANCE_TYPE (p))
|
|
133 {
|
|
134 case IMAGE_MONO_PIXMAP:
|
|
135 case IMAGE_COLOR_PIXMAP:
|
|
136 case IMAGE_POINTER:
|
|
137 sprintf (buf, " (0x%lx", (unsigned long) IMAGE_INSTANCE_X_PIXMAP (p));
|
|
138 write_c_string (buf, printcharfun);
|
|
139 if (IMAGE_INSTANCE_X_MASK (p))
|
|
140 {
|
|
141 sprintf (buf, "/0x%lx", (unsigned long) IMAGE_INSTANCE_X_MASK (p));
|
|
142 write_c_string (buf, printcharfun);
|
|
143 }
|
|
144 write_c_string (")", printcharfun);
|
|
145 break;
|
36
|
146 #if HAVE_SUBWINDOWS
|
0
|
147 case IMAGE_SUBWINDOW:
|
|
148 /* #### implement me */
|
36
|
149 #endif
|
0
|
150 default:
|
|
151 break;
|
|
152 }
|
|
153 }
|
|
154
|
|
155 static void
|
|
156 x_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
157 {
|
|
158 if (!p->data)
|
|
159 return;
|
|
160
|
|
161 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
162 {
|
|
163 Screen *scr = LISP_DEVICE_TO_X_SCREEN (IMAGE_INSTANCE_DEVICE (p));
|
|
164
|
|
165 if (IMAGE_INSTANCE_X_PIXMAP (p))
|
|
166 XFreePixmap (DisplayOfScreen (scr), IMAGE_INSTANCE_X_PIXMAP (p));
|
|
167 if (IMAGE_INSTANCE_X_MASK (p) &&
|
|
168 IMAGE_INSTANCE_X_MASK (p) != IMAGE_INSTANCE_X_PIXMAP (p))
|
|
169 XFreePixmap (DisplayOfScreen (scr), IMAGE_INSTANCE_X_MASK (p));
|
|
170 IMAGE_INSTANCE_X_PIXMAP (p) = 0;
|
|
171 IMAGE_INSTANCE_X_MASK (p) = 0;
|
|
172
|
|
173 if (IMAGE_INSTANCE_X_CURSOR (p))
|
|
174 {
|
|
175 XFreeCursor (DisplayOfScreen (scr), IMAGE_INSTANCE_X_CURSOR (p));
|
|
176 IMAGE_INSTANCE_X_CURSOR (p) = 0;
|
|
177 }
|
|
178
|
|
179 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0)
|
|
180 {
|
|
181 XFreeColors (DisplayOfScreen (scr),
|
|
182 DefaultColormapOfScreen (scr),
|
|
183 IMAGE_INSTANCE_X_PIXELS (p),
|
|
184 IMAGE_INSTANCE_X_NPIXELS (p), 0);
|
|
185 IMAGE_INSTANCE_X_NPIXELS (p) = 0;
|
|
186 }
|
|
187 }
|
|
188 if (IMAGE_INSTANCE_X_PIXELS (p))
|
|
189 {
|
|
190 xfree (IMAGE_INSTANCE_X_PIXELS (p));
|
|
191 IMAGE_INSTANCE_X_PIXELS (p) = 0;
|
|
192 }
|
|
193
|
|
194 xfree (p->data);
|
|
195 p->data = 0;
|
|
196 }
|
|
197
|
|
198 static int
|
|
199 x_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
200 struct Lisp_Image_Instance *p2, int depth)
|
|
201 {
|
|
202 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
203 {
|
|
204 case IMAGE_MONO_PIXMAP:
|
|
205 case IMAGE_COLOR_PIXMAP:
|
|
206 case IMAGE_POINTER:
|
|
207 if (IMAGE_INSTANCE_X_NPIXELS (p1) != IMAGE_INSTANCE_X_NPIXELS (p2))
|
|
208 return 0;
|
|
209 break;
|
36
|
210 #if HAVE_SUBWINDOWS
|
0
|
211 case IMAGE_SUBWINDOW:
|
|
212 /* #### implement me */
|
36
|
213 #endif
|
0
|
214 break;
|
|
215 default:
|
|
216 break;
|
|
217 }
|
|
218
|
|
219 return 1;
|
|
220 }
|
|
221
|
|
222 static unsigned long
|
|
223 x_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
224 {
|
|
225 switch (IMAGE_INSTANCE_TYPE (p))
|
|
226 {
|
|
227 case IMAGE_MONO_PIXMAP:
|
|
228 case IMAGE_COLOR_PIXMAP:
|
|
229 case IMAGE_POINTER:
|
|
230 return IMAGE_INSTANCE_X_NPIXELS (p);
|
36
|
231 #if HAVE_SUBWINDOWS
|
0
|
232 case IMAGE_SUBWINDOW:
|
|
233 /* #### implement me */
|
36
|
234 #endif
|
0
|
235 return 0;
|
|
236 default:
|
|
237 return 0;
|
|
238 }
|
|
239 }
|
|
240
|
|
241 /* Set all the slots in an image instance structure to reasonable
|
|
242 default values. This is used somewhere within an instantiate
|
|
243 method. It is assumed that the device slot within the image
|
|
244 instance is already set -- this is the case when instantiate
|
|
245 methods are called. */
|
|
246
|
|
247 static void
|
|
248 x_initialize_pixmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
249 enum image_instance_type type)
|
|
250 {
|
|
251 ii->data = malloc_type_and_zero (struct x_image_instance_data);
|
|
252 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
253 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
254 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
255 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
256 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
257 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
258 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
259 }
|
|
260
|
|
261
|
|
262 /************************************************************************/
|
|
263 /* pixmap file functions */
|
|
264 /************************************************************************/
|
|
265
|
|
266 /* Where bitmaps are; initialized from resource database */
|
|
267 Lisp_Object Vx_bitmap_file_path;
|
|
268
|
|
269 #ifndef BITMAPDIR
|
|
270 #define BITMAPDIR "/usr/include/X11/bitmaps"
|
|
271 #endif
|
|
272
|
|
273 #define USE_XBMLANGPATH
|
|
274
|
|
275 /* Given a pixmap filename, look through all of the "standard" places
|
|
276 where the file might be located. Return a full pathname if found;
|
|
277 otherwise, return Qnil. */
|
|
278
|
|
279 static Lisp_Object
|
|
280 locate_pixmap_file (Lisp_Object name)
|
|
281 {
|
|
282 /* This function can GC if IN_REDISPLAY is false */
|
|
283 Display *display;
|
|
284
|
|
285 /* Check non-absolute pathnames with a directory component relative to
|
|
286 the search path; that's the way Xt does it. */
|
|
287 /* #### Unix-specific */
|
14
|
288 if (XSTRING_BYTE (name, 0) == '/' ||
|
|
289 (XSTRING_BYTE (name, 0) == '.' &&
|
|
290 (XSTRING_BYTE (name, 1) == '/' ||
|
|
291 (XSTRING_BYTE (name, 1) == '.' &&
|
|
292 (XSTRING_BYTE (name, 2) == '/')))))
|
0
|
293 {
|
|
294 if (!NILP (Ffile_readable_p (name)))
|
|
295 return name;
|
|
296 else
|
|
297 return Qnil;
|
|
298 }
|
|
299
|
|
300 if (NILP (Vdefault_x_device))
|
|
301 /* This may occur during intialization. */
|
|
302 return Qnil;
|
|
303 else
|
|
304 /* We only check the bitmapFilePath resource on the original X device. */
|
|
305 display = DEVICE_X_DISPLAY (XDEVICE (Vdefault_x_device));
|
|
306
|
|
307 #ifdef USE_XBMLANGPATH
|
|
308 {
|
|
309 char *path = egetenv ("XBMLANGPATH");
|
|
310 SubstitutionRec subs[1];
|
|
311 subs[0].match = 'B';
|
14
|
312 subs[0].substitution = (char *) XSTRING_DATA (name);
|
0
|
313 /* #### Motif uses a big hairy default if $XBMLANGPATH isn't set.
|
|
314 We don't. If you want it used, set it. */
|
|
315 if (path &&
|
|
316 (path = XtResolvePathname (display, "bitmaps", 0, 0, path,
|
|
317 subs, XtNumber (subs), 0)))
|
|
318 {
|
|
319 name = build_string (path);
|
|
320 XtFree (path);
|
|
321 return (name);
|
|
322 }
|
|
323 }
|
|
324 #endif
|
|
325
|
|
326 if (NILP (Vx_bitmap_file_path))
|
|
327 {
|
|
328 char *type = 0;
|
|
329 XrmValue value;
|
|
330 if (XrmGetResource (XtDatabase (display),
|
|
331 "bitmapFilePath", "BitmapFilePath", &type, &value)
|
|
332 && !strcmp (type, "String"))
|
|
333 Vx_bitmap_file_path = decode_env_path (0, (char *) value.addr);
|
|
334 Vx_bitmap_file_path = nconc2 (Vx_bitmap_file_path,
|
|
335 (list1 (build_string (BITMAPDIR))));
|
|
336 }
|
|
337
|
|
338 {
|
|
339 Lisp_Object found;
|
|
340 if (locate_file (Vx_bitmap_file_path, name, "", &found, R_OK) < 0)
|
|
341 {
|
|
342 Lisp_Object temp = list1 (Vdata_directory);
|
|
343 struct gcpro gcpro1;
|
|
344
|
|
345 GCPRO1 (temp);
|
|
346 locate_file (temp, name, "", &found, R_OK);
|
|
347 UNGCPRO;
|
|
348 }
|
|
349
|
|
350 return found;
|
|
351 }
|
|
352 }
|
|
353
|
|
354 /* If INSTANTIATOR refers to inline data, return Qnil.
|
|
355 If INSTANTIATOR refers to data in a file, return the full filename
|
|
356 if it exists; otherwise, return a cons of (filename).
|
|
357
|
|
358 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the
|
|
359 keywords used to look up the file and inline data,
|
|
360 respectively, in the instantiator. Normally these would
|
|
361 be Q_file and Q_data, but might be different for mask data. */
|
|
362
|
|
363 static Lisp_Object
|
|
364 potential_pixmap_file_instantiator (Lisp_Object instantiator,
|
|
365 Lisp_Object file_keyword,
|
|
366 Lisp_Object data_keyword)
|
|
367 {
|
|
368 Lisp_Object file;
|
|
369 Lisp_Object data;
|
|
370
|
|
371 assert (VECTORP (instantiator));
|
|
372
|
|
373 data = find_keyword_in_vector (instantiator, data_keyword);
|
|
374 file = find_keyword_in_vector (instantiator, file_keyword);
|
|
375
|
|
376 if (!NILP (file) && NILP (data))
|
|
377 {
|
|
378 Lisp_Object retval = locate_pixmap_file (file);
|
|
379 if (!NILP (retval))
|
|
380 return retval;
|
|
381 else
|
|
382 return Fcons (file, Qnil); /* should have been file */
|
|
383 }
|
|
384
|
|
385 return Qnil;
|
|
386 }
|
|
387
|
|
388
|
|
389 static Lisp_Object
|
|
390 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type,
|
|
391 Lisp_Object image_type_tag)
|
|
392 {
|
|
393 Lisp_Object file = Qnil;
|
|
394 struct gcpro gcpro1, gcpro2;
|
|
395 Lisp_Object alist = Qnil;
|
|
396
|
|
397 GCPRO2 (file, alist);
|
|
398
|
|
399 /* Now, convert any file data into inline data. At the end of this,
|
|
400 `data' will contain the inline data (if any) or Qnil, and `file'
|
|
401 will contain the name this data was derived from (if known) or
|
|
402 Qnil.
|
|
403
|
|
404 Note that if we cannot generate any regular inline data, we
|
|
405 skip out. */
|
|
406
|
|
407 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
408
|
|
409 if (CONSP (file)) /* failure locating filename */
|
|
410 signal_double_file_error ("Opening pixmap file",
|
|
411 "no such file or directory",
|
|
412 Fcar (file));
|
|
413
|
|
414 if (NILP (file)) /* no conversion necessary */
|
|
415 RETURN_UNGCPRO (inst);
|
|
416
|
|
417 alist = tagged_vector_to_alist (inst);
|
|
418
|
|
419 {
|
|
420 Lisp_Object data = make_string_from_file (file);
|
|
421 alist = remassq_no_quit (Q_file, alist);
|
|
422 /* there can't be a :data at this point. */
|
|
423 alist = Fcons (Fcons (Q_file, file),
|
|
424 Fcons (Fcons (Q_data, data), alist));
|
|
425 }
|
|
426
|
|
427 {
|
|
428 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist);
|
|
429 free_alist (alist);
|
|
430 RETURN_UNGCPRO (result);
|
|
431 }
|
|
432 }
|
|
433
|
|
434 static void
|
|
435 write_lisp_string_to_temp_file (Lisp_Object string, char *filename_out)
|
|
436 {
|
|
437 Extbyte *bytes;
|
|
438 Extcount len;
|
|
439 FILE *stream;
|
|
440
|
|
441 /* #### This is a definite problem under Mule due to the amount of
|
|
442 stack data it might allocate. Need to be able to convert and
|
|
443 write out to a file. */
|
|
444 GET_STRING_BINARY_DATA_ALLOCA (string, bytes, len);
|
|
445
|
|
446 /* Write out to a temporary file ... */
|
|
447 sprintf (filename_out, "/tmp/emacs%d.XXXXXX", (int) getpid ());
|
|
448 mktemp (filename_out);
|
|
449 stream = fopen (filename_out, "w");
|
|
450 if (!stream)
|
|
451 {
|
|
452 temp_file_error:
|
|
453 if (stream)
|
|
454 {
|
|
455 int old_errno = errno;
|
|
456 fclose (stream);
|
|
457 unlink (filename_out);
|
|
458 errno = old_errno;
|
|
459 }
|
|
460 report_file_error ("Creating temp file",
|
|
461 list1 (build_string (filename_out)));
|
|
462 }
|
|
463
|
|
464 if (fwrite (bytes, len, 1, stream) != 1)
|
|
465 goto temp_file_error;
|
|
466
|
|
467 if (fclose (stream) != 0)
|
|
468 {
|
|
469 stream = 0;
|
|
470 goto temp_file_error;
|
|
471 }
|
|
472 }
|
|
473
|
|
474
|
|
475 /************************************************************************/
|
|
476 /* cursor functions */
|
|
477 /************************************************************************/
|
|
478
|
|
479 /* Check that this server supports cursors of size WIDTH * HEIGHT. If
|
|
480 not, signal an error. INSTANTIATOR is only used in the error
|
|
481 message. */
|
|
482
|
|
483 static void
|
|
484 check_pointer_sizes (Screen *xs, unsigned int width, unsigned int height,
|
|
485 Lisp_Object instantiator)
|
|
486 {
|
|
487 unsigned int best_width, best_height;
|
|
488 if (! XQueryBestCursor (DisplayOfScreen (xs), RootWindowOfScreen (xs),
|
|
489 width, height, &best_width, &best_height))
|
|
490 /* this means that an X error of some sort occurred (we trap
|
|
491 these so they're not fatal). */
|
|
492 signal_simple_error ("XQueryBestCursor() failed?", instantiator);
|
|
493
|
|
494 if (width > best_width || height > best_height)
|
|
495 error_with_frob (instantiator,
|
|
496 "pointer too large (%dx%d): "
|
|
497 "server requires %dx%d or smaller",
|
|
498 width, height, best_width, best_height);
|
|
499 }
|
|
500
|
|
501
|
|
502 static void
|
|
503 generate_cursor_fg_bg (Lisp_Object device, Lisp_Object *foreground,
|
|
504 Lisp_Object *background, XColor *xfg, XColor *xbg)
|
|
505 {
|
|
506 if (!NILP (*foreground) && !COLOR_INSTANCEP (*foreground))
|
|
507 *foreground =
|
|
508 Fmake_color_instance (*foreground, device,
|
|
509 encode_error_behavior_flag (ERROR_ME));
|
|
510 if (COLOR_INSTANCEP (*foreground))
|
|
511 *xfg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (*foreground));
|
|
512 else
|
|
513 {
|
|
514 xfg->pixel = 0;
|
|
515 xfg->red = xfg->green = xfg->blue = 0;
|
|
516 }
|
|
517
|
|
518 if (!NILP (*background) && !COLOR_INSTANCEP (*background))
|
|
519 *background =
|
|
520 Fmake_color_instance (*background, device,
|
|
521 encode_error_behavior_flag (ERROR_ME));
|
|
522 if (COLOR_INSTANCEP (*background))
|
|
523 *xbg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (*background));
|
|
524 else
|
|
525 {
|
|
526 xbg->pixel = 0;
|
|
527 xbg->red = xbg->green = xbg->blue = ~0;
|
|
528 }
|
|
529 }
|
|
530
|
|
531 static void
|
|
532 maybe_recolor_cursor (Lisp_Object image_instance, Lisp_Object foreground,
|
|
533 Lisp_Object background)
|
|
534 {
|
|
535 Lisp_Object device = XIMAGE_INSTANCE_DEVICE (image_instance);
|
|
536 XColor xfg, xbg;
|
|
537
|
|
538 generate_cursor_fg_bg (device, &foreground, &background, &xfg, &xbg);
|
|
539 if (!NILP (foreground) || !NILP (background))
|
|
540 {
|
|
541 XRecolorCursor (DEVICE_X_DISPLAY (XDEVICE (device)),
|
|
542 XIMAGE_INSTANCE_X_CURSOR (image_instance),
|
|
543 &xfg, &xbg);
|
|
544 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
545 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
546 }
|
|
547 }
|
|
548
|
|
549
|
|
550 /************************************************************************/
|
|
551 /* color pixmap functions */
|
|
552 /************************************************************************/
|
|
553
|
|
554 /* Initialize an image instance from an XImage.
|
|
555
|
|
556 DEST_MASK specifies the mask of allowed image types.
|
|
557
|
|
558 PIXELS and NPIXELS specify an array of pixels that are used in
|
|
559 the image. These need to be kept around for the duration of the
|
|
560 image. When the image instance is freed, XFreeColors() will
|
|
561 automatically be called on all the pixels specified here; thus,
|
|
562 you should have allocated the pixels yourself using XAllocColor()
|
|
563 or the like. The array passed in is used directly without
|
|
564 being copied, so it should be heap data created with xmalloc().
|
|
565 It will be freed using xfree() when the image instance is
|
|
566 destroyed.
|
|
567
|
|
568 If this fails, signal an error. INSTANTIATOR is only used
|
|
569 in the error message.
|
|
570
|
|
571 #### This should be able to handle conversion into `pointer'.
|
|
572 Use the same code as for `xpm'. */
|
|
573
|
|
574 static void
|
|
575 init_image_instance_from_x_image (struct Lisp_Image_Instance *ii,
|
|
576 XImage *ximage,
|
|
577 int dest_mask,
|
|
578 unsigned long *pixels,
|
|
579 int npixels,
|
|
580 Lisp_Object instantiator)
|
|
581 {
|
|
582 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
583 Display *dpy;
|
|
584 Screen *xs;
|
|
585 GC gc;
|
|
586 Drawable d;
|
|
587 Pixmap pixmap;
|
|
588
|
|
589 if (!DEVICE_X_P (XDEVICE (device)))
|
|
590 signal_simple_error ("Not an X device", device);
|
|
591
|
|
592 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
593 xs = DefaultScreenOfDisplay (dpy);
|
|
594 d = RootWindowOfScreen (xs);
|
|
595
|
|
596 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
597 incompatible_image_types (instantiator, dest_mask,
|
|
598 IMAGE_COLOR_PIXMAP_MASK);
|
|
599
|
|
600 pixmap = XCreatePixmap (dpy, d, ximage->width,
|
|
601 ximage->height, ximage->depth);
|
|
602 if (!pixmap)
|
|
603 signal_simple_error ("Unable to create pixmap", instantiator);
|
|
604
|
|
605 gc = XCreateGC (dpy, pixmap, 0, NULL);
|
|
606 if (!gc)
|
|
607 {
|
|
608 XFreePixmap (dpy, pixmap);
|
|
609 signal_simple_error ("Unable to create GC", instantiator);
|
|
610 }
|
|
611
|
|
612 XPutImage (dpy, pixmap, gc, ximage, 0, 0, 0, 0,
|
|
613 ximage->width, ximage->height);
|
|
614
|
|
615 XFreeGC (dpy, gc);
|
|
616
|
|
617 x_initialize_pixmap_image_instance (ii, IMAGE_COLOR_PIXMAP);
|
|
618
|
|
619 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
620 find_keyword_in_vector (instantiator, Q_file);
|
|
621
|
|
622 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
|
|
623 IMAGE_INSTANCE_X_MASK (ii) = 0;
|
|
624 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = ximage->width;
|
|
625 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = ximage->height;
|
|
626 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = ximage->depth;
|
|
627 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
|
|
628 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
|
|
629 }
|
|
630
|
|
631
|
|
632 /**********************************************************************
|
|
633 * XBM *
|
|
634 **********************************************************************/
|
|
635
|
|
636 /* Check if DATA represents a valid inline XBM spec (i.e. a list
|
|
637 of (width height bits), with checking done on the dimensions).
|
|
638 If not, signal an error. */
|
|
639
|
|
640 static void
|
|
641 check_valid_xbm_inline (Lisp_Object data)
|
|
642 {
|
|
643 Lisp_Object width, height, bits;
|
|
644
|
|
645 CHECK_CONS (data);
|
|
646 if (!CONSP (XCDR (data)) || !CONSP (XCDR (XCDR (data))) ||
|
|
647 !NILP (XCDR (XCDR (XCDR (data)))))
|
|
648 signal_simple_error ("Must be list of 3 elements", data);
|
|
649
|
|
650 width = XCAR (data);
|
|
651 height = XCAR (XCDR (data));
|
|
652 bits = XCAR (XCDR (XCDR (data)));
|
|
653
|
|
654 if (!INTP (width) || !INTP (height) || !STRINGP (bits))
|
|
655 signal_simple_error ("Must be (width height bits)",
|
|
656 vector3 (width, height, bits));
|
|
657
|
|
658 if (XINT (width) <= 0)
|
|
659 signal_simple_error ("Width must be > 0", width);
|
|
660
|
|
661 if (XINT (height) <= 0)
|
|
662 signal_simple_error ("Height must be > 0", height);
|
|
663
|
|
664 if (((unsigned) (XINT (width) * XINT (height)) / 8)
|
|
665 > string_char_length (XSTRING (bits)))
|
|
666 signal_simple_error ("data is too short for W and H",
|
|
667 vector3 (width, height, bits));
|
|
668 }
|
|
669
|
|
670 /* Validate method for XBM's. */
|
|
671
|
|
672 static void
|
|
673 xbm_validate (Lisp_Object instantiator)
|
|
674 {
|
|
675 file_or_data_must_be_present (instantiator);
|
|
676 }
|
|
677
|
|
678 /* Given a filename that is supposed to contain XBM data, return
|
|
679 the inline representation of it as (width height bits). Return
|
|
680 the hotspot through XHOT and YHOT, if those pointers are not 0.
|
|
681 If there is no hotspot, XHOT and YHOT will contain -1.
|
|
682
|
|
683 If the function fails:
|
|
684
|
|
685 -- if OK_IF_DATA_INVALID is set and the data was invalid,
|
|
686 return Qt.
|
|
687 -- maybe return an error, or return Qnil.
|
|
688 */
|
|
689
|
|
690
|
|
691 static Lisp_Object
|
|
692 bitmap_to_lisp_data (Lisp_Object name, int *xhot, int *yhot,
|
|
693 int ok_if_data_invalid)
|
|
694 {
|
|
695 unsigned int w, h;
|
|
696 Extbyte *data;
|
|
697 int result;
|
|
698 CONST char *filename_ext;
|
|
699
|
|
700 GET_C_STRING_FILENAME_DATA_ALLOCA (name, filename_ext);
|
|
701 result = XmuReadBitmapDataFromFile (filename_ext, &w, &h, &data, xhot, yhot);
|
|
702
|
|
703 if (result == BitmapSuccess)
|
|
704 {
|
|
705 Lisp_Object retval;
|
|
706 int len = (w + 7) / 8 * h;
|
|
707
|
|
708 retval = list3 (make_int (w), make_int (h),
|
|
709 make_ext_string (data, len, FORMAT_BINARY));
|
|
710 XFree ((char *) data);
|
|
711 return retval;
|
|
712 }
|
|
713
|
|
714 switch (result)
|
|
715 {
|
|
716 case BitmapOpenFailed:
|
|
717 {
|
|
718 /* should never happen */
|
|
719 signal_double_file_error ("Opening bitmap file",
|
|
720 "no such file or directory",
|
|
721 name);
|
|
722 }
|
|
723 case BitmapFileInvalid:
|
|
724 {
|
|
725 if (ok_if_data_invalid)
|
|
726 return Qt;
|
|
727 signal_double_file_error ("Reading bitmap file",
|
|
728 "invalid data in file",
|
|
729 name);
|
|
730 }
|
|
731 case BitmapNoMemory:
|
|
732 {
|
|
733 signal_double_file_error ("Reading bitmap file",
|
|
734 "out of memory",
|
|
735 name);
|
|
736 }
|
|
737 default:
|
|
738 {
|
|
739 signal_double_file_error_2 ("Reading bitmap file",
|
|
740 "unknown error code",
|
|
741 make_int (result), name);
|
|
742 }
|
|
743 }
|
|
744
|
|
745 return Qnil; /* not reached */
|
|
746 }
|
|
747
|
|
748 static Lisp_Object
|
|
749 xbm_mask_file_munging (Lisp_Object alist, Lisp_Object file,
|
|
750 Lisp_Object mask_file)
|
|
751 {
|
|
752 /* This is unclean but it's fairly standard -- a number of the
|
|
753 bitmaps in /usr/include/X11/bitmaps use it -- so we support
|
|
754 it. */
|
|
755 if (NILP (mask_file)
|
|
756 /* don't override explicitly specified mask data. */
|
|
757 && NILP (assq_no_quit (Q_mask_data, alist))
|
|
758 && !NILP (file))
|
|
759 {
|
|
760 mask_file =
|
|
761 locate_pixmap_file (concat2 (file, build_string ("Mask")));
|
|
762 if (NILP (mask_file))
|
|
763 mask_file =
|
|
764 locate_pixmap_file (concat2 (file, build_string ("msk")));
|
|
765 }
|
|
766
|
|
767 if (!NILP (mask_file))
|
|
768 {
|
|
769 Lisp_Object mask_data =
|
|
770 bitmap_to_lisp_data (mask_file, 0, 0, 0);
|
|
771 alist = remassq_no_quit (Q_mask_file, alist);
|
|
772 /* there can't be a :mask-data at this point. */
|
|
773 alist = Fcons (Fcons (Q_mask_file, mask_file),
|
|
774 Fcons (Fcons (Q_mask_data, mask_data), alist));
|
|
775 }
|
|
776
|
|
777 return alist;
|
|
778 }
|
|
779
|
|
780 /* Normalize method for XBM's. */
|
|
781
|
|
782 static Lisp_Object
|
|
783 xbm_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
784 {
|
|
785 Lisp_Object file = Qnil, mask_file = Qnil;
|
|
786 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
787 Lisp_Object alist = Qnil;
|
|
788
|
|
789 GCPRO3 (file, mask_file, alist);
|
|
790
|
|
791 /* Now, convert any file data into inline data for both the regular
|
|
792 data and the mask data. At the end of this, `data' will contain
|
|
793 the inline data (if any) or Qnil, and `file' will contain
|
|
794 the name this data was derived from (if known) or Qnil.
|
|
795 Likewise for `mask_file' and `mask_data'.
|
|
796
|
|
797 Note that if we cannot generate any regular inline data, we
|
|
798 skip out. */
|
|
799
|
|
800 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
801 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
|
|
802 Q_mask_data);
|
|
803
|
|
804 if (CONSP (file)) /* failure locating filename */
|
|
805 signal_double_file_error ("Opening bitmap file",
|
|
806 "no such file or directory",
|
|
807 Fcar (file));
|
|
808
|
|
809 if (NILP (file) && NILP (mask_file)) /* no conversion necessary */
|
|
810 RETURN_UNGCPRO (inst);
|
|
811
|
|
812 alist = tagged_vector_to_alist (inst);
|
|
813
|
|
814 if (!NILP (file))
|
|
815 {
|
|
816 int xhot, yhot;
|
|
817 Lisp_Object data = bitmap_to_lisp_data (file, &xhot, &yhot, 0);
|
|
818 alist = remassq_no_quit (Q_file, alist);
|
|
819 /* there can't be a :data at this point. */
|
|
820 alist = Fcons (Fcons (Q_file, file),
|
|
821 Fcons (Fcons (Q_data, data), alist));
|
|
822
|
|
823 if (xhot != -1 && NILP (assq_no_quit (Q_hotspot_x, alist)))
|
|
824 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
825 alist);
|
|
826 if (yhot != -1 && NILP (assq_no_quit (Q_hotspot_y, alist)))
|
|
827 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
828 alist);
|
|
829 }
|
|
830
|
|
831 alist = xbm_mask_file_munging (alist, file, mask_file);
|
|
832
|
|
833 {
|
|
834 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
835 free_alist (alist);
|
|
836 RETURN_UNGCPRO (result);
|
|
837 }
|
|
838 }
|
|
839
|
|
840 /* Given inline data for a mono pixmap, create and return the
|
|
841 corresponding X object. */
|
|
842
|
|
843 static Pixmap
|
|
844 pixmap_from_xbm_inline (Lisp_Object device, int width, int height,
|
|
845 /* Note that data is in ext-format! */
|
|
846 CONST Extbyte *bits)
|
|
847 {
|
|
848 Screen *screen = LISP_DEVICE_TO_X_SCREEN (device);
|
|
849 return XCreatePixmapFromBitmapData (DisplayOfScreen (screen),
|
|
850 RootWindowOfScreen (screen),
|
|
851 (char *) bits, width, height,
|
|
852 1, 0, 1);
|
|
853 }
|
|
854
|
|
855 /* Given inline data for a mono pixmap, initialize the given
|
|
856 image instance accordingly. */
|
|
857
|
|
858 static void
|
|
859 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii,
|
|
860 int width, int height,
|
|
861 /* Note that data is in ext-format! */
|
|
862 CONST char *bits,
|
|
863 Lisp_Object instantiator,
|
|
864 Lisp_Object pointer_fg,
|
|
865 Lisp_Object pointer_bg,
|
|
866 int dest_mask,
|
|
867 Pixmap mask,
|
|
868 Lisp_Object mask_filename)
|
|
869 {
|
|
870 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
871 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
872 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
|
|
873 Display *dpy;
|
|
874 Screen *scr;
|
|
875 enum image_instance_type type;
|
|
876
|
|
877 if (!DEVICE_X_P (XDEVICE (device)))
|
|
878 signal_simple_error ("Not an X device", device);
|
|
879
|
|
880 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
881 scr = DefaultScreenOfDisplay (dpy);
|
|
882
|
|
883 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
|
|
884 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
885 {
|
|
886 if (!NILP (foreground) || !NILP (background))
|
|
887 type = IMAGE_COLOR_PIXMAP;
|
|
888 else
|
|
889 type = IMAGE_MONO_PIXMAP;
|
|
890 }
|
|
891 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
892 type = IMAGE_MONO_PIXMAP;
|
|
893 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
894 type = IMAGE_COLOR_PIXMAP;
|
|
895 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
896 type = IMAGE_POINTER;
|
|
897 else
|
|
898 incompatible_image_types (instantiator, dest_mask,
|
|
899 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
900 | IMAGE_POINTER_MASK);
|
|
901
|
|
902 x_initialize_pixmap_image_instance (ii, type);
|
|
903 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
|
|
904 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
|
|
905 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
906 find_keyword_in_vector (instantiator, Q_file);
|
|
907
|
|
908 switch (type)
|
|
909 {
|
|
910 case IMAGE_MONO_PIXMAP:
|
|
911 {
|
|
912 IMAGE_INSTANCE_X_PIXMAP (ii) =
|
|
913 pixmap_from_xbm_inline (device, width, height, (Extbyte *) bits);
|
|
914 }
|
|
915 break;
|
|
916
|
|
917 case IMAGE_COLOR_PIXMAP:
|
|
918 {
|
|
919 Dimension d = DefaultDepthOfScreen (scr);
|
|
920 unsigned long fg = BlackPixelOfScreen (scr);
|
|
921 unsigned long bg = WhitePixelOfScreen (scr);
|
|
922
|
|
923 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
|
|
924 foreground =
|
|
925 Fmake_color_instance (foreground, device,
|
|
926 encode_error_behavior_flag (ERROR_ME));
|
|
927
|
|
928 if (COLOR_INSTANCEP (foreground))
|
|
929 fg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground)).pixel;
|
|
930
|
|
931 if (!NILP (background) && !COLOR_INSTANCEP (background))
|
|
932 background =
|
|
933 Fmake_color_instance (background, device,
|
|
934 encode_error_behavior_flag (ERROR_ME));
|
|
935
|
|
936 if (COLOR_INSTANCEP (background))
|
|
937 bg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background)).pixel;
|
|
938
|
|
939 /* We used to duplicate the pixels using XAllocColor(), to protect
|
|
940 against their getting freed. Just as easy to just store the
|
|
941 color instances here and GC-protect them, so this doesn't
|
|
942 happen. */
|
|
943 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
944 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
945 IMAGE_INSTANCE_X_PIXMAP (ii) =
|
|
946 XCreatePixmapFromBitmapData (DisplayOfScreen (scr),
|
|
947 RootWindowOfScreen (scr),
|
|
948 (char *) bits, width, height,
|
|
949 fg, bg, d);
|
|
950 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
|
|
951 }
|
|
952 break;
|
|
953
|
|
954 case IMAGE_POINTER:
|
|
955 {
|
|
956 XColor fg_color, bg_color;
|
|
957 Pixmap source;
|
|
958
|
|
959 check_pointer_sizes (scr, width, height, instantiator);
|
|
960
|
|
961 source =
|
|
962 XCreatePixmapFromBitmapData (DisplayOfScreen (scr),
|
|
963 RootWindowOfScreen (scr),
|
|
964 (char *) bits, width, height,
|
|
965 1, 0, 1);
|
|
966
|
|
967 if (NILP (foreground))
|
|
968 foreground = pointer_fg;
|
|
969 if (NILP (background))
|
|
970 background = pointer_bg;
|
|
971 generate_cursor_fg_bg (device, &foreground, &background,
|
|
972 &fg_color, &bg_color);
|
|
973
|
|
974 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
975 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
976 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
|
|
977 find_keyword_in_vector (instantiator, Q_hotspot_x);
|
|
978 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
|
|
979 find_keyword_in_vector (instantiator, Q_hotspot_y);
|
|
980 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
981 XCreatePixmapCursor
|
|
982 (dpy, source, mask, &fg_color, &bg_color,
|
|
983 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ?
|
|
984 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) : 0,
|
|
985 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) ?
|
|
986 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) : 0);
|
|
987 }
|
|
988 break;
|
|
989
|
|
990 default:
|
|
991 abort ();
|
|
992 }
|
|
993 }
|
|
994
|
|
995 static int
|
16
|
996 xbm_possible_dest_types (void)
|
0
|
997 {
|
16
|
998 return
|
|
999 IMAGE_MONO_PIXMAP_MASK |
|
|
1000 IMAGE_COLOR_PIXMAP_MASK |
|
0
|
1001 IMAGE_POINTER_MASK;
|
|
1002 }
|
|
1003
|
|
1004 static void
|
|
1005 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1006 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1007 int dest_mask, int width, int height,
|
|
1008 /* Note that data is in ext-format! */
|
|
1009 CONST char *bits)
|
|
1010 {
|
|
1011 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
|
|
1012 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
|
|
1013 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1014 Pixmap mask = 0;
|
|
1015 CONST char *gcc_may_you_rot_in_hell;
|
|
1016
|
|
1017 if (!NILP (mask_data))
|
|
1018 {
|
|
1019 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))),
|
|
1020 gcc_may_you_rot_in_hell);
|
|
1021 mask =
|
|
1022 pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii),
|
|
1023 XINT (XCAR (mask_data)),
|
|
1024 XINT (XCAR (XCDR (mask_data))),
|
|
1025 (CONST unsigned char *)
|
|
1026 gcc_may_you_rot_in_hell);
|
|
1027 }
|
|
1028
|
|
1029 init_image_instance_from_xbm_inline (ii, width, height, bits,
|
|
1030 instantiator, pointer_fg, pointer_bg,
|
|
1031 dest_mask, mask, mask_file);
|
|
1032 }
|
|
1033
|
|
1034 /* Instantiate method for XBM's. */
|
|
1035
|
|
1036 static void
|
|
1037 xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1038 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1039 int dest_mask)
|
|
1040 {
|
|
1041 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1042 CONST char *gcc_go_home;
|
|
1043
|
|
1044 assert (!NILP (data));
|
|
1045
|
|
1046 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (data))),
|
|
1047 gcc_go_home);
|
|
1048
|
|
1049 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1050 pointer_bg, dest_mask, XINT (XCAR (data)),
|
|
1051 XINT (XCAR (XCDR (data))), gcc_go_home);
|
|
1052 }
|
|
1053
|
|
1054
|
|
1055 #ifdef HAVE_JPEG
|
|
1056
|
|
1057 /**********************************************************************
|
|
1058 * JPEG *
|
|
1059 **********************************************************************/
|
|
1060
|
|
1061 #include "jpeglib.h"
|
|
1062 #include "jerror.h"
|
|
1063
|
6
|
1064 /* The in-core jpeg code doesn't work, so I'm avoiding it for now. -sb */
|
|
1065 #define USE_TEMP_FILES_FOR_JPEG_IMAGES 1
|
|
1066
|
0
|
1067 static void
|
|
1068 jpeg_validate (Lisp_Object instantiator)
|
|
1069 {
|
|
1070 file_or_data_must_be_present (instantiator);
|
|
1071 }
|
|
1072
|
|
1073 static Lisp_Object
|
|
1074 jpeg_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1075 {
|
|
1076 return simple_image_type_normalize (inst, console_type, Qjpeg);
|
|
1077 }
|
|
1078
|
|
1079 static int
|
16
|
1080 jpeg_possible_dest_types (void)
|
0
|
1081 {
|
|
1082 return IMAGE_COLOR_PIXMAP_MASK;
|
|
1083 }
|
|
1084
|
|
1085 /* To survive the otherwise baffling complexity of making sure
|
|
1086 everything gets cleaned up in the presence of an error, we
|
|
1087 use an unwind_protect(). */
|
|
1088
|
|
1089 struct jpeg_unwind_data
|
|
1090 {
|
|
1091 Display *dpy;
|
|
1092 /* Stream that we need to close */
|
|
1093 FILE *instream;
|
|
1094 /* Object that holds state info for JPEG decoding */
|
|
1095 struct jpeg_decompress_struct *cinfo_ptr;
|
|
1096 /* Pixels to keep around while the image is active */
|
|
1097 unsigned long *pixels;
|
|
1098 int npixels;
|
|
1099 /* Client-side image structure */
|
|
1100 XImage *ximage;
|
|
1101 /* Tempfile to remove */
|
|
1102 char tempfile[50];
|
|
1103 int tempfile_needs_to_be_removed;
|
|
1104 };
|
|
1105
|
|
1106 static Lisp_Object
|
|
1107 jpeg_instantiate_unwind (Lisp_Object unwind_obj)
|
|
1108 {
|
|
1109 struct jpeg_unwind_data *data =
|
|
1110 (struct jpeg_unwind_data *) get_opaque_ptr (unwind_obj);
|
|
1111
|
|
1112 free_opaque_ptr (unwind_obj);
|
|
1113 if (data->cinfo_ptr)
|
|
1114 jpeg_destroy_decompress (data->cinfo_ptr);
|
|
1115
|
|
1116 if (data->instream)
|
|
1117 fclose (data->instream);
|
|
1118
|
|
1119 if (data->tempfile_needs_to_be_removed)
|
|
1120 unlink (data->tempfile);
|
|
1121
|
|
1122 if (data->npixels > 0)
|
|
1123 {
|
|
1124 Screen *scr = DefaultScreenOfDisplay (data->dpy);
|
|
1125 Colormap cmap = DefaultColormapOfScreen (scr);
|
|
1126 XFreeColors (data->dpy, cmap, data->pixels, data->npixels, 0L);
|
|
1127 xfree (data->pixels);
|
|
1128 }
|
|
1129
|
|
1130 if (data->ximage)
|
|
1131 {
|
|
1132 if (data->ximage->data)
|
|
1133 {
|
|
1134 xfree (data->ximage->data);
|
|
1135 data->ximage->data = 0;
|
|
1136 }
|
|
1137 XDestroyImage (data->ximage);
|
|
1138 }
|
|
1139
|
|
1140 return Qnil;
|
|
1141 }
|
|
1142
|
|
1143 /*
|
|
1144 * ERROR HANDLING:
|
|
1145 *
|
|
1146 * The JPEG library's standard error handler (jerror.c) is divided into
|
|
1147 * several "methods" which you can override individually. This lets you
|
|
1148 * adjust the behavior without duplicating a lot of code, which you might
|
|
1149 * have to update with each future release.
|
|
1150 *
|
|
1151 * Our example here shows how to override the "error_exit" method so that
|
|
1152 * control is returned to the library's caller when a fatal error occurs,
|
|
1153 * rather than calling exit() as the standard error_exit method does.
|
|
1154 *
|
|
1155 * We use C's setjmp/longjmp facility to return control. This means that the
|
|
1156 * routine which calls the JPEG library must first execute a setjmp() call to
|
|
1157 * establish the return point. We want the replacement error_exit to do a
|
|
1158 * longjmp(). But we need to make the setjmp buffer accessible to the
|
|
1159 * error_exit routine. To do this, we make a private extension of the
|
|
1160 * standard JPEG error handler object. (If we were using C++, we'd say we
|
|
1161 * were making a subclass of the regular error handler.)
|
|
1162 *
|
|
1163 * Here's the extended error handler struct:
|
|
1164 */
|
|
1165
|
|
1166 struct my_jpeg_error_mgr
|
|
1167 {
|
|
1168 struct jpeg_error_mgr pub; /* "public" fields */
|
|
1169 jmp_buf setjmp_buffer; /* for return to caller */
|
|
1170 };
|
|
1171
|
|
1172 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
|
|
1173 METHODDEF(void)
|
|
1174 #else
|
|
1175 METHODDEF void
|
|
1176 #endif
|
|
1177 our_init_source (j_decompress_ptr cinfo) {
|
|
1178 }
|
|
1179
|
|
1180 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
|
|
1181 METHODDEF(boolean)
|
|
1182 #else
|
|
1183 METHODDEF boolean
|
|
1184 #endif
|
|
1185 our_fill_input_buffer (j_decompress_ptr cinfo) {
|
|
1186 ERREXIT(cinfo,JERR_INPUT_EOF);
|
|
1187 return FALSE;
|
|
1188 }
|
|
1189
|
|
1190 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
|
|
1191 METHODDEF(void)
|
|
1192 #else
|
|
1193 METHODDEF void
|
|
1194 #endif
|
|
1195 our_skip_input_data (j_decompress_ptr cinfo, long num_bytes) {
|
|
1196 }
|
|
1197
|
|
1198 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
|
|
1199 METHODDEF(void)
|
|
1200 #else
|
|
1201 METHODDEF void
|
|
1202 #endif
|
|
1203 our_term_source (j_decompress_ptr cinfo) {
|
|
1204 }
|
|
1205
|
|
1206 typedef struct {
|
|
1207 struct jpeg_source_mgr pub;
|
|
1208 } our_jpeg_source_mgr;
|
|
1209
|
|
1210 static void jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data,
|
|
1211 unsigned int len)
|
|
1212 {
|
|
1213 struct jpeg_source_mgr *src = NULL;
|
|
1214
|
|
1215 if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
|
1216 cinfo->src = (struct jpeg_source_mgr *)
|
|
1217 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
|
1218 sizeof(our_jpeg_source_mgr));
|
|
1219 src = (struct jpeg_source_mgr *) cinfo->src;
|
|
1220 src->next_input_byte = data;
|
|
1221 }
|
|
1222 src = (struct jpeg_source_mgr *) cinfo->src;
|
|
1223 src->init_source = our_init_source;
|
|
1224 src->fill_input_buffer = our_fill_input_buffer;
|
|
1225 src->skip_input_data = our_skip_input_data;
|
|
1226 src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
|
1227 src->term_source = our_term_source;
|
|
1228 src->bytes_in_buffer = len;
|
|
1229 src->next_input_byte = data;
|
|
1230 }
|
|
1231
|
|
1232 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
|
|
1233 METHODDEF(void)
|
|
1234 #else
|
|
1235 METHODDEF void
|
|
1236 #endif
|
|
1237 my_jpeg_error_exit (j_common_ptr cinfo)
|
|
1238 {
|
|
1239 /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
|
|
1240 struct my_jpeg_error_mgr *myerr = (struct my_jpeg_error_mgr *) cinfo->err;
|
|
1241
|
|
1242 /* Return control to the setjmp point */
|
|
1243 longjmp (myerr->setjmp_buffer, 1);
|
|
1244 }
|
|
1245
|
|
1246 /* The code in this routine is based on example.c from the JPEG library
|
|
1247 source code and from gif_instantiate() */
|
|
1248 static void
|
|
1249 jpeg_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1250 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1251 int dest_mask)
|
|
1252 {
|
|
1253 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1254 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1255 Display *dpy;
|
|
1256 Screen *scr;
|
|
1257 /* It is OK for the unwind data to be local to this function,
|
|
1258 because the unwind-protect is always executed when this
|
|
1259 stack frame is still valid. */
|
|
1260 struct jpeg_unwind_data unwind;
|
|
1261 int speccount = specpdl_depth ();
|
|
1262
|
|
1263 /* This struct contains the JPEG decompression parameters and pointers to
|
|
1264 * working space (which is allocated as needed by the JPEG library).
|
|
1265 */
|
|
1266 struct jpeg_decompress_struct cinfo;
|
|
1267 /* We use our private extension JPEG error handler.
|
|
1268 * Note that this struct must live as long as the main JPEG parameter
|
|
1269 * struct, to avoid dangling-pointer problems.
|
|
1270 */
|
|
1271 struct my_jpeg_error_mgr jerr;
|
|
1272
|
|
1273 if (!DEVICE_X_P (XDEVICE (device)))
|
|
1274 signal_simple_error ("Not an X device", device);
|
|
1275
|
|
1276 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1277 scr = DefaultScreenOfDisplay (dpy);
|
|
1278
|
|
1279 /* Step -1: First record our unwind-protect, which will clean up after
|
|
1280 any exit, normal or not */
|
|
1281
|
|
1282 memset (&unwind, 0, sizeof (unwind));
|
|
1283 unwind.dpy = dpy;
|
|
1284 record_unwind_protect (jpeg_instantiate_unwind, make_opaque_ptr (&unwind));
|
|
1285
|
6
|
1286 #ifdef USE_TEMP_FILES_FOR_JPEG_IMAGES
|
0
|
1287 /* Step 0: Write out to a temp file.
|
|
1288
|
|
1289 The JPEG routines require you to read from a file unless
|
|
1290 you provide your own special input handlers, which I don't
|
|
1291 feel like doing. */
|
|
1292 {
|
|
1293 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1294
|
|
1295 assert (!NILP (data));
|
|
1296
|
|
1297 write_lisp_string_to_temp_file (data, unwind.tempfile);
|
|
1298 unwind.tempfile_needs_to_be_removed = 1;
|
|
1299
|
|
1300 /* VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
|
|
1301 * requires it in order to read binary files.
|
|
1302 */
|
|
1303
|
|
1304 if ((unwind.instream = fopen (unwind.tempfile, "r")) == NULL)
|
|
1305 report_file_error ("Opening JPEG temp file",
|
|
1306 list1 (build_string (unwind.tempfile)));
|
|
1307 }
|
|
1308 #endif
|
|
1309
|
|
1310 /* Step 1: allocate and initialize JPEG decompression object */
|
|
1311
|
|
1312 /* We set up the normal JPEG error routines, then override error_exit. */
|
|
1313 cinfo.err = jpeg_std_error (&jerr.pub);
|
|
1314 jerr.pub.error_exit = my_jpeg_error_exit;
|
|
1315
|
|
1316 /* Establish the setjmp return context for my_error_exit to use. */
|
|
1317 if (setjmp (jerr.setjmp_buffer))
|
|
1318 {
|
|
1319 /* If we get here, the JPEG code has signaled an error.
|
|
1320 * We need to clean up the JPEG object, close the input file, and return.
|
|
1321 */
|
|
1322
|
|
1323 {
|
|
1324 Lisp_Object errstring;
|
|
1325 char buffer[JMSG_LENGTH_MAX];
|
|
1326
|
|
1327 /* Create the message */
|
|
1328 (*cinfo.err->format_message) ((j_common_ptr) &cinfo, buffer);
|
|
1329 errstring = build_string (buffer);
|
|
1330
|
|
1331 signal_simple_error_2 ("JPEG decoding error",
|
|
1332 errstring, instantiator);
|
|
1333 }
|
|
1334 }
|
|
1335
|
|
1336 /* Now we can initialize the JPEG decompression object. */
|
|
1337 jpeg_create_decompress (&cinfo);
|
|
1338 unwind.cinfo_ptr = &cinfo;
|
|
1339
|
|
1340 /* Step 2: specify data source (eg, a file) */
|
|
1341
|
6
|
1342 #ifdef USE_TEMP_FILES_FOR_JPEG_IMAGES
|
0
|
1343 jpeg_stdio_src (&cinfo, unwind.instream);
|
|
1344 #else
|
|
1345 {
|
|
1346 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1347 Extbyte *bytes;
|
|
1348 Extcount len;
|
|
1349
|
|
1350 /* #### This is a definite problem under Mule due to the amount of
|
|
1351 stack data it might allocate. Need to be able to convert and
|
|
1352 write out to a file. */
|
|
1353 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
1354 jpeg_memory_src (&cinfo, bytes, len);
|
|
1355 }
|
|
1356 #endif
|
|
1357
|
|
1358 /* Step 3: read file parameters with jpeg_read_header() */
|
|
1359
|
|
1360 (void) jpeg_read_header (&cinfo, TRUE);
|
|
1361 /* We can ignore the return value from jpeg_read_header since
|
|
1362 * (a) suspension is not possible with the stdio data source, and
|
|
1363 * (b) we passed TRUE to reject a tables-only JPEG file as an error.
|
|
1364 * See libjpeg.doc for more info.
|
|
1365 */
|
|
1366
|
|
1367 /* Step 4: set parameters for decompression. */
|
|
1368
|
|
1369 /* We request that the JPEG file be automatically quantized into
|
|
1370 8-bit color in case it's not already (many JPEGs are stored in
|
|
1371 24-bit color). "Two-pass quantize" means that the colormap
|
|
1372 is determined on-the-fly for this particular image rather than
|
|
1373 quantizing to a supplied colormap. We can get away with this
|
|
1374 because we then use allocate_nearest_color().
|
|
1375
|
|
1376 #### Note of course that this is not the most color-effective
|
|
1377 way of doing things -- we could quantize an image that has
|
|
1378 lots of very similar colors, and eat up the colormap with these
|
|
1379 (useless to other images) colors. Unfortunately I don't think
|
|
1380 there's any "general" way of maximizing the overall image
|
|
1381 quality of lots of images, given that we don't know the
|
|
1382 colors of the images until we come across each one. Best we
|
|
1383 could do would be various sorts of heuristics, which I don't
|
|
1384 feel like dealing with now. A better scheme would be the
|
|
1385 way things are done under MS Windows, where the colormap is
|
|
1386 dynamically adjusted for various applications; but that kind
|
|
1387 of thing would have to be provided by X, which it isn't. */
|
|
1388
|
|
1389 cinfo.quantize_colors = TRUE;
|
|
1390 cinfo.two_pass_quantize = TRUE;
|
|
1391 cinfo.colormap = NULL;
|
|
1392
|
|
1393 /* Step 5: Start decompressor */
|
|
1394
|
|
1395 (void) jpeg_start_decompress (&cinfo);
|
|
1396 /* We can ignore the return value since suspension is not possible
|
|
1397 * with the stdio data source.
|
|
1398 */
|
|
1399
|
|
1400 /* At this point we know the size of the image and the colormap. */
|
|
1401
|
|
1402 /* Step 5.33: Allocate the colors */
|
|
1403 {
|
|
1404 int i;
|
|
1405
|
|
1406 /* Just in case the image contains out-of-range pixels, we go
|
|
1407 ahead and allocate space for all of them. */
|
|
1408 unwind.pixels = (unsigned long *) xmalloc (256 * sizeof (unsigned long));
|
|
1409 unwind.npixels = cinfo.actual_number_of_colors;
|
|
1410
|
|
1411 for (i = 0; i < 256; i++)
|
|
1412 unwind.pixels[i] = 0; /* Use a reasonable color for out of range. */
|
|
1413
|
|
1414 /* Allocate pixels for the various colors. */
|
|
1415 for (i = 0; i < unwind.npixels; i++)
|
|
1416 {
|
|
1417 XColor color;
|
|
1418 int ri, gi, bi;
|
|
1419
|
|
1420 ri = 0;
|
|
1421 gi = cinfo.out_color_components > 1 ? 1 : 0;
|
|
1422 bi = cinfo.out_color_components > 2 ? 2 : 0;
|
|
1423
|
|
1424 /* Ok... apparently, an entry of cinfo.colormap can be NULL if
|
|
1425 there are no bits of that color in the image. How incredibly
|
|
1426 gross. Wouldn't it be nice to have exceptions!? */
|
|
1427 color.red = cinfo.colormap[ri] ? cinfo.colormap[ri][i] << 8 : 0;
|
|
1428 color.green = cinfo.colormap[gi] ? cinfo.colormap[gi][i] << 8 : 0;
|
|
1429 color.blue = cinfo.colormap[bi] ? cinfo.colormap[bi][i] << 8 : 0;
|
|
1430 color.flags = DoRed | DoGreen | DoBlue;
|
|
1431
|
|
1432 allocate_nearest_color (dpy, DefaultColormapOfScreen (scr), &color);
|
|
1433 unwind.pixels[i] = color.pixel;
|
|
1434 }
|
|
1435 }
|
|
1436
|
|
1437 /* Step 5.66: Create the image */
|
|
1438 {
|
|
1439 int height = cinfo.output_height;
|
|
1440 int width = cinfo.output_width;
|
|
1441 int depth;
|
|
1442 int bitmap_pad;
|
|
1443
|
|
1444 depth = DefaultDepthOfScreen (scr);
|
|
1445
|
|
1446 /* first get bitmap_pad (from XPM) */
|
|
1447 if (depth > 16)
|
|
1448 bitmap_pad = 32;
|
|
1449 else if (depth > 8)
|
|
1450 bitmap_pad = 16;
|
|
1451 else
|
|
1452 bitmap_pad = 8;
|
|
1453
|
|
1454 unwind.ximage = XCreateImage (dpy, DefaultVisualOfScreen (scr),
|
|
1455 depth, ZPixmap, 0, 0, width, height,
|
|
1456 bitmap_pad, 0);
|
|
1457
|
|
1458 if (!unwind.ximage)
|
|
1459 signal_simple_error ("Unable to create X image struct", instantiator);
|
|
1460
|
|
1461 /* now that bytes_per_line must have been set properly alloc data */
|
|
1462 unwind.ximage->data =
|
|
1463 (char *) xmalloc (unwind.ximage->bytes_per_line * height);
|
|
1464 }
|
|
1465
|
|
1466 /* Step 6: Read in the data and put into image */
|
|
1467 {
|
|
1468 JSAMPARRAY row_buffer; /* Output row buffer */
|
|
1469 int row_stride; /* physical row width in output buffer */
|
|
1470
|
|
1471 /* We may need to do some setup of our own at this point before reading
|
|
1472 * the data. After jpeg_start_decompress() we have the correct scaled
|
|
1473 * output image dimensions available, as well as the output colormap
|
|
1474 * if we asked for color quantization.
|
|
1475 * In this example, we need to make an output work buffer of the right size.
|
|
1476 */
|
|
1477 /* JSAMPLEs per row in output buffer.
|
|
1478 Since we asked for quantized output, cinfo.output_components
|
|
1479 will always be 1. */
|
|
1480 row_stride = cinfo.output_width * cinfo.output_components;
|
|
1481 /* Make a one-row-high sample array that will go away when done
|
|
1482 with image */
|
|
1483 row_buffer = ((*cinfo.mem->alloc_sarray)
|
|
1484 ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1));
|
|
1485
|
|
1486 /* Here we use the library's state variable cinfo.output_scanline as the
|
|
1487 * loop counter, so that we don't have to keep track ourselves.
|
|
1488 */
|
|
1489 while (cinfo.output_scanline < cinfo.output_height)
|
|
1490 {
|
|
1491 int i;
|
|
1492 int scanline = cinfo.output_scanline;
|
|
1493
|
|
1494 /* jpeg_read_scanlines expects an array of pointers to scanlines.
|
|
1495 * Here the array is only one element long, but you could ask for
|
|
1496 * more than one scanline at a time if that's more convenient.
|
|
1497 */
|
|
1498 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1);
|
|
1499
|
|
1500 for (i = 0; i < cinfo.output_width; i++)
|
|
1501 XPutPixel (unwind.ximage, i, scanline,
|
|
1502 /* Let's make sure we avoid getting bit like
|
|
1503 what happened for GIF's. It's probably the
|
|
1504 case that JSAMPLE's are unsigned chars as
|
|
1505 opposed to chars, but you never know.
|
|
1506
|
|
1507 (They could even be shorts if the library
|
|
1508 was compiled with 12-bit samples -- ####
|
|
1509 We should deal with this possibility) */
|
|
1510 unwind.pixels[(unsigned char) row_buffer[0][i]]);
|
|
1511 }
|
|
1512 }
|
|
1513
|
|
1514 /* Step 6.5: Create the pixmap and set up the image instance */
|
|
1515 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask,
|
|
1516 unwind.pixels, unwind.npixels,
|
|
1517 instantiator);
|
|
1518
|
|
1519 /* Step 7: Finish decompression */
|
|
1520
|
|
1521 (void) jpeg_finish_decompress (&cinfo);
|
|
1522 /* We can ignore the return value since suspension is not possible
|
|
1523 * with the stdio data source.
|
|
1524 */
|
|
1525
|
|
1526 /* And we're done!
|
|
1527
|
|
1528 Now that we've succeeded, we don't want the pixels
|
|
1529 freed right now. They're kept around in the image instance
|
|
1530 structure until it's destroyed. */
|
|
1531 unwind.npixels = 0;
|
|
1532
|
|
1533 /* This will clean up everything else. */
|
|
1534 unbind_to (speccount, Qnil);
|
|
1535 }
|
|
1536
|
|
1537 #endif /* HAVE_JPEG */
|
|
1538
|
|
1539
|
|
1540 #ifdef HAVE_GIF
|
|
1541
|
|
1542 /**********************************************************************
|
|
1543 * GIF *
|
|
1544 **********************************************************************/
|
|
1545
|
|
1546 #include "gif_lib.h" /* This is in our own source tree */
|
|
1547
|
|
1548 static void
|
|
1549 gif_validate (Lisp_Object instantiator)
|
|
1550 {
|
|
1551 file_or_data_must_be_present (instantiator);
|
|
1552 }
|
|
1553
|
|
1554 static Lisp_Object
|
|
1555 gif_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1556 {
|
|
1557 return simple_image_type_normalize (inst, console_type, Qgif);
|
|
1558 }
|
|
1559
|
|
1560 static int
|
16
|
1561 gif_possible_dest_types (void)
|
0
|
1562 {
|
|
1563 return IMAGE_COLOR_PIXMAP_MASK;
|
|
1564 }
|
|
1565
|
|
1566 /* To survive the otherwise baffling complexity of making sure
|
|
1567 everything gets cleaned up in the presence of an error, we
|
|
1568 use an unwind_protect(). */
|
|
1569
|
|
1570 struct gif_unwind_data
|
|
1571 {
|
|
1572 Display *dpy;
|
|
1573 /* Object that holds the decoded data from a GIF file */
|
|
1574 GifFileType *giffile;
|
|
1575 /* Pixels to keep around while the image is active */
|
|
1576 unsigned long *pixels;
|
|
1577 int npixels;
|
|
1578 /* Client-side image structure */
|
|
1579 XImage *ximage;
|
|
1580 /* Tempfile to remove */
|
|
1581 char tempfile[50];
|
|
1582 int tempfile_needs_to_be_removed;
|
|
1583 };
|
|
1584
|
|
1585 static Lisp_Object
|
|
1586 gif_instantiate_unwind (Lisp_Object unwind_obj)
|
|
1587 {
|
|
1588 struct gif_unwind_data *data =
|
|
1589 (struct gif_unwind_data *) get_opaque_ptr (unwind_obj);
|
|
1590
|
|
1591 free_opaque_ptr (unwind_obj);
|
|
1592 if (data->giffile)
|
|
1593 DGifCloseFile (data->giffile);
|
|
1594 if (data->tempfile_needs_to_be_removed)
|
|
1595 unlink (data->tempfile);
|
|
1596 if (data->npixels > 0)
|
|
1597 {
|
|
1598 Screen *scr = DefaultScreenOfDisplay (data->dpy);
|
|
1599 Colormap cmap = DefaultColormapOfScreen (scr);
|
|
1600 XFreeColors (data->dpy, cmap, data->pixels, data->npixels, 0L);
|
|
1601 xfree (data->pixels);
|
|
1602 }
|
|
1603 if (data->ximage)
|
|
1604 {
|
|
1605 if (data->ximage->data)
|
|
1606 {
|
|
1607 xfree (data->ximage->data);
|
|
1608 data->ximage->data = 0;
|
|
1609 }
|
|
1610 XDestroyImage (data->ximage);
|
|
1611 }
|
|
1612
|
|
1613 return Qnil;
|
|
1614 }
|
|
1615
|
36
|
1616 #if 0
|
0
|
1617 /* We provide our own version of DGifSlurp() because the standardly
|
|
1618 provided one doesn't handle interlaced GIFs. This is based on
|
|
1619 code in gif2x11.c. */
|
|
1620
|
|
1621 /* Return value is GIF_ERROR, GIF_OK, or -1.
|
|
1622 #### We are using "forbidden" knowledge that neither of these
|
|
1623 constants is -1. */
|
|
1624
|
|
1625 static int
|
|
1626 our_own_dgif_slurp_from_gif2x11_c (GifFileType *GifFile)
|
|
1627 {
|
|
1628 int i, j, Row, Col, Width, Height;
|
|
1629 int ExtCode, Count;
|
|
1630 GifRecordType RecordType;
|
|
1631 GifByteType *Extension;
|
|
1632 SavedImage *sp = NULL;
|
|
1633 static int InterlacedOffset[] = { 0, 4, 2, 1 };
|
|
1634 static int InterlacedJumps[] = { 8, 8, 4, 2 };
|
|
1635
|
|
1636 GifPixelType *ScreenBuffer =
|
|
1637 (GifPixelType *) xmalloc (GifFile->SHeight * GifFile->SWidth *
|
|
1638 sizeof (GifPixelType));
|
|
1639 GifFile->SavedImages = (SavedImage *) xmalloc (sizeof(SavedImage));
|
|
1640
|
|
1641 for (i = 0; i < GifFile->SHeight * GifFile->SWidth; i++)
|
|
1642 ScreenBuffer[i] = GifFile->SBackGroundColor;
|
|
1643
|
|
1644 /* Scan the content of the GIF file and load the image(s) in: */
|
|
1645 do
|
|
1646 {
|
|
1647 if (DGifGetRecordType (GifFile, &RecordType) == GIF_ERROR)
|
|
1648 return GIF_ERROR;
|
|
1649
|
|
1650 switch (RecordType)
|
|
1651 {
|
|
1652 case IMAGE_DESC_RECORD_TYPE:
|
|
1653 if (DGifGetImageDesc (GifFile) == GIF_ERROR)
|
|
1654 return GIF_ERROR;
|
|
1655
|
|
1656 sp = &GifFile->SavedImages[GifFile->ImageCount-1];
|
|
1657 Row = GifFile->Image.Top; /* Image Position relative to Screen. */
|
|
1658 Col = GifFile->Image.Left;
|
|
1659 Width = GifFile->Image.Width;
|
|
1660 Height = GifFile->Image.Height;
|
|
1661 if (GifFile->Image.Left + GifFile->Image.Width > GifFile->SWidth ||
|
|
1662 GifFile->Image.Top + GifFile->Image.Height > GifFile->SHeight)
|
|
1663 return -1;
|
|
1664
|
|
1665 sp->RasterBits = (GifPixelType*) xmalloc(Width * Height *
|
|
1666 sizeof (GifPixelType));
|
|
1667
|
|
1668 if (GifFile->Image.Interlace)
|
|
1669 {
|
|
1670 /* Need to perform 4 passes on the images: */
|
|
1671 for (Count = i = 0; i < 4; i++)
|
|
1672 for (j = Row + InterlacedOffset[i]; j < Row + Height;
|
|
1673 j += InterlacedJumps[i])
|
|
1674 {
|
|
1675 if (DGifGetLine (GifFile, &sp->RasterBits[j * Width + Col],
|
|
1676 Width) == GIF_ERROR)
|
|
1677 return GIF_ERROR;
|
|
1678 }
|
|
1679 }
|
|
1680 else
|
|
1681 {
|
|
1682 for (i = 0; i < Height; i++)
|
|
1683 {
|
|
1684 if (DGifGetLine (GifFile,
|
|
1685 &sp->RasterBits[(Row++) * Width + Col],
|
|
1686 Width) == GIF_ERROR)
|
|
1687 return GIF_ERROR;
|
|
1688 }
|
|
1689 }
|
34
|
1690
|
|
1691 /* Only get 1 image from animated gifs. */
|
|
1692 /* #### if the rest of the file was bad, we still return
|
|
1693 GIF_OK, since we don't even bother looking at it. Should
|
|
1694 probably check for ImageCount == 1 above too, hmm. */
|
|
1695 goto done;
|
0
|
1696 break;
|
|
1697
|
|
1698 case EXTENSION_RECORD_TYPE:
|
|
1699 /* Skip any extension blocks in file: */
|
|
1700 if (DGifGetExtension (GifFile, &ExtCode, &Extension) == GIF_ERROR)
|
|
1701 return GIF_ERROR;
|
|
1702
|
|
1703 while (Extension != NULL)
|
|
1704 {
|
|
1705 if (DGifGetExtensionNext (GifFile, &Extension) == GIF_ERROR)
|
|
1706 return GIF_ERROR;
|
|
1707 }
|
|
1708 break;
|
|
1709
|
|
1710 case TERMINATE_RECORD_TYPE:
|
|
1711 break;
|
|
1712
|
|
1713 default: /* Should be traps by DGifGetRecordType. */
|
|
1714 break;
|
|
1715 }
|
|
1716 }
|
|
1717 while (RecordType != TERMINATE_RECORD_TYPE);
|
|
1718
|
34
|
1719 done:
|
|
1720
|
0
|
1721 return GIF_OK;
|
|
1722 }
|
36
|
1723 #endif
|
0
|
1724
|
|
1725 static void
|
|
1726 gif_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1727 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1728 int dest_mask)
|
|
1729 {
|
|
1730 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1731 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1732 Display *dpy;
|
|
1733 Screen *scr;
|
|
1734 /* It is OK for the unwind data to be local to this function,
|
|
1735 because the unwind-protect is always executed when this
|
|
1736 stack frame is still valid. */
|
|
1737 struct gif_unwind_data unwind;
|
|
1738 int speccount = specpdl_depth ();
|
|
1739
|
|
1740 if (!DEVICE_X_P (XDEVICE (device)))
|
|
1741 signal_simple_error ("Not an X device", device);
|
|
1742
|
|
1743 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1744 scr = DefaultScreenOfDisplay (dpy);
|
|
1745
|
|
1746 memset (&unwind, 0, sizeof (unwind));
|
|
1747 unwind.dpy = dpy;
|
|
1748 record_unwind_protect (gif_instantiate_unwind, make_opaque_ptr (&unwind));
|
|
1749
|
|
1750 /* 1. Now decode the data. */
|
|
1751
|
|
1752 /* #### The GIF routines currently require that you read from a file,
|
|
1753 so write out to a temp file. We should change this. */
|
|
1754 {
|
|
1755 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1756
|
|
1757 assert (!NILP (data));
|
|
1758
|
|
1759 write_lisp_string_to_temp_file (data, unwind.tempfile);
|
|
1760 unwind.tempfile_needs_to_be_removed = 1;
|
|
1761
|
|
1762 /* Then slurp the image into memory, decoding along the way.
|
|
1763 The result is the image in a simple one-byte-per-pixel
|
|
1764 format (#### the GIF routines only support 8-bit GIFs,
|
|
1765 it appears). */
|
|
1766 unwind.giffile = DGifOpenFileName (unwind.tempfile);
|
|
1767 if (unwind.giffile == NULL)
|
|
1768 {
|
|
1769 gif_decode_error:
|
|
1770 signal_simple_error ("Unable to decode GIF",
|
|
1771 build_string (EmacsPrintGifError ()));
|
|
1772 }
|
36
|
1773 #if 0
|
0
|
1774 if (our_own_dgif_slurp_from_gif2x11_c(unwind.giffile) != GIF_OK)
|
|
1775 #else
|
36
|
1776 /* DGifSlurp() doesn't handle interlaced files. */
|
|
1777 /* Actually, it does, sort of. It just sets the Interlace flag
|
|
1778 and stores RasterBits in interlaced order. We handle that below. */
|
0
|
1779 if (DGifSlurp (unwind.giffile) != GIF_OK)
|
|
1780 #endif
|
|
1781 goto gif_decode_error;
|
|
1782 }
|
|
1783
|
|
1784 /* 2. Now allocate the colors for the image. */
|
|
1785 {
|
|
1786 int i;
|
|
1787 ColorMapObject *cmap = unwind.giffile->SColorMap;
|
|
1788 /* Just in case the image contains out-of-range pixels, we go
|
|
1789 ahead and allocate space for all of them. */
|
|
1790 unwind.pixels = (unsigned long *) xmalloc (256 * sizeof (unsigned long));
|
|
1791 unwind.npixels = cmap->ColorCount;
|
|
1792
|
|
1793 for (i = 0; i < 256; i++)
|
|
1794 unwind.pixels[i] = 0; /* Use a reasonable color for out of range. */
|
|
1795
|
|
1796 /* Allocate pixels for the various colors. */
|
|
1797 for (i = 0; i < cmap->ColorCount; i++)
|
|
1798 {
|
|
1799 XColor color;
|
|
1800
|
|
1801 color.red = cmap->Colors[i].Red << 8;
|
|
1802 color.green = cmap->Colors[i].Green << 8;
|
|
1803 color.blue = cmap->Colors[i].Blue << 8;
|
|
1804 color.flags = DoRed | DoGreen | DoBlue;
|
|
1805
|
|
1806 allocate_nearest_color (dpy, DefaultColormapOfScreen (scr), &color);
|
|
1807 unwind.pixels[i] = color.pixel;
|
|
1808 }
|
|
1809 }
|
|
1810
|
|
1811 /* 3. Now create the image */
|
|
1812 {
|
|
1813 int height = unwind.giffile->SHeight;
|
|
1814 int width = unwind.giffile->SWidth;
|
|
1815 int depth;
|
|
1816 int bitmap_pad;
|
36
|
1817 int i, j, row, pass, interlace;
|
|
1818 /* interlaced gifs have rows in this order:
|
|
1819 0, 8, 16, ..., 4, 12, 20, ..., 2, 6, 10, ..., 1, 3, 5, ... */
|
|
1820 static int InterlacedOffset[] = { 0, 4, 2, 1 };
|
|
1821 static int InterlacedJumps[] = { 8, 8, 4, 2 };
|
|
1822
|
0
|
1823
|
|
1824 depth = DefaultDepthOfScreen (scr);
|
|
1825
|
|
1826 /* first get bitmap_pad (from XPM) */
|
|
1827 if (depth > 16)
|
|
1828 bitmap_pad = 32;
|
|
1829 else if (depth > 8)
|
|
1830 bitmap_pad = 16;
|
|
1831 else
|
|
1832 bitmap_pad = 8;
|
|
1833
|
|
1834 unwind.ximage = XCreateImage (dpy, DefaultVisualOfScreen (scr),
|
|
1835 depth, ZPixmap, 0, 0, width, height,
|
|
1836 bitmap_pad, 0);
|
|
1837
|
|
1838 if (!unwind.ximage)
|
|
1839 signal_simple_error ("Unable to create X image struct", instantiator);
|
|
1840
|
|
1841 /* now that bytes_per_line must have been set properly alloc data */
|
|
1842 unwind.ximage->data =
|
|
1843 (char *) xmalloc (unwind.ximage->bytes_per_line * height);
|
|
1844
|
|
1845 /* write the data --
|
|
1846 #### XPutPixel() is a client-side-only function but could
|
|
1847 still be slow. Another possibility is to just convert to
|
|
1848 XPM format and use the Xpm routines, which optimize this
|
|
1849 stuff; but it's doubtful that this will be faster in the
|
|
1850 long run, what with all the XPM overhead. If this proves
|
|
1851 to be a bottleneck here, maybe we should just copy the
|
|
1852 optimization routines from XPM (they're in turn mostly
|
|
1853 copied from the Xlib source code). */
|
|
1854
|
36
|
1855 /* Note: We just use the first image in the file and ignore the rest.
|
|
1856 We check here that that image covers the full "screen" size.
|
|
1857 I don't know whether that's always the case.
|
|
1858 -dkindred@cs.cmu.edu */
|
|
1859 if (unwind.giffile->SavedImages[0].ImageDesc.Height != height
|
|
1860 || unwind.giffile->SavedImages[0].ImageDesc.Width != width
|
|
1861 || unwind.giffile->SavedImages[0].ImageDesc.Left != 0
|
|
1862 || unwind.giffile->SavedImages[0].ImageDesc.Top != 0)
|
|
1863 signal_simple_error ("First image in GIF file is not full size",
|
|
1864 instantiator);
|
|
1865
|
|
1866 interlace = unwind.giffile->SavedImages[0].ImageDesc.Interlace;
|
|
1867 pass = 0;
|
|
1868 row = interlace ? InterlacedOffset[pass] : 0;
|
0
|
1869 for (i = 0; i < height; i++)
|
36
|
1870 {
|
|
1871 if (interlace && row >= height)
|
|
1872 row = InterlacedOffset[++pass];
|
|
1873
|
|
1874 for (j = 0; j < width; j++)
|
|
1875 XPutPixel (unwind.ximage, j, row,
|
|
1876 unwind.pixels[(unsigned char)
|
|
1877 /* incorrect signed declaration
|
|
1878 of RasterBits[] */
|
|
1879 (unwind.giffile->SavedImages[0].
|
|
1880 RasterBits[i * width + j])]);
|
|
1881
|
|
1882 row += interlace ? InterlacedJumps[pass] : 1;
|
|
1883 }
|
0
|
1884 }
|
|
1885
|
|
1886 /* 4. Now create the pixmap and set up the image instance */
|
|
1887 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask,
|
|
1888 unwind.pixels, unwind.npixels,
|
|
1889 instantiator);
|
|
1890 /* Now that we've succeeded, we don't want the pixels
|
|
1891 freed right now. They're kept around in the image instance
|
|
1892 structure until it's destroyed. */
|
|
1893 unwind.npixels = 0;
|
|
1894 unbind_to (speccount, Qnil);
|
|
1895 }
|
|
1896
|
|
1897 #endif /* HAVE_GIF */
|
|
1898
|
|
1899
|
|
1900 #ifdef HAVE_PNG
|
|
1901
|
|
1902 #include <png.h>
|
|
1903
|
|
1904 /**********************************************************************
|
|
1905 * PNG *
|
|
1906 **********************************************************************/
|
|
1907 static void
|
|
1908 png_validate (Lisp_Object instantiator)
|
|
1909 {
|
|
1910 file_or_data_must_be_present (instantiator);
|
|
1911 }
|
|
1912
|
|
1913 static Lisp_Object
|
|
1914 png_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1915 {
|
|
1916 return simple_image_type_normalize (inst, console_type, Qpng);
|
|
1917 }
|
|
1918
|
|
1919 static int
|
16
|
1920 png_possible_dest_types (void)
|
0
|
1921 {
|
|
1922 return IMAGE_COLOR_PIXMAP_MASK;
|
|
1923 }
|
|
1924
|
|
1925 #if !defined (USE_TEMP_FILES_FOR_IMAGES) && (PNG_LIBPNG_VER >= 87)
|
|
1926 struct png_memory_storage
|
|
1927 {
|
|
1928 Extbyte *bytes; /* The data */
|
|
1929 Extcount len; /* How big is it? */
|
|
1930 int index; /* Where are we? */
|
|
1931 };
|
|
1932
|
|
1933 static void png_read_from_memory(png_structp png_ptr, png_bytep data,
|
|
1934 png_uint_32 length)
|
|
1935 {
|
|
1936 struct png_memory_storage *tbr =
|
|
1937 (struct png_memory_storage *) png_get_io_ptr (png_ptr);
|
|
1938
|
|
1939 if (length > (tbr->len - tbr->index))
|
2
|
1940 png_error (png_ptr, (png_const_charp) "Read Error");
|
0
|
1941 memcpy(data,tbr->bytes + tbr->index,length);
|
|
1942 tbr->index = tbr->index + length;
|
|
1943 }
|
|
1944 #endif /* !USE_TEMP_FILES_FOR_IMAGESS || PNG_LIBPNG_VER >= 87 */
|
|
1945
|
|
1946 struct png_unwind_data
|
|
1947 {
|
|
1948 Display *dpy;
|
|
1949 FILE *instream;
|
|
1950 png_struct *png_ptr;
|
|
1951 png_info *info_ptr;
|
|
1952 unsigned long *pixels;
|
|
1953 int npixels;
|
|
1954 XImage *ximage;
|
|
1955 char tempfile[50];
|
|
1956 int tempfile_needs_to_be_removed;
|
|
1957 };
|
|
1958
|
|
1959 static Lisp_Object
|
|
1960 png_instantiate_unwind (Lisp_Object unwind_obj)
|
|
1961 {
|
|
1962 struct png_unwind_data *data =
|
|
1963 (struct png_unwind_data *) get_opaque_ptr (unwind_obj);
|
|
1964
|
|
1965 free_opaque_ptr (unwind_obj);
|
|
1966 if (data->png_ptr)
|
|
1967 png_read_destroy (data->png_ptr, data->info_ptr, (png_info *) NULL);
|
|
1968 if (data->instream)
|
|
1969 fclose (data->instream);
|
|
1970 if (data->tempfile_needs_to_be_removed)
|
|
1971 unlink (data->tempfile);
|
|
1972 if (data->npixels > 0)
|
|
1973 {
|
|
1974 Screen *scr = DefaultScreenOfDisplay (data->dpy);
|
|
1975 Colormap cmap = DefaultColormapOfScreen (scr);
|
|
1976 XFreeColors (data->dpy, cmap, data->pixels, data->npixels, 0L);
|
|
1977 xfree (data->pixels);
|
|
1978 }
|
|
1979
|
|
1980 if (data->ximage)
|
|
1981 {
|
|
1982 if (data->ximage->data)
|
|
1983 {
|
|
1984 xfree (data->ximage->data);
|
|
1985 data->ximage->data = 0;
|
|
1986 }
|
|
1987 XDestroyImage (data->ximage);
|
|
1988 }
|
|
1989
|
|
1990 return Qnil;
|
|
1991 }
|
|
1992
|
2
|
1993 /* This doesn't appear to be used. */
|
|
1994 #if 0
|
0
|
1995 #define get_png_val(p) _get_png_val (&(p), info_ptr.bit_depth)
|
|
1996 png_uint_16
|
|
1997 _get_png_val (png_byte **pp, int bit_depth)
|
|
1998 {
|
|
1999 png_uint_16 c = 0;
|
|
2000
|
|
2001 if (bit_depth == 16) {
|
|
2002 c = (*((*pp)++)) << 8;
|
|
2003 }
|
|
2004 c |= (*((*pp)++));
|
|
2005
|
|
2006 return c;
|
|
2007 }
|
2
|
2008 #endif
|
0
|
2009
|
|
2010 static void
|
|
2011 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2012 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2013 int dest_mask)
|
|
2014 {
|
|
2015 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2016 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
2017 Display *dpy;
|
|
2018 Screen *scr;
|
|
2019 struct png_unwind_data unwind;
|
|
2020 int speccount = specpdl_depth ();
|
|
2021
|
|
2022 /* PNG variables */
|
|
2023 png_struct *png_ptr;
|
|
2024 png_info *info_ptr;
|
|
2025
|
|
2026 if (!DEVICE_X_P (XDEVICE (device)))
|
|
2027 signal_simple_error ("Not an X device", device);
|
|
2028
|
|
2029 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
2030 scr = DefaultScreenOfDisplay (dpy);
|
|
2031
|
|
2032 png_ptr = (png_struct *) xmalloc (sizeof (png_struct));
|
|
2033 info_ptr = (png_info *) xmalloc (sizeof (png_info));
|
|
2034
|
|
2035 memset (&unwind, 0, sizeof (unwind));
|
|
2036 unwind.png_ptr = png_ptr;
|
|
2037 unwind.info_ptr = info_ptr;
|
|
2038 unwind.dpy = dpy;
|
|
2039
|
|
2040 record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind));
|
|
2041
|
|
2042 /* This code is a mixture of stuff from Ben's GIF/JPEG stuff from
|
|
2043 this file, example.c from the libpng 0.81 distribution, and the
|
|
2044 pngtopnm sources. -WMP-
|
|
2045 */
|
|
2046 #if defined (USE_TEMP_FILES_FOR_IMAGES) || (PNG_LIBPNG_VER < 87)
|
|
2047 /* Write out to a temp file - we really should take the time to
|
|
2048 write appropriate memory bound IO stuff, but I am just trying
|
|
2049 to get the stupid thing working right now.
|
|
2050 */
|
|
2051 {
|
|
2052 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
2053
|
|
2054 assert (!NILP (data));
|
|
2055
|
|
2056 write_lisp_string_to_temp_file (data, unwind.tempfile);
|
|
2057 unwind.tempfile_needs_to_be_removed = 1;
|
|
2058
|
|
2059 if ((unwind.instream = fopen (unwind.tempfile, "rb")) == NULL)
|
|
2060 report_file_error ("Opening PNG temp file",
|
|
2061 list1 (build_string (unwind.tempfile)));
|
|
2062 }
|
|
2063 #else
|
|
2064 /* Nothing */
|
|
2065 #endif
|
|
2066
|
|
2067 /* Set the jmp_buf reurn context for png_error ... if this returns !0, then
|
|
2068 we ran into a problem somewhere, and need to clean up after ourselves. */
|
|
2069 if (setjmp (png_ptr->jmpbuf))
|
|
2070 {
|
|
2071 /* Am I doing enough here? I think so, since most things happen
|
|
2072 in png_unwind */
|
|
2073 png_read_destroy (png_ptr, info_ptr, (png_info *) NULL);
|
|
2074 signal_simple_error ("Error decoding PNG", instantiator);
|
|
2075 }
|
|
2076
|
|
2077 /* Initialize all PNG structures */
|
|
2078 png_info_init (info_ptr);
|
|
2079 png_read_init (png_ptr);
|
|
2080
|
|
2081 /* Initialize the IO layer and read in header information */
|
|
2082 #if defined (USE_TEMP_FILES_FOR_IMAGES) || (PNG_LIBPNG_VER < 87)
|
|
2083 png_init_io (png_ptr, unwind.instream);
|
|
2084 #else
|
|
2085 {
|
|
2086 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
2087 Extbyte *bytes;
|
|
2088 Extcount len;
|
|
2089 struct png_memory_storage tbr; /* Data to be read */
|
|
2090
|
|
2091 assert (!NILP (data));
|
|
2092
|
|
2093 /* #### This is a definite problem under Mule due to the amount of
|
|
2094 stack data it might allocate. Need to be able to convert and
|
|
2095 write out to a file. */
|
|
2096 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
2097 tbr.bytes = bytes;
|
|
2098 tbr.len = len;
|
|
2099 tbr.index = 0;
|
|
2100 png_set_read_fn(png_ptr,(void *) &tbr, png_read_from_memory);
|
|
2101 }
|
|
2102 #endif
|
|
2103
|
|
2104 png_read_info (png_ptr, info_ptr);
|
|
2105
|
|
2106 /* set up the transformations you want. Note that these are
|
|
2107 all optional. Only call them if you want them */
|
|
2108 /* tell libpng to strip 16 bit depth files down to 8 bits */
|
|
2109 if (info_ptr->bit_depth == 16)
|
|
2110 png_set_strip_16 (png_ptr);
|
|
2111 if (info_ptr->bit_depth < 8)
|
|
2112 png_set_packing (png_ptr);
|
|
2113 /* ##### Perhaps some way to specify the screen gamma should be in here? */
|
|
2114
|
|
2115 {
|
|
2116 int height = info_ptr->height;
|
|
2117 int width = info_ptr->width;
|
|
2118 int depth = info_ptr->bit_depth;
|
|
2119 int linesize = max (info_ptr->bit_depth >> 3, 1) * width;
|
|
2120 int bitmap_pad;
|
|
2121 int y;
|
|
2122 XColor color;
|
|
2123 png_byte *png_pixels;
|
|
2124 png_byte **row_pointers;
|
|
2125 png_color static_color_cube[216];
|
|
2126
|
|
2127 /* Wow, allocate all the memory. Truly, exciting. */
|
|
2128 unwind.pixels = (unsigned long *) xmalloc (256 * sizeof (unsigned long));
|
|
2129 png_pixels = (png_byte *) xmalloc (linesize * height * sizeof (png_byte*));
|
|
2130 row_pointers = (png_byte **) xmalloc (height * sizeof (png_byte *));
|
|
2131
|
|
2132 for (y = 0; y < 256; y++)
|
|
2133 unwind.pixels[y] = 0;
|
|
2134 for (y = 0; y < height; y++)
|
|
2135 row_pointers[y] = png_pixels + (linesize * y);
|
|
2136
|
|
2137 /* #### This is where we should handle transparency, but I am unsure of
|
|
2138 how exactly to get that information right now, in a safe manner. */
|
|
2139 #if 0
|
|
2140 {
|
|
2141 png_color_16 current_background;
|
|
2142
|
|
2143 /* Some appropriate magic should go here to get the current
|
|
2144 buffers (device?) background color and convert it to a
|
|
2145 png_color_16 struct */
|
|
2146 if (info_ptr->valid & PNG_INFO_bKGD)
|
|
2147 png_set_background (png_ptr, &(info_ptr->background), PNG_GAMMA_FILE,
|
|
2148 1, 1.0);
|
|
2149 else
|
|
2150 png_set_background (png_ptr, ¤t_background, PNG_GAMMA_SCREEN,
|
|
2151 0, 1.0);
|
|
2152 }
|
|
2153 #endif
|
|
2154
|
|
2155 if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
|
|
2156 (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA))
|
|
2157 {
|
|
2158 if (!(info_ptr->valid & PNG_INFO_PLTE))
|
|
2159 {
|
|
2160 for (y = 0; y < 216; y++)
|
|
2161 {
|
|
2162 static_color_cube[y].red = (y % 6) * 255.0 / 5;
|
|
2163 static_color_cube[y].green = ((y / 6) % 6) * 255.0 / 5;
|
|
2164 static_color_cube[y].blue = (y / 36) * 255.0 / 5;
|
|
2165 }
|
|
2166 png_set_dither (png_ptr, static_color_cube, 216, 216, NULL, 1);
|
|
2167 }
|
|
2168 else
|
|
2169 {
|
|
2170 png_set_dither (png_ptr, info_ptr->palette, info_ptr->num_palette,
|
|
2171 info_ptr->num_palette, info_ptr->hist, 1);
|
|
2172 }
|
|
2173 }
|
|
2174
|
|
2175 png_read_image (png_ptr, row_pointers);
|
|
2176 png_read_end (png_ptr, info_ptr);
|
|
2177
|
|
2178 /* Ok, now we go and allocate all the colors */
|
|
2179 if (info_ptr->valid & PNG_INFO_PLTE)
|
|
2180 {
|
|
2181 unwind.npixels = info_ptr->num_palette;
|
|
2182 for (y = 0; y < unwind.npixels; y++)
|
|
2183 {
|
|
2184 color.red = info_ptr->palette[y].red << 8;
|
|
2185 color.green = info_ptr->palette[y].green << 8;
|
|
2186 color.blue = info_ptr->palette[y].blue << 8;
|
|
2187 color.flags = DoRed | DoGreen | DoBlue;
|
|
2188 allocate_nearest_color (dpy, DefaultColormapOfScreen (scr),
|
|
2189 &color);
|
|
2190 unwind.pixels[y] = color.pixel;
|
|
2191 }
|
|
2192 }
|
|
2193 else
|
|
2194 {
|
|
2195 unwind.npixels = 216;
|
|
2196 for (y = 0; y < 216; y++)
|
|
2197 {
|
|
2198 color.red = static_color_cube[y].red << 8;
|
|
2199 color.green = static_color_cube[y].green << 8;
|
|
2200 color.blue = static_color_cube[y].blue << 8;
|
|
2201 color.flags = DoRed|DoGreen|DoBlue;
|
|
2202 allocate_nearest_color (dpy, DefaultColormapOfScreen (scr),
|
|
2203 &color);
|
|
2204 unwind.pixels[y] = color.pixel;
|
|
2205 }
|
|
2206 }
|
|
2207
|
|
2208 #ifdef PNG_SHOW_COMMENTS
|
|
2209 /* ####
|
|
2210 * I turn this off by default now, because the !%^@#!% comments
|
|
2211 * show up every time the image is instantiated, which can get
|
|
2212 * really really annoying. There should be some way to pass this
|
|
2213 * type of data down into the glyph code, where you can get to it
|
|
2214 * from lisp anyway. - WMP
|
|
2215 */
|
|
2216 {
|
|
2217 int i;
|
|
2218
|
|
2219 for (i = 0 ; i < info_ptr->num_text ; i++)
|
|
2220 {
|
|
2221 /* How paranoid do I have to be about no trailing NULLs, and
|
|
2222 using (int)info_ptr->text[i].text_length, and strncpy and a temp
|
|
2223 string somewhere? */
|
|
2224
|
|
2225 warn_when_safe (Qpng, Qinfo, "%s - %s",
|
|
2226 info_ptr->text[i].key,
|
|
2227 info_ptr->text[i].text);
|
|
2228 }
|
|
2229 }
|
|
2230 #endif
|
|
2231
|
|
2232 /* Now create the image */
|
|
2233
|
|
2234 depth = DefaultDepthOfScreen (scr);
|
|
2235
|
|
2236 /* first get bitmap_pad (from XPM) */
|
|
2237 if (depth > 16)
|
|
2238 bitmap_pad = 32;
|
|
2239 else if (depth > 8)
|
|
2240 bitmap_pad = 16;
|
|
2241 else
|
|
2242 bitmap_pad = 8;
|
|
2243
|
|
2244 unwind.ximage = XCreateImage (dpy, DefaultVisualOfScreen (scr),
|
|
2245 depth, ZPixmap, 0, 0, width, height,
|
|
2246 bitmap_pad, 0);
|
|
2247
|
|
2248 if (!unwind.ximage)
|
|
2249 signal_simple_error ("Unable to create X image struct",
|
|
2250 instantiator);
|
|
2251
|
|
2252 /* now that bytes_per_line must have been set properly alloc data */
|
|
2253 unwind.ximage->data = (char *) xmalloc (unwind.ximage->bytes_per_line *
|
|
2254 height);
|
|
2255
|
|
2256 {
|
|
2257 int i, j;
|
|
2258 for (i = 0; i < height; i++)
|
|
2259 for (j = 0; j < width; j++)
|
|
2260 XPutPixel (unwind.ximage, j, i,
|
|
2261 unwind.pixels[png_pixels[i * width + j]]);
|
|
2262 }
|
|
2263
|
|
2264 xfree (row_pointers);
|
|
2265 xfree (png_pixels);
|
|
2266 }
|
|
2267
|
|
2268 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask,
|
|
2269 unwind.pixels, unwind.npixels,
|
|
2270 instantiator);
|
|
2271
|
|
2272 /* This will clean up everything else. */
|
|
2273 unwind.npixels = 0;
|
|
2274 unbind_to (speccount, Qnil);
|
|
2275 }
|
|
2276
|
|
2277 #endif /* HAVE_PNG */
|
|
2278
|
|
2279
|
|
2280 #ifdef HAVE_TIFF
|
|
2281
|
|
2282 /**********************************************************************
|
|
2283 * TIFF *
|
|
2284 **********************************************************************/
|
|
2285 static void
|
|
2286 tiff_validate (Lisp_Object instantiator)
|
|
2287 {
|
|
2288 file_or_data_must_be_present (instantiator);
|
|
2289 }
|
|
2290
|
|
2291 static Lisp_Object
|
|
2292 tiff_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
2293 {
|
|
2294 signal_simple_error ("No TIFF support yet", inst);
|
|
2295 return Qnil;
|
|
2296 }
|
|
2297
|
|
2298 static int
|
16
|
2299 tiff_possible_dest_types (void)
|
0
|
2300 {
|
|
2301 return IMAGE_COLOR_PIXMAP_MASK;
|
|
2302 }
|
|
2303
|
|
2304 static void
|
|
2305 tiff_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2306 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2307 int dest_mask)
|
|
2308 {
|
|
2309 abort ();
|
|
2310 }
|
|
2311
|
|
2312 #endif /* HAVE_TIFF */
|
|
2313
|
|
2314
|
|
2315 #ifdef HAVE_XPM
|
|
2316
|
|
2317 /**********************************************************************
|
|
2318 * XPM *
|
|
2319 **********************************************************************/
|
|
2320
|
|
2321 static void
|
|
2322 check_valid_xpm_color_symbols (Lisp_Object data)
|
|
2323 {
|
|
2324 Lisp_Object rest;
|
|
2325
|
|
2326 for (rest = data; !NILP (rest); rest = XCDR (rest))
|
|
2327 {
|
|
2328 if (!CONSP (rest) ||
|
|
2329 !CONSP (XCAR (rest)) ||
|
|
2330 !STRINGP (XCAR (XCAR (rest))) ||
|
|
2331 (!STRINGP (XCDR (XCAR (rest))) &&
|
|
2332 !COLOR_SPECIFIERP (XCDR (XCAR (rest)))))
|
|
2333 signal_simple_error ("Invalid color symbol alist", data);
|
|
2334 }
|
|
2335 }
|
|
2336
|
|
2337 static void
|
|
2338 xpm_validate (Lisp_Object instantiator)
|
|
2339 {
|
|
2340 file_or_data_must_be_present (instantiator);
|
|
2341 }
|
|
2342
|
|
2343 static Lisp_Object
|
|
2344 pixmap_to_lisp_data (Lisp_Object name, int ok_if_data_invalid)
|
|
2345 {
|
|
2346 char **data;
|
|
2347 int result;
|
|
2348
|
14
|
2349 result = XpmReadFileToData ((char *) XSTRING_DATA (name), &data);
|
0
|
2350
|
|
2351 if (result == XpmSuccess)
|
|
2352 {
|
|
2353 Lisp_Object retval = Qnil;
|
|
2354 struct buffer *old_buffer = current_buffer;
|
|
2355 Lisp_Object temp_buffer =
|
|
2356 Fget_buffer_create (build_string (" *pixmap conversion*"));
|
|
2357 int elt;
|
|
2358 int height, width, ncolors;
|
|
2359 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2360 int speccount = specpdl_depth ();
|
|
2361
|
|
2362 GCPRO3 (name, retval, temp_buffer);
|
|
2363
|
|
2364 specbind (Qinhibit_quit, Qt);
|
|
2365 set_buffer_internal (XBUFFER (temp_buffer));
|
|
2366 Ferase_buffer (Fcurrent_buffer ());
|
|
2367
|
|
2368 buffer_insert_c_string (current_buffer, "/* XPM */\r");
|
|
2369 buffer_insert_c_string (current_buffer, "static char *pixmap[] = {\r");
|
|
2370
|
|
2371 sscanf (data[0], "%d %d %d", &height, &width, &ncolors);
|
|
2372 for (elt = 0; elt <= width + ncolors; elt++)
|
|
2373 {
|
|
2374 buffer_insert_c_string (current_buffer, "\"");
|
|
2375 buffer_insert_c_string (current_buffer, data[elt]);
|
|
2376
|
|
2377 if (elt < width + ncolors)
|
|
2378 buffer_insert_c_string (current_buffer, "\",\r");
|
|
2379 else
|
|
2380 buffer_insert_c_string (current_buffer, "\"};\r");
|
|
2381 }
|
|
2382
|
|
2383 retval = Fbuffer_substring (Qnil, Qnil, Fcurrent_buffer ());
|
|
2384 XpmFree (data);
|
|
2385
|
|
2386 set_buffer_internal (old_buffer);
|
|
2387 unbind_to (speccount, Qnil);
|
|
2388
|
|
2389 RETURN_UNGCPRO (retval);
|
|
2390 }
|
|
2391
|
|
2392 switch (result)
|
|
2393 {
|
|
2394 case XpmFileInvalid:
|
|
2395 {
|
|
2396 if (ok_if_data_invalid)
|
|
2397 return Qt;
|
|
2398 signal_simple_error ("invalid XPM data in file", name);
|
|
2399 }
|
|
2400 case XpmNoMemory:
|
|
2401 {
|
|
2402 signal_double_file_error ("Reading pixmap file",
|
|
2403 "out of memory", name);
|
|
2404 }
|
|
2405 case XpmOpenFailed:
|
|
2406 {
|
|
2407 /* should never happen? */
|
|
2408 signal_double_file_error ("Opening pixmap file",
|
|
2409 "no such file or directory", name);
|
|
2410 }
|
|
2411 default:
|
|
2412 {
|
|
2413 signal_double_file_error_2 ("Parsing pixmap file",
|
|
2414 "unknown error code",
|
|
2415 make_int (result), name);
|
|
2416 break;
|
|
2417 }
|
|
2418 }
|
|
2419
|
|
2420 return Qnil; /* not reached */
|
|
2421 }
|
|
2422
|
|
2423 Lisp_Object Vxpm_color_symbols;
|
|
2424
|
|
2425 static Lisp_Object
|
|
2426 evaluate_xpm_color_symbols (void)
|
|
2427 {
|
|
2428 Lisp_Object rest, results = Qnil;
|
|
2429 struct gcpro gcpro1, gcpro2;
|
|
2430
|
|
2431 GCPRO2 (rest, results);
|
|
2432 for (rest = Vxpm_color_symbols; !NILP (rest); rest = XCDR (rest))
|
|
2433 {
|
|
2434 Lisp_Object name, value, cons;
|
|
2435
|
|
2436 CHECK_CONS (rest);
|
|
2437 cons = XCAR (rest);
|
|
2438 CHECK_CONS (cons);
|
|
2439 name = XCAR (cons);
|
|
2440 CHECK_STRING (name);
|
|
2441 value = XCDR (cons);
|
|
2442 CHECK_CONS (value);
|
|
2443 value = XCAR (value);
|
|
2444 value = Feval (value);
|
|
2445 if (NILP (value))
|
|
2446 continue;
|
|
2447 if (!STRINGP (value) && !COLOR_SPECIFIERP (value))
|
|
2448 signal_simple_error
|
|
2449 ("Result from xpm-color-symbols eval must be nil, string, or color",
|
|
2450 value);
|
|
2451 results = Fcons (Fcons (name, value), results);
|
|
2452 }
|
|
2453 UNGCPRO; /* no more evaluation */
|
|
2454 return results;
|
|
2455 }
|
|
2456
|
|
2457 static Lisp_Object
|
|
2458 xpm_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
2459 {
|
|
2460 Lisp_Object file = Qnil;
|
|
2461 Lisp_Object color_symbols;
|
|
2462 struct gcpro gcpro1, gcpro2;
|
|
2463 Lisp_Object alist = Qnil;
|
|
2464
|
|
2465 GCPRO2 (file, alist);
|
|
2466
|
|
2467 /* Now, convert any file data into inline data. At the end of this,
|
|
2468 `data' will contain the inline data (if any) or Qnil, and
|
|
2469 `file' will contain the name this data was derived from (if
|
|
2470 known) or Qnil.
|
|
2471
|
|
2472 Note that if we cannot generate any regular inline data, we
|
|
2473 skip out. */
|
|
2474
|
|
2475 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
2476
|
|
2477 if (CONSP (file)) /* failure locating filename */
|
|
2478 signal_double_file_error ("Opening pixmap file",
|
|
2479 "no such file or directory",
|
|
2480 Fcar (file));
|
|
2481
|
|
2482 color_symbols = find_keyword_in_vector_or_given (inst, Q_color_symbols,
|
|
2483 Qunbound);
|
|
2484
|
|
2485 if (NILP (file) && !UNBOUNDP (color_symbols))
|
|
2486 /* no conversion necessary */
|
|
2487 RETURN_UNGCPRO (inst);
|
|
2488
|
|
2489 alist = tagged_vector_to_alist (inst);
|
|
2490
|
|
2491 if (!NILP (file))
|
|
2492 {
|
|
2493 Lisp_Object data = pixmap_to_lisp_data (file, 0);
|
|
2494 alist = remassq_no_quit (Q_file, alist);
|
|
2495 /* there can't be a :data at this point. */
|
|
2496 alist = Fcons (Fcons (Q_file, file),
|
|
2497 Fcons (Fcons (Q_data, data), alist));
|
|
2498 }
|
|
2499
|
|
2500 if (UNBOUNDP (color_symbols))
|
|
2501 {
|
|
2502 color_symbols = evaluate_xpm_color_symbols ();
|
|
2503 alist = Fcons (Fcons (Q_color_symbols, color_symbols),
|
|
2504 alist);
|
|
2505 }
|
|
2506
|
|
2507 {
|
|
2508 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
2509 free_alist (alist);
|
|
2510 RETURN_UNGCPRO (result);
|
|
2511 }
|
|
2512 }
|
|
2513
|
|
2514 static int
|
16
|
2515 xpm_possible_dest_types (void)
|
0
|
2516 {
|
16
|
2517 return
|
|
2518 IMAGE_MONO_PIXMAP_MASK |
|
|
2519 IMAGE_COLOR_PIXMAP_MASK |
|
0
|
2520 IMAGE_POINTER_MASK;
|
|
2521 }
|
|
2522
|
|
2523 /* xpm 3.2g and better has XpmCreatePixmapFromBuffer()...
|
|
2524 There was no version number in xpm.h before 3.3, but this should do.
|
|
2525 */
|
|
2526 #if (XpmVersion >= 3) || defined(XpmExactColors)
|
|
2527 # define XPM_DOES_BUFFERS
|
|
2528 #endif
|
|
2529
|
|
2530 #ifndef XPM_DOES_BUFFERS
|
|
2531 Your version of XPM is too old. You cannot compile with it.
|
|
2532 Upgrade to version 3.2g or better or compile with --with-xpm=no.
|
|
2533 #endif /* !XPM_DOES_BUFFERS */
|
|
2534
|
|
2535 static XpmColorSymbol *
|
|
2536 extract_xpm_color_names (XpmAttributes *xpmattrs, Lisp_Object device,
|
|
2537 Lisp_Object color_symbol_alist)
|
|
2538 {
|
|
2539 /* This function can GC */
|
|
2540 Screen *xs = LISP_DEVICE_TO_X_SCREEN (device);
|
|
2541 Display *dpy = DisplayOfScreen (xs);
|
|
2542 Colormap cmap = DefaultColormapOfScreen (xs);
|
|
2543 XColor color;
|
|
2544 Lisp_Object rest;
|
|
2545 Lisp_Object results = Qnil;
|
|
2546 int i;
|
|
2547 XpmColorSymbol *symbols;
|
|
2548 struct gcpro gcpro1, gcpro2;
|
|
2549
|
|
2550 GCPRO2 (results, device);
|
|
2551
|
|
2552 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
2553 error happens we don't lose any malloc()ed data, or more importantly,
|
|
2554 leave any pixels allocated in the server. */
|
|
2555 i = 0;
|
|
2556 LIST_LOOP (rest, color_symbol_alist)
|
|
2557 {
|
|
2558 Lisp_Object cons = XCAR (rest);
|
|
2559 Lisp_Object name = XCAR (cons);
|
|
2560 Lisp_Object value = XCDR (cons);
|
|
2561 if (NILP (value))
|
|
2562 continue;
|
|
2563 if (STRINGP (value))
|
|
2564 value =
|
|
2565 Fmake_color_instance
|
|
2566 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
|
|
2567 else
|
|
2568 {
|
|
2569 assert (COLOR_SPECIFIERP (value));
|
24
|
2570 value = Fspecifier_instance (value, Qnil, Qnil, Qnil);
|
0
|
2571 }
|
|
2572 if (NILP (value))
|
|
2573 continue;
|
|
2574 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
2575 i++;
|
|
2576 }
|
|
2577 UNGCPRO; /* no more evaluation */
|
|
2578
|
|
2579 if (i == 0) return 0;
|
|
2580
|
|
2581 symbols = (XpmColorSymbol *) xmalloc (i * sizeof (XpmColorSymbol));
|
|
2582 xpmattrs->valuemask |= XpmColorSymbols;
|
|
2583 xpmattrs->colorsymbols = symbols;
|
|
2584 xpmattrs->numsymbols = i;
|
|
2585
|
|
2586 while (--i >= 0)
|
|
2587 {
|
|
2588 Lisp_Object cons = XCAR (results);
|
|
2589 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
2590 /* Duplicate the pixel value so that we still have a lock on it if
|
|
2591 the pixel we were passed is later freed. */
|
|
2592 if (! XAllocColor (dpy, cmap, &color))
|
|
2593 abort (); /* it must be allocable since we're just duplicating it */
|
|
2594
|
14
|
2595 symbols [i].name = (char *) XSTRING_DATA (XCAR (cons));
|
0
|
2596 symbols [i].pixel = color.pixel;
|
|
2597 symbols [i].value = 0;
|
|
2598 free_cons (XCONS (cons));
|
|
2599 cons = results;
|
|
2600 results = XCDR (results);
|
|
2601 free_cons (XCONS (cons));
|
|
2602 }
|
|
2603 return symbols;
|
|
2604 }
|
|
2605
|
|
2606 static void
|
|
2607 xpm_free (XpmAttributes *xpmattrs)
|
|
2608 {
|
|
2609 /* Could conceivably lose if XpmXXX returned an error without first
|
|
2610 initializing this structure, if we didn't know that initializing it
|
|
2611 to all zeros was ok (and also that it's ok to call XpmFreeAttributes()
|
|
2612 multiple times, since it zeros slots as it frees them...) */
|
|
2613 XpmFreeAttributes (xpmattrs);
|
|
2614 }
|
|
2615
|
|
2616 static void
|
|
2617 xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2618 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2619 int dest_mask)
|
|
2620 {
|
|
2621 /* This function can GC */
|
|
2622 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2623 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
2624 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
2625 Display *dpy;
|
|
2626 Screen *xs;
|
|
2627 Pixmap pixmap;
|
|
2628 Pixmap mask = 0;
|
|
2629 XpmAttributes xpmattrs;
|
|
2630 int result;
|
|
2631 XpmColorSymbol *color_symbols;
|
|
2632 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
2633 Q_color_symbols);
|
|
2634 enum image_instance_type type;
|
|
2635 int force_mono;
|
|
2636 unsigned int w, h;
|
|
2637
|
|
2638 if (!DEVICE_X_P (XDEVICE (device)))
|
|
2639 signal_simple_error ("Not an X device", device);
|
|
2640
|
|
2641 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
2642 xs = DefaultScreenOfDisplay (dpy);
|
|
2643
|
|
2644 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
2645 type = IMAGE_COLOR_PIXMAP;
|
|
2646 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
2647 type = IMAGE_MONO_PIXMAP;
|
|
2648 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
2649 type = IMAGE_POINTER;
|
|
2650 else
|
|
2651 incompatible_image_types (instantiator, dest_mask,
|
|
2652 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
2653 | IMAGE_POINTER_MASK);
|
|
2654 force_mono = (type != IMAGE_COLOR_PIXMAP);
|
|
2655
|
|
2656 x_initialize_pixmap_image_instance (ii, type);
|
|
2657
|
|
2658 assert (!NILP (data));
|
|
2659
|
|
2660 retry:
|
|
2661
|
|
2662 memset (&xpmattrs, 0, sizeof (xpmattrs)); /* want XpmInitAttributes() */
|
|
2663 xpmattrs.valuemask = XpmReturnPixels;
|
|
2664 if (force_mono)
|
|
2665 {
|
|
2666 /* Without this, we get a 1-bit version of the color image, which
|
|
2667 isn't quite right. With this, we get the mono image, which might
|
|
2668 be very different looking. */
|
|
2669 xpmattrs.valuemask |= XpmColorKey;
|
|
2670 xpmattrs.color_key = XPM_MONO;
|
|
2671 xpmattrs.depth = 1;
|
|
2672 xpmattrs.valuemask |= XpmDepth;
|
|
2673 }
|
|
2674 else
|
|
2675 {
|
|
2676 xpmattrs.closeness = 65535;
|
|
2677 xpmattrs.valuemask |= XpmCloseness;
|
|
2678 }
|
|
2679
|
|
2680 color_symbols = extract_xpm_color_names (&xpmattrs, device,
|
|
2681 color_symbol_alist);
|
|
2682
|
|
2683 result = XpmCreatePixmapFromBuffer (dpy,
|
|
2684 RootWindowOfScreen (xs),
|
14
|
2685 (char *) XSTRING_DATA (data),
|
0
|
2686 &pixmap, &mask, &xpmattrs);
|
|
2687
|
|
2688 if (color_symbols)
|
|
2689 {
|
|
2690 xfree (color_symbols);
|
|
2691 xpmattrs.colorsymbols = 0; /* in case XpmFreeAttr is too smart... */
|
|
2692 xpmattrs.numsymbols = 0;
|
|
2693 }
|
|
2694
|
|
2695 switch (result)
|
|
2696 {
|
|
2697 case XpmSuccess:
|
|
2698 break;
|
|
2699 case XpmFileInvalid:
|
|
2700 {
|
|
2701 xpm_free (&xpmattrs);
|
|
2702 signal_simple_error ("invalid XPM data", data);
|
|
2703 }
|
|
2704 case XpmColorFailed:
|
|
2705 case XpmColorError:
|
|
2706 {
|
|
2707 xpm_free (&xpmattrs);
|
|
2708 if (force_mono)
|
|
2709 {
|
|
2710 /* second time; blow out. */
|
|
2711 signal_double_file_error ("Reading pixmap data",
|
|
2712 "color allocation failed",
|
|
2713 data);
|
|
2714 }
|
|
2715 else
|
|
2716 {
|
|
2717 if (! (dest_mask & IMAGE_MONO_PIXMAP_MASK))
|
|
2718 {
|
|
2719 /* second time; blow out. */
|
|
2720 signal_double_file_error ("Reading pixmap data",
|
|
2721 "color allocation failed",
|
|
2722 data);
|
|
2723 }
|
|
2724 force_mono = 1;
|
|
2725 IMAGE_INSTANCE_TYPE (ii) = IMAGE_MONO_PIXMAP;
|
|
2726 goto retry;
|
|
2727 }
|
|
2728 }
|
|
2729 case XpmNoMemory:
|
|
2730 {
|
|
2731 xpm_free (&xpmattrs);
|
|
2732 signal_double_file_error ("Parsing pixmap data",
|
|
2733 "out of memory", data);
|
|
2734 }
|
|
2735 default:
|
|
2736 {
|
|
2737 xpm_free (&xpmattrs);
|
|
2738 signal_double_file_error_2 ("Parsing pixmap data",
|
|
2739 "unknown error code",
|
|
2740 make_int (result), data);
|
|
2741 }
|
|
2742 }
|
|
2743
|
|
2744 w = xpmattrs.width;
|
|
2745 h = xpmattrs.height;
|
|
2746
|
|
2747 {
|
|
2748 int npixels = xpmattrs.npixels;
|
|
2749 Pixel *pixels = 0;
|
|
2750
|
|
2751 if (npixels != 0)
|
|
2752 {
|
|
2753 pixels = xmalloc (npixels * sizeof (Pixel));
|
|
2754 memcpy (pixels, xpmattrs.pixels, npixels * sizeof (Pixel));
|
|
2755 }
|
|
2756 else
|
|
2757 pixels = 0;
|
|
2758
|
|
2759 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
|
|
2760 IMAGE_INSTANCE_X_MASK (ii) = mask;
|
|
2761 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
|
|
2762 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
|
|
2763 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w;
|
|
2764 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h;
|
|
2765 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
2766 find_keyword_in_vector (instantiator, Q_file);
|
|
2767 }
|
|
2768
|
|
2769 switch (type)
|
|
2770 {
|
|
2771 case IMAGE_MONO_PIXMAP:
|
|
2772 break;
|
|
2773
|
|
2774 case IMAGE_COLOR_PIXMAP:
|
|
2775 {
|
|
2776 /* XpmReadFileToPixmap() doesn't return the depth (bogus!) so
|
|
2777 we need to get it ourself. (No, xpmattrs.depth is not it;
|
|
2778 that's an input slot, not output.) We could just assume
|
|
2779 that it has the same depth as the root window, but some
|
|
2780 devices allow more than one depth, so that isn't
|
|
2781 necessarily correct (I guess?) */
|
|
2782 Window root;
|
|
2783 int x, y;
|
|
2784 unsigned int w2, h2, bw;
|
|
2785
|
|
2786 unsigned int d;
|
|
2787
|
|
2788 if (!XGetGeometry (dpy, pixmap, &root, &x, &y, &w2, &h2, &bw, &d))
|
|
2789 abort ();
|
|
2790 if (w != w2 || h != h2)
|
|
2791 abort ();
|
|
2792
|
|
2793 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
|
|
2794 }
|
|
2795 break;
|
|
2796
|
|
2797 case IMAGE_POINTER:
|
|
2798 {
|
|
2799 int npixels = xpmattrs.npixels;
|
|
2800 Pixel *pixels = xpmattrs.pixels;
|
|
2801 XColor fg, bg;
|
|
2802 int i;
|
|
2803 int xhot = 0, yhot = 0;
|
|
2804
|
|
2805 if (xpmattrs.valuemask & XpmHotspot)
|
|
2806 {
|
|
2807 xhot = xpmattrs.x_hotspot;
|
|
2808 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), xpmattrs.x_hotspot);
|
|
2809 }
|
|
2810 if (xpmattrs.valuemask & XpmHotspot)
|
|
2811 {
|
|
2812 yhot = xpmattrs.y_hotspot;
|
|
2813 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), xpmattrs.y_hotspot);
|
|
2814 }
|
|
2815 check_pointer_sizes (xs, w, h, instantiator);
|
|
2816
|
|
2817 /* If the loaded pixmap has colors allocated (meaning it came from an
|
|
2818 XPM file), then use those as the default colors for the cursor we
|
|
2819 create. Otherwise, default to pointer_fg and pointer_bg.
|
|
2820 */
|
|
2821 if (npixels >= 2)
|
|
2822 {
|
|
2823 /* With an XBM file, it's obvious which bit is foreground
|
|
2824 and which is background, or rather, it's implicit: in
|
|
2825 an XBM file, a 1 bit is foreground, and a 0 bit is
|
|
2826 background.
|
|
2827
|
|
2828 XCreatePixmapCursor() assumes this property of the
|
|
2829 pixmap it is called with as well; the `foreground'
|
|
2830 color argument is used for the 1 bits.
|
|
2831
|
|
2832 With an XPM file, it's tricker, since the elements of
|
|
2833 the pixmap don't represent FG and BG, but are actual
|
|
2834 pixel values. So we need to figure out which of those
|
|
2835 pixels is the foreground color and which is the
|
|
2836 background. We do it by comparing RGB and assuming
|
|
2837 that the darker color is the foreground. This works
|
|
2838 with the result of xbmtopbm|ppmtoxpm, at least.
|
|
2839
|
|
2840 It might be nice if there was some way to tag the
|
|
2841 colors in the XPM file with whether they are the
|
|
2842 foreground - perhaps with logical color names somehow?
|
|
2843
|
|
2844 Once we have decided which color is the foreground, we
|
|
2845 need to ensure that that color corresponds to a `1' bit
|
|
2846 in the Pixmap. The XPM library wrote into the (1-bit)
|
|
2847 pixmap with XPutPixel, which will ignore all but the
|
|
2848 least significant bit.
|
|
2849
|
|
2850 This means that a 1 bit in the image corresponds to
|
|
2851 `fg' only if `fg.pixel' is odd.
|
|
2852
|
|
2853 (This also means that the image will be all the same
|
|
2854 color if both `fg' and `bg' are odd or even, but we can
|
|
2855 safely assume that that won't happen if the XPM file is
|
|
2856 sensible I think.)
|
|
2857
|
|
2858 The desired result is that the image use `1' to
|
|
2859 represent the foreground color, and `0' to represent
|
|
2860 the background color. So, we may need to invert the
|
|
2861 image to accomplish this; we invert if fg is
|
|
2862 odd. (Remember that WhitePixel and BlackPixel are not
|
|
2863 necessarily 1 and 0 respectively, though I think it
|
|
2864 might be safe to assume that one of them is always 1
|
|
2865 and the other is always 0. We also pretty much need to
|
|
2866 assume that one is even and the other is odd.)
|
|
2867 */
|
|
2868
|
|
2869 fg.pixel = pixels[0]; /* pick a pixel at random. */
|
|
2870 bg.pixel = fg.pixel;
|
|
2871 for (i = 1; i < npixels; i++) /* Look for an "other" pixel value.*/
|
|
2872 {
|
|
2873 bg.pixel = pixels[i];
|
|
2874 if (fg.pixel != bg.pixel)
|
|
2875 break;
|
|
2876 }
|
|
2877
|
|
2878 /* If (fg.pixel == bg.pixel) then probably something has
|
|
2879 gone wrong, but I don't think signalling an error would
|
|
2880 be appropriate. */
|
|
2881
|
|
2882 XQueryColor (dpy, DefaultColormapOfScreen (xs), &fg);
|
|
2883 XQueryColor (dpy, DefaultColormapOfScreen (xs), &bg);
|
|
2884
|
|
2885 /* If the foreground is lighter than the background, swap them.
|
|
2886 (This occurs semi-randomly, depending on the ordering of the
|
|
2887 color list in the XPM file.)
|
|
2888 */
|
|
2889 {
|
|
2890 unsigned short fg_total = ((fg.red / 3) + (fg.green / 3)
|
|
2891 + (fg.blue / 3));
|
|
2892 unsigned short bg_total = ((bg.red / 3) + (bg.green / 3)
|
|
2893 + (bg.blue / 3));
|
|
2894 if (fg_total > bg_total)
|
|
2895 {
|
|
2896 XColor swap;
|
|
2897 swap = fg;
|
|
2898 fg = bg;
|
|
2899 bg = swap;
|
|
2900 }
|
|
2901 }
|
|
2902
|
|
2903 /* If the fg pixel corresponds to a `0' in the bitmap, invert it.
|
|
2904 (This occurs (only?) on servers with Black=0, White=1.)
|
|
2905 */
|
|
2906 if ((fg.pixel & 1) == 0)
|
|
2907 {
|
|
2908 XGCValues gcv;
|
|
2909 GC gc;
|
|
2910 gcv.function = GXxor;
|
|
2911 gcv.foreground = 1;
|
|
2912 gc = XCreateGC (dpy, pixmap, (GCFunction | GCForeground),
|
|
2913 &gcv);
|
|
2914 XFillRectangle (dpy, pixmap, gc, 0, 0, w, h);
|
|
2915 XFreeGC (dpy, gc);
|
|
2916 }
|
|
2917 }
|
|
2918 else
|
|
2919 {
|
|
2920 generate_cursor_fg_bg (device, &pointer_fg, &pointer_bg,
|
|
2921 &fg, &bg);
|
|
2922 IMAGE_INSTANCE_PIXMAP_FG (ii) = pointer_fg;
|
|
2923 IMAGE_INSTANCE_PIXMAP_BG (ii) = pointer_bg;
|
|
2924 }
|
|
2925
|
|
2926 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
2927 XCreatePixmapCursor
|
|
2928 (dpy, pixmap, mask, &fg, &bg, xhot, yhot);
|
|
2929 }
|
|
2930
|
|
2931 break;
|
|
2932
|
|
2933 default:
|
|
2934 abort ();
|
|
2935 }
|
|
2936
|
|
2937 xpm_free (&xpmattrs); /* after we've read pixels and hotspot */
|
|
2938 }
|
|
2939
|
|
2940 #endif /* HAVE_XPM */
|
|
2941
|
|
2942
|
|
2943 #ifdef HAVE_XFACE
|
|
2944
|
|
2945 /**********************************************************************
|
|
2946 * X-Face *
|
|
2947 **********************************************************************/
|
|
2948
|
|
2949 static void
|
|
2950 xface_validate (Lisp_Object instantiator)
|
|
2951 {
|
|
2952 file_or_data_must_be_present (instantiator);
|
|
2953 }
|
|
2954
|
|
2955 static Lisp_Object
|
|
2956 xface_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
2957 {
|
|
2958 Lisp_Object file = Qnil, mask_file = Qnil;
|
|
2959 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2960 Lisp_Object alist = Qnil;
|
|
2961
|
|
2962 GCPRO3 (file, mask_file, alist);
|
|
2963
|
|
2964 /* Now, convert any file data into inline data for both the regular
|
|
2965 data and the mask data. At the end of this, `data' will contain
|
|
2966 the inline data (if any) or Qnil, and `file' will contain
|
|
2967 the name this data was derived from (if known) or Qnil.
|
|
2968 Likewise for `mask_file' and `mask_data'.
|
|
2969
|
|
2970 Note that if we cannot generate any regular inline data, we
|
|
2971 skip out. */
|
|
2972
|
|
2973 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
2974 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
|
|
2975 Q_mask_data);
|
|
2976
|
|
2977 if (CONSP (file)) /* failure locating filename */
|
|
2978 signal_double_file_error ("Opening bitmap file",
|
|
2979 "no such file or directory",
|
|
2980 Fcar (file));
|
|
2981
|
|
2982 if (NILP (file) && NILP (mask_file)) /* no conversion necessary */
|
|
2983 RETURN_UNGCPRO (inst);
|
|
2984
|
|
2985 alist = tagged_vector_to_alist (inst);
|
|
2986
|
|
2987 {
|
|
2988 Lisp_Object data = make_string_from_file (file);
|
|
2989 alist = remassq_no_quit (Q_file, alist);
|
|
2990 /* there can't be a :data at this point. */
|
|
2991 alist = Fcons (Fcons (Q_file, file),
|
|
2992 Fcons (Fcons (Q_data, data), alist));
|
|
2993 }
|
|
2994
|
|
2995 alist = xbm_mask_file_munging (alist, file, mask_file);
|
|
2996
|
|
2997 {
|
|
2998 Lisp_Object result = alist_to_tagged_vector (Qxface, alist);
|
|
2999 free_alist (alist);
|
|
3000 RETURN_UNGCPRO (result);
|
|
3001 }
|
|
3002 }
|
|
3003
|
|
3004 static int
|
16
|
3005 xface_possible_dest_types (void)
|
0
|
3006 {
|
16
|
3007 return
|
|
3008 IMAGE_MONO_PIXMAP_MASK |
|
|
3009 IMAGE_COLOR_PIXMAP_MASK |
|
0
|
3010 IMAGE_POINTER_MASK;
|
|
3011 }
|
|
3012
|
|
3013 #if defined(EXTERN)
|
|
3014 /* This is about to get redefined! */
|
|
3015 #undef EXTERN
|
|
3016 #endif
|
|
3017 /* We have to define SYSV32 so that compface.h includes string.h
|
|
3018 instead of strings.h. */
|
|
3019 #define SYSV32
|
|
3020 #include <compface.h>
|
|
3021 /* JMP_BUF cannot be used here because if it doesn't get defined
|
|
3022 to jmp_buf we end up with a conflicting type error with the
|
|
3023 definition in compface.h */
|
|
3024 extern jmp_buf comp_env;
|
|
3025 #undef SYSV32
|
|
3026
|
|
3027 static void
|
|
3028 xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
3029 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
3030 int dest_mask)
|
|
3031 {
|
|
3032 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
3033 int i, stattis;
|
|
3034 char *p, *bits, *bp;
|
16
|
3035 CONST char * volatile emsg = 0;
|
|
3036 CONST char * volatile dstring;
|
0
|
3037
|
|
3038 assert (!NILP (data));
|
|
3039
|
|
3040 GET_C_STRING_BINARY_DATA_ALLOCA (data, dstring);
|
|
3041
|
|
3042 if ((p = strchr (dstring, ':')))
|
|
3043 {
|
|
3044 dstring = p + 1;
|
|
3045 }
|
|
3046
|
|
3047 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
|
|
3048 if (!(stattis = setjmp (comp_env)))
|
|
3049 {
|
|
3050 UnCompAll ((char *) dstring);
|
|
3051 UnGenFace ();
|
|
3052 }
|
|
3053
|
|
3054 switch (stattis)
|
|
3055 {
|
|
3056 case -2:
|
|
3057 emsg = "uncompface: internal error";
|
|
3058 break;
|
|
3059 case -1:
|
|
3060 emsg = "uncompface: insufficient or invalid data";
|
|
3061 break;
|
|
3062 case 1:
|
|
3063 emsg = "uncompface: excess data ignored";
|
|
3064 break;
|
|
3065 }
|
|
3066
|
|
3067 if (emsg)
|
|
3068 signal_simple_error_2 (emsg, data, Qimage);
|
|
3069
|
|
3070 bp = bits = (char *) alloca (PIXELS / 8);
|
|
3071
|
|
3072 /* the compface library exports char F[], which uses a single byte per
|
|
3073 pixel to represent a 48x48 bitmap. Yuck. */
|
|
3074 for (i = 0, p = F; i < (PIXELS / 8); ++i)
|
|
3075 {
|
|
3076 int n, b;
|
|
3077 /* reverse the bit order of each byte... */
|
|
3078 for (b = n = 0; b < 8; ++b)
|
|
3079 {
|
|
3080 n |= ((*p++) << b);
|
|
3081 }
|
|
3082 *bp++ = (char) n;
|
|
3083 }
|
|
3084
|
|
3085 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
3086 pointer_bg, dest_mask, 48, 48, bits);
|
|
3087 }
|
|
3088
|
|
3089 #endif /* HAVE_XFACE */
|
|
3090
|
|
3091
|
|
3092 /**********************************************************************
|
|
3093 * Autodetect *
|
|
3094 **********************************************************************/
|
|
3095
|
|
3096 static void
|
|
3097 autodetect_validate (Lisp_Object instantiator)
|
|
3098 {
|
|
3099 data_must_be_present (instantiator);
|
|
3100 }
|
|
3101
|
|
3102 static Lisp_Object
|
|
3103 autodetect_normalize (Lisp_Object instantiator, Lisp_Object console_type)
|
|
3104 {
|
|
3105 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data);
|
|
3106 Lisp_Object filename = Qnil;
|
|
3107 Lisp_Object data = Qnil;
|
|
3108 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3109 Lisp_Object alist = Qnil;
|
|
3110
|
|
3111 GCPRO3 (filename, data, alist);
|
|
3112
|
|
3113 if (NILP (file)) /* no conversion necessary */
|
|
3114 RETURN_UNGCPRO (instantiator);
|
|
3115
|
|
3116 alist = tagged_vector_to_alist (instantiator);
|
|
3117
|
|
3118 filename = locate_pixmap_file (file);
|
|
3119 if (!NILP (filename))
|
|
3120 {
|
|
3121 int xhot, yhot;
|
|
3122 /* #### Apparently some versions of XpmReadFileToData, which is
|
|
3123 called by pixmap_to_lisp_data, don't return an error value
|
|
3124 if the given file is not a valid XPM file. Instead, they
|
|
3125 just seg fault. It is definitely caused by passing a
|
|
3126 bitmap. To try and avoid this we check for bitmaps first. */
|
|
3127
|
|
3128 data = bitmap_to_lisp_data (filename, &xhot, &yhot, 1);
|
|
3129
|
|
3130 if (!EQ (data, Qt))
|
|
3131 {
|
|
3132 alist = remassq_no_quit (Q_data, alist);
|
|
3133 alist = Fcons (Fcons (Q_file, filename),
|
|
3134 Fcons (Fcons (Q_data, data), alist));
|
|
3135 if (xhot != -1)
|
|
3136 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
3137 alist);
|
|
3138 if (yhot != -1)
|
|
3139 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
3140 alist);
|
|
3141
|
|
3142 alist = xbm_mask_file_munging (alist, filename, Qnil);
|
|
3143
|
|
3144 {
|
|
3145 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
3146 free_alist (alist);
|
|
3147 RETURN_UNGCPRO (result);
|
|
3148 }
|
|
3149 }
|
|
3150
|
|
3151 #ifdef HAVE_XPM
|
|
3152 data = pixmap_to_lisp_data (filename, 1);
|
|
3153
|
|
3154 if (!EQ (data, Qt))
|
|
3155 {
|
|
3156 alist = remassq_no_quit (Q_data, alist);
|
|
3157 alist = Fcons (Fcons (Q_file, filename),
|
|
3158 Fcons (Fcons (Q_data, data), alist));
|
|
3159 alist = Fcons (Fcons (Q_color_symbols,
|
|
3160 evaluate_xpm_color_symbols ()),
|
|
3161 alist);
|
|
3162 {
|
|
3163 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
3164 free_alist (alist);
|
|
3165 RETURN_UNGCPRO (result);
|
|
3166 }
|
|
3167 }
|
|
3168 #endif
|
|
3169 }
|
|
3170
|
|
3171 /* If we couldn't convert it, just put it back as it is.
|
|
3172 We might try to further frob it later as a cursor-font
|
|
3173 specification. (We can't do that now because we don't know
|
|
3174 what dest-types it's going to be instantiated into.) */
|
|
3175 {
|
|
3176 Lisp_Object result = alist_to_tagged_vector (Qautodetect, alist);
|
|
3177 free_alist (alist);
|
|
3178 RETURN_UNGCPRO (result);
|
|
3179 }
|
|
3180 }
|
|
3181
|
|
3182 static int
|
16
|
3183 autodetect_possible_dest_types (void)
|
0
|
3184 {
|
16
|
3185 return
|
|
3186 IMAGE_MONO_PIXMAP_MASK |
|
|
3187 IMAGE_COLOR_PIXMAP_MASK |
|
|
3188 IMAGE_POINTER_MASK |
|
|
3189 IMAGE_TEXT_MASK;
|
0
|
3190 }
|
|
3191
|
|
3192 static void
|
|
3193 autodetect_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
3194 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
3195 int dest_mask)
|
|
3196 {
|
|
3197 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
3198 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3199 Lisp_Object alist = Qnil;
|
|
3200 Lisp_Object result = Qnil;
|
|
3201 int is_cursor_font = 0;
|
|
3202
|
|
3203 GCPRO3 (data, alist, result);
|
|
3204
|
|
3205 alist = tagged_vector_to_alist (instantiator);
|
|
3206 if (dest_mask & IMAGE_POINTER_MASK)
|
|
3207 {
|
|
3208 CONST char *name_ext;
|
|
3209 GET_C_STRING_FILENAME_DATA_ALLOCA (data, name_ext);
|
|
3210 if (XmuCursorNameToIndex (name_ext) != -1)
|
|
3211 {
|
|
3212 result = alist_to_tagged_vector (Qcursor_font, alist);
|
|
3213 is_cursor_font = 1;
|
|
3214 }
|
|
3215 }
|
|
3216
|
|
3217 if (!is_cursor_font)
|
|
3218 result = alist_to_tagged_vector (Qstring, alist);
|
|
3219 free_alist (alist);
|
|
3220
|
|
3221 if (is_cursor_font)
|
|
3222 cursor_font_instantiate (image_instance, result, pointer_fg,
|
|
3223 pointer_bg, dest_mask);
|
|
3224 else
|
|
3225 string_instantiate (image_instance, result, pointer_fg,
|
|
3226 pointer_bg, dest_mask);
|
|
3227
|
|
3228 UNGCPRO;
|
|
3229 }
|
|
3230
|
|
3231
|
|
3232 /**********************************************************************
|
|
3233 * Font *
|
|
3234 **********************************************************************/
|
|
3235
|
|
3236 static void
|
|
3237 font_validate (Lisp_Object instantiator)
|
|
3238 {
|
|
3239 data_must_be_present (instantiator);
|
|
3240 }
|
|
3241
|
|
3242 /* XmuCvtStringToCursor is bogus in the following ways:
|
|
3243
|
|
3244 - When it can't convert the given string to a real cursor, it will
|
|
3245 sometimes return a "success" value, after triggering a BadPixmap
|
|
3246 error. It then gives you a cursor that will itself generate BadCursor
|
|
3247 errors. So we install this error handler to catch/notice the X error
|
|
3248 and take that as meaning "couldn't convert."
|
|
3249
|
|
3250 - When you tell it to find a cursor file that doesn't exist, it prints
|
|
3251 an error message on stderr. You can't make it not do that.
|
|
3252
|
|
3253 - Also, using Xmu means we can't properly hack Lisp_Image_Instance
|
|
3254 objects, or XPM files, or $XBMLANGPATH.
|
|
3255 */
|
|
3256
|
|
3257 /* Duplicate the behavior of XmuCvtStringToCursor() to bypass its bogusness. */
|
|
3258
|
|
3259 static int XLoadFont_got_error;
|
|
3260
|
|
3261 static int
|
|
3262 XLoadFont_error_handler (Display *dpy, XErrorEvent *xerror)
|
|
3263 {
|
|
3264 XLoadFont_got_error = 1;
|
|
3265 return 0;
|
|
3266 }
|
|
3267
|
|
3268 static Font
|
|
3269 safe_XLoadFont (Display *dpy, char *name)
|
|
3270 {
|
|
3271 Font font;
|
|
3272 int (*old_handler) (Display *, XErrorEvent *);
|
|
3273 XLoadFont_got_error = 0;
|
|
3274 XSync (dpy, 0);
|
|
3275 old_handler = XSetErrorHandler (XLoadFont_error_handler);
|
|
3276 font = XLoadFont (dpy, name);
|
|
3277 XSync (dpy, 0);
|
|
3278 XSetErrorHandler (old_handler);
|
|
3279 if (XLoadFont_got_error) return 0;
|
|
3280 return font;
|
|
3281 }
|
|
3282
|
|
3283 static int
|
16
|
3284 font_possible_dest_types (void)
|
0
|
3285 {
|
|
3286 return IMAGE_POINTER_MASK;
|
|
3287 }
|
|
3288
|
|
3289 static void
|
|
3290 font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
3291 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
3292 int dest_mask)
|
|
3293 {
|
|
3294 /* This function can GC */
|
|
3295 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
3296 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
3297 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
3298 Display *dpy;
|
|
3299 XColor fg, bg;
|
|
3300 Font source, mask;
|
|
3301 char source_name[MAXPATHLEN], mask_name[MAXPATHLEN], dummy;
|
|
3302 int source_char, mask_char;
|
|
3303 int count;
|
|
3304 Lisp_Object foreground, background;
|
|
3305
|
|
3306 if (!DEVICE_X_P (XDEVICE (device)))
|
|
3307 signal_simple_error ("Not an X device", device);
|
|
3308
|
|
3309 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
3310
|
|
3311 if (!STRINGP (data) ||
|
14
|
3312 strncmp ("FONT ", (char *) XSTRING_DATA (data), 5))
|
0
|
3313 signal_simple_error ("Invalid font-glyph instantiator",
|
|
3314 instantiator);
|
|
3315
|
|
3316 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
3317 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
3318
|
|
3319 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
3320 if (NILP (foreground))
|
|
3321 foreground = pointer_fg;
|
|
3322 background = find_keyword_in_vector (instantiator, Q_background);
|
|
3323 if (NILP (background))
|
|
3324 background = pointer_bg;
|
|
3325
|
|
3326 generate_cursor_fg_bg (device, &foreground, &background, &fg, &bg);
|
|
3327
|
14
|
3328 count = sscanf ((char *) XSTRING_DATA (data),
|
0
|
3329 "FONT %s %d %s %d %c",
|
|
3330 source_name, &source_char,
|
|
3331 mask_name, &mask_char, &dummy);
|
|
3332 /* Allow "%s %d %d" as well... */
|
|
3333 if (count == 3 && (1 == sscanf (mask_name, "%d %c", &mask_char, &dummy)))
|
|
3334 count = 4, mask_name[0] = 0;
|
|
3335
|
|
3336 if (count != 2 && count != 4)
|
|
3337 signal_simple_error ("invalid cursor specification", data);
|
|
3338 source = safe_XLoadFont (dpy, source_name);
|
|
3339 if (! source)
|
|
3340 signal_simple_error_2 ("couldn't load font",
|
|
3341 build_string (source_name),
|
|
3342 data);
|
|
3343 if (count == 2)
|
|
3344 mask = 0;
|
|
3345 else if (!mask_name[0])
|
|
3346 mask = source;
|
|
3347 else
|
|
3348 {
|
|
3349 mask = safe_XLoadFont (dpy, mask_name);
|
|
3350 if (!mask)
|
|
3351 /* continuable */
|
|
3352 Fsignal (Qerror, list3 (build_string ("couldn't load font"),
|
|
3353 build_string (mask_name), data));
|
|
3354 }
|
|
3355 if (!mask)
|
|
3356 mask_char = 0;
|
|
3357
|
|
3358 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */
|
|
3359
|
|
3360 x_initialize_pixmap_image_instance (ii, IMAGE_POINTER);
|
|
3361 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
3362 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char,
|
|
3363 &fg, &bg);
|
|
3364 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
3365 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
3366 XUnloadFont (dpy, source);
|
|
3367 if (mask && mask != source) XUnloadFont (dpy, mask);
|
|
3368 }
|
|
3369
|
|
3370
|
|
3371 /**********************************************************************
|
|
3372 * Cursor-Font *
|
|
3373 **********************************************************************/
|
|
3374
|
|
3375 static void
|
|
3376 cursor_font_validate (Lisp_Object instantiator)
|
|
3377 {
|
|
3378 data_must_be_present (instantiator);
|
|
3379 }
|
|
3380
|
|
3381 static int
|
16
|
3382 cursor_font_possible_dest_types (void)
|
0
|
3383 {
|
|
3384 return IMAGE_POINTER_MASK;
|
|
3385 }
|
|
3386
|
|
3387 static void
|
|
3388 cursor_font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
3389 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
3390 int dest_mask)
|
|
3391 {
|
|
3392 /* This function can GC */
|
|
3393 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
3394 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
3395 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
3396 Display *dpy;
|
|
3397 int i;
|
|
3398 CONST char *name_ext;
|
|
3399 Lisp_Object foreground, background;
|
|
3400
|
|
3401 if (!DEVICE_X_P (XDEVICE (device)))
|
|
3402 signal_simple_error ("Not an X device", device);
|
|
3403
|
|
3404 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
3405
|
|
3406 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
3407 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
3408
|
|
3409 GET_C_STRING_FILENAME_DATA_ALLOCA (data, name_ext);
|
|
3410 if ((i = XmuCursorNameToIndex (name_ext)) == -1)
|
|
3411 signal_simple_error ("Unrecognized cursor-font name", data);
|
|
3412
|
|
3413 x_initialize_pixmap_image_instance (ii, IMAGE_POINTER);
|
|
3414 IMAGE_INSTANCE_X_CURSOR (ii) = XCreateFontCursor (dpy, i);
|
|
3415 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
3416 if (NILP (foreground))
|
|
3417 foreground = pointer_fg;
|
|
3418 background = find_keyword_in_vector (instantiator, Q_background);
|
|
3419 if (NILP (background))
|
|
3420 background = pointer_bg;
|
|
3421 maybe_recolor_cursor (image_instance, foreground, background);
|
|
3422 }
|
|
3423
|
|
3424 static int
|
|
3425 x_colorize_image_instance (Lisp_Object image_instance,
|
|
3426 Lisp_Object foreground, Lisp_Object background)
|
|
3427 {
|
|
3428 struct Lisp_Image_Instance *p;
|
|
3429
|
|
3430 p = XIMAGE_INSTANCE (image_instance);
|
|
3431
|
|
3432 switch (IMAGE_INSTANCE_TYPE (p))
|
|
3433 {
|
|
3434 case IMAGE_MONO_PIXMAP:
|
|
3435 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
|
|
3436 /* Make sure there aren't two pointers to the same mask, causing
|
|
3437 it to get freed twice. */
|
|
3438 IMAGE_INSTANCE_X_MASK (p) = 0;
|
|
3439 break;
|
|
3440
|
|
3441 default:
|
|
3442 return 0;
|
|
3443 }
|
|
3444
|
|
3445 {
|
|
3446 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
3447 Screen *scr = DefaultScreenOfDisplay (dpy);
|
|
3448 Dimension d = DefaultDepthOfScreen (scr);
|
|
3449 Pixmap new = XCreatePixmap (dpy, RootWindowOfScreen (scr),
|
|
3450 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
3451 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), d);
|
|
3452 XColor color;
|
|
3453 XGCValues gcv;
|
|
3454 GC gc;
|
|
3455 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground));
|
|
3456 gcv.foreground = color.pixel;
|
|
3457 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background));
|
|
3458 gcv.background = color.pixel;
|
|
3459 gc = XCreateGC (dpy, new, GCBackground|GCForeground, &gcv);
|
|
3460 XCopyPlane (dpy, IMAGE_INSTANCE_X_PIXMAP (p), new, gc, 0, 0,
|
|
3461 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
3462 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
3463 0, 0, 1);
|
|
3464 XFreeGC (dpy, gc);
|
|
3465 IMAGE_INSTANCE_X_PIXMAP (p) = new;
|
|
3466 IMAGE_INSTANCE_PIXMAP_DEPTH (p) = d;
|
|
3467 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
|
|
3468 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
|
|
3469 return 1;
|
|
3470 }
|
|
3471 }
|
|
3472
|
|
3473
|
36
|
3474 #if HAVE_SUBWINDOWS
|
0
|
3475 /************************************************************************/
|
|
3476 /* subwindows */
|
|
3477 /************************************************************************/
|
|
3478
|
|
3479 Lisp_Object Qsubwindowp;
|
|
3480 static Lisp_Object mark_subwindow (Lisp_Object, void (*) (Lisp_Object));
|
|
3481 static void print_subwindow (Lisp_Object, Lisp_Object, int);
|
|
3482 static void finalize_subwindow (void *, int);
|
|
3483 static int subwindow_equal (Lisp_Object o1, Lisp_Object o2, int depth);
|
|
3484 static unsigned long subwindow_hash (Lisp_Object obj, int depth);
|
|
3485 DEFINE_LRECORD_IMPLEMENTATION ("subwindow", subwindow,
|
|
3486 mark_subwindow, print_subwindow,
|
|
3487 finalize_subwindow, subwindow_equal,
|
|
3488 subwindow_hash, struct Lisp_Subwindow);
|
|
3489
|
|
3490 static Lisp_Object
|
|
3491 mark_subwindow (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
3492 {
|
|
3493 struct Lisp_Subwindow *sw = XSUBWINDOW (obj);
|
|
3494 return sw->frame;
|
|
3495 }
|
|
3496
|
|
3497 static void
|
|
3498 print_subwindow (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
3499 {
|
|
3500 char buf[100];
|
|
3501 struct Lisp_Subwindow *sw = XSUBWINDOW (obj);
|
|
3502 struct frame *frm = XFRAME (sw->frame);
|
|
3503
|
|
3504 if (print_readably)
|
|
3505 error ("printing unreadable object #<subwindow 0x%x>",
|
|
3506 sw->header.uid);
|
|
3507
|
|
3508 write_c_string ("#<subwindow", printcharfun);
|
|
3509 sprintf (buf, " %dx%d", sw->width, sw->height);
|
|
3510 write_c_string (buf, printcharfun);
|
|
3511
|
|
3512 /* This is stolen from frame.c. Subwindows are strange in that they
|
|
3513 are specific to a particular frame so we want to print in their
|
|
3514 description what that frame is. */
|
|
3515
|
|
3516 write_c_string (" on #<", printcharfun);
|
|
3517 if (!FRAME_LIVE_P (frm))
|
|
3518 write_c_string ("dead", printcharfun);
|
|
3519 else if (FRAME_TTY_P (frm))
|
|
3520 write_c_string ("tty", printcharfun);
|
|
3521 else if (FRAME_X_P (frm))
|
|
3522 write_c_string ("x", printcharfun);
|
|
3523 else
|
|
3524 write_c_string ("UNKNOWN", printcharfun);
|
|
3525 write_c_string ("-frame ", printcharfun);
|
|
3526 print_internal (frm->name, printcharfun, 1);
|
|
3527 sprintf (buf, " 0x%x>", frm->header.uid);
|
|
3528 write_c_string (buf, printcharfun);
|
|
3529
|
|
3530 sprintf (buf, ") 0x%x>", sw->header.uid);
|
|
3531 write_c_string (buf, printcharfun);
|
|
3532 }
|
|
3533
|
|
3534 static void
|
|
3535 finalize_subwindow (void *header, int for_disksave)
|
|
3536 {
|
|
3537 struct Lisp_Subwindow *sw = (struct Lisp_Subwindow *) header;
|
|
3538 if (for_disksave) finalose (sw);
|
|
3539 if (sw->subwindow)
|
|
3540 {
|
|
3541 XDestroyWindow (DisplayOfScreen (sw->xscreen), sw->subwindow);
|
|
3542 sw->subwindow = 0;
|
|
3543 }
|
|
3544 }
|
|
3545
|
|
3546 /* subwindows are equal iff they have the same window XID */
|
|
3547 static int
|
|
3548 subwindow_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
3549 {
|
|
3550 return (XSUBWINDOW (o1)->subwindow == XSUBWINDOW (o2)->subwindow);
|
|
3551 }
|
|
3552
|
|
3553 static unsigned long
|
|
3554 subwindow_hash (Lisp_Object obj, int depth)
|
|
3555 {
|
|
3556 return XSUBWINDOW (obj)->subwindow;
|
|
3557 }
|
|
3558
|
|
3559 /* #### PROBLEM: The display routines assume that the glyph is only
|
|
3560 being displayed in one buffer. If it is in two different buffers
|
|
3561 which are both being displayed simultaneously you will lose big time.
|
|
3562 This can be dealt with in the new redisplay. */
|
|
3563
|
|
3564 /* #### These are completely un-re-implemented in 19.14. Get it done
|
|
3565 for 19.15. */
|
|
3566
|
20
|
3567 DEFUN ("make-subwindow", Fmake_subwindow, 0, 3, 0, /*
|
0
|
3568 Creates a new `subwindow' object of size WIDTH x HEIGHT.
|
|
3569 The default is a window of size 1x1, which is also the minimum allowed
|
|
3570 window size. Subwindows are per-frame. A buffer being shown in two
|
|
3571 different frames will only display a subwindow glyph in the frame in
|
|
3572 which it was actually created. If two windows on the same frame are
|
|
3573 displaying the buffer then the most recently used window will actually
|
|
3574 display the window. If the frame is not specified, the selected frame
|
|
3575 is used.
|
|
3576
|
|
3577 Subwindows are not currently implemented.
|
20
|
3578 */
|
|
3579 (width, height, frame))
|
0
|
3580 {
|
|
3581 Display *dpy;
|
|
3582 Screen *xs;
|
|
3583 Window pw;
|
|
3584 struct frame *f;
|
|
3585 unsigned int iw, ih;
|
|
3586 XSetWindowAttributes xswa;
|
|
3587 Mask valueMask = 0;
|
|
3588
|
|
3589 error ("subwindows are not functional in 19.14; they will be in 19.15");
|
|
3590
|
|
3591 f = decode_x_frame (frame);
|
|
3592
|
|
3593 xs = LISP_DEVICE_TO_X_SCREEN (FRAME_DEVICE (f));
|
|
3594 dpy = DisplayOfScreen (xs);
|
|
3595 pw = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
3596
|
|
3597 if (NILP (width))
|
|
3598 iw = 1;
|
|
3599 else
|
|
3600 {
|
|
3601 CHECK_INT (width);
|
|
3602 iw = XINT (width);
|
|
3603 if (iw < 1) iw = 1;
|
|
3604 }
|
|
3605 if (NILP (height))
|
|
3606 ih = 1;
|
|
3607 else
|
|
3608 {
|
|
3609 CHECK_INT (height);
|
|
3610 ih = XINT (height);
|
|
3611 if (ih < 1) ih = 1;
|
|
3612 }
|
|
3613
|
|
3614 {
|
|
3615 struct Lisp_Subwindow *sw = alloc_lcrecord (sizeof (struct Lisp_Subwindow),
|
|
3616 lrecord_subwindow);
|
|
3617 Lisp_Object val;
|
|
3618 sw->frame = frame;
|
|
3619 sw->xscreen = xs;
|
|
3620 sw->parent_window = pw;
|
|
3621 sw->height = ih;
|
|
3622 sw->width = iw;
|
|
3623
|
|
3624 xswa.backing_store = Always;
|
|
3625 valueMask |= CWBackingStore;
|
|
3626
|
|
3627 xswa.colormap = DefaultColormapOfScreen (xs);
|
|
3628 valueMask |= CWColormap;
|
|
3629
|
|
3630 sw->subwindow = XCreateWindow (dpy, pw, 0, 0, iw, ih, 0, CopyFromParent,
|
|
3631 InputOutput, CopyFromParent, valueMask,
|
|
3632 &xswa);
|
|
3633
|
|
3634 XSETSUBWINDOW (val, sw);
|
|
3635 return val;
|
|
3636 }
|
|
3637 }
|
|
3638
|
|
3639 /* #### Should this function exist? */
|
20
|
3640 DEFUN ("change-subwindow-property", Fchange_subwindow_property, 3, 3, 0, /*
|
0
|
3641 For the given SUBWINDOW, set PROPERTY to DATA, which is a string.
|
|
3642 Subwindows are not currently implemented.
|
20
|
3643 */
|
|
3644 (subwindow, property, data))
|
0
|
3645 {
|
|
3646 Atom property_atom;
|
|
3647 struct Lisp_Subwindow *sw;
|
|
3648 Display *dpy;
|
|
3649
|
|
3650 CHECK_SUBWINDOW (subwindow);
|
|
3651 CHECK_STRING (property);
|
|
3652 CHECK_STRING (data);
|
|
3653
|
|
3654 sw = XSUBWINDOW (subwindow);
|
|
3655 dpy = DisplayOfScreen (LISP_DEVICE_TO_X_SCREEN
|
|
3656 (FRAME_DEVICE (XFRAME (sw->frame))));
|
|
3657
|
16
|
3658 property_atom = XInternAtom (dpy, (char *) XSTRING_DATA (property), False);
|
0
|
3659 XChangeProperty (dpy, sw->subwindow, property_atom, XA_STRING, 8,
|
16
|
3660 PropModeReplace,
|
|
3661 XSTRING_DATA (data),
|
14
|
3662 XSTRING_LENGTH (data));
|
0
|
3663
|
|
3664 return (property);
|
|
3665 }
|
|
3666
|
20
|
3667 DEFUN ("subwindowp", Fsubwindowp, 1, 1, 0, /*
|
0
|
3668 Return non-nil if OBJECT is a subwindow.
|
|
3669 Subwindows are not currently implemented.
|
20
|
3670 */
|
|
3671 (object))
|
0
|
3672 {
|
|
3673 return (SUBWINDOWP (object) ? Qt : Qnil);
|
|
3674 }
|
|
3675
|
20
|
3676 DEFUN ("subwindow-width", Fsubwindow_width, 1, 1, 0, /*
|
0
|
3677 Width of SUBWINDOW.
|
|
3678 Subwindows are not currently implemented.
|
20
|
3679 */
|
|
3680 (subwindow))
|
0
|
3681 {
|
|
3682 CHECK_SUBWINDOW (subwindow);
|
|
3683 return (make_int (XSUBWINDOW (subwindow)->width));
|
|
3684 }
|
|
3685
|
20
|
3686 DEFUN ("subwindow-height", Fsubwindow_height, 1, 1, 0, /*
|
0
|
3687 Height of SUBWINDOW.
|
|
3688 Subwindows are not currently implemented.
|
20
|
3689 */
|
|
3690 (subwindow))
|
0
|
3691 {
|
|
3692 CHECK_SUBWINDOW (subwindow);
|
|
3693 return (make_int (XSUBWINDOW (subwindow)->height));
|
|
3694 }
|
|
3695
|
20
|
3696 DEFUN ("subwindow-xid", Fsubwindow_xid, 1, 1, 0, /*
|
0
|
3697 Return the xid of SUBWINDOW as a number.
|
|
3698 Subwindows are not currently implemented.
|
20
|
3699 */
|
|
3700 (subwindow))
|
0
|
3701 {
|
|
3702 CHECK_SUBWINDOW (subwindow);
|
|
3703 return (make_int (XSUBWINDOW (subwindow)->subwindow));
|
|
3704 }
|
|
3705
|
20
|
3706 DEFUN ("resize-subwindow", Fresize_subwindow, 1, 3, 0, /*
|
0
|
3707 Resize SUBWINDOW to WIDTH x HEIGHT.
|
|
3708 If a value is nil that parameter is not changed.
|
|
3709 Subwindows are not currently implemented.
|
20
|
3710 */
|
|
3711 (subwindow, width, height))
|
0
|
3712 {
|
|
3713 int neww, newh;
|
|
3714 struct Lisp_Subwindow *sw;
|
|
3715
|
|
3716 CHECK_SUBWINDOW (subwindow);
|
|
3717 sw = XSUBWINDOW (subwindow);
|
|
3718
|
|
3719 if (NILP (width))
|
|
3720 neww = sw->width;
|
|
3721 else
|
|
3722 neww = XINT (width);
|
|
3723
|
|
3724 if (NILP (height))
|
|
3725 newh = sw->height;
|
|
3726 else
|
|
3727 newh = XINT (height);
|
|
3728
|
|
3729 XResizeWindow (DisplayOfScreen (sw->xscreen), sw->subwindow, neww, newh);
|
|
3730
|
|
3731 sw->height = newh;
|
|
3732 sw->width = neww;
|
|
3733
|
|
3734 return subwindow;
|
|
3735 }
|
|
3736
|
20
|
3737 DEFUN ("force-subwindow-map", Fforce_subwindow_map, 1, 1, 0, /*
|
0
|
3738 Generate a Map event for SUBWINDOW.
|
|
3739 Subwindows are not currently implemented.
|
20
|
3740 */
|
|
3741 (subwindow))
|
0
|
3742 {
|
|
3743 CHECK_SUBWINDOW (subwindow);
|
|
3744
|
|
3745 XMapWindow (DisplayOfScreen (XSUBWINDOW (subwindow)->xscreen),
|
|
3746 XSUBWINDOW (subwindow)->subwindow);
|
|
3747
|
|
3748 return subwindow;
|
|
3749 }
|
36
|
3750 #endif
|
0
|
3751
|
|
3752 /************************************************************************/
|
|
3753 /* initialization */
|
|
3754 /************************************************************************/
|
|
3755
|
|
3756 void
|
|
3757 syms_of_glyphs_x (void)
|
|
3758 {
|
36
|
3759 #if HAVE_SUBWINDOWS
|
0
|
3760 defsymbol (&Qsubwindowp, "subwindowp");
|
|
3761
|
20
|
3762 DEFSUBR (Fmake_subwindow);
|
|
3763 DEFSUBR (Fchange_subwindow_property);
|
|
3764 DEFSUBR (Fsubwindowp);
|
|
3765 DEFSUBR (Fsubwindow_width);
|
|
3766 DEFSUBR (Fsubwindow_height);
|
|
3767 DEFSUBR (Fsubwindow_xid);
|
|
3768 DEFSUBR (Fresize_subwindow);
|
|
3769 DEFSUBR (Fforce_subwindow_map);
|
36
|
3770 #endif
|
0
|
3771
|
|
3772 defkeyword (&Q_mask_file, ":mask-file");
|
|
3773 defkeyword (&Q_mask_data, ":mask-data");
|
|
3774 defkeyword (&Q_hotspot_x, ":hotspot-x");
|
|
3775 defkeyword (&Q_hotspot_y, ":hotspot-y");
|
|
3776 defkeyword (&Q_foreground, ":foreground");
|
|
3777 defkeyword (&Q_background, ":background");
|
|
3778
|
|
3779 #ifdef HAVE_XPM
|
|
3780 defkeyword (&Q_color_symbols, ":color-symbols");
|
|
3781 #endif
|
|
3782 }
|
|
3783
|
|
3784 void
|
|
3785 console_type_create_glyphs_x (void)
|
|
3786 {
|
|
3787 /* image methods */
|
|
3788
|
|
3789 CONSOLE_HAS_METHOD (x, print_image_instance);
|
|
3790 CONSOLE_HAS_METHOD (x, finalize_image_instance);
|
|
3791 CONSOLE_HAS_METHOD (x, image_instance_equal);
|
|
3792 CONSOLE_HAS_METHOD (x, image_instance_hash);
|
|
3793 CONSOLE_HAS_METHOD (x, colorize_image_instance);
|
|
3794 }
|
|
3795
|
|
3796 void
|
|
3797 image_instantiator_format_create_glyphs_x (void)
|
|
3798 {
|
|
3799 /* image-instantiator types */
|
|
3800
|
|
3801 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xbm, "xbm");
|
|
3802
|
|
3803 IIFORMAT_HAS_METHOD (xbm, validate);
|
|
3804 IIFORMAT_HAS_METHOD (xbm, normalize);
|
|
3805 IIFORMAT_HAS_METHOD (xbm, possible_dest_types);
|
|
3806 IIFORMAT_HAS_METHOD (xbm, instantiate);
|
|
3807
|
|
3808 IIFORMAT_VALID_KEYWORD (xbm, Q_data, check_valid_xbm_inline);
|
|
3809 IIFORMAT_VALID_KEYWORD (xbm, Q_file, check_valid_string);
|
|
3810 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_data, check_valid_xbm_inline);
|
|
3811 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_file, check_valid_string);
|
|
3812 IIFORMAT_VALID_KEYWORD (xbm, Q_hotspot_x, check_valid_int);
|
|
3813 IIFORMAT_VALID_KEYWORD (xbm, Q_hotspot_y, check_valid_int);
|
|
3814 IIFORMAT_VALID_KEYWORD (xbm, Q_foreground, check_valid_string);
|
|
3815 IIFORMAT_VALID_KEYWORD (xbm, Q_background, check_valid_string);
|
|
3816
|
|
3817 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font");
|
|
3818
|
|
3819 IIFORMAT_HAS_METHOD (cursor_font, validate);
|
|
3820 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types);
|
|
3821 IIFORMAT_HAS_METHOD (cursor_font, instantiate);
|
|
3822
|
|
3823 IIFORMAT_VALID_KEYWORD (cursor_font, Q_data, check_valid_string);
|
|
3824 IIFORMAT_VALID_KEYWORD (cursor_font, Q_foreground, check_valid_string);
|
|
3825 IIFORMAT_VALID_KEYWORD (cursor_font, Q_background, check_valid_string);
|
|
3826
|
|
3827 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font");
|
|
3828
|
|
3829 IIFORMAT_HAS_METHOD (font, validate);
|
|
3830 IIFORMAT_HAS_METHOD (font, possible_dest_types);
|
|
3831 IIFORMAT_HAS_METHOD (font, instantiate);
|
|
3832
|
|
3833 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string);
|
|
3834 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string);
|
|
3835 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string);
|
|
3836
|
|
3837 #ifdef HAVE_JPEG
|
|
3838 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (jpeg, "jpeg");
|
|
3839
|
|
3840 IIFORMAT_HAS_METHOD (jpeg, validate);
|
|
3841 IIFORMAT_HAS_METHOD (jpeg, normalize);
|
|
3842 IIFORMAT_HAS_METHOD (jpeg, possible_dest_types);
|
|
3843 IIFORMAT_HAS_METHOD (jpeg, instantiate);
|
|
3844
|
|
3845 IIFORMAT_VALID_KEYWORD (jpeg, Q_data, check_valid_string);
|
|
3846 IIFORMAT_VALID_KEYWORD (jpeg, Q_file, check_valid_string);
|
|
3847 #endif
|
|
3848
|
|
3849 #ifdef HAVE_GIF
|
|
3850 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (gif, "gif");
|
|
3851
|
|
3852 IIFORMAT_HAS_METHOD (gif, validate);
|
|
3853 IIFORMAT_HAS_METHOD (gif, normalize);
|
|
3854 IIFORMAT_HAS_METHOD (gif, possible_dest_types);
|
|
3855 IIFORMAT_HAS_METHOD (gif, instantiate);
|
|
3856
|
|
3857 IIFORMAT_VALID_KEYWORD (gif, Q_data, check_valid_string);
|
|
3858 IIFORMAT_VALID_KEYWORD (gif, Q_file, check_valid_string);
|
|
3859 #endif
|
|
3860
|
|
3861 #ifdef HAVE_PNG
|
|
3862 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (png, "png");
|
|
3863
|
|
3864 IIFORMAT_HAS_METHOD (png, validate);
|
|
3865 IIFORMAT_HAS_METHOD (png, normalize);
|
|
3866 IIFORMAT_HAS_METHOD (png, possible_dest_types);
|
|
3867 IIFORMAT_HAS_METHOD (png, instantiate);
|
|
3868
|
|
3869 IIFORMAT_VALID_KEYWORD (png, Q_data, check_valid_string);
|
|
3870 IIFORMAT_VALID_KEYWORD (png, Q_file, check_valid_string);
|
|
3871 #endif
|
|
3872
|
|
3873 #ifdef HAVE_TIFF
|
|
3874 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (tiff, "tiff");
|
|
3875
|
|
3876 IIFORMAT_HAS_METHOD (tiff, validate);
|
|
3877 IIFORMAT_HAS_METHOD (tiff, normalize);
|
|
3878 IIFORMAT_HAS_METHOD (tiff, possible_dest_types);
|
|
3879 IIFORMAT_HAS_METHOD (tiff, instantiate);
|
|
3880
|
|
3881 IIFORMAT_VALID_KEYWORD (tiff, Q_data, check_valid_string);
|
|
3882 IIFORMAT_VALID_KEYWORD (tiff, Q_file, check_valid_string);
|
|
3883 #endif
|
|
3884
|
|
3885 #ifdef HAVE_XPM
|
|
3886 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xpm, "xpm");
|
|
3887
|
|
3888 IIFORMAT_HAS_METHOD (xpm, validate);
|
|
3889 IIFORMAT_HAS_METHOD (xpm, normalize);
|
|
3890 IIFORMAT_HAS_METHOD (xpm, possible_dest_types);
|
|
3891 IIFORMAT_HAS_METHOD (xpm, instantiate);
|
|
3892
|
|
3893 IIFORMAT_VALID_KEYWORD (xpm, Q_data, check_valid_string);
|
|
3894 IIFORMAT_VALID_KEYWORD (xpm, Q_file, check_valid_string);
|
|
3895 IIFORMAT_VALID_KEYWORD (xpm, Q_color_symbols, check_valid_xpm_color_symbols);
|
|
3896 #endif
|
|
3897
|
|
3898 #ifdef HAVE_XFACE
|
|
3899 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xface, "xface");
|
|
3900
|
|
3901 IIFORMAT_HAS_METHOD (xface, validate);
|
|
3902 IIFORMAT_HAS_METHOD (xface, normalize);
|
|
3903 IIFORMAT_HAS_METHOD (xface, possible_dest_types);
|
|
3904 IIFORMAT_HAS_METHOD (xface, instantiate);
|
|
3905
|
|
3906 IIFORMAT_VALID_KEYWORD (xface, Q_data, check_valid_string);
|
|
3907 IIFORMAT_VALID_KEYWORD (xface, Q_file, check_valid_string);
|
|
3908 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_x, check_valid_int);
|
|
3909 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_y, check_valid_int);
|
|
3910 IIFORMAT_VALID_KEYWORD (xface, Q_foreground, check_valid_string);
|
|
3911 IIFORMAT_VALID_KEYWORD (xface, Q_background, check_valid_string);
|
|
3912 #endif
|
|
3913
|
|
3914 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (autodetect, "autodetect");
|
|
3915
|
|
3916 IIFORMAT_HAS_METHOD (autodetect, validate);
|
|
3917 IIFORMAT_HAS_METHOD (autodetect, normalize);
|
|
3918 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types);
|
|
3919 IIFORMAT_HAS_METHOD (autodetect, instantiate);
|
|
3920
|
|
3921 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string);
|
|
3922 }
|
|
3923
|
|
3924 void
|
|
3925 vars_of_glyphs_x (void)
|
|
3926 {
|
|
3927 #ifdef HAVE_JPEG
|
|
3928 Fprovide (Qjpeg);
|
|
3929 #endif
|
|
3930
|
|
3931 #ifdef HAVE_GIF
|
|
3932 Fprovide (Qgif);
|
|
3933 #endif
|
|
3934
|
|
3935 #ifdef HAVE_PNG
|
|
3936 Fprovide (Qpng);
|
|
3937 #endif
|
|
3938
|
|
3939 #ifdef HAVE_TIFF
|
|
3940 Fprovide (Qtiff);
|
|
3941 #endif
|
|
3942
|
|
3943 #ifdef HAVE_XPM
|
|
3944 Fprovide (Qxpm);
|
|
3945
|
|
3946 DEFVAR_LISP ("xpm-color-symbols", &Vxpm_color_symbols /*
|
|
3947 Definitions of logical color-names used when reading XPM files.
|
|
3948 Elements of this list should be of the form (COLOR-NAME FORM-TO-EVALUATE).
|
|
3949 The COLOR-NAME should be a string, which is the name of the color to define;
|
|
3950 the FORM should evaluate to a `color' specifier object, or a string to be
|
|
3951 passed to `make-color-instance'. If a loaded XPM file references a symbolic
|
|
3952 color called COLOR-NAME, it will display as the computed color instead.
|
|
3953
|
|
3954 The default value of this variable defines the logical color names
|
|
3955 \"foreground\" and \"background\" to be the colors of the `default' face.
|
|
3956 */ );
|
|
3957 Vxpm_color_symbols = Qnil; /* initialized in x-faces.el */
|
|
3958 #endif
|
|
3959
|
|
3960 #ifdef HAVE_XFACE
|
|
3961 Fprovide (Qxface);
|
|
3962 #endif
|
|
3963
|
|
3964 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path /*
|
|
3965 A list of the directories in which X bitmap files may be found.
|
|
3966 If nil, this is initialized from the \"*bitmapFilePath\" resource.
|
|
3967 This is used by the `make-image-instance' function (however, note that if
|
|
3968 the environment variable XBMLANGPATH is set, it is consulted first).
|
|
3969 */ );
|
|
3970 Vx_bitmap_file_path = Qnil;
|
|
3971 }
|
|
3972
|
|
3973 void
|
|
3974 complex_vars_of_glyphs_x (void)
|
|
3975 {
|
|
3976 #define BUILD_GLYPH_INST(variable, name) \
|
|
3977 Fadd_spec_to_specifier \
|
|
3978 (GLYPH_IMAGE (XGLYPH (variable)), \
|
|
3979 vector3 (Qxbm, Q_data, \
|
|
3980 list3 (make_int (name##_width), \
|
|
3981 make_int (name##_height), \
|
|
3982 make_ext_string (name##_bits, \
|
|
3983 sizeof (name##_bits), \
|
|
3984 FORMAT_BINARY))), \
|
|
3985 Qglobal, Qx, Qnil)
|
|
3986
|
|
3987 BUILD_GLYPH_INST (Vtruncation_glyph, truncator);
|
|
3988 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer);
|
|
3989 BUILD_GLYPH_INST (Vxemacs_logo, xemacs);
|
8
|
3990 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll);
|
0
|
3991
|
|
3992 #undef BUILD_GLYPH_INST
|
|
3993 }
|