Mercurial > hg > xemacs-beta
comparison src/glyphs-x.c @ 280:7df0dd720c89 r21-0b38
Import from CVS: tag r21-0b38
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:32:22 +0200 |
parents | 90d73dddcdc4 |
children | e11d67e05968 |
comparison
equal
deleted
inserted
replaced
279:c20b2fb5bb0a | 280:7df0dd720c89 |
---|---|
150 /* proper display */ | 150 /* proper display */ |
151 /************************************************************************/ | 151 /************************************************************************/ |
152 static XImage * | 152 static XImage * |
153 convert_EImage_to_XImage (Lisp_Object device, int width, int height, | 153 convert_EImage_to_XImage (Lisp_Object device, int width, int height, |
154 unsigned char *pic, unsigned long **pixtbl, | 154 unsigned char *pic, unsigned long **pixtbl, |
155 int *pixcount, int *npixels) | 155 int *npixels) |
156 { | 156 { |
157 Display *dpy; | 157 Display *dpy; |
158 Colormap cmap; | 158 Colormap cmap; |
159 Visual *vis; | 159 Visual *vis; |
160 XImage *outimg; | 160 XImage *outimg; |
199 outimg->data = (char *) data; | 199 outimg->data = (char *) data; |
200 | 200 |
201 if (vis->class == PseudoColor) | 201 if (vis->class == PseudoColor) |
202 { | 202 { |
203 unsigned long pixarray[256]; | 203 unsigned long pixarray[256]; |
204 int n; | 204 int pixcount, n; |
205 /* use our quantize table to allocate the colors */ | 205 /* use our quantize table to allocate the colors */ |
206 *pixcount = 32; | 206 pixcount = 32; |
207 *pixtbl = xnew_array (unsigned long, *pixcount); | 207 *pixtbl = xnew_array (unsigned long, pixcount); |
208 *npixels = 0; | 208 *npixels = 0; |
209 | 209 |
210 /* ### should implement a sort by popularity to assure proper allocation */ | 210 /* ### should implement a sort by popularity to assure proper allocation */ |
211 n = *npixels; | 211 n = *npixels; |
212 for (i = 0; i < qtable->num_active_colors; i++) | 212 for (i = 0; i < qtable->num_active_colors; i++) |
219 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0; | 219 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0; |
220 color.flags = DoRed | DoGreen | DoBlue; | 220 color.flags = DoRed | DoGreen | DoBlue; |
221 res = allocate_nearest_color (dpy, cmap, vis, &color); | 221 res = allocate_nearest_color (dpy, cmap, vis, &color); |
222 if (res > 0 && res < 3) | 222 if (res > 0 && res < 3) |
223 { | 223 { |
224 DO_REALLOC(*pixtbl, *pixcount, n+1, unsigned long); | 224 DO_REALLOC(*pixtbl, pixcount, n+1, unsigned long); |
225 (*pixtbl)[n] = color.pixel; | 225 (*pixtbl)[n] = color.pixel; |
226 n++; | 226 n++; |
227 } | 227 } |
228 pixarray[i] = color.pixel; | 228 pixarray[i] = color.pixel; |
229 } | 229 } |
472 | 472 |
473 /* Given a pixmap filename, look through all of the "standard" places | 473 /* Given a pixmap filename, look through all of the "standard" places |
474 where the file might be located. Return a full pathname if found; | 474 where the file might be located. Return a full pathname if found; |
475 otherwise, return Qnil. */ | 475 otherwise, return Qnil. */ |
476 | 476 |
477 Lisp_Object | 477 static Lisp_Object |
478 x_locate_pixmap_file (Lisp_Object name) | 478 x_locate_pixmap_file (Lisp_Object name) |
479 { | 479 { |
480 /* This function can GC if IN_REDISPLAY is false */ | 480 /* This function can GC if IN_REDISPLAY is false */ |
481 Display *display; | 481 Display *display; |
482 | 482 |
554 { | 554 { |
555 return x_locate_pixmap_file (name); | 555 return x_locate_pixmap_file (name); |
556 } | 556 } |
557 | 557 |
558 #if 0 | 558 #if 0 |
559 /* If INSTANTIATOR refers to inline data, return Qnil. | |
560 If INSTANTIATOR refers to data in a file, return the full filename | |
561 if it exists; otherwise, return a cons of (filename). | |
562 | |
563 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the | |
564 keywords used to look up the file and inline data, | |
565 respectively, in the instantiator. Normally these would | |
566 be Q_file and Q_data, but might be different for mask data. */ | |
567 | |
568 static Lisp_Object | |
569 potential_pixmap_file_instantiator (Lisp_Object instantiator, | |
570 Lisp_Object file_keyword, | |
571 Lisp_Object data_keyword) | |
572 { | |
573 Lisp_Object file; | |
574 Lisp_Object data; | |
575 | |
576 assert (VECTORP (instantiator)); | |
577 | |
578 data = find_keyword_in_vector (instantiator, data_keyword); | |
579 file = find_keyword_in_vector (instantiator, file_keyword); | |
580 | |
581 if (!NILP (file) && NILP (data)) | |
582 { | |
583 Lisp_Object retval = locate_pixmap_file (file); | |
584 if (!NILP (retval)) | |
585 return retval; | |
586 else | |
587 return Fcons (file, Qnil); /* should have been file */ | |
588 } | |
589 | |
590 return Qnil; | |
591 } | |
592 | |
593 | |
594 static Lisp_Object | |
595 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type, | |
596 Lisp_Object image_type_tag) | |
597 { | |
598 /* This function can call lisp */ | |
599 Lisp_Object file = Qnil; | |
600 struct gcpro gcpro1, gcpro2; | |
601 Lisp_Object alist = Qnil; | |
602 | |
603 GCPRO2 (file, alist); | |
604 | |
605 /* Now, convert any file data into inline data. At the end of this, | |
606 `data' will contain the inline data (if any) or Qnil, and `file' | |
607 will contain the name this data was derived from (if known) or | |
608 Qnil. | |
609 | |
610 Note that if we cannot generate any regular inline data, we | |
611 skip out. */ | |
612 | |
613 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data, | |
614 console_type); | |
615 | |
616 if (CONSP (file)) /* failure locating filename */ | |
617 signal_double_file_error ("Opening pixmap file", | |
618 "no such file or directory", | |
619 Fcar (file)); | |
620 | |
621 if (NILP (file)) /* no conversion necessary */ | |
622 RETURN_UNGCPRO (inst); | |
623 | |
624 alist = tagged_vector_to_alist (inst); | |
625 | |
626 { | |
627 Lisp_Object data = make_string_from_file (file); | |
628 alist = remassq_no_quit (Q_file, alist); | |
629 /* there can't be a :data at this point. */ | |
630 alist = Fcons (Fcons (Q_file, file), | |
631 Fcons (Fcons (Q_data, data), alist)); | |
632 } | |
633 | |
634 { | |
635 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist); | |
636 free_alist (alist); | |
637 RETURN_UNGCPRO (result); | |
638 } | |
639 } | |
640 #endif | |
641 | |
642 #if 0 | |
643 static void | 559 static void |
644 write_lisp_string_to_temp_file (Lisp_Object string, char *filename_out) | 560 write_lisp_string_to_temp_file (Lisp_Object string, char *filename_out) |
645 { | 561 { |
646 Lisp_Object instream, outstream; | 562 Lisp_Object instream, outstream; |
647 Lstream *istr, *ostr; | 563 Lstream *istr, *ostr; |
907 Lisp_Object instantiator, | 823 Lisp_Object instantiator, |
908 Lisp_Object domain) | 824 Lisp_Object domain) |
909 { | 825 { |
910 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | 826 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
911 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device)); | 827 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device)); |
912 unsigned long *pixtbl; | 828 unsigned long *pixtbl = NULL; |
913 int pixcount; | 829 int npixels = 0; |
914 int npixels; | |
915 XImage* ximage; | 830 XImage* ximage; |
916 | 831 |
917 ximage = convert_EImage_to_XImage (device, width, height, eimage, | 832 ximage = convert_EImage_to_XImage (device, width, height, eimage, |
918 &pixtbl, &pixcount, &npixels); | 833 &pixtbl, &npixels); |
919 if (!ximage) | 834 if (!ximage) |
920 signal_image_error("EImage to XImage conversion failed", instantiator); | 835 { |
921 | 836 if (pixtbl) xfree (pixtbl); |
837 signal_image_error("EImage to XImage conversion failed", instantiator); | |
838 } | |
839 | |
922 /* Now create the pixmap and set up the image instance */ | 840 /* Now create the pixmap and set up the image instance */ |
923 init_image_instance_from_x_image (ii, ximage, dest_mask, | 841 init_image_instance_from_x_image (ii, ximage, dest_mask, |
924 cmap, pixtbl, npixels, | 842 cmap, pixtbl, npixels, |
925 instantiator); | 843 instantiator); |
926 | 844 |
1360 #ifdef HAVE_XPM | 1278 #ifdef HAVE_XPM |
1361 | 1279 |
1362 /********************************************************************** | 1280 /********************************************************************** |
1363 * XPM * | 1281 * XPM * |
1364 **********************************************************************/ | 1282 **********************************************************************/ |
1365 | |
1366 static Lisp_Object | |
1367 pixmap_to_lisp_data (Lisp_Object name, int ok_if_data_invalid) | |
1368 { | |
1369 char **data; | |
1370 int result; | |
1371 | |
1372 result = XpmReadFileToData ((char *) XSTRING_DATA (name), &data); | |
1373 | |
1374 if (result == XpmSuccess) | |
1375 { | |
1376 Lisp_Object retval = Qnil; | |
1377 struct buffer *old_buffer = current_buffer; | |
1378 Lisp_Object temp_buffer = | |
1379 Fget_buffer_create (build_string (" *pixmap conversion*")); | |
1380 int elt; | |
1381 int height, width, ncolors; | |
1382 struct gcpro gcpro1, gcpro2, gcpro3; | |
1383 int speccount = specpdl_depth (); | |
1384 | |
1385 GCPRO3 (name, retval, temp_buffer); | |
1386 | |
1387 specbind (Qinhibit_quit, Qt); | |
1388 set_buffer_internal (XBUFFER (temp_buffer)); | |
1389 Ferase_buffer (Qnil); | |
1390 | |
1391 buffer_insert_c_string (current_buffer, "/* XPM */\r"); | |
1392 buffer_insert_c_string (current_buffer, "static char *pixmap[] = {\r"); | |
1393 | |
1394 sscanf (data[0], "%d %d %d", &height, &width, &ncolors); | |
1395 for (elt = 0; elt <= width + ncolors; elt++) | |
1396 { | |
1397 buffer_insert_c_string (current_buffer, "\""); | |
1398 buffer_insert_c_string (current_buffer, data[elt]); | |
1399 | |
1400 if (elt < width + ncolors) | |
1401 buffer_insert_c_string (current_buffer, "\",\r"); | |
1402 else | |
1403 buffer_insert_c_string (current_buffer, "\"};\r"); | |
1404 } | |
1405 | |
1406 retval = Fbuffer_substring (Qnil, Qnil, Qnil); | |
1407 XpmFree (data); | |
1408 | |
1409 set_buffer_internal (old_buffer); | |
1410 unbind_to (speccount, Qnil); | |
1411 | |
1412 RETURN_UNGCPRO (retval); | |
1413 } | |
1414 | |
1415 switch (result) | |
1416 { | |
1417 case XpmFileInvalid: | |
1418 { | |
1419 if (ok_if_data_invalid) | |
1420 return Qt; | |
1421 signal_image_error ("invalid XPM data in file", name); | |
1422 } | |
1423 case XpmNoMemory: | |
1424 { | |
1425 signal_double_file_error ("Reading pixmap file", | |
1426 "out of memory", name); | |
1427 } | |
1428 case XpmOpenFailed: | |
1429 { | |
1430 /* should never happen? */ | |
1431 signal_double_file_error ("Opening pixmap file", | |
1432 "no such file or directory", name); | |
1433 } | |
1434 default: | |
1435 { | |
1436 signal_double_file_error_2 ("Parsing pixmap file", | |
1437 "unknown error code", | |
1438 make_int (result), name); | |
1439 break; | |
1440 } | |
1441 } | |
1442 | |
1443 return Qnil; /* not reached */ | |
1444 } | |
1445 | |
1446 Lisp_Object | |
1447 x_xpm_normalize (Lisp_Object inst, Lisp_Object console_type) | |
1448 { | |
1449 Lisp_Object file = Qnil; | |
1450 Lisp_Object color_symbols; | |
1451 struct gcpro gcpro1, gcpro2; | |
1452 Lisp_Object alist = Qnil; | |
1453 | |
1454 GCPRO2 (file, alist); | |
1455 | |
1456 /* Now, convert any file data into inline data. At the end of this, | |
1457 `data' will contain the inline data (if any) or Qnil, and | |
1458 `file' will contain the name this data was derived from (if | |
1459 known) or Qnil. | |
1460 | |
1461 Note that if we cannot generate any regular inline data, we | |
1462 skip out. */ | |
1463 | |
1464 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data, | |
1465 console_type); | |
1466 | |
1467 if (CONSP (file)) /* failure locating filename */ | |
1468 signal_double_file_error ("Opening pixmap file", | |
1469 "no such file or directory", | |
1470 Fcar (file)); | |
1471 | |
1472 color_symbols = find_keyword_in_vector_or_given (inst, Q_color_symbols, | |
1473 Qunbound); | |
1474 | |
1475 if (NILP (file) && !UNBOUNDP (color_symbols)) | |
1476 /* no conversion necessary */ | |
1477 RETURN_UNGCPRO (inst); | |
1478 | |
1479 alist = tagged_vector_to_alist (inst); | |
1480 | |
1481 if (!NILP (file)) | |
1482 { | |
1483 Lisp_Object data = pixmap_to_lisp_data (file, 0); | |
1484 alist = remassq_no_quit (Q_file, alist); | |
1485 /* there can't be a :data at this point. */ | |
1486 alist = Fcons (Fcons (Q_file, file), | |
1487 Fcons (Fcons (Q_data, data), alist)); | |
1488 } | |
1489 | |
1490 if (UNBOUNDP (color_symbols)) | |
1491 { | |
1492 color_symbols = evaluate_xpm_color_symbols (); | |
1493 alist = Fcons (Fcons (Q_color_symbols, color_symbols), | |
1494 alist); | |
1495 } | |
1496 | |
1497 { | |
1498 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist); | |
1499 free_alist (alist); | |
1500 RETURN_UNGCPRO (result); | |
1501 } | |
1502 } | |
1503 | |
1504 /* xpm 3.2g and better has XpmCreatePixmapFromBuffer()... | 1283 /* xpm 3.2g and better has XpmCreatePixmapFromBuffer()... |
1505 There was no version number in xpm.h before 3.3, but this should do. | 1284 There was no version number in xpm.h before 3.3, but this should do. |
1506 */ | 1285 */ |
1507 #if (XpmVersion >= 3) || defined(XpmExactColors) | 1286 #if (XpmVersion >= 3) || defined(XpmExactColors) |
1508 # define XPM_DOES_BUFFERS | 1287 # define XPM_DOES_BUFFERS |
1592 to all zeros was ok (and also that it's ok to call XpmFreeAttributes() | 1371 to all zeros was ok (and also that it's ok to call XpmFreeAttributes() |
1593 multiple times, since it zeros slots as it frees them...) */ | 1372 multiple times, since it zeros slots as it frees them...) */ |
1594 XpmFreeAttributes (xpmattrs); | 1373 XpmFreeAttributes (xpmattrs); |
1595 } | 1374 } |
1596 | 1375 |
1597 void | 1376 static void |
1598 x_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | 1377 x_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, |
1599 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | 1378 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
1600 int dest_mask, Lisp_Object domain) | 1379 int dest_mask, Lisp_Object domain) |
1601 { | 1380 { |
1602 /* This function can GC */ | 1381 /* This function can GC */ |
1605 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | 1384 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); |
1606 Display *dpy; | 1385 Display *dpy; |
1607 Screen *xs; | 1386 Screen *xs; |
1608 Colormap cmap; | 1387 Colormap cmap; |
1609 int depth; | 1388 int depth; |
1389 Visual *visual; | |
1610 Pixmap pixmap; | 1390 Pixmap pixmap; |
1611 Pixmap mask = 0; | 1391 Pixmap mask = 0; |
1612 XpmAttributes xpmattrs; | 1392 XpmAttributes xpmattrs; |
1613 int result; | 1393 int result; |
1614 XpmColorSymbol *color_symbols; | 1394 XpmColorSymbol *color_symbols; |
1636 | IMAGE_POINTER_MASK); | 1416 | IMAGE_POINTER_MASK); |
1637 force_mono = (type != IMAGE_COLOR_PIXMAP); | 1417 force_mono = (type != IMAGE_COLOR_PIXMAP); |
1638 | 1418 |
1639 #if 1 | 1419 #if 1 |
1640 /* Although I haven't found it documented yet, it appears that pointers are | 1420 /* Although I haven't found it documented yet, it appears that pointers are |
1641 always colored via the default window colormap... Sigh. However, with | 1421 always colored via the default window colormap... Sigh. */ |
1642 the current color structure, this will blow the doors off as things aren't set up | |
1643 to differenciate between two colormaps per console. AARGH! */ | |
1644 if (type == IMAGE_POINTER) | 1422 if (type == IMAGE_POINTER) |
1645 { | 1423 { |
1646 cmap = DefaultColormap(dpy, DefaultScreen(dpy)); | 1424 cmap = DefaultColormap(dpy, DefaultScreen(dpy)); |
1647 depth = DefaultDepthOfScreen (xs); | 1425 depth = DefaultDepthOfScreen (xs); |
1426 visual = DefaultVisualOfScreen (xs); | |
1648 } | 1427 } |
1649 else | 1428 else |
1650 { | 1429 { |
1651 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); | 1430 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); |
1652 depth = DEVICE_X_DEPTH (XDEVICE(device)); | 1431 depth = DEVICE_X_DEPTH (XDEVICE(device)); |
1432 visual = DEVICE_X_VISUAL (XDEVICE(device)); | |
1653 } | 1433 } |
1654 #else | 1434 #else |
1655 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); | 1435 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); |
1656 depth = DEVICE_X_DEPTH (XDEVICE(device)); | 1436 depth = DEVICE_X_DEPTH (XDEVICE(device)); |
1437 visual = DEVICE_X_VISUAL (XDEVICE(device)); | |
1657 #endif | 1438 #endif |
1658 | 1439 |
1659 x_initialize_pixmap_image_instance (ii, type); | 1440 x_initialize_pixmap_image_instance (ii, type); |
1660 | 1441 |
1661 assert (!NILP (data)); | 1442 assert (!NILP (data)); |
1678 { | 1459 { |
1679 xpmattrs.closeness = 65535; | 1460 xpmattrs.closeness = 65535; |
1680 xpmattrs.valuemask |= XpmCloseness; | 1461 xpmattrs.valuemask |= XpmCloseness; |
1681 xpmattrs.depth = depth; | 1462 xpmattrs.depth = depth; |
1682 xpmattrs.valuemask |= XpmDepth; | 1463 xpmattrs.valuemask |= XpmDepth; |
1683 xpmattrs.visual = DEVICE_X_VISUAL (XDEVICE(device)); | 1464 xpmattrs.visual = visual; |
1684 xpmattrs.valuemask |= XpmVisual; | 1465 xpmattrs.valuemask |= XpmVisual; |
1685 xpmattrs.colormap = cmap; | 1466 xpmattrs.colormap = cmap; |
1686 xpmattrs.valuemask |= XpmColormap; | 1467 xpmattrs.valuemask |= XpmColormap; |
1687 } | 1468 } |
1688 | 1469 |
4573 CONSOLE_HAS_METHOD (x, image_instance_equal); | 4354 CONSOLE_HAS_METHOD (x, image_instance_equal); |
4574 CONSOLE_HAS_METHOD (x, image_instance_hash); | 4355 CONSOLE_HAS_METHOD (x, image_instance_hash); |
4575 CONSOLE_HAS_METHOD (x, colorize_image_instance); | 4356 CONSOLE_HAS_METHOD (x, colorize_image_instance); |
4576 CONSOLE_HAS_METHOD (x, init_image_instance_from_eimage); | 4357 CONSOLE_HAS_METHOD (x, init_image_instance_from_eimage); |
4577 CONSOLE_HAS_METHOD (x, locate_pixmap_file); | 4358 CONSOLE_HAS_METHOD (x, locate_pixmap_file); |
4359 #ifdef HAVE_XPM | |
4360 CONSOLE_HAS_METHOD (x, xpm_instantiate); | |
4361 #endif | |
4578 } | 4362 } |
4579 | 4363 |
4580 void | 4364 void |
4581 image_instantiator_format_create_glyphs_x (void) | 4365 image_instantiator_format_create_glyphs_x (void) |
4582 { | 4366 { |
4586 | 4370 |
4587 IIFORMAT_HAS_METHOD (xbm, validate); | 4371 IIFORMAT_HAS_METHOD (xbm, validate); |
4588 IIFORMAT_HAS_METHOD (xbm, normalize); | 4372 IIFORMAT_HAS_METHOD (xbm, normalize); |
4589 IIFORMAT_HAS_METHOD (xbm, possible_dest_types); | 4373 IIFORMAT_HAS_METHOD (xbm, possible_dest_types); |
4590 IIFORMAT_HAS_METHOD (xbm, instantiate); | 4374 IIFORMAT_HAS_METHOD (xbm, instantiate); |
4375 | |
4591 | 4376 |
4592 IIFORMAT_VALID_KEYWORD (xbm, Q_data, check_valid_xbm_inline); | 4377 IIFORMAT_VALID_KEYWORD (xbm, Q_data, check_valid_xbm_inline); |
4593 IIFORMAT_VALID_KEYWORD (xbm, Q_file, check_valid_string); | 4378 IIFORMAT_VALID_KEYWORD (xbm, Q_file, check_valid_string); |
4594 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_data, check_valid_xbm_inline); | 4379 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_data, check_valid_xbm_inline); |
4595 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_file, check_valid_string); | 4380 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_file, check_valid_string); |