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