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