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