diff options
| author | Jason Rumney | 2002-03-24 15:50:33 +0000 |
|---|---|---|
| committer | Jason Rumney | 2002-03-24 15:50:33 +0000 |
| commit | 217e5be0a12d7573094b428cc95f4ed2970e3907 (patch) | |
| tree | 0cb2bc978a0e2526c5dd83df70610ca5f0521ed9 /src | |
| parent | bb2f7e35d4b72c942828afb21a2e0876fbd5a37c (diff) | |
| download | emacs-217e5be0a12d7573094b428cc95f4ed2970e3907.tar.gz emacs-217e5be0a12d7573094b428cc95f4ed2970e3907.zip | |
(xbm_scan, xbm_load_image, xbm_read_bitmap_data)
(xbm_file_p): Add prototypes.
(xbm_format, xbm_image_p): Sync with xfns.c.
(reflect_byte): New function.
(xbm_read_bitmap_data): Sync with xfns.c, adapt for Windows.
(xbm_load_image): Create bitmaps with a depth of 1.
(init_xfns): Enable XBM images.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 10 | ||||
| -rw-r--r-- | src/w32fns.c | 97 |
2 files changed, 72 insertions, 35 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index af21da83d78..7b93227c8c1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2002-03-24 Jason Rumney <jasonr@gnu.org> | ||
| 2 | |||
| 3 | * w32fns.c (xbm_scan, xbm_load_image, xbm_read_bitmap_data) | ||
| 4 | (xbm_file_p): Add prototypes. | ||
| 5 | (xbm_format, xbm_image_p): Sync with xfns.c. | ||
| 6 | (reflect_byte): New function. | ||
| 7 | (xbm_read_bitmap_data): Sync with xfns.c, adapt for Windows. | ||
| 8 | (xbm_load_image): Create bitmaps with a depth of 1. | ||
| 9 | (init_xfns): Enable XBM images. | ||
| 10 | |||
| 1 | 2002-03-23 Jason Rumney <jasonr@gnu.org> | 11 | 2002-03-23 Jason Rumney <jasonr@gnu.org> |
| 2 | 12 | ||
| 3 | * w32term.c (w32_handle_tool_bar_click): Detect up and down events | 13 | * w32term.c (w32_handle_tool_bar_click): Detect up and down events |
diff --git a/src/w32fns.c b/src/w32fns.c index 6712541f094..3740445a3e5 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -9507,12 +9507,14 @@ slurp_file (file, size) | |||
| 9507 | XBM images | 9507 | XBM images |
| 9508 | ***********************************************************************/ | 9508 | ***********************************************************************/ |
| 9509 | 9509 | ||
| 9510 | static int xbm_scan P_ ((char **, char *, char *, int *)); | ||
| 9510 | static int xbm_load P_ ((struct frame *f, struct image *img)); | 9511 | static int xbm_load P_ ((struct frame *f, struct image *img)); |
| 9511 | static int xbm_load_image_from_file P_ ((struct frame *f, struct image *img, | 9512 | static int xbm_load_image P_ ((struct frame *f, struct image *img, |
| 9512 | Lisp_Object file)); | 9513 | char *, char *)); |
| 9513 | static int xbm_image_p P_ ((Lisp_Object object)); | 9514 | static int xbm_image_p P_ ((Lisp_Object object)); |
| 9514 | static int xbm_read_bitmap_file_data P_ ((char *, int *, int *, | 9515 | static int xbm_read_bitmap_data P_ ((char *, char *, int *, int *, |
| 9515 | unsigned char **)); | 9516 | unsigned char **)); |
| 9517 | static int xbm_file_p P_ ((Lisp_Object)); | ||
| 9516 | 9518 | ||
| 9517 | 9519 | ||
| 9518 | /* Indices of image specification fields in xbm_format, below. */ | 9520 | /* Indices of image specification fields in xbm_format, below. */ |
| @@ -9545,13 +9547,14 @@ static struct image_keyword xbm_format[XBM_LAST] = | |||
| 9545 | {":width", IMAGE_POSITIVE_INTEGER_VALUE, 0}, | 9547 | {":width", IMAGE_POSITIVE_INTEGER_VALUE, 0}, |
| 9546 | {":height", IMAGE_POSITIVE_INTEGER_VALUE, 0}, | 9548 | {":height", IMAGE_POSITIVE_INTEGER_VALUE, 0}, |
| 9547 | {":data", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 9549 | {":data", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9548 | {":foreground", IMAGE_STRING_OR_NIL_VALUE, 0}, | 9550 | {":foreground", IMAGE_STRING_OR_NIL_VALUE, 0}, |
| 9549 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0}, | 9551 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0}, |
| 9550 | {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0}, | 9552 | {":ascent", IMAGE_ASCENT_VALUE, 0}, |
| 9551 | {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, | 9553 | {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, |
| 9552 | {":relief", IMAGE_INTEGER_VALUE, 0}, | 9554 | {":relief", IMAGE_INTEGER_VALUE, 0}, |
| 9553 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 9555 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9554 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0} | 9556 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9557 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0} | ||
| 9555 | }; | 9558 | }; |
| 9556 | 9559 | ||
| 9557 | /* Structure describing the image type XBM. */ | 9560 | /* Structure describing the image type XBM. */ |
| @@ -9594,10 +9597,14 @@ enum xbm_token | |||
| 9594 | 3. a vector of strings or bool-vectors, one for each line of the | 9597 | 3. a vector of strings or bool-vectors, one for each line of the |
| 9595 | bitmap. | 9598 | bitmap. |
| 9596 | 9599 | ||
| 9600 | 4. A string containing an in-memory XBM file. WIDTH and HEIGHT | ||
| 9601 | may not be specified in this case because they are defined in the | ||
| 9602 | XBM file. | ||
| 9603 | |||
| 9597 | Both the file and data forms may contain the additional entries | 9604 | Both the file and data forms may contain the additional entries |
| 9598 | `:background COLOR' and `:foreground COLOR'. If not present, | 9605 | `:background COLOR' and `:foreground COLOR'. If not present, |
| 9599 | foreground and background of the frame on which the image is | 9606 | foreground and background of the frame on which the image is |
| 9600 | displayed, is used. */ | 9607 | displayed is used. */ |
| 9601 | 9608 | ||
| 9602 | static int | 9609 | static int |
| 9603 | xbm_image_p (object) | 9610 | xbm_image_p (object) |
| @@ -9616,6 +9623,12 @@ xbm_image_p (object) | |||
| 9616 | if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_DATA].count) | 9623 | if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_DATA].count) |
| 9617 | return 0; | 9624 | return 0; |
| 9618 | } | 9625 | } |
| 9626 | else if (kw[XBM_DATA].count && xbm_file_p (kw[XBM_DATA].value)) | ||
| 9627 | { | ||
| 9628 | /* In-memory XBM file. */ | ||
| 9629 | if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_FILE].count) | ||
| 9630 | return 0; | ||
| 9631 | } | ||
| 9619 | else | 9632 | else |
| 9620 | { | 9633 | { |
| 9621 | Lisp_Object data; | 9634 | Lisp_Object data; |
| @@ -9677,11 +9690,6 @@ xbm_image_p (object) | |||
| 9677 | return 0; | 9690 | return 0; |
| 9678 | } | 9691 | } |
| 9679 | 9692 | ||
| 9680 | /* Baseline must be a value between 0 and 100 (a percentage). */ | ||
| 9681 | if (kw[XBM_ASCENT].count | ||
| 9682 | && XFASTINT (kw[XBM_ASCENT].value) > 100) | ||
| 9683 | return 0; | ||
| 9684 | |||
| 9685 | return 1; | 9693 | return 1; |
| 9686 | } | 9694 | } |
| 9687 | 9695 | ||
| @@ -9780,6 +9788,21 @@ xbm_scan (s, end, sval, ival) | |||
| 9780 | } | 9788 | } |
| 9781 | 9789 | ||
| 9782 | 9790 | ||
| 9791 | /* XBM bits seem to be backward within bytes compared with how | ||
| 9792 | Windows does things. */ | ||
| 9793 | static unsigned char reflect_byte (unsigned char orig) | ||
| 9794 | { | ||
| 9795 | int i; | ||
| 9796 | unsigned char reflected = 0x00; | ||
| 9797 | for (i = 0; i < 8; i++) | ||
| 9798 | { | ||
| 9799 | if (orig & (0x01 << i)) | ||
| 9800 | reflected |= 0x80 >> i; | ||
| 9801 | } | ||
| 9802 | return reflected; | ||
| 9803 | } | ||
| 9804 | |||
| 9805 | |||
| 9783 | /* Replacement for XReadBitmapFileData which isn't available under old | 9806 | /* Replacement for XReadBitmapFileData which isn't available under old |
| 9784 | X versions. CONTENTS is a pointer to a buffer to parse; END is the | 9807 | X versions. CONTENTS is a pointer to a buffer to parse; END is the |
| 9785 | buffer's end. Set *WIDTH and *HEIGHT to the width and height of | 9808 | buffer's end. Set *WIDTH and *HEIGHT to the width and height of |
| @@ -9797,13 +9820,13 @@ xbm_read_bitmap_data (contents, end, width, height, data) | |||
| 9797 | char buffer[BUFSIZ]; | 9820 | char buffer[BUFSIZ]; |
| 9798 | int padding_p = 0; | 9821 | int padding_p = 0; |
| 9799 | int v10 = 0; | 9822 | int v10 = 0; |
| 9800 | int bytes_per_line, i, nbytes; | 9823 | int bytes_in_per_line, bytes_out_per_line, i, nbytes; |
| 9801 | unsigned char *p; | 9824 | unsigned char *p; |
| 9802 | int value; | 9825 | int value; |
| 9803 | int LA1; | 9826 | int LA1; |
| 9804 | 9827 | ||
| 9805 | #define match() \ | 9828 | #define match() \ |
| 9806 | LA1 = xbm_scan (contents, end, buffer, &value) | 9829 | LA1 = xbm_scan (&s, end, buffer, &value) |
| 9807 | 9830 | ||
| 9808 | #define expect(TOKEN) \ | 9831 | #define expect(TOKEN) \ |
| 9809 | if (LA1 != (TOKEN)) \ | 9832 | if (LA1 != (TOKEN)) \ |
| @@ -9850,6 +9873,10 @@ xbm_read_bitmap_data (contents, end, width, height, data) | |||
| 9850 | expect_ident ("static"); | 9873 | expect_ident ("static"); |
| 9851 | if (LA1 == XBM_TK_IDENT) | 9874 | if (LA1 == XBM_TK_IDENT) |
| 9852 | { | 9875 | { |
| 9876 | /* On Windows, all images need padding to 16 bit boundaries. */ | ||
| 9877 | if (*width % 16 && *width % 16 < 9) | ||
| 9878 | padding_p = 1; | ||
| 9879 | |||
| 9853 | if (strcmp (buffer, "unsigned") == 0) | 9880 | if (strcmp (buffer, "unsigned") == 0) |
| 9854 | { | 9881 | { |
| 9855 | match (); | 9882 | match (); |
| @@ -9859,8 +9886,6 @@ xbm_read_bitmap_data (contents, end, width, height, data) | |||
| 9859 | { | 9886 | { |
| 9860 | match (); | 9887 | match (); |
| 9861 | v10 = 1; | 9888 | v10 = 1; |
| 9862 | if (*width % 16 && *width % 16 < 9) | ||
| 9863 | padding_p = 1; | ||
| 9864 | } | 9889 | } |
| 9865 | else if (strcmp (buffer, "char") == 0) | 9890 | else if (strcmp (buffer, "char") == 0) |
| 9866 | match (); | 9891 | match (); |
| @@ -9876,21 +9901,23 @@ xbm_read_bitmap_data (contents, end, width, height, data) | |||
| 9876 | expect ('='); | 9901 | expect ('='); |
| 9877 | expect ('{'); | 9902 | expect ('{'); |
| 9878 | 9903 | ||
| 9879 | bytes_per_line = (*width + 7) / 8 + padding_p; | 9904 | /* Bytes per line on input. Only count padding for v10 XBMs. */ |
| 9880 | nbytes = bytes_per_line * *height; | 9905 | bytes_in_per_line = (*width + 7) / 8 + (v10 ? padding_p : 0); |
| 9881 | p = *data = (char *) xmalloc (nbytes); | 9906 | bytes_out_per_line = (*width + 7) / 8 + padding_p; |
| 9907 | |||
| 9908 | nbytes = bytes_in_per_line * *height; | ||
| 9909 | p = *data = (char *) xmalloc (bytes_out_per_line * *height); | ||
| 9882 | 9910 | ||
| 9883 | if (v10) | 9911 | if (v10) |
| 9884 | { | 9912 | { |
| 9885 | |||
| 9886 | for (i = 0; i < nbytes; i += 2) | 9913 | for (i = 0; i < nbytes; i += 2) |
| 9887 | { | 9914 | { |
| 9888 | int val = value; | 9915 | int val = value; |
| 9889 | expect (XBM_TK_NUMBER); | 9916 | expect (XBM_TK_NUMBER); |
| 9890 | 9917 | ||
| 9891 | *p++ = val; | 9918 | *p++ = reflect_byte (val); |
| 9892 | if (!padding_p || ((i + 2) % bytes_per_line)) | 9919 | if (!padding_p || ((i + 2) % bytes_in_per_line)) |
| 9893 | *p++ = value >> 8; | 9920 | *p++ = reflect_byte (value >> 8); |
| 9894 | 9921 | ||
| 9895 | if (LA1 == ',' || LA1 == '}') | 9922 | if (LA1 == ',' || LA1 == '}') |
| 9896 | match (); | 9923 | match (); |
| @@ -9905,8 +9932,10 @@ xbm_read_bitmap_data (contents, end, width, height, data) | |||
| 9905 | int val = value; | 9932 | int val = value; |
| 9906 | expect (XBM_TK_NUMBER); | 9933 | expect (XBM_TK_NUMBER); |
| 9907 | 9934 | ||
| 9908 | *p++ = val; | 9935 | *p++ = reflect_byte (val); |
| 9909 | 9936 | if (padding_p && ((i + 1) % bytes_in_per_line) == 0) | |
| 9937 | *p++ = 0; | ||
| 9938 | |||
| 9910 | if (LA1 == ',' || LA1 == '}') | 9939 | if (LA1 == ',' || LA1 == '}') |
| 9911 | match (); | 9940 | match (); |
| 9912 | else | 9941 | else |
| @@ -9949,9 +9978,6 @@ xbm_load_image (f, img, contents, end) | |||
| 9949 | rc = xbm_read_bitmap_data (contents, end, &img->width, &img->height, &data); | 9978 | rc = xbm_read_bitmap_data (contents, end, &img->width, &img->height, &data); |
| 9950 | if (rc) | 9979 | if (rc) |
| 9951 | { | 9980 | { |
| 9952 | int depth = one_w32_display_info.n_cbits; | ||
| 9953 | int planes = one_w32_display_info.n_planes; | ||
| 9954 | |||
| 9955 | unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); | 9981 | unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); |
| 9956 | unsigned long background = FRAME_BACKGROUND_PIXEL (f); | 9982 | unsigned long background = FRAME_BACKGROUND_PIXEL (f); |
| 9957 | Lisp_Object value; | 9983 | Lisp_Object value; |
| @@ -9970,7 +9996,7 @@ xbm_load_image (f, img, contents, end) | |||
| 9970 | img->background_valid = 1; | 9996 | img->background_valid = 1; |
| 9971 | } | 9997 | } |
| 9972 | img->pixmap | 9998 | img->pixmap |
| 9973 | = CreateBitmap (img->width, img->height, planes, depth, data); | 9999 | = CreateBitmap (img->width, img->height, 1, 1, data); |
| 9974 | 10000 | ||
| 9975 | xfree (data); | 10001 | xfree (data); |
| 9976 | 10002 | ||
| @@ -10061,7 +10087,7 @@ xbm_load (f, img) | |||
| 10061 | data = image_spec_value (img->spec, QCdata, NULL); | 10087 | data = image_spec_value (img->spec, QCdata, NULL); |
| 10062 | in_memory_file_p = xbm_file_p (data); | 10088 | in_memory_file_p = xbm_file_p (data); |
| 10063 | 10089 | ||
| 10064 | /* Parse the list specification. */ | 10090 | /* Parse the image specification. */ |
| 10065 | bcopy (xbm_format, fmt, sizeof fmt); | 10091 | bcopy (xbm_format, fmt, sizeof fmt); |
| 10066 | parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm); | 10092 | parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm); |
| 10067 | xassert (parsed_p); | 10093 | xassert (parsed_p); |
| @@ -10073,6 +10099,7 @@ xbm_load (f, img) | |||
| 10073 | img->height = XFASTINT (fmt[XBM_HEIGHT].value); | 10099 | img->height = XFASTINT (fmt[XBM_HEIGHT].value); |
| 10074 | xassert (img->width > 0 && img->height > 0); | 10100 | xassert (img->width > 0 && img->height > 0); |
| 10075 | } | 10101 | } |
| 10102 | |||
| 10076 | /* Get foreground and background colors, maybe allocate colors. */ | 10103 | /* Get foreground and background colors, maybe allocate colors. */ |
| 10077 | if (fmt[XBM_FOREGROUND].count | 10104 | if (fmt[XBM_FOREGROUND].count |
| 10078 | && STRINGP (fmt[XBM_FOREGROUND].value)) | 10105 | && STRINGP (fmt[XBM_FOREGROUND].value)) |
| @@ -10109,7 +10136,7 @@ xbm_load (f, img) | |||
| 10109 | bits = XSTRING (data)->data; | 10136 | bits = XSTRING (data)->data; |
| 10110 | else | 10137 | else |
| 10111 | bits = XBOOL_VECTOR (data)->data; | 10138 | bits = XBOOL_VECTOR (data)->data; |
| 10112 | #ifdef TODO /* image support. */ | 10139 | #ifdef TODO /* full image support. */ |
| 10113 | /* Create the pixmap. */ | 10140 | /* Create the pixmap. */ |
| 10114 | depth = one_w32_display_info.n_cbits; | 10141 | depth = one_w32_display_info.n_cbits; |
| 10115 | img->pixmap | 10142 | img->pixmap |
| @@ -11012,6 +11039,7 @@ x_build_heuristic_mask (f, img, how) | |||
| 11012 | return 0; | 11039 | return 0; |
| 11013 | #endif | 11040 | #endif |
| 11014 | } | 11041 | } |
| 11042 | |||
| 11015 | 11043 | ||
| 11016 | /*********************************************************************** | 11044 | /*********************************************************************** |
| 11017 | PBM (mono, gray, color) | 11045 | PBM (mono, gray, color) |
| @@ -15339,9 +15367,8 @@ init_xfns () | |||
| 15339 | Vimage_types = Qnil; | 15367 | Vimage_types = Qnil; |
| 15340 | 15368 | ||
| 15341 | define_image_type (&pbm_type); | 15369 | define_image_type (&pbm_type); |
| 15342 | |||
| 15343 | #if 0 /* TODO : Image support for W32 */ | ||
| 15344 | define_image_type (&xbm_type); | 15370 | define_image_type (&xbm_type); |
| 15371 | #if 0 /* TODO : Image support for W32 */ | ||
| 15345 | define_image_type (&gs_type); | 15372 | define_image_type (&gs_type); |
| 15346 | #endif | 15373 | #endif |
| 15347 | 15374 | ||