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