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