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