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