267
|
1 /* mswindows-specific Lisp objects.
|
280
|
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 Copyright (C) 1998 Andy Piper.
|
267
|
8
|
|
9 This file is part of XEmacs.
|
|
10
|
|
11 XEmacs is free software; you can redistribute it and/or modify it
|
|
12 under the terms of the GNU General Public License as published by the
|
|
13 Free Software Foundation; either version 2, or (at your option) any
|
|
14 later version.
|
|
15
|
|
16 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
19 for more details.
|
|
20
|
|
21 You should have received a copy of the GNU General Public License
|
|
22 along with XEmacs; see the file COPYING. If not, write to
|
|
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
24 Boston, MA 02111-1307, USA. */
|
|
25
|
|
26 /* Synched up with: Not in FSF. */
|
|
27
|
|
28 /* written by Andy Piper <andyp@parallax.co.uk> plagerising buts from
|
|
29 glyphs-x.c */
|
|
30
|
|
31 #include <config.h>
|
|
32 #include "lisp.h"
|
|
33 #include "lstream.h"
|
|
34 #include "console-msw.h"
|
|
35 #include "glyphs-msw.h"
|
|
36 #include "objects-msw.h"
|
|
37
|
|
38 #include "buffer.h"
|
|
39 #include "frame.h"
|
|
40 #include "insdel.h"
|
|
41 #include "opaque.h"
|
|
42 #include "sysfile.h"
|
|
43 #include "faces.h"
|
|
44 #include "imgproc.h"
|
|
45
|
|
46 #ifdef FILE_CODING
|
|
47 #include "file-coding.h"
|
|
48 #endif
|
|
49
|
|
50 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
|
|
51 Lisp_Object Qbmp;
|
|
52 Lisp_Object Vmswindows_bitmap_file_path;
|
|
53
|
|
54 static void
|
|
55 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
56 enum image_instance_type type);
|
|
57
|
269
|
58 COLORREF mswindows_string_to_color (CONST char *name);
|
267
|
59
|
|
60 /************************************************************************/
|
|
61 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/
|
|
62 /* proper display */
|
|
63 /************************************************************************/
|
278
|
64 static BITMAPINFO* convert_EImage_to_DIBitmap (Lisp_Object device,
|
|
65 int width, int height,
|
|
66 unsigned char *pic,
|
|
67 int *bit_count,
|
|
68 unsigned char** bmp_data)
|
267
|
69 {
|
|
70 struct device *d = XDEVICE (device);
|
269
|
71 int i,j;
|
267
|
72 RGBQUAD* colortbl;
|
|
73 int ncolors;
|
|
74 BITMAPINFO* bmp_info;
|
269
|
75 unsigned char *ip, *dp;
|
267
|
76
|
269
|
77 if (DEVICE_MSWINDOWS_BITSPIXEL (d) > 0)
|
267
|
78 {
|
269
|
79 int bpline=(int)(~3UL & (unsigned long)((width*3) +3));
|
267
|
80 /* FIXME: we can do this because 24bpp implies no colour table, once
|
|
81 * we start paletizing this is no longer true. The X versions of
|
|
82 * this function quantises to 256 colours or bit masks down to a
|
|
83 * long. Windows can actually handle rgb triples in the raw so I
|
272
|
84 * don't see much point trying to optimize down to the best
|
267
|
85 * structure - unless it has memory / color allocation implications
|
|
86 * .... */
|
269
|
87 bmp_info=xnew_and_zero (BITMAPINFO);
|
267
|
88
|
|
89 if (!bmp_info)
|
|
90 {
|
|
91 return NULL;
|
|
92 }
|
|
93
|
|
94 bmp_info->bmiHeader.biBitCount=24; /* just RGB triples for now */
|
|
95 bmp_info->bmiHeader.biCompression=BI_RGB; /* just RGB triples for now */
|
|
96 bmp_info->bmiHeader.biSizeImage=width*height*3;
|
|
97
|
|
98 /* bitmap data needs to be in blue, green, red triples - in that
|
|
99 order, eimage is in RGB format so we need to convert */
|
272
|
100 *bmp_data = xnew_array_and_zero (unsigned char, bpline * height);
|
278
|
101 *bit_count = bpline * height;
|
267
|
102
|
|
103 if (!bmp_data)
|
|
104 {
|
272
|
105 xfree (bmp_info);
|
267
|
106 return NULL;
|
|
107 }
|
272
|
108
|
|
109 ip = pic;
|
|
110 for (i = height-1; i >= 0; i--) {
|
|
111 dp = (*bmp_data) + (i * bpline);
|
|
112 for (j = 0; j < width; j++) {
|
|
113 dp[2] =*ip++;
|
|
114 dp[1] =*ip++;
|
|
115 *dp =*ip++;
|
|
116 dp += 3;
|
267
|
117 }
|
272
|
118 }
|
267
|
119 }
|
|
120 else /* scale to 256 colors */
|
|
121 {
|
272
|
122 int rd,gr,bl;
|
267
|
123 quant_table *qtable;
|
|
124 int bpline= (int)(~3UL & (unsigned long)(width +3));
|
|
125 /* Quantize the image and get a histogram while we're at it.
|
|
126 Do this first to save memory */
|
269
|
127 qtable = build_EImage_quantable(pic, width, height, 256);
|
267
|
128 if (qtable == NULL) return NULL;
|
|
129
|
|
130 /* use our quantize table to allocate the colors */
|
|
131 ncolors = qtable->num_active_colors;
|
272
|
132 bmp_info=(BITMAPINFO*)xmalloc_and_zero (sizeof(BITMAPINFOHEADER) +
|
267
|
133 sizeof(RGBQUAD) * ncolors);
|
|
134 if (!bmp_info)
|
|
135 {
|
272
|
136 xfree (qtable);
|
267
|
137 return NULL;
|
|
138 }
|
|
139
|
|
140 colortbl=(RGBQUAD*)(((unsigned char*)bmp_info)+sizeof(BITMAPINFOHEADER));
|
|
141
|
|
142 bmp_info->bmiHeader.biBitCount=8;
|
|
143 bmp_info->bmiHeader.biCompression=BI_RGB;
|
|
144 bmp_info->bmiHeader.biSizeImage=bpline*height;
|
|
145 bmp_info->bmiHeader.biClrUsed=ncolors;
|
|
146 bmp_info->bmiHeader.biClrImportant=ncolors;
|
|
147
|
|
148 *bmp_data = (unsigned char *) xmalloc_and_zero (bpline * height);
|
|
149 *bit_count = bpline * height;
|
|
150
|
|
151 if (!*bmp_data)
|
|
152 {
|
269
|
153 xfree (qtable);
|
|
154 xfree (bmp_info);
|
267
|
155 return NULL;
|
|
156 }
|
|
157
|
|
158 /* build up an RGBQUAD colortable */
|
|
159 for (i = 0; i < qtable->num_active_colors; i++) {
|
|
160 colortbl[i].rgbRed = qtable->rm[i];
|
|
161 colortbl[i].rgbGreen = qtable->gm[i];
|
|
162 colortbl[i].rgbBlue = qtable->bm[i];
|
|
163 colortbl[i].rgbReserved = 0;
|
|
164 }
|
|
165
|
|
166 /* now build up the data. picture has to be upside-down and
|
|
167 back-to-front for msw bitmaps */
|
|
168 ip = pic;
|
|
169 for (i = height-1; i >= 0; i--) {
|
|
170 dp = (*bmp_data) + (i * bpline);
|
|
171 for (j = 0; j < width; j++) {
|
|
172 rd = *ip++;
|
|
173 gr = *ip++;
|
|
174 bl = *ip++;
|
269
|
175 *dp++ = QUANT_GET_COLOR (qtable,rd,gr,bl);
|
267
|
176 }
|
|
177 }
|
269
|
178 xfree (qtable);
|
267
|
179 }
|
|
180 /* fix up the standard stuff */
|
|
181 bmp_info->bmiHeader.biWidth=width;
|
|
182 bmp_info->bmiHeader.biHeight=height;
|
|
183 bmp_info->bmiHeader.biPlanes=1;
|
|
184 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
269
|
185 bmp_info->bmiHeader.biXPelsPerMeter=0; /* unless you know better */
|
|
186 bmp_info->bmiHeader.biYPelsPerMeter=0;
|
267
|
187
|
|
188 return bmp_info;
|
|
189 }
|
|
190
|
|
191 /* Given a pixmap filename, look through all of the "standard" places
|
|
192 where the file might be located. Return a full pathname if found;
|
|
193 otherwise, return Qnil. */
|
|
194
|
280
|
195 static Lisp_Object
|
278
|
196 mswindows_locate_pixmap_file (Lisp_Object name)
|
267
|
197 {
|
|
198 /* This function can GC if IN_REDISPLAY is false */
|
276
|
199 Lisp_Object found;
|
267
|
200
|
|
201 /* Check non-absolute pathnames with a directory component relative to
|
|
202 the search path; that's the way Xt does it. */
|
269
|
203 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) ||
|
267
|
204 (XSTRING_BYTE (name, 0) == '.' &&
|
269
|
205 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 1)) ||
|
267
|
206 (XSTRING_BYTE (name, 1) == '.' &&
|
269
|
207 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 2)))))))
|
267
|
208 {
|
|
209 if (!NILP (Ffile_readable_p (name)))
|
|
210 return name;
|
|
211 else
|
|
212 return Qnil;
|
|
213 }
|
|
214
|
276
|
215 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0)
|
|
216 {
|
|
217 Lisp_Object temp = list1 (Vdata_directory);
|
|
218 struct gcpro gcpro1;
|
267
|
219
|
276
|
220 GCPRO1 (temp);
|
|
221 locate_file (temp, name, "", &found, R_OK);
|
|
222 UNGCPRO;
|
|
223 }
|
267
|
224
|
276
|
225 return found;
|
267
|
226 }
|
|
227
|
|
228
|
|
229 /* Initialize an image instance from a bitmap
|
|
230
|
|
231 DEST_MASK specifies the mask of allowed image types.
|
|
232
|
|
233 If this fails, signal an error. INSTANTIATOR is only used
|
|
234 in the error message. */
|
|
235
|
|
236 static void
|
|
237 init_image_instance_from_dibitmap (struct Lisp_Image_Instance *ii,
|
|
238 BITMAPINFO *bmp_info,
|
|
239 int dest_mask,
|
|
240 void *bmp_data,
|
|
241 int bmp_bits,
|
|
242 Lisp_Object instantiator)
|
|
243 {
|
|
244 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
245 struct device *d = XDEVICE (device);
|
269
|
246 struct frame *f = XFRAME (DEVICE_SELECTED_FRAME (d));
|
267
|
247 void* bmp_buf=0;
|
|
248 HBITMAP bitmap;
|
269
|
249 HDC hdc;
|
267
|
250
|
|
251 if (!DEVICE_MSWINDOWS_P (d))
|
|
252 signal_simple_error ("Not an mswindows device", device);
|
|
253
|
|
254 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
255 signal_simple_error ("No selected frame on mswindows device", device);
|
|
256
|
|
257 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
258 incompatible_image_types (instantiator, dest_mask,
|
|
259 IMAGE_COLOR_PIXMAP_MASK);
|
|
260 hdc = FRAME_MSWINDOWS_DC (f);
|
|
261
|
269
|
262 bitmap=CreateDIBSection (hdc,
|
267
|
263 bmp_info,
|
|
264 DIB_RGB_COLORS,
|
|
265 &bmp_buf,
|
|
266 0,0);
|
|
267
|
|
268 if (!bitmap || !bmp_buf)
|
|
269 signal_simple_error ("Unable to create bitmap", instantiator);
|
|
270
|
|
271 /* copy in the actual bitmap */
|
269
|
272 memcpy (bmp_buf, bmp_data, bmp_bits);
|
267
|
273
|
|
274 mswindows_initialize_dibitmap_image_instance (ii, IMAGE_COLOR_PIXMAP);
|
|
275
|
|
276 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
277 find_keyword_in_vector (instantiator, Q_file);
|
|
278
|
|
279 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap;
|
272
|
280 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = bitmap;
|
267
|
281 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth;
|
|
282 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight;
|
|
283 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount;
|
|
284 }
|
|
285
|
278
|
286 static void
|
|
287 mswindows_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii,
|
|
288 int width, int height,
|
|
289 unsigned char *eimage,
|
|
290 int dest_mask,
|
|
291 Lisp_Object instantiator,
|
|
292 Lisp_Object domain)
|
|
293 {
|
|
294 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
295 BITMAPINFO* bmp_info;
|
|
296 unsigned char* bmp_data;
|
|
297 int bmp_bits;
|
|
298 COLORREF bkcolor;
|
|
299
|
|
300 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
301 signal_simple_error ("Not an mswindows device", device);
|
|
302
|
|
303 /* this is a hack but MaskBlt and TransparentBlt are not supported
|
|
304 on most windows variants */
|
|
305 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
306 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
|
|
307
|
|
308 /* build a bitmap from the eimage */
|
|
309 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
|
|
310 &bmp_bits, &bmp_data)))
|
|
311 {
|
|
312 signal_simple_error ("EImage to DIBitmap conversion failed",
|
|
313 instantiator);
|
|
314 }
|
|
315
|
|
316 /* Now create the pixmap and set up the image instance */
|
|
317 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
|
318 bmp_data, bmp_bits, instantiator);
|
|
319
|
|
320 xfree (bmp_info);
|
|
321 xfree (bmp_data);
|
|
322 }
|
|
323
|
276
|
324 void
|
|
325 mswindows_create_icon_from_image(Lisp_Object image, struct frame* f, int size)
|
|
326 {
|
|
327 HBITMAP mask, bmp;
|
|
328 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
|
329 HDC hdcDst = CreateCompatibleDC (hcdc);
|
|
330 ICONINFO x_icon;
|
|
331
|
|
332 if (size!=16 && size!=32)
|
|
333 {
|
|
334 signal_simple_error("Icons must be 16x16 or 32x32", image);
|
|
335 }
|
|
336
|
|
337 #if 0
|
|
338 iIconWidth = GetSystemMetrics(SM_CXICON);
|
|
339 iIconHeight = GetSystemMetrics(SM_CYICON);
|
|
340 #endif
|
|
341
|
|
342 SelectObject(hcdc, XIMAGE_INSTANCE_MSWINDOWS_BITMAP (image));
|
|
343
|
|
344 bmp = CreateCompatibleBitmap(hcdc, size, size);
|
|
345 DeleteObject( SelectObject(hdcDst, bmp) );
|
|
346
|
|
347 if (!StretchBlt(hdcDst, 0, 0, size, size,
|
|
348 hcdc, 0, 0,
|
|
349 XIMAGE_INSTANCE_PIXMAP_WIDTH (image),
|
|
350 XIMAGE_INSTANCE_PIXMAP_HEIGHT (image),
|
|
351 SRCCOPY))
|
|
352 {
|
|
353 printf("StretchBlt failed\n");
|
|
354 }
|
|
355
|
|
356 if (!(mask = CreateBitmap(size, size, 1, 1, NULL)))
|
|
357 {
|
|
358 printf("CreateBitmap() failed\n");
|
|
359 }
|
|
360 if (!SelectObject(hdcDst, mask)
|
|
361 ||
|
|
362 !SelectObject(hcdc, bmp))
|
|
363 {
|
|
364 printf("SelectObject() failed\n");
|
|
365 }
|
|
366
|
|
367 if (!BitBlt(hdcDst, 0, 0, size, size,
|
|
368 hcdc, 0, 0,
|
|
369 NOTSRCCOPY))
|
|
370 {
|
|
371 printf("BitBlt failed\n");
|
|
372 }
|
|
373
|
|
374 SelectObject(hdcDst, 0);
|
|
375 SelectObject(hcdc, 0);
|
|
376 /* PatBlt(hdcDst, 0, 0, size, size, WHITENESS);*/
|
|
377
|
|
378 x_icon.fIcon=TRUE;
|
280
|
379 x_icon.xHotspot=XINT (XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image));
|
|
380 x_icon.yHotspot=XINT (XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image));
|
276
|
381 x_icon.hbmMask=mask;
|
|
382 x_icon.hbmColor=bmp;
|
|
383
|
|
384 XIMAGE_INSTANCE_MSWINDOWS_ICON (image)=
|
|
385 CreateIconIndirect (&x_icon);
|
|
386 XIMAGE_INSTANCE_MSWINDOWS_MASK (image)=mask;
|
|
387
|
|
388 DeleteDC(hdcDst);
|
|
389 }
|
|
390
|
|
391 int
|
|
392 mswindows_resize_dibitmap_instance (struct Lisp_Image_Instance* ii,
|
|
393 struct frame* f,
|
|
394 int newx, int newy)
|
|
395 {
|
|
396 HBITMAP newbmp;
|
|
397 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
|
398 HDC hdcDst = CreateCompatibleDC (hcdc);
|
|
399
|
|
400 SelectObject(hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
|
|
401
|
|
402 newbmp = CreateCompatibleBitmap(hcdc, newx, newy);
|
|
403
|
|
404 DeleteObject( SelectObject(hdcDst, newbmp) );
|
|
405
|
|
406 if (!StretchBlt(hdcDst, 0, 0, newx, newy,
|
|
407 hcdc, 0, 0,
|
|
408 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
409 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
410 SRCCOPY))
|
|
411 {
|
|
412 return FALSE;
|
|
413 }
|
|
414
|
|
415 SelectObject(hdcDst, 0);
|
|
416 SelectObject(hcdc, 0);
|
|
417
|
|
418 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii))
|
|
419 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
|
|
420 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
|
|
421 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
|
|
422
|
|
423 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp;
|
|
424 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newbmp;
|
|
425 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx;
|
|
426 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy;
|
|
427
|
|
428 DeleteDC(hdcDst);
|
|
429
|
|
430 return TRUE;
|
|
431 }
|
|
432
|
267
|
433 /**********************************************************************
|
|
434 * XPM *
|
|
435 **********************************************************************/
|
|
436
|
|
437 #ifdef HAVE_XPM
|
280
|
438
|
|
439 struct color_symbol
|
|
440 {
|
|
441 char* name;
|
|
442 COLORREF color;
|
|
443 };
|
|
444
|
|
445 static struct color_symbol*
|
|
446 extract_xpm_color_names (Lisp_Object device,
|
|
447 Lisp_Object domain,
|
|
448 Lisp_Object color_symbol_alist,
|
|
449 int* nsymbols)
|
|
450 {
|
|
451 /* This function can GC */
|
|
452 Lisp_Object rest;
|
|
453 Lisp_Object results = Qnil;
|
|
454 int i, j;
|
|
455 struct color_symbol *colortbl;
|
|
456 struct gcpro gcpro1, gcpro2;
|
|
457
|
|
458 GCPRO2 (results, device);
|
|
459
|
|
460 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
461 error happens we don't lose any malloc()ed data, or more importantly,
|
|
462 leave any pixels allocated in the server. */
|
|
463 i = 0;
|
|
464 LIST_LOOP (rest, color_symbol_alist)
|
|
465 {
|
|
466 Lisp_Object cons = XCAR (rest);
|
|
467 Lisp_Object name = XCAR (cons);
|
|
468 Lisp_Object value = XCDR (cons);
|
|
469 if (NILP (value))
|
|
470 continue;
|
|
471 if (STRINGP (value))
|
|
472 value =
|
|
473 Fmake_color_instance
|
|
474 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
|
|
475 else
|
|
476 {
|
|
477 assert (COLOR_SPECIFIERP (value));
|
|
478 value = Fspecifier_instance (value, domain, Qnil, Qnil);
|
|
479 }
|
|
480 if (NILP (value))
|
|
481 continue;
|
|
482 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
483 i++;
|
|
484 }
|
|
485 UNGCPRO; /* no more evaluation */
|
|
486
|
|
487 *nsymbols=i;
|
|
488 if (i == 0) return 0;
|
|
489
|
|
490 colortbl = xnew_array_and_zero (struct color_symbol, i);
|
|
491
|
|
492 for (j=0; j<i; j++)
|
|
493 {
|
|
494 Lisp_Object cons = XCAR (results);
|
|
495 colortbl[j].color =
|
|
496 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
497
|
|
498 colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons));
|
|
499 free_cons (XCONS (cons));
|
|
500 cons = results;
|
|
501 results = XCDR (results);
|
|
502 free_cons (XCONS (cons));
|
|
503 }
|
|
504 return colortbl;
|
|
505 }
|
|
506
|
269
|
507 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer,
|
276
|
508 unsigned char** data,
|
|
509 int* width, int* height,
|
|
510 int* x_hot, int* y_hot,
|
280
|
511 COLORREF bg, struct color_symbol* color_symbols,
|
|
512 int nsymbols)
|
267
|
513 {
|
|
514 XpmImage xpmimage;
|
|
515 XpmInfo xpminfo;
|
280
|
516 int result, i, j, transp_idx, maskbpline;
|
267
|
517 unsigned char* dptr;
|
|
518 unsigned int* sptr;
|
|
519 COLORREF color; /* the american spelling virus hits again .. */
|
|
520 COLORREF* colortbl;
|
|
521
|
272
|
522 xzero (xpmimage);
|
|
523 xzero (xpminfo);
|
276
|
524 xpminfo.valuemask=XpmHotspot;
|
|
525
|
269
|
526 result = XpmCreateXpmImageFromBuffer ((char*)buffer,
|
267
|
527 &xpmimage,
|
|
528 &xpminfo);
|
269
|
529 switch (result)
|
267
|
530 {
|
|
531 case XpmSuccess:
|
|
532 break;
|
|
533 case XpmFileInvalid:
|
|
534 {
|
|
535 signal_simple_error ("invalid XPM data", image);
|
|
536 }
|
|
537 case XpmNoMemory:
|
|
538 {
|
|
539 signal_double_file_error ("Parsing pixmap data",
|
|
540 "out of memory", image);
|
|
541 }
|
|
542 default:
|
|
543 {
|
|
544 signal_double_file_error_2 ("Parsing pixmap data",
|
|
545 "unknown error code",
|
|
546 make_int (result), image);
|
|
547 }
|
|
548 }
|
|
549
|
|
550 *width = xpmimage.width;
|
|
551 *height = xpmimage.height;
|
276
|
552 maskbpline = (int)(~3UL & (unsigned long)
|
|
553 (((~7UL & (unsigned long)(*width + 7)) / 8) + 3));
|
|
554
|
|
555 *data = xnew_array_and_zero (unsigned char, *width * *height * 3);
|
267
|
556
|
|
557 if (!*data)
|
|
558 {
|
269
|
559 XpmFreeXpmImage (&xpmimage);
|
|
560 XpmFreeXpmInfo (&xpminfo);
|
267
|
561 return 0;
|
|
562 }
|
|
563
|
|
564 /* build a color table to speed things up */
|
|
565 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors);
|
|
566 if (!colortbl)
|
|
567 {
|
269
|
568 xfree (*data);
|
|
569 XpmFreeXpmImage (&xpmimage);
|
|
570 XpmFreeXpmInfo (&xpminfo);
|
267
|
571 return 0;
|
|
572 }
|
|
573
|
|
574 for (i=0; i<xpmimage.ncolors; i++)
|
|
575 {
|
280
|
576 /* pick up symbolic colors */
|
|
577 if (xpmimage.colorTable[i].c_color == 0
|
|
578 &&
|
|
579 xpmimage.colorTable[i].symbolic != 0)
|
|
580 {
|
|
581 if (!color_symbols)
|
|
582 {
|
|
583 xfree (*data);
|
|
584 xfree (colortbl);
|
|
585 XpmFreeXpmImage (&xpmimage);
|
|
586 XpmFreeXpmInfo (&xpminfo);
|
|
587 return 0;
|
|
588 }
|
|
589 for (j = 0; j<nsymbols; j++)
|
|
590 {
|
|
591 if (!strcmp (xpmimage.colorTable[i].symbolic,
|
|
592 color_symbols[j].name ))
|
|
593 {
|
|
594 colortbl[i]=color_symbols[j].color;
|
|
595 }
|
|
596 }
|
|
597 }
|
267
|
598 /* pick up transparencies */
|
280
|
599 else if (!strcmp (xpmimage.colorTable[i].c_color,"None"))
|
267
|
600 {
|
276
|
601 colortbl[i]=bg; /* PALETTERGB(0,0,0); */
|
|
602 transp_idx=i;
|
267
|
603 }
|
|
604 else
|
|
605 {
|
|
606 colortbl[i]=
|
269
|
607 mswindows_string_to_color (xpmimage.colorTable[i].c_color);
|
267
|
608 }
|
|
609 }
|
|
610
|
|
611 /* convert the image */
|
|
612 sptr=xpmimage.data;
|
|
613 dptr=*data;
|
|
614 for (i = 0; i< *width * *height; i++)
|
|
615 {
|
|
616 color = colortbl[*sptr++];
|
|
617
|
|
618 /* split out the 0x02bbggrr colorref into an rgb triple */
|
269
|
619 *dptr++=GetRValue (color); /* red */
|
|
620 *dptr++=GetGValue (color); /* green */
|
|
621 *dptr++=GetBValue (color); /* blue */
|
267
|
622 }
|
|
623
|
276
|
624 *x_hot=xpminfo.x_hotspot;
|
|
625 *y_hot=xpminfo.y_hotspot;
|
|
626
|
269
|
627 XpmFreeXpmImage (&xpmimage);
|
|
628 XpmFreeXpmInfo (&xpminfo);
|
|
629 xfree (colortbl);
|
267
|
630 return TRUE;
|
|
631 }
|
|
632
|
280
|
633 static void
|
267
|
634 mswindows_xpm_instantiate (Lisp_Object image_instance,
|
|
635 Lisp_Object instantiator,
|
|
636 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
637 int dest_mask, Lisp_Object domain)
|
|
638 {
|
|
639 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
640 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
641 CONST Extbyte *bytes;
|
|
642 Extcount len;
|
|
643 unsigned char *eimage;
|
276
|
644 int width, height, x_hot, y_hot;
|
267
|
645 BITMAPINFO* bmp_info;
|
|
646 unsigned char* bmp_data;
|
|
647 int bmp_bits;
|
|
648 COLORREF bkcolor;
|
280
|
649 int nsymbols=0;
|
|
650 struct color_symbol* color_symbols=NULL;
|
267
|
651
|
|
652 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
280
|
653 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
654 Q_color_symbols);
|
267
|
655
|
|
656 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
657 signal_simple_error ("Not an mswindows device", device);
|
|
658
|
|
659 assert (!NILP (data));
|
|
660
|
|
661 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
662
|
|
663 /* this is a hack but MaskBlt and TransparentBlt are not supported
|
|
664 on most windows variants */
|
|
665 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
|
269
|
666 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
|
267
|
667
|
280
|
668 /* in case we have color symbols */
|
|
669 color_symbols = extract_xpm_color_names (device, domain,
|
|
670 color_symbol_alist, &nsymbols);
|
|
671
|
267
|
672 /* convert to an eimage to make processing easier */
|
269
|
673 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height,
|
280
|
674 &x_hot, &y_hot, bkcolor, color_symbols, nsymbols))
|
267
|
675 {
|
|
676 signal_simple_error ("XPM to EImage conversion failed",
|
|
677 image_instance);
|
|
678 }
|
|
679
|
280
|
680 if (color_symbols)
|
|
681 xfree(color_symbols);
|
|
682
|
267
|
683 /* build a bitmap from the eimage */
|
278
|
684 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
|
|
685 &bmp_bits, &bmp_data)))
|
267
|
686 {
|
|
687 signal_simple_error ("XPM to EImage conversion failed",
|
|
688 image_instance);
|
|
689 }
|
269
|
690 xfree (eimage);
|
267
|
691
|
|
692 /* Now create the pixmap and set up the image instance */
|
|
693 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
|
694 bmp_data, bmp_bits, instantiator);
|
|
695
|
276
|
696 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), x_hot);
|
|
697 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), y_hot);
|
|
698
|
269
|
699 xfree (bmp_info);
|
|
700 xfree (bmp_data);
|
267
|
701 }
|
|
702 #endif /* HAVE_XPM */
|
|
703
|
|
704 /**********************************************************************
|
|
705 * BMP *
|
|
706 **********************************************************************/
|
|
707
|
|
708 static void
|
|
709 bmp_validate (Lisp_Object instantiator)
|
|
710 {
|
|
711 file_or_data_must_be_present (instantiator);
|
|
712 }
|
|
713
|
|
714 static Lisp_Object
|
|
715 bmp_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
716 {
|
|
717 return simple_image_type_normalize (inst, console_type, Qbmp);
|
|
718 }
|
|
719
|
|
720 static int
|
|
721 bmp_possible_dest_types (void)
|
|
722 {
|
|
723 return IMAGE_COLOR_PIXMAP_MASK;
|
|
724 }
|
|
725
|
|
726 static void
|
|
727 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
728 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
729 int dest_mask, Lisp_Object domain)
|
|
730 {
|
|
731 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
732 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
733 CONST Extbyte *bytes;
|
|
734 Extcount len;
|
|
735 BITMAPFILEHEADER* bmp_file_header;
|
|
736 BITMAPINFO* bmp_info;
|
|
737 void* bmp_data;
|
|
738 int bmp_bits;
|
|
739 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
740
|
|
741 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
742 signal_simple_error ("Not an mswindows device", device);
|
|
743
|
|
744 assert (!NILP (data));
|
|
745
|
|
746 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
747
|
|
748 /* Then slurp the image into memory, decoding along the way.
|
|
749 The result is the image in a simple one-byte-per-pixel
|
|
750 format. */
|
|
751
|
|
752 bmp_file_header=(BITMAPFILEHEADER*)bytes;
|
|
753 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER));
|
|
754 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits;
|
|
755 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits;
|
|
756
|
|
757 /* Now create the pixmap and set up the image instance */
|
|
758 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
|
759 bmp_data, bmp_bits, instantiator);
|
|
760 }
|
|
761
|
|
762
|
|
763 /************************************************************************/
|
|
764 /* image instance methods */
|
|
765 /************************************************************************/
|
|
766
|
|
767 static void
|
|
768 mswindows_print_image_instance (struct Lisp_Image_Instance *p,
|
|
769 Lisp_Object printcharfun,
|
|
770 int escapeflag)
|
|
771 {
|
|
772 char buf[100];
|
|
773
|
|
774 switch (IMAGE_INSTANCE_TYPE (p))
|
|
775 {
|
|
776 case IMAGE_MONO_PIXMAP:
|
|
777 case IMAGE_COLOR_PIXMAP:
|
|
778 case IMAGE_POINTER:
|
|
779 sprintf (buf, " (0x%lx",
|
|
780 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
|
781 write_c_string (buf, printcharfun);
|
|
782 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
783 {
|
|
784 sprintf (buf, "/0x%lx",
|
|
785 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
786 write_c_string (buf, printcharfun);
|
|
787 }
|
|
788 write_c_string (")", printcharfun);
|
|
789 break;
|
|
790 default:
|
|
791 break;
|
|
792 }
|
|
793 }
|
|
794
|
|
795 static void
|
|
796 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
797 {
|
|
798 if (!p->data)
|
|
799 return;
|
|
800
|
|
801 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
802 {
|
|
803 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p))
|
269
|
804 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
267
|
805 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0;
|
272
|
806 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
807 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
808 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0;
|
|
809 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p))
|
|
810 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p));
|
|
811 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0;
|
267
|
812 }
|
|
813
|
|
814 xfree (p->data);
|
|
815 p->data = 0;
|
|
816 }
|
|
817
|
|
818 static int
|
|
819 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
820 struct Lisp_Image_Instance *p2, int depth)
|
|
821 {
|
|
822 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
823 {
|
|
824 case IMAGE_MONO_PIXMAP:
|
|
825 case IMAGE_COLOR_PIXMAP:
|
|
826 case IMAGE_POINTER:
|
|
827 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
|
|
828 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
|
|
829 return 0;
|
|
830 break;
|
|
831 default:
|
|
832 break;
|
|
833 }
|
|
834
|
|
835 return 1;
|
|
836 }
|
|
837
|
|
838 static unsigned long
|
|
839 mswindows_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
840 {
|
|
841 switch (IMAGE_INSTANCE_TYPE (p))
|
|
842 {
|
|
843 case IMAGE_MONO_PIXMAP:
|
|
844 case IMAGE_COLOR_PIXMAP:
|
|
845 case IMAGE_POINTER:
|
|
846 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
|
|
847 default:
|
|
848 return 0;
|
|
849 }
|
|
850 }
|
|
851
|
|
852 /* Set all the slots in an image instance structure to reasonable
|
|
853 default values. This is used somewhere within an instantiate
|
|
854 method. It is assumed that the device slot within the image
|
|
855 instance is already set -- this is the case when instantiate
|
|
856 methods are called. */
|
|
857
|
|
858 static void
|
|
859 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
860 enum image_instance_type type)
|
|
861 {
|
|
862 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
|
|
863 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
864 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
865 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
866 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
867 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
868 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
869 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
870 }
|
|
871
|
|
872
|
|
873 /************************************************************************/
|
|
874 /* initialization */
|
|
875 /************************************************************************/
|
|
876
|
|
877 void
|
|
878 syms_of_glyphs_mswindows (void)
|
|
879 {
|
|
880 }
|
|
881
|
|
882 void
|
|
883 console_type_create_glyphs_mswindows (void)
|
|
884 {
|
|
885 /* image methods */
|
|
886
|
|
887 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
|
|
888 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
|
|
889 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
|
|
890 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
|
278
|
891 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage);
|
|
892 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file);
|
280
|
893 #ifdef HAVE_XPM
|
|
894 CONSOLE_HAS_METHOD (mswindows, xpm_instantiate);
|
|
895 #endif
|
267
|
896 }
|
|
897
|
|
898 void
|
|
899 image_instantiator_format_create_glyphs_mswindows (void)
|
|
900 {
|
|
901 /* image-instantiator types */
|
|
902
|
|
903 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
|
|
904
|
|
905 IIFORMAT_HAS_METHOD (bmp, validate);
|
|
906 IIFORMAT_HAS_METHOD (bmp, normalize);
|
|
907 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
|
|
908 IIFORMAT_HAS_METHOD (bmp, instantiate);
|
|
909
|
|
910 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
|
|
911 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
|
|
912 }
|
|
913
|
|
914 void
|
|
915 vars_of_glyphs_mswindows (void)
|
|
916 {
|
|
917 Fprovide (Qbmp);
|
|
918 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
|
|
919 A list of the directories in which mswindows bitmap files may be found.
|
|
920 This is used by the `make-image-instance' function.
|
|
921 */ );
|
|
922 Vmswindows_bitmap_file_path = Qnil;
|
|
923 }
|
|
924
|
|
925 void
|
|
926 complex_vars_of_glyphs_mswindows (void)
|
|
927 {
|
|
928 }
|