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