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