267
|
1 /* mswindows-specific Lisp objects.
|
|
2 Copyright (C) 1998 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
|
23 /* written by Andy Piper <andyp@parallax.co.uk> plagerising buts from
|
|
24 glyphs-x.c */
|
|
25
|
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28 #include "lstream.h"
|
|
29 #include "console-msw.h"
|
|
30 #include "glyphs-msw.h"
|
|
31 #include "objects-msw.h"
|
|
32
|
|
33 #include "buffer.h"
|
|
34 #include "frame.h"
|
|
35 #include "insdel.h"
|
|
36 #include "opaque.h"
|
|
37 #include "sysfile.h"
|
|
38 #include "faces.h"
|
|
39 #include "imgproc.h"
|
|
40
|
|
41 #ifdef HAVE_XPM
|
|
42 #include <X11/xpm.h>
|
|
43 #endif
|
|
44
|
|
45 #ifdef FILE_CODING
|
|
46 #include "file-coding.h"
|
|
47 #endif
|
|
48
|
|
49 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
|
|
50 Lisp_Object Qbmp;
|
|
51 Lisp_Object Vmswindows_bitmap_file_path;
|
|
52
|
|
53 static void
|
|
54 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
55 enum image_instance_type type);
|
|
56
|
269
|
57 COLORREF mswindows_string_to_color (CONST char *name);
|
267
|
58
|
|
59 /************************************************************************/
|
|
60 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/
|
|
61 /* proper display */
|
|
62 /************************************************************************/
|
269
|
63 BITMAPINFO* EImage2DIBitmap (Lisp_Object device, int width, int height,
|
267
|
64 unsigned char *pic,
|
|
65 int *bit_count,
|
|
66 unsigned char** bmp_data)
|
|
67 {
|
|
68 struct device *d = XDEVICE (device);
|
269
|
69 int i,j;
|
267
|
70 RGBQUAD* colortbl;
|
|
71 int ncolors;
|
|
72 BITMAPINFO* bmp_info;
|
269
|
73 unsigned char *ip, *dp;
|
267
|
74
|
269
|
75 if (DEVICE_MSWINDOWS_BITSPIXEL (d) > 0)
|
267
|
76 {
|
269
|
77 int bpline=(int)(~3UL & (unsigned long)((width*3) +3));
|
267
|
78 /* FIXME: we can do this because 24bpp implies no colour table, once
|
|
79 * we start paletizing this is no longer true. The X versions of
|
|
80 * this function quantises to 256 colours or bit masks down to a
|
|
81 * long. Windows can actually handle rgb triples in the raw so I
|
|
82 * don't see much point trying to optimise down to the best
|
|
83 * structure - unless it has memory / color allocation implications
|
|
84 * .... */
|
269
|
85 bmp_info=xnew_and_zero (BITMAPINFO);
|
267
|
86
|
|
87 if (!bmp_info)
|
|
88 {
|
|
89 return NULL;
|
|
90 }
|
|
91
|
|
92 bmp_info->bmiHeader.biBitCount=24; /* just RGB triples for now */
|
|
93 bmp_info->bmiHeader.biCompression=BI_RGB; /* just RGB triples for now */
|
|
94 bmp_info->bmiHeader.biSizeImage=width*height*3;
|
|
95
|
|
96 /* bitmap data needs to be in blue, green, red triples - in that
|
|
97 order, eimage is in RGB format so we need to convert */
|
|
98 *bmp_data = xnew_array_and_zero (unsigned char, width * height * 3);
|
|
99 *bit_count = width * height * 3;
|
|
100
|
|
101 if (!bmp_data)
|
|
102 {
|
|
103 xfree(bmp_info);
|
|
104 return NULL;
|
|
105 }
|
|
106 for (i=0; i<width*height; i++)
|
|
107 {
|
|
108 (*bmp_data)[2]=*pic;
|
|
109 (*bmp_data)[1]= pic[1];
|
|
110 **bmp_data = pic[2];
|
|
111 (*bmp_data) += 3;
|
|
112 }
|
|
113 }
|
|
114 else /* scale to 256 colors */
|
|
115 {
|
|
116 int rd,gr,bl, j;
|
|
117 unsigned char *ip, *dp;
|
|
118 quant_table *qtable;
|
|
119 int bpline= (int)(~3UL & (unsigned long)(width +3));
|
|
120 /* Quantize the image and get a histogram while we're at it.
|
|
121 Do this first to save memory */
|
269
|
122 qtable = build_EImage_quantable(pic, width, height, 256);
|
267
|
123 if (qtable == NULL) return NULL;
|
|
124
|
|
125 /* use our quantize table to allocate the colors */
|
|
126 ncolors = qtable->num_active_colors;
|
|
127 bmp_info=(BITMAPINFO*)xmalloc_and_zero(sizeof(BITMAPINFOHEADER) +
|
|
128 sizeof(RGBQUAD) * ncolors);
|
|
129 if (!bmp_info)
|
|
130 {
|
|
131 xfree(qtable);
|
|
132 return NULL;
|
|
133 }
|
|
134
|
|
135 colortbl=(RGBQUAD*)(((unsigned char*)bmp_info)+sizeof(BITMAPINFOHEADER));
|
|
136
|
|
137 bmp_info->bmiHeader.biBitCount=8;
|
|
138 bmp_info->bmiHeader.biCompression=BI_RGB;
|
|
139 bmp_info->bmiHeader.biSizeImage=bpline*height;
|
|
140 bmp_info->bmiHeader.biClrUsed=ncolors;
|
|
141 bmp_info->bmiHeader.biClrImportant=ncolors;
|
|
142
|
|
143 *bmp_data = (unsigned char *) xmalloc_and_zero (bpline * height);
|
|
144 *bit_count = bpline * height;
|
|
145
|
|
146 if (!*bmp_data)
|
|
147 {
|
269
|
148 xfree (qtable);
|
|
149 xfree (bmp_info);
|
267
|
150 return NULL;
|
|
151 }
|
|
152
|
|
153 /* build up an RGBQUAD colortable */
|
|
154 for (i = 0; i < qtable->num_active_colors; i++) {
|
|
155 colortbl[i].rgbRed = qtable->rm[i];
|
|
156 colortbl[i].rgbGreen = qtable->gm[i];
|
|
157 colortbl[i].rgbBlue = qtable->bm[i];
|
|
158 colortbl[i].rgbReserved = 0;
|
|
159 }
|
|
160
|
|
161 /* now build up the data. picture has to be upside-down and
|
|
162 back-to-front for msw bitmaps */
|
|
163 ip = pic;
|
|
164 for (i = height-1; i >= 0; i--) {
|
|
165 dp = (*bmp_data) + (i * bpline);
|
|
166 for (j = 0; j < width; j++) {
|
|
167 rd = *ip++;
|
|
168 gr = *ip++;
|
|
169 bl = *ip++;
|
269
|
170 *dp++ = QUANT_GET_COLOR (qtable,rd,gr,bl);
|
267
|
171 }
|
|
172 }
|
269
|
173 xfree (qtable);
|
267
|
174 }
|
|
175 /* fix up the standard stuff */
|
|
176 bmp_info->bmiHeader.biWidth=width;
|
|
177 bmp_info->bmiHeader.biHeight=height;
|
|
178 bmp_info->bmiHeader.biPlanes=1;
|
|
179 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
269
|
180 bmp_info->bmiHeader.biXPelsPerMeter=0; /* unless you know better */
|
|
181 bmp_info->bmiHeader.biYPelsPerMeter=0;
|
267
|
182
|
|
183 return bmp_info;
|
|
184 }
|
|
185
|
|
186 /* Given a pixmap filename, look through all of the "standard" places
|
|
187 where the file might be located. Return a full pathname if found;
|
|
188 otherwise, return Qnil. */
|
|
189
|
|
190 static Lisp_Object
|
|
191 locate_pixmap_file (Lisp_Object name)
|
|
192 {
|
|
193 /* This function can GC if IN_REDISPLAY is false */
|
|
194
|
|
195 /* Check non-absolute pathnames with a directory component relative to
|
|
196 the search path; that's the way Xt does it. */
|
269
|
197 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) ||
|
267
|
198 (XSTRING_BYTE (name, 0) == '.' &&
|
269
|
199 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 1)) ||
|
267
|
200 (XSTRING_BYTE (name, 1) == '.' &&
|
269
|
201 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 2)))))))
|
267
|
202 {
|
|
203 if (!NILP (Ffile_readable_p (name)))
|
|
204 return name;
|
|
205 else
|
|
206 return Qnil;
|
|
207 }
|
|
208
|
269
|
209 if (!NILP (Vmswindows_bitmap_file_path))
|
267
|
210 {
|
|
211 Lisp_Object found;
|
|
212 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0)
|
|
213 {
|
|
214 Lisp_Object temp = list1 (Vdata_directory);
|
|
215 struct gcpro gcpro1;
|
|
216
|
|
217 GCPRO1 (temp);
|
|
218 locate_file (temp, name, "", &found, R_OK);
|
|
219 UNGCPRO;
|
|
220 }
|
|
221
|
|
222 return found;
|
|
223 }
|
|
224 else
|
|
225 return Qnil;
|
|
226 }
|
|
227
|
|
228 /* If INSTANTIATOR refers to inline data, return Qnil.
|
|
229 If INSTANTIATOR refers to data in a file, return the full filename
|
|
230 if it exists; otherwise, return a cons of (filename).
|
|
231
|
|
232 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the
|
|
233 keywords used to look up the file and inline data,
|
|
234 respectively, in the instantiator. Normally these would
|
|
235 be Q_file and Q_data, but might be different for mask data. */
|
|
236
|
|
237 static Lisp_Object
|
|
238 potential_pixmap_file_instantiator (Lisp_Object instantiator,
|
|
239 Lisp_Object file_keyword,
|
|
240 Lisp_Object data_keyword)
|
|
241 {
|
|
242 Lisp_Object file;
|
|
243 Lisp_Object data;
|
|
244
|
|
245 assert (VECTORP (instantiator));
|
|
246
|
|
247 data = find_keyword_in_vector (instantiator, data_keyword);
|
|
248 file = find_keyword_in_vector (instantiator, file_keyword);
|
|
249
|
|
250 if (!NILP (file) && NILP (data))
|
|
251 {
|
269
|
252 Lisp_Object retval = locate_pixmap_file(file);
|
267
|
253 if (!NILP (retval))
|
|
254 return retval;
|
|
255 else
|
|
256 return Fcons (file, Qnil); /* should have been file */
|
|
257 }
|
|
258
|
|
259 return Qnil;
|
|
260 }
|
|
261
|
|
262 static Lisp_Object
|
|
263 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type,
|
|
264 Lisp_Object image_type_tag)
|
|
265 {
|
|
266 /* This function can call lisp */
|
|
267 Lisp_Object file = Qnil;
|
|
268 struct gcpro gcpro1, gcpro2;
|
|
269 Lisp_Object alist = Qnil;
|
|
270
|
|
271 GCPRO2 (file, alist);
|
|
272
|
|
273 /* Now, convert any file data into inline data. At the end of this,
|
|
274 `data' will contain the inline data (if any) or Qnil, and `file'
|
|
275 will contain the name this data was derived from (if known) or
|
|
276 Qnil.
|
|
277
|
|
278 Note that if we cannot generate any regular inline data, we
|
|
279 skip out. */
|
|
280
|
|
281 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
282
|
|
283 if (CONSP (file)) /* failure locating filename */
|
|
284 signal_double_file_error ("Opening pixmap file",
|
|
285 "no such file or directory",
|
|
286 Fcar (file));
|
|
287
|
|
288 if (NILP (file)) /* no conversion necessary */
|
|
289 RETURN_UNGCPRO (inst);
|
|
290
|
|
291 alist = tagged_vector_to_alist (inst);
|
|
292
|
|
293 {
|
|
294 Lisp_Object data = make_string_from_file (file);
|
|
295 alist = remassq_no_quit (Q_file, alist);
|
|
296 /* there can't be a :data at this point. */
|
|
297 alist = Fcons (Fcons (Q_file, file),
|
|
298 Fcons (Fcons (Q_data, data), alist));
|
|
299 }
|
|
300
|
|
301 {
|
|
302 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist);
|
|
303 free_alist (alist);
|
|
304 RETURN_UNGCPRO (result);
|
|
305 }
|
|
306 }
|
|
307
|
|
308
|
|
309 /* Initialize an image instance from a bitmap
|
|
310
|
|
311 DEST_MASK specifies the mask of allowed image types.
|
|
312
|
|
313 If this fails, signal an error. INSTANTIATOR is only used
|
|
314 in the error message. */
|
|
315
|
|
316 static void
|
|
317 init_image_instance_from_dibitmap (struct Lisp_Image_Instance *ii,
|
|
318 BITMAPINFO *bmp_info,
|
|
319 int dest_mask,
|
|
320 void *bmp_data,
|
|
321 int bmp_bits,
|
|
322 Lisp_Object instantiator)
|
|
323 {
|
|
324 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
325 struct device *d = XDEVICE (device);
|
269
|
326 struct frame *f = XFRAME (DEVICE_SELECTED_FRAME (d));
|
267
|
327 void* bmp_buf=0;
|
|
328 HBITMAP bitmap;
|
269
|
329 HDC hdc;
|
267
|
330
|
|
331 if (!DEVICE_MSWINDOWS_P (d))
|
|
332 signal_simple_error ("Not an mswindows device", device);
|
|
333
|
|
334 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
335 signal_simple_error ("No selected frame on mswindows device", device);
|
|
336
|
|
337 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
338 incompatible_image_types (instantiator, dest_mask,
|
|
339 IMAGE_COLOR_PIXMAP_MASK);
|
|
340 hdc = FRAME_MSWINDOWS_DC (f);
|
|
341
|
269
|
342 bitmap=CreateDIBSection (hdc,
|
267
|
343 bmp_info,
|
|
344 DIB_RGB_COLORS,
|
|
345 &bmp_buf,
|
|
346 0,0);
|
|
347
|
|
348 if (!bitmap || !bmp_buf)
|
|
349 signal_simple_error ("Unable to create bitmap", instantiator);
|
|
350
|
|
351 /* copy in the actual bitmap */
|
269
|
352 memcpy (bmp_buf, bmp_data, bmp_bits);
|
267
|
353
|
|
354 mswindows_initialize_dibitmap_image_instance (ii, IMAGE_COLOR_PIXMAP);
|
|
355
|
|
356 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
357 find_keyword_in_vector (instantiator, Q_file);
|
|
358
|
|
359 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap;
|
|
360 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth;
|
|
361 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight;
|
|
362 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount;
|
|
363 }
|
|
364
|
|
365 /**********************************************************************
|
|
366 * XPM *
|
|
367 **********************************************************************/
|
|
368
|
|
369 #ifdef HAVE_XPM
|
269
|
370 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer,
|
267
|
371 unsigned char** data,
|
|
372 int* width, int* height,
|
|
373 COLORREF bg)
|
|
374 {
|
|
375 XpmImage xpmimage;
|
|
376 XpmInfo xpminfo;
|
|
377 int result, i;
|
|
378 unsigned char* dptr;
|
|
379 unsigned int* sptr;
|
|
380 COLORREF color; /* the american spelling virus hits again .. */
|
|
381 COLORREF* colortbl;
|
|
382
|
|
383 memset (&xpmimage, 0, sizeof (xpmimage));
|
|
384 memset (&xpminfo, 0, sizeof (xpmimage));
|
|
385
|
269
|
386 result = XpmCreateXpmImageFromBuffer ((char*)buffer,
|
267
|
387 &xpmimage,
|
|
388 &xpminfo);
|
269
|
389 switch (result)
|
267
|
390 {
|
|
391 case XpmSuccess:
|
|
392 break;
|
|
393 case XpmFileInvalid:
|
|
394 {
|
|
395 signal_simple_error ("invalid XPM data", image);
|
|
396 }
|
|
397 case XpmNoMemory:
|
|
398 {
|
|
399 signal_double_file_error ("Parsing pixmap data",
|
|
400 "out of memory", image);
|
|
401 }
|
|
402 default:
|
|
403 {
|
|
404 signal_double_file_error_2 ("Parsing pixmap data",
|
|
405 "unknown error code",
|
|
406 make_int (result), image);
|
|
407 }
|
|
408 }
|
|
409
|
|
410 *width = xpmimage.width;
|
|
411 *height = xpmimage.height;
|
|
412
|
|
413 *data = xnew_array_and_zero (unsigned char, *width * *height * 3);
|
|
414 if (!*data)
|
|
415 {
|
269
|
416 XpmFreeXpmImage (&xpmimage);
|
|
417 XpmFreeXpmInfo (&xpminfo);
|
267
|
418 return 0;
|
|
419 }
|
|
420
|
|
421 /* build a color table to speed things up */
|
|
422 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors);
|
|
423 if (!colortbl)
|
|
424 {
|
269
|
425 xfree (*data);
|
|
426 XpmFreeXpmImage (&xpmimage);
|
|
427 XpmFreeXpmInfo (&xpminfo);
|
267
|
428 return 0;
|
|
429 }
|
|
430
|
|
431 for (i=0; i<xpmimage.ncolors; i++)
|
|
432 {
|
|
433 /* pick up transparencies */
|
269
|
434 if (!strcmp (xpmimage.colorTable[i].c_color,"None"))
|
267
|
435 {
|
|
436 colortbl[i]=bg;
|
|
437 }
|
|
438 else
|
|
439 {
|
|
440 colortbl[i]=
|
269
|
441 mswindows_string_to_color (xpmimage.colorTable[i].c_color);
|
267
|
442 }
|
|
443 }
|
|
444
|
|
445 /* convert the image */
|
|
446 sptr=xpmimage.data;
|
|
447 dptr=*data;
|
|
448 for (i = 0; i< *width * *height; i++)
|
|
449 {
|
|
450 color = colortbl[*sptr++];
|
|
451
|
|
452 /* split out the 0x02bbggrr colorref into an rgb triple */
|
269
|
453 *dptr++=GetRValue (color); /* red */
|
|
454 *dptr++=GetGValue (color); /* green */
|
|
455 *dptr++=GetBValue (color); /* blue */
|
267
|
456 }
|
|
457
|
269
|
458 XpmFreeXpmImage (&xpmimage);
|
|
459 XpmFreeXpmInfo (&xpminfo);
|
|
460 xfree (colortbl);
|
267
|
461 return TRUE;
|
|
462 }
|
|
463
|
|
464 void
|
|
465 mswindows_xpm_instantiate (Lisp_Object image_instance,
|
|
466 Lisp_Object instantiator,
|
|
467 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
468 int dest_mask, Lisp_Object domain)
|
|
469 {
|
|
470 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
471 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
472 CONST Extbyte *bytes;
|
|
473 Extcount len;
|
|
474 unsigned char *eimage;
|
|
475 int width, height;
|
|
476 BITMAPINFO* bmp_info;
|
|
477 unsigned char* bmp_data;
|
|
478 int bmp_bits;
|
|
479 COLORREF bkcolor;
|
|
480
|
|
481 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
482
|
|
483 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
484 signal_simple_error ("Not an mswindows device", device);
|
|
485
|
|
486 assert (!NILP (data));
|
|
487
|
|
488 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
489
|
|
490 /* this is a hack but MaskBlt and TransparentBlt are not supported
|
|
491 on most windows variants */
|
|
492 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
|
269
|
493 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
|
267
|
494
|
|
495 /* convert to an eimage to make processing easier */
|
269
|
496 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height,
|
267
|
497 bkcolor))
|
|
498 {
|
|
499 signal_simple_error ("XPM to EImage conversion failed",
|
|
500 image_instance);
|
|
501 }
|
|
502
|
|
503 /* build a bitmap from the eimage */
|
269
|
504 if (!(bmp_info=EImage2DIBitmap (device, width, height, eimage,
|
267
|
505 &bmp_bits, &bmp_data)))
|
|
506 {
|
269
|
507 xfree (eimage);
|
267
|
508 signal_simple_error ("XPM to EImage conversion failed",
|
|
509 image_instance);
|
|
510 }
|
269
|
511 xfree (eimage);
|
267
|
512
|
|
513 /* Now create the pixmap and set up the image instance */
|
|
514 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
|
515 bmp_data, bmp_bits, instantiator);
|
|
516
|
269
|
517 xfree (bmp_info);
|
|
518 xfree (bmp_data);
|
267
|
519 }
|
|
520 #endif /* HAVE_XPM */
|
|
521
|
|
522 /**********************************************************************
|
|
523 * BMP *
|
|
524 **********************************************************************/
|
|
525
|
|
526 static void
|
|
527 bmp_validate (Lisp_Object instantiator)
|
|
528 {
|
|
529 file_or_data_must_be_present (instantiator);
|
|
530 }
|
|
531
|
|
532 static Lisp_Object
|
|
533 bmp_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
534 {
|
|
535 return simple_image_type_normalize (inst, console_type, Qbmp);
|
|
536 }
|
|
537
|
|
538 static int
|
|
539 bmp_possible_dest_types (void)
|
|
540 {
|
|
541 return IMAGE_COLOR_PIXMAP_MASK;
|
|
542 }
|
|
543
|
|
544 static void
|
|
545 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
546 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
547 int dest_mask, Lisp_Object domain)
|
|
548 {
|
|
549 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
550 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
551 CONST Extbyte *bytes;
|
|
552 Extcount len;
|
|
553 BITMAPFILEHEADER* bmp_file_header;
|
|
554 BITMAPINFO* bmp_info;
|
|
555 void* bmp_data;
|
|
556 int bmp_bits;
|
|
557 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
558
|
|
559 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
560 signal_simple_error ("Not an mswindows device", device);
|
|
561
|
|
562 assert (!NILP (data));
|
|
563
|
|
564 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
565
|
|
566 /* Then slurp the image into memory, decoding along the way.
|
|
567 The result is the image in a simple one-byte-per-pixel
|
|
568 format. */
|
|
569
|
|
570 bmp_file_header=(BITMAPFILEHEADER*)bytes;
|
|
571 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER));
|
|
572 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits;
|
|
573 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits;
|
|
574
|
|
575 /* Now create the pixmap and set up the image instance */
|
|
576 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
|
577 bmp_data, bmp_bits, instantiator);
|
|
578 }
|
|
579
|
|
580
|
|
581 /************************************************************************/
|
|
582 /* image instance methods */
|
|
583 /************************************************************************/
|
|
584
|
|
585 static void
|
|
586 mswindows_print_image_instance (struct Lisp_Image_Instance *p,
|
|
587 Lisp_Object printcharfun,
|
|
588 int escapeflag)
|
|
589 {
|
|
590 char buf[100];
|
|
591
|
|
592 switch (IMAGE_INSTANCE_TYPE (p))
|
|
593 {
|
|
594 case IMAGE_MONO_PIXMAP:
|
|
595 case IMAGE_COLOR_PIXMAP:
|
|
596 case IMAGE_POINTER:
|
|
597 sprintf (buf, " (0x%lx",
|
|
598 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
|
599 write_c_string (buf, printcharfun);
|
|
600 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
601 {
|
|
602 sprintf (buf, "/0x%lx",
|
|
603 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
604 write_c_string (buf, printcharfun);
|
|
605 }
|
|
606 write_c_string (")", printcharfun);
|
|
607 break;
|
|
608 default:
|
|
609 break;
|
|
610 }
|
|
611 }
|
|
612
|
|
613 static void
|
|
614 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
615 {
|
|
616 if (!p->data)
|
|
617 return;
|
|
618
|
|
619 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
620 {
|
|
621 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p))
|
269
|
622 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
267
|
623 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0;
|
|
624 }
|
|
625
|
|
626 xfree (p->data);
|
|
627 p->data = 0;
|
|
628 }
|
|
629
|
|
630 static int
|
|
631 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
632 struct Lisp_Image_Instance *p2, int depth)
|
|
633 {
|
|
634 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
635 {
|
|
636 case IMAGE_MONO_PIXMAP:
|
|
637 case IMAGE_COLOR_PIXMAP:
|
|
638 case IMAGE_POINTER:
|
|
639 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
|
|
640 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
|
|
641 return 0;
|
|
642 break;
|
|
643 default:
|
|
644 break;
|
|
645 }
|
|
646
|
|
647 return 1;
|
|
648 }
|
|
649
|
|
650 static unsigned long
|
|
651 mswindows_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
652 {
|
|
653 switch (IMAGE_INSTANCE_TYPE (p))
|
|
654 {
|
|
655 case IMAGE_MONO_PIXMAP:
|
|
656 case IMAGE_COLOR_PIXMAP:
|
|
657 case IMAGE_POINTER:
|
|
658 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
|
|
659 default:
|
|
660 return 0;
|
|
661 }
|
|
662 }
|
|
663
|
|
664 /* Set all the slots in an image instance structure to reasonable
|
|
665 default values. This is used somewhere within an instantiate
|
|
666 method. It is assumed that the device slot within the image
|
|
667 instance is already set -- this is the case when instantiate
|
|
668 methods are called. */
|
|
669
|
|
670 static void
|
|
671 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
672 enum image_instance_type type)
|
|
673 {
|
|
674 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
|
|
675 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
676 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
677 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
678 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
679 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
680 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
681 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
682 }
|
|
683
|
|
684
|
|
685 /************************************************************************/
|
|
686 /* initialization */
|
|
687 /************************************************************************/
|
|
688
|
|
689 void
|
|
690 syms_of_glyphs_mswindows (void)
|
|
691 {
|
|
692 }
|
|
693
|
|
694 void
|
|
695 console_type_create_glyphs_mswindows (void)
|
|
696 {
|
|
697 /* image methods */
|
|
698
|
|
699 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
|
|
700 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
|
|
701 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
|
|
702 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
|
|
703 }
|
|
704
|
|
705 void
|
|
706 image_instantiator_format_create_glyphs_mswindows (void)
|
|
707 {
|
|
708 /* image-instantiator types */
|
|
709
|
|
710 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
|
|
711
|
|
712 IIFORMAT_HAS_METHOD (bmp, validate);
|
|
713 IIFORMAT_HAS_METHOD (bmp, normalize);
|
|
714 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
|
|
715 IIFORMAT_HAS_METHOD (bmp, instantiate);
|
|
716
|
|
717 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
|
|
718 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
|
|
719 }
|
|
720
|
|
721 void
|
|
722 vars_of_glyphs_mswindows (void)
|
|
723 {
|
|
724 Fprovide (Qbmp);
|
|
725 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
|
|
726 A list of the directories in which mswindows bitmap files may be found.
|
|
727 This is used by the `make-image-instance' function.
|
|
728 */ );
|
|
729 Vmswindows_bitmap_file_path = Qnil;
|
|
730 }
|
|
731
|
|
732 void
|
|
733 complex_vars_of_glyphs_mswindows (void)
|
|
734 {
|
|
735 }
|
|
736
|