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