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 FILE_CODING
|
|
42 #include "file-coding.h"
|
|
43 #endif
|
|
44
|
|
45 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
|
|
46 Lisp_Object Qbmp;
|
|
47 Lisp_Object Vmswindows_bitmap_file_path;
|
|
48
|
|
49 static void
|
|
50 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
51 enum image_instance_type type);
|
|
52
|
269
|
53 COLORREF mswindows_string_to_color (CONST char *name);
|
267
|
54
|
|
55 /************************************************************************/
|
|
56 /* convert from a series of RGB triples to a BITMAPINFO formated for the*/
|
|
57 /* proper display */
|
|
58 /************************************************************************/
|
278
|
59 static BITMAPINFO* convert_EImage_to_DIBitmap (Lisp_Object device,
|
|
60 int width, int height,
|
|
61 unsigned char *pic,
|
|
62 int *bit_count,
|
|
63 unsigned char** bmp_data)
|
267
|
64 {
|
|
65 struct device *d = XDEVICE (device);
|
269
|
66 int i,j;
|
267
|
67 RGBQUAD* colortbl;
|
|
68 int ncolors;
|
|
69 BITMAPINFO* bmp_info;
|
269
|
70 unsigned char *ip, *dp;
|
267
|
71
|
269
|
72 if (DEVICE_MSWINDOWS_BITSPIXEL (d) > 0)
|
267
|
73 {
|
269
|
74 int bpline=(int)(~3UL & (unsigned long)((width*3) +3));
|
267
|
75 /* FIXME: we can do this because 24bpp implies no colour table, once
|
|
76 * we start paletizing this is no longer true. The X versions of
|
|
77 * this function quantises to 256 colours or bit masks down to a
|
|
78 * long. Windows can actually handle rgb triples in the raw so I
|
272
|
79 * don't see much point trying to optimize down to the best
|
267
|
80 * structure - unless it has memory / color allocation implications
|
|
81 * .... */
|
269
|
82 bmp_info=xnew_and_zero (BITMAPINFO);
|
267
|
83
|
|
84 if (!bmp_info)
|
|
85 {
|
|
86 return NULL;
|
|
87 }
|
|
88
|
|
89 bmp_info->bmiHeader.biBitCount=24; /* just RGB triples for now */
|
|
90 bmp_info->bmiHeader.biCompression=BI_RGB; /* just RGB triples for now */
|
|
91 bmp_info->bmiHeader.biSizeImage=width*height*3;
|
|
92
|
|
93 /* bitmap data needs to be in blue, green, red triples - in that
|
|
94 order, eimage is in RGB format so we need to convert */
|
272
|
95 *bmp_data = xnew_array_and_zero (unsigned char, bpline * height);
|
278
|
96 *bit_count = bpline * height;
|
267
|
97
|
|
98 if (!bmp_data)
|
|
99 {
|
272
|
100 xfree (bmp_info);
|
267
|
101 return NULL;
|
|
102 }
|
272
|
103
|
|
104 ip = pic;
|
|
105 for (i = height-1; i >= 0; i--) {
|
|
106 dp = (*bmp_data) + (i * bpline);
|
|
107 for (j = 0; j < width; j++) {
|
|
108 dp[2] =*ip++;
|
|
109 dp[1] =*ip++;
|
|
110 *dp =*ip++;
|
|
111 dp += 3;
|
267
|
112 }
|
272
|
113 }
|
267
|
114 }
|
|
115 else /* scale to 256 colors */
|
|
116 {
|
272
|
117 int rd,gr,bl;
|
267
|
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;
|
272
|
127 bmp_info=(BITMAPINFO*)xmalloc_and_zero (sizeof(BITMAPINFOHEADER) +
|
267
|
128 sizeof(RGBQUAD) * ncolors);
|
|
129 if (!bmp_info)
|
|
130 {
|
272
|
131 xfree (qtable);
|
267
|
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
|
278
|
190 Lisp_Object
|
|
191 mswindows_locate_pixmap_file (Lisp_Object name)
|
267
|
192 {
|
|
193 /* This function can GC if IN_REDISPLAY is false */
|
276
|
194 Lisp_Object found;
|
267
|
195
|
|
196 /* Check non-absolute pathnames with a directory component relative to
|
|
197 the search path; that's the way Xt does it. */
|
269
|
198 if (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 0)) ||
|
267
|
199 (XSTRING_BYTE (name, 0) == '.' &&
|
269
|
200 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 1)) ||
|
267
|
201 (XSTRING_BYTE (name, 1) == '.' &&
|
269
|
202 (IS_DIRECTORY_SEP(XSTRING_BYTE (name, 2)))))))
|
267
|
203 {
|
|
204 if (!NILP (Ffile_readable_p (name)))
|
|
205 return name;
|
|
206 else
|
|
207 return Qnil;
|
|
208 }
|
|
209
|
276
|
210 if (locate_file (Vmswindows_bitmap_file_path, name, "", &found, R_OK) < 0)
|
|
211 {
|
|
212 Lisp_Object temp = list1 (Vdata_directory);
|
|
213 struct gcpro gcpro1;
|
267
|
214
|
276
|
215 GCPRO1 (temp);
|
|
216 locate_file (temp, name, "", &found, R_OK);
|
|
217 UNGCPRO;
|
|
218 }
|
267
|
219
|
276
|
220 return found;
|
267
|
221 }
|
|
222
|
278
|
223 #if 0
|
267
|
224 /* If INSTANTIATOR refers to inline data, return Qnil.
|
|
225 If INSTANTIATOR refers to data in a file, return the full filename
|
|
226 if it exists; otherwise, return a cons of (filename).
|
|
227
|
|
228 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the
|
|
229 keywords used to look up the file and inline data,
|
|
230 respectively, in the instantiator. Normally these would
|
|
231 be Q_file and Q_data, but might be different for mask data. */
|
|
232
|
|
233 static Lisp_Object
|
|
234 potential_pixmap_file_instantiator (Lisp_Object instantiator,
|
|
235 Lisp_Object file_keyword,
|
|
236 Lisp_Object data_keyword)
|
|
237 {
|
|
238 Lisp_Object file;
|
|
239 Lisp_Object data;
|
|
240
|
|
241 assert (VECTORP (instantiator));
|
|
242
|
|
243 data = find_keyword_in_vector (instantiator, data_keyword);
|
|
244 file = find_keyword_in_vector (instantiator, file_keyword);
|
|
245
|
|
246 if (!NILP (file) && NILP (data))
|
|
247 {
|
269
|
248 Lisp_Object retval = locate_pixmap_file(file);
|
267
|
249 if (!NILP (retval))
|
|
250 return retval;
|
|
251 else
|
|
252 return Fcons (file, Qnil); /* should have been file */
|
|
253 }
|
|
254
|
|
255 return Qnil;
|
|
256 }
|
|
257
|
|
258 static Lisp_Object
|
|
259 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type,
|
|
260 Lisp_Object image_type_tag)
|
|
261 {
|
|
262 /* This function can call lisp */
|
|
263 Lisp_Object file = Qnil;
|
|
264 struct gcpro gcpro1, gcpro2;
|
|
265 Lisp_Object alist = Qnil;
|
|
266
|
|
267 GCPRO2 (file, alist);
|
|
268
|
|
269 /* Now, convert any file data into inline data. At the end of this,
|
|
270 `data' will contain the inline data (if any) or Qnil, and `file'
|
|
271 will contain the name this data was derived from (if known) or
|
|
272 Qnil.
|
|
273
|
|
274 Note that if we cannot generate any regular inline data, we
|
|
275 skip out. */
|
|
276
|
|
277 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
278
|
|
279 if (CONSP (file)) /* failure locating filename */
|
|
280 signal_double_file_error ("Opening pixmap file",
|
|
281 "no such file or directory",
|
|
282 Fcar (file));
|
|
283
|
|
284 if (NILP (file)) /* no conversion necessary */
|
|
285 RETURN_UNGCPRO (inst);
|
|
286
|
|
287 alist = tagged_vector_to_alist (inst);
|
|
288
|
|
289 {
|
|
290 Lisp_Object data = make_string_from_file (file);
|
|
291 alist = remassq_no_quit (Q_file, alist);
|
|
292 /* there can't be a :data at this point. */
|
|
293 alist = Fcons (Fcons (Q_file, file),
|
|
294 Fcons (Fcons (Q_data, data), alist));
|
|
295 }
|
|
296
|
|
297 {
|
|
298 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist);
|
|
299 free_alist (alist);
|
|
300 RETURN_UNGCPRO (result);
|
|
301 }
|
|
302 }
|
278
|
303 #endif
|
267
|
304
|
|
305
|
|
306 /* Initialize an image instance from a bitmap
|
|
307
|
|
308 DEST_MASK specifies the mask of allowed image types.
|
|
309
|
|
310 If this fails, signal an error. INSTANTIATOR is only used
|
|
311 in the error message. */
|
|
312
|
|
313 static void
|
|
314 init_image_instance_from_dibitmap (struct Lisp_Image_Instance *ii,
|
|
315 BITMAPINFO *bmp_info,
|
|
316 int dest_mask,
|
|
317 void *bmp_data,
|
|
318 int bmp_bits,
|
|
319 Lisp_Object instantiator)
|
|
320 {
|
|
321 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
322 struct device *d = XDEVICE (device);
|
269
|
323 struct frame *f = XFRAME (DEVICE_SELECTED_FRAME (d));
|
267
|
324 void* bmp_buf=0;
|
|
325 HBITMAP bitmap;
|
269
|
326 HDC hdc;
|
267
|
327
|
|
328 if (!DEVICE_MSWINDOWS_P (d))
|
|
329 signal_simple_error ("Not an mswindows device", device);
|
|
330
|
|
331 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
332 signal_simple_error ("No selected frame on mswindows device", device);
|
|
333
|
|
334 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
335 incompatible_image_types (instantiator, dest_mask,
|
|
336 IMAGE_COLOR_PIXMAP_MASK);
|
|
337 hdc = FRAME_MSWINDOWS_DC (f);
|
|
338
|
269
|
339 bitmap=CreateDIBSection (hdc,
|
267
|
340 bmp_info,
|
|
341 DIB_RGB_COLORS,
|
|
342 &bmp_buf,
|
|
343 0,0);
|
|
344
|
|
345 if (!bitmap || !bmp_buf)
|
|
346 signal_simple_error ("Unable to create bitmap", instantiator);
|
|
347
|
|
348 /* copy in the actual bitmap */
|
269
|
349 memcpy (bmp_buf, bmp_data, bmp_bits);
|
267
|
350
|
|
351 mswindows_initialize_dibitmap_image_instance (ii, IMAGE_COLOR_PIXMAP);
|
|
352
|
|
353 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
354 find_keyword_in_vector (instantiator, Q_file);
|
|
355
|
|
356 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = bitmap;
|
272
|
357 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = bitmap;
|
267
|
358 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = bmp_info->bmiHeader.biWidth;
|
|
359 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = bmp_info->bmiHeader.biHeight;
|
|
360 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = bmp_info->bmiHeader.biBitCount;
|
|
361 }
|
|
362
|
278
|
363 static void
|
|
364 mswindows_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii,
|
|
365 int width, int height,
|
|
366 unsigned char *eimage,
|
|
367 int dest_mask,
|
|
368 Lisp_Object instantiator,
|
|
369 Lisp_Object domain)
|
|
370 {
|
|
371 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
372 BITMAPINFO* bmp_info;
|
|
373 unsigned char* bmp_data;
|
|
374 int bmp_bits;
|
|
375 COLORREF bkcolor;
|
|
376
|
|
377 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
378 signal_simple_error ("Not an mswindows device", device);
|
|
379
|
|
380 /* this is a hack but MaskBlt and TransparentBlt are not supported
|
|
381 on most windows variants */
|
|
382 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
383 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
|
|
384
|
|
385 /* build a bitmap from the eimage */
|
|
386 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
|
|
387 &bmp_bits, &bmp_data)))
|
|
388 {
|
|
389 signal_simple_error ("EImage to DIBitmap conversion failed",
|
|
390 instantiator);
|
|
391 }
|
|
392
|
|
393 /* Now create the pixmap and set up the image instance */
|
|
394 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
|
395 bmp_data, bmp_bits, instantiator);
|
|
396
|
|
397 xfree (bmp_info);
|
|
398 xfree (bmp_data);
|
|
399 }
|
|
400
|
276
|
401 void
|
|
402 mswindows_create_icon_from_image(Lisp_Object image, struct frame* f, int size)
|
|
403 {
|
|
404 HBITMAP mask, bmp;
|
|
405 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
|
406 HDC hdcDst = CreateCompatibleDC (hcdc);
|
|
407 ICONINFO x_icon;
|
|
408
|
|
409 if (size!=16 && size!=32)
|
|
410 {
|
|
411 signal_simple_error("Icons must be 16x16 or 32x32", image);
|
|
412 }
|
|
413
|
|
414 #if 0
|
|
415 iIconWidth = GetSystemMetrics(SM_CXICON);
|
|
416 iIconHeight = GetSystemMetrics(SM_CYICON);
|
|
417 #endif
|
|
418
|
|
419 SelectObject(hcdc, XIMAGE_INSTANCE_MSWINDOWS_BITMAP (image));
|
|
420
|
|
421 bmp = CreateCompatibleBitmap(hcdc, size, size);
|
|
422 DeleteObject( SelectObject(hdcDst, bmp) );
|
|
423
|
|
424 if (!StretchBlt(hdcDst, 0, 0, size, size,
|
|
425 hcdc, 0, 0,
|
|
426 XIMAGE_INSTANCE_PIXMAP_WIDTH (image),
|
|
427 XIMAGE_INSTANCE_PIXMAP_HEIGHT (image),
|
|
428 SRCCOPY))
|
|
429 {
|
|
430 printf("StretchBlt failed\n");
|
|
431 }
|
|
432
|
|
433 if (!(mask = CreateBitmap(size, size, 1, 1, NULL)))
|
|
434 {
|
|
435 printf("CreateBitmap() failed\n");
|
|
436 }
|
|
437 if (!SelectObject(hdcDst, mask)
|
|
438 ||
|
|
439 !SelectObject(hcdc, bmp))
|
|
440 {
|
|
441 printf("SelectObject() failed\n");
|
|
442 }
|
|
443
|
|
444 if (!BitBlt(hdcDst, 0, 0, size, size,
|
|
445 hcdc, 0, 0,
|
|
446 NOTSRCCOPY))
|
|
447 {
|
|
448 printf("BitBlt failed\n");
|
|
449 }
|
|
450
|
|
451 SelectObject(hdcDst, 0);
|
|
452 SelectObject(hcdc, 0);
|
|
453 /* PatBlt(hdcDst, 0, 0, size, size, WHITENESS);*/
|
|
454
|
|
455 x_icon.fIcon=TRUE;
|
|
456 x_icon.xHotspot=XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image);
|
|
457 x_icon.yHotspot=XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image);
|
|
458 x_icon.hbmMask=mask;
|
|
459 x_icon.hbmColor=bmp;
|
|
460
|
|
461 XIMAGE_INSTANCE_MSWINDOWS_ICON (image)=
|
|
462 CreateIconIndirect (&x_icon);
|
|
463 XIMAGE_INSTANCE_MSWINDOWS_MASK (image)=mask;
|
|
464
|
|
465 DeleteDC(hdcDst);
|
|
466 }
|
|
467
|
|
468 int
|
|
469 mswindows_resize_dibitmap_instance (struct Lisp_Image_Instance* ii,
|
|
470 struct frame* f,
|
|
471 int newx, int newy)
|
|
472 {
|
|
473 HBITMAP newbmp;
|
|
474 HDC hcdc = FRAME_MSWINDOWS_CDC (f);
|
|
475 HDC hdcDst = CreateCompatibleDC (hcdc);
|
|
476
|
|
477 SelectObject(hcdc, IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
|
|
478
|
|
479 newbmp = CreateCompatibleBitmap(hcdc, newx, newy);
|
|
480
|
|
481 DeleteObject( SelectObject(hdcDst, newbmp) );
|
|
482
|
|
483 if (!StretchBlt(hdcDst, 0, 0, newx, newy,
|
|
484 hcdc, 0, 0,
|
|
485 IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
486 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
487 SRCCOPY))
|
|
488 {
|
|
489 return FALSE;
|
|
490 }
|
|
491
|
|
492 SelectObject(hdcDst, 0);
|
|
493 SelectObject(hcdc, 0);
|
|
494
|
|
495 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii))
|
|
496 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii));
|
|
497 if (IMAGE_INSTANCE_MSWINDOWS_MASK (ii))
|
|
498 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (ii));
|
|
499
|
|
500 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = newbmp;
|
|
501 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = newbmp;
|
|
502 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = newx;
|
|
503 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = newy;
|
|
504
|
|
505 DeleteDC(hdcDst);
|
|
506
|
|
507 return TRUE;
|
|
508 }
|
|
509
|
267
|
510 /**********************************************************************
|
|
511 * XPM *
|
|
512 **********************************************************************/
|
|
513
|
|
514 #ifdef HAVE_XPM
|
269
|
515 static int xpm_to_eimage (Lisp_Object image, CONST Extbyte *buffer,
|
276
|
516 unsigned char** data,
|
|
517 int* width, int* height,
|
|
518 int* x_hot, int* y_hot,
|
|
519 COLORREF bg)
|
267
|
520 {
|
|
521 XpmImage xpmimage;
|
|
522 XpmInfo xpminfo;
|
276
|
523 int result, i, transp_idx, maskbpline;
|
267
|
524 unsigned char* dptr;
|
|
525 unsigned int* sptr;
|
|
526 COLORREF color; /* the american spelling virus hits again .. */
|
|
527 COLORREF* colortbl;
|
|
528
|
272
|
529 xzero (xpmimage);
|
|
530 xzero (xpminfo);
|
276
|
531 xpminfo.valuemask=XpmHotspot;
|
|
532
|
269
|
533 result = XpmCreateXpmImageFromBuffer ((char*)buffer,
|
267
|
534 &xpmimage,
|
|
535 &xpminfo);
|
269
|
536 switch (result)
|
267
|
537 {
|
|
538 case XpmSuccess:
|
|
539 break;
|
|
540 case XpmFileInvalid:
|
|
541 {
|
|
542 signal_simple_error ("invalid XPM data", image);
|
|
543 }
|
|
544 case XpmNoMemory:
|
|
545 {
|
|
546 signal_double_file_error ("Parsing pixmap data",
|
|
547 "out of memory", image);
|
|
548 }
|
|
549 default:
|
|
550 {
|
|
551 signal_double_file_error_2 ("Parsing pixmap data",
|
|
552 "unknown error code",
|
|
553 make_int (result), image);
|
|
554 }
|
|
555 }
|
|
556
|
|
557 *width = xpmimage.width;
|
|
558 *height = xpmimage.height;
|
276
|
559 maskbpline = (int)(~3UL & (unsigned long)
|
|
560 (((~7UL & (unsigned long)(*width + 7)) / 8) + 3));
|
|
561
|
|
562 *data = xnew_array_and_zero (unsigned char, *width * *height * 3);
|
267
|
563
|
|
564 if (!*data)
|
|
565 {
|
269
|
566 XpmFreeXpmImage (&xpmimage);
|
|
567 XpmFreeXpmInfo (&xpminfo);
|
267
|
568 return 0;
|
|
569 }
|
|
570
|
|
571 /* build a color table to speed things up */
|
|
572 colortbl = xnew_array_and_zero (COLORREF, xpmimage.ncolors);
|
|
573 if (!colortbl)
|
|
574 {
|
269
|
575 xfree (*data);
|
|
576 XpmFreeXpmImage (&xpmimage);
|
|
577 XpmFreeXpmInfo (&xpminfo);
|
267
|
578 return 0;
|
|
579 }
|
|
580
|
|
581 for (i=0; i<xpmimage.ncolors; i++)
|
|
582 {
|
|
583 /* pick up transparencies */
|
269
|
584 if (!strcmp (xpmimage.colorTable[i].c_color,"None"))
|
267
|
585 {
|
276
|
586 colortbl[i]=bg; /* PALETTERGB(0,0,0); */
|
|
587 transp_idx=i;
|
267
|
588 }
|
|
589 else
|
|
590 {
|
|
591 colortbl[i]=
|
269
|
592 mswindows_string_to_color (xpmimage.colorTable[i].c_color);
|
267
|
593 }
|
|
594 }
|
|
595
|
|
596 /* convert the image */
|
|
597 sptr=xpmimage.data;
|
|
598 dptr=*data;
|
|
599 for (i = 0; i< *width * *height; i++)
|
|
600 {
|
|
601 color = colortbl[*sptr++];
|
|
602
|
|
603 /* split out the 0x02bbggrr colorref into an rgb triple */
|
269
|
604 *dptr++=GetRValue (color); /* red */
|
|
605 *dptr++=GetGValue (color); /* green */
|
|
606 *dptr++=GetBValue (color); /* blue */
|
267
|
607 }
|
|
608
|
276
|
609 *x_hot=xpminfo.x_hotspot;
|
|
610 *y_hot=xpminfo.y_hotspot;
|
|
611
|
269
|
612 XpmFreeXpmImage (&xpmimage);
|
|
613 XpmFreeXpmInfo (&xpminfo);
|
|
614 xfree (colortbl);
|
267
|
615 return TRUE;
|
|
616 }
|
|
617
|
276
|
618 Lisp_Object
|
|
619 mswindows_xpm_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
620 {
|
|
621 return simple_image_type_normalize (inst, console_type, Qxpm);
|
|
622 }
|
|
623
|
267
|
624 void
|
|
625 mswindows_xpm_instantiate (Lisp_Object image_instance,
|
|
626 Lisp_Object instantiator,
|
|
627 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
628 int dest_mask, Lisp_Object domain)
|
|
629 {
|
|
630 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
631 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
632 CONST Extbyte *bytes;
|
|
633 Extcount len;
|
|
634 unsigned char *eimage;
|
276
|
635 int width, height, x_hot, y_hot;
|
267
|
636 BITMAPINFO* bmp_info;
|
|
637 unsigned char* bmp_data;
|
|
638 int bmp_bits;
|
|
639 COLORREF bkcolor;
|
|
640
|
|
641 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
642
|
|
643 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
644 signal_simple_error ("Not an mswindows device", device);
|
|
645
|
|
646 assert (!NILP (data));
|
|
647
|
|
648 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
649
|
|
650 /* this is a hack but MaskBlt and TransparentBlt are not supported
|
|
651 on most windows variants */
|
|
652 bkcolor = COLOR_INSTANCE_MSWINDOWS_COLOR
|
269
|
653 (XCOLOR_INSTANCE (FACE_BACKGROUND (Vdefault_face, domain)));
|
267
|
654
|
|
655 /* convert to an eimage to make processing easier */
|
269
|
656 if (!xpm_to_eimage (image_instance, bytes, &eimage, &width, &height,
|
276
|
657 &x_hot, &y_hot, bkcolor))
|
267
|
658 {
|
|
659 signal_simple_error ("XPM to EImage conversion failed",
|
|
660 image_instance);
|
|
661 }
|
|
662
|
|
663 /* build a bitmap from the eimage */
|
278
|
664 if (!(bmp_info=convert_EImage_to_DIBitmap (device, width, height, eimage,
|
|
665 &bmp_bits, &bmp_data)))
|
267
|
666 {
|
|
667 signal_simple_error ("XPM to EImage conversion failed",
|
|
668 image_instance);
|
|
669 }
|
269
|
670 xfree (eimage);
|
267
|
671
|
|
672 /* Now create the pixmap and set up the image instance */
|
|
673 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
|
674 bmp_data, bmp_bits, instantiator);
|
|
675
|
276
|
676 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), x_hot);
|
|
677 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), y_hot);
|
|
678
|
269
|
679 xfree (bmp_info);
|
|
680 xfree (bmp_data);
|
267
|
681 }
|
|
682 #endif /* HAVE_XPM */
|
|
683
|
|
684 /**********************************************************************
|
|
685 * BMP *
|
|
686 **********************************************************************/
|
|
687
|
|
688 static void
|
|
689 bmp_validate (Lisp_Object instantiator)
|
|
690 {
|
|
691 file_or_data_must_be_present (instantiator);
|
|
692 }
|
|
693
|
|
694 static Lisp_Object
|
|
695 bmp_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
696 {
|
|
697 return simple_image_type_normalize (inst, console_type, Qbmp);
|
|
698 }
|
|
699
|
|
700 static int
|
|
701 bmp_possible_dest_types (void)
|
|
702 {
|
|
703 return IMAGE_COLOR_PIXMAP_MASK;
|
|
704 }
|
|
705
|
|
706 static void
|
|
707 bmp_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
708 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
709 int dest_mask, Lisp_Object domain)
|
|
710 {
|
|
711 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
712 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
713 CONST Extbyte *bytes;
|
|
714 Extcount len;
|
|
715 BITMAPFILEHEADER* bmp_file_header;
|
|
716 BITMAPINFO* bmp_info;
|
|
717 void* bmp_data;
|
|
718 int bmp_bits;
|
|
719 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
720
|
|
721 if (!DEVICE_MSWINDOWS_P (XDEVICE (device)))
|
|
722 signal_simple_error ("Not an mswindows device", device);
|
|
723
|
|
724 assert (!NILP (data));
|
|
725
|
|
726 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
|
|
727
|
|
728 /* Then slurp the image into memory, decoding along the way.
|
|
729 The result is the image in a simple one-byte-per-pixel
|
|
730 format. */
|
|
731
|
|
732 bmp_file_header=(BITMAPFILEHEADER*)bytes;
|
|
733 bmp_info = (BITMAPINFO*)(bytes + sizeof(BITMAPFILEHEADER));
|
|
734 bmp_data = (Extbyte*)bytes + bmp_file_header->bfOffBits;
|
|
735 bmp_bits = bmp_file_header->bfSize - bmp_file_header->bfOffBits;
|
|
736
|
|
737 /* Now create the pixmap and set up the image instance */
|
|
738 init_image_instance_from_dibitmap (ii, bmp_info, dest_mask,
|
|
739 bmp_data, bmp_bits, instantiator);
|
|
740 }
|
|
741
|
|
742
|
|
743 /************************************************************************/
|
|
744 /* image instance methods */
|
|
745 /************************************************************************/
|
|
746
|
|
747 static void
|
|
748 mswindows_print_image_instance (struct Lisp_Image_Instance *p,
|
|
749 Lisp_Object printcharfun,
|
|
750 int escapeflag)
|
|
751 {
|
|
752 char buf[100];
|
|
753
|
|
754 switch (IMAGE_INSTANCE_TYPE (p))
|
|
755 {
|
|
756 case IMAGE_MONO_PIXMAP:
|
|
757 case IMAGE_COLOR_PIXMAP:
|
|
758 case IMAGE_POINTER:
|
|
759 sprintf (buf, " (0x%lx",
|
|
760 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
|
761 write_c_string (buf, printcharfun);
|
|
762 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
763 {
|
|
764 sprintf (buf, "/0x%lx",
|
|
765 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
766 write_c_string (buf, printcharfun);
|
|
767 }
|
|
768 write_c_string (")", printcharfun);
|
|
769 break;
|
|
770 default:
|
|
771 break;
|
|
772 }
|
|
773 }
|
|
774
|
|
775 static void
|
|
776 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
777 {
|
|
778 if (!p->data)
|
|
779 return;
|
|
780
|
|
781 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
782 {
|
|
783 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p))
|
269
|
784 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
|
267
|
785 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0;
|
272
|
786 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
|
|
787 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p));
|
|
788 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0;
|
|
789 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p))
|
|
790 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p));
|
|
791 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0;
|
267
|
792 }
|
|
793
|
|
794 xfree (p->data);
|
|
795 p->data = 0;
|
|
796 }
|
|
797
|
|
798 static int
|
|
799 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
800 struct Lisp_Image_Instance *p2, int depth)
|
|
801 {
|
|
802 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
803 {
|
|
804 case IMAGE_MONO_PIXMAP:
|
|
805 case IMAGE_COLOR_PIXMAP:
|
|
806 case IMAGE_POINTER:
|
|
807 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
|
|
808 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
|
|
809 return 0;
|
|
810 break;
|
|
811 default:
|
|
812 break;
|
|
813 }
|
|
814
|
|
815 return 1;
|
|
816 }
|
|
817
|
|
818 static unsigned long
|
|
819 mswindows_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
820 {
|
|
821 switch (IMAGE_INSTANCE_TYPE (p))
|
|
822 {
|
|
823 case IMAGE_MONO_PIXMAP:
|
|
824 case IMAGE_COLOR_PIXMAP:
|
|
825 case IMAGE_POINTER:
|
|
826 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
|
|
827 default:
|
|
828 return 0;
|
|
829 }
|
|
830 }
|
|
831
|
|
832 /* Set all the slots in an image instance structure to reasonable
|
|
833 default values. This is used somewhere within an instantiate
|
|
834 method. It is assumed that the device slot within the image
|
|
835 instance is already set -- this is the case when instantiate
|
|
836 methods are called. */
|
|
837
|
|
838 static void
|
|
839 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
840 enum image_instance_type type)
|
|
841 {
|
|
842 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
|
|
843 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
844 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
845 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
846 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
847 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
848 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
849 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
850 }
|
|
851
|
|
852
|
|
853 /************************************************************************/
|
|
854 /* initialization */
|
|
855 /************************************************************************/
|
|
856
|
|
857 void
|
|
858 syms_of_glyphs_mswindows (void)
|
|
859 {
|
|
860 }
|
|
861
|
|
862 void
|
|
863 console_type_create_glyphs_mswindows (void)
|
|
864 {
|
|
865 /* image methods */
|
|
866
|
|
867 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
|
|
868 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
|
|
869 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
|
|
870 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
|
278
|
871 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage);
|
|
872 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file);
|
267
|
873 }
|
|
874
|
|
875 void
|
|
876 image_instantiator_format_create_glyphs_mswindows (void)
|
|
877 {
|
|
878 /* image-instantiator types */
|
|
879
|
|
880 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
|
|
881
|
|
882 IIFORMAT_HAS_METHOD (bmp, validate);
|
|
883 IIFORMAT_HAS_METHOD (bmp, normalize);
|
|
884 IIFORMAT_HAS_METHOD (bmp, possible_dest_types);
|
|
885 IIFORMAT_HAS_METHOD (bmp, instantiate);
|
|
886
|
|
887 IIFORMAT_VALID_KEYWORD (bmp, Q_data, check_valid_string);
|
|
888 IIFORMAT_VALID_KEYWORD (bmp, Q_file, check_valid_string);
|
|
889 }
|
|
890
|
|
891 void
|
|
892 vars_of_glyphs_mswindows (void)
|
|
893 {
|
|
894 Fprovide (Qbmp);
|
|
895 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
|
|
896 A list of the directories in which mswindows bitmap files may be found.
|
|
897 This is used by the `make-image-instance' function.
|
|
898 */ );
|
|
899 Vmswindows_bitmap_file_path = Qnil;
|
|
900 }
|
|
901
|
|
902 void
|
|
903 complex_vars_of_glyphs_mswindows (void)
|
|
904 {
|
|
905 }
|