aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Rumney2002-05-18 15:30:47 +0000
committerJason Rumney2002-05-18 15:30:47 +0000
commitaf3f7be76e6a5d05ea9e8430955467f484d4e55b (patch)
treed4a6f846ee87eed4205fb32461c1a772ddc22a67
parent9a4b515707812883f1d337830dc205db3fcb5b78 (diff)
downloademacs-af3f7be76e6a5d05ea9e8430955467f484d4e55b.tar.gz
emacs-af3f7be76e6a5d05ea9e8430955467f484d4e55b.zip
(w32_create_pixmap_from_bitmap_data): New function.
(xbm_load_image): Use it. (xbm_load): Ditto. (xbm_read_bitmap_data): Reverted to xfns.c version. From David Ponce <dponce@voila.fr>.
-rw-r--r--src/w32fns.c68
1 files changed, 41 insertions, 27 deletions
diff --git a/src/w32fns.c b/src/w32fns.c
index 799bc084f16..91d5b3ab878 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -9726,7 +9726,7 @@ xbm_scan (s, end, sval, ival)
9726 loop: 9726 loop:
9727 9727
9728 /* Skip white space. */ 9728 /* Skip white space. */
9729 while (*s < end &&(c = *(*s)++, isspace (c))) 9729 while (*s < end && (c = *(*s)++, isspace (c)))
9730 ; 9730 ;
9731 9731
9732 if (*s >= end) 9732 if (*s >= end)
@@ -9818,6 +9818,31 @@ static unsigned char reflect_byte (unsigned char orig)
9818} 9818}
9819 9819
9820 9820
9821/* Create a Windows bitmap from X bitmap data. */
9822static HBITMAP
9823w32_create_pixmap_from_bitmap_data (int width, int height, char *data)
9824{
9825 int i, j, w1, w2;
9826 char *bits, *p;
9827 HBITMAP bmp;
9828
9829 w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */
9830 w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */
9831 bits = (char *) xmalloc (height * w2);
9832 bzero (bits, height * w2);
9833 for (i = 0; i < height; i++)
9834 {
9835 p = bits + i*w2;
9836 for (j = 0; j < w1; j++)
9837 *p++ = reflect_byte(*data++);
9838 }
9839 bmp = CreateBitmap (width, height, 1, 1, bits);
9840 xfree (bits);
9841
9842 return bmp;
9843}
9844
9845
9821/* Replacement for XReadBitmapFileData which isn't available under old 9846/* Replacement for XReadBitmapFileData which isn't available under old
9822 X versions. CONTENTS is a pointer to a buffer to parse; END is the 9847 X versions. CONTENTS is a pointer to a buffer to parse; END is the
9823 buffer's end. Set *WIDTH and *HEIGHT to the width and height of 9848 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
@@ -9835,7 +9860,7 @@ xbm_read_bitmap_data (contents, end, width, height, data)
9835 char buffer[BUFSIZ]; 9860 char buffer[BUFSIZ];
9836 int padding_p = 0; 9861 int padding_p = 0;
9837 int v10 = 0; 9862 int v10 = 0;
9838 int bytes_in_per_line, bytes_out_per_line, i, nbytes; 9863 int bytes_per_line, i, nbytes;
9839 unsigned char *p; 9864 unsigned char *p;
9840 int value; 9865 int value;
9841 int LA1; 9866 int LA1;
@@ -9888,10 +9913,6 @@ xbm_read_bitmap_data (contents, end, width, height, data)
9888 expect_ident ("static"); 9913 expect_ident ("static");
9889 if (LA1 == XBM_TK_IDENT) 9914 if (LA1 == XBM_TK_IDENT)
9890 { 9915 {
9891 /* On Windows, all images need padding to 16 bit boundaries. */
9892 if (*width % 16 && *width % 16 < 9)
9893 padding_p = 1;
9894
9895 if (strcmp (buffer, "unsigned") == 0) 9916 if (strcmp (buffer, "unsigned") == 0)
9896 { 9917 {
9897 match (); 9918 match ();
@@ -9901,6 +9922,8 @@ xbm_read_bitmap_data (contents, end, width, height, data)
9901 { 9922 {
9902 match (); 9923 match ();
9903 v10 = 1; 9924 v10 = 1;
9925 if (*width % 16 && *width % 16 < 9)
9926 padding_p = 1;
9904 } 9927 }
9905 else if (strcmp (buffer, "char") == 0) 9928 else if (strcmp (buffer, "char") == 0)
9906 match (); 9929 match ();
@@ -9916,12 +9939,9 @@ xbm_read_bitmap_data (contents, end, width, height, data)
9916 expect ('='); 9939 expect ('=');
9917 expect ('{'); 9940 expect ('{');
9918 9941
9919 /* Bytes per line on input. Only count padding for v10 XBMs. */ 9942 bytes_per_line = (*width + 7) / 8 + padding_p;
9920 bytes_in_per_line = (*width + 7) / 8 + (v10 ? padding_p : 0); 9943 nbytes = bytes_per_line * *height;
9921 bytes_out_per_line = (*width + 7) / 8 + padding_p; 9944 p = *data = (char *) xmalloc (nbytes);
9922
9923 nbytes = bytes_in_per_line * *height;
9924 p = *data = (char *) xmalloc (bytes_out_per_line * *height);
9925 9945
9926 if (v10) 9946 if (v10)
9927 { 9947 {
@@ -9930,9 +9950,9 @@ xbm_read_bitmap_data (contents, end, width, height, data)
9930 int val = value; 9950 int val = value;
9931 expect (XBM_TK_NUMBER); 9951 expect (XBM_TK_NUMBER);
9932 9952
9933 *p++ = reflect_byte (val); 9953 *p++ = val;
9934 if (!padding_p || ((i + 2) % bytes_in_per_line)) 9954 if (!padding_p || ((i + 2) % bytes_per_line))
9935 *p++ = reflect_byte (value >> 8); 9955 *p++ = value >> 8;
9936 9956
9937 if (LA1 == ',' || LA1 == '}') 9957 if (LA1 == ',' || LA1 == '}')
9938 match (); 9958 match ();
@@ -9947,9 +9967,7 @@ xbm_read_bitmap_data (contents, end, width, height, data)
9947 int val = value; 9967 int val = value;
9948 expect (XBM_TK_NUMBER); 9968 expect (XBM_TK_NUMBER);
9949 9969
9950 *p++ = reflect_byte (val); 9970 *p++ = val;
9951 if (padding_p && ((i + 1) % bytes_in_per_line) == 0)
9952 *p++ = 0;
9953 9971
9954 if (LA1 == ',' || LA1 == '}') 9972 if (LA1 == ',' || LA1 == '}')
9955 match (); 9973 match ();
@@ -10011,7 +10029,7 @@ xbm_load_image (f, img, contents, end)
10011 img->background_valid = 1; 10029 img->background_valid = 1;
10012 } 10030 }
10013 img->pixmap 10031 img->pixmap
10014 = CreateBitmap (img->width, img->height, 1, 1, data); 10032 = w32_create_pixmap_from_bitmap_data (img->width, img->height, data);
10015 10033
10016 xfree (data); 10034 xfree (data);
10017 10035
@@ -10151,17 +10169,13 @@ xbm_load (f, img)
10151 bits = XSTRING (data)->data; 10169 bits = XSTRING (data)->data;
10152 else 10170 else
10153 bits = XBOOL_VECTOR (data)->data; 10171 bits = XBOOL_VECTOR (data)->data;
10154#ifdef TODO /* full image support. */ 10172
10155 /* Create the pixmap. */ 10173 /* Create the pixmap. */
10156 depth = one_w32_display_info.n_cbits; 10174 depth = one_w32_display_info.n_cbits;
10157 img->pixmap 10175 img->pixmap
10158 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), 10176 = w32_create_pixmap_from_bitmap_data (img->width, img->height,
10159 FRAME_X_WINDOW (f), 10177 bits);
10160 bits, 10178
10161 img->width, img->height,
10162 foreground, background,
10163 depth);
10164#endif
10165 if (img->pixmap) 10179 if (img->pixmap)
10166 success_p = 1; 10180 success_p = 1;
10167 else 10181 else