diff options
| author | Gerd Moellmann | 2000-04-27 19:11:04 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-04-27 19:11:04 +0000 |
| commit | 5be6c3b044e2b0b2dd79a41285df932226f59962 (patch) | |
| tree | 536f8f31c77edd39a04b1712e03b7b707866a9dc | |
| parent | 035eec486e617046cffd65a0086db3fec4edb05f (diff) | |
| download | emacs-5be6c3b044e2b0b2dd79a41285df932226f59962.tar.gz emacs-5be6c3b044e2b0b2dd79a41285df932226f59962.zip | |
(slurp_file): New function.
(xbm_image_p): Handle case of in-memory XBM files.
(xbm_scan): Rewritten to work on memory buffers instead of files.
(xbm_read_bitmap_data): Renamed from xbm_read_bitmap_file_data.
Work on memory buffers instead of files. If DATA is null test
if buffer looks like an in-memory XBM file.
(xbm_load_image): Renamed from xbm_load_image_file. Work on
memory buffers instead of files.
(xbm_file_p): New function.
(xbm_load): Accept :data DATA where DATA is an in-memory XBM file.
| -rw-r--r-- | src/xfns.c | 331 |
1 files changed, 192 insertions, 139 deletions
diff --git a/src/xfns.c b/src/xfns.c index 7cbe2a3d6f9..be2f63c32c1 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -5737,10 +5737,12 @@ x_put_x_image (f, ximg, pixmap, width, height) | |||
| 5737 | 5737 | ||
| 5738 | 5738 | ||
| 5739 | /*********************************************************************** | 5739 | /*********************************************************************** |
| 5740 | Searching files | 5740 | File Handling |
| 5741 | ***********************************************************************/ | 5741 | ***********************************************************************/ |
| 5742 | 5742 | ||
| 5743 | static Lisp_Object x_find_image_file P_ ((Lisp_Object)); | 5743 | static Lisp_Object x_find_image_file P_ ((Lisp_Object)); |
| 5744 | static char *slurp_file P_ ((char *, int *)); | ||
| 5745 | |||
| 5744 | 5746 | ||
| 5745 | /* Find image file FILE. Look in data-directory, then | 5747 | /* Find image file FILE. Look in data-directory, then |
| 5746 | x-bitmap-file-path. Value is the full name of the file found, or | 5748 | x-bitmap-file-path. Value is the full name of the file found, or |
| @@ -5771,17 +5773,55 @@ x_find_image_file (file) | |||
| 5771 | } | 5773 | } |
| 5772 | 5774 | ||
| 5773 | 5775 | ||
| 5776 | /* Read FILE into memory. Value is a pointer to a buffer allocated | ||
| 5777 | with xmalloc holding FILE's contents. Value is null if an error | ||
| 5778 | occured. *SIZE is set to the size of the file. */ | ||
| 5779 | |||
| 5780 | static char * | ||
| 5781 | slurp_file (file, size) | ||
| 5782 | char *file; | ||
| 5783 | int *size; | ||
| 5784 | { | ||
| 5785 | FILE *fp = NULL; | ||
| 5786 | char *buf = NULL; | ||
| 5787 | struct stat st; | ||
| 5788 | |||
| 5789 | if (stat (file, &st) == 0 | ||
| 5790 | && (fp = fopen (file, "r")) != NULL | ||
| 5791 | && (buf = (char *) xmalloc (st.st_size), | ||
| 5792 | fread (buf, 1, st.st_size, fp) == st.st_size)) | ||
| 5793 | { | ||
| 5794 | *size = st.st_size; | ||
| 5795 | fclose (fp); | ||
| 5796 | } | ||
| 5797 | else | ||
| 5798 | { | ||
| 5799 | if (fp) | ||
| 5800 | fclose (fp); | ||
| 5801 | if (buf) | ||
| 5802 | { | ||
| 5803 | xfree (buf); | ||
| 5804 | buf = NULL; | ||
| 5805 | } | ||
| 5806 | } | ||
| 5807 | |||
| 5808 | return buf; | ||
| 5809 | } | ||
| 5810 | |||
| 5811 | |||
| 5774 | 5812 | ||
| 5775 | /*********************************************************************** | 5813 | /*********************************************************************** |
| 5776 | XBM images | 5814 | XBM images |
| 5777 | ***********************************************************************/ | 5815 | ***********************************************************************/ |
| 5778 | 5816 | ||
| 5817 | static int xbm_scan P_ ((char **, char *, char *, int *)); | ||
| 5779 | static int xbm_load P_ ((struct frame *f, struct image *img)); | 5818 | static int xbm_load P_ ((struct frame *f, struct image *img)); |
| 5780 | static int xbm_load_image_from_file P_ ((struct frame *f, struct image *img, | 5819 | static int xbm_load_image P_ ((struct frame *f, struct image *img, |
| 5781 | Lisp_Object file)); | 5820 | char *, char *)); |
| 5782 | static int xbm_image_p P_ ((Lisp_Object object)); | 5821 | static int xbm_image_p P_ ((Lisp_Object object)); |
| 5783 | static int xbm_read_bitmap_file_data P_ ((char *, int *, int *, | 5822 | static int xbm_read_bitmap_data P_ ((char *, char *, int *, int *, |
| 5784 | unsigned char **)); | 5823 | unsigned char **)); |
| 5824 | static int xbm_file_p P_ ((Lisp_Object)); | ||
| 5785 | 5825 | ||
| 5786 | 5826 | ||
| 5787 | /* Indices of image specification fields in xbm_format, below. */ | 5827 | /* Indices of image specification fields in xbm_format, below. */ |
| @@ -5862,6 +5902,10 @@ enum xbm_token | |||
| 5862 | 3. a vector of strings or bool-vectors, one for each line of the | 5902 | 3. a vector of strings or bool-vectors, one for each line of the |
| 5863 | bitmap. | 5903 | bitmap. |
| 5864 | 5904 | ||
| 5905 | 4. A string containing an in-memory XBM file. WIDTH and HEIGHT | ||
| 5906 | may not be specified in this case because they are defined in the | ||
| 5907 | XBM file. | ||
| 5908 | |||
| 5865 | Both the file and data forms may contain the additional entries | 5909 | Both the file and data forms may contain the additional entries |
| 5866 | `:background COLOR' and `:foreground COLOR'. If not present, | 5910 | `:background COLOR' and `:foreground COLOR'. If not present, |
| 5867 | foreground and background of the frame on which the image is | 5911 | foreground and background of the frame on which the image is |
| @@ -5884,6 +5928,12 @@ xbm_image_p (object) | |||
| 5884 | if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_DATA].count) | 5928 | if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_DATA].count) |
| 5885 | return 0; | 5929 | return 0; |
| 5886 | } | 5930 | } |
| 5931 | else if (kw[XBM_DATA].count && xbm_file_p (kw[XBM_DATA].value)) | ||
| 5932 | { | ||
| 5933 | /* In-memory XBM file. */ | ||
| 5934 | if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_FILE].count) | ||
| 5935 | return 0; | ||
| 5936 | } | ||
| 5887 | else | 5937 | else |
| 5888 | { | 5938 | { |
| 5889 | Lisp_Object data; | 5939 | Lisp_Object data; |
| @@ -5961,30 +6011,31 @@ xbm_image_p (object) | |||
| 5961 | scanning a number, store its value in *IVAL. */ | 6011 | scanning a number, store its value in *IVAL. */ |
| 5962 | 6012 | ||
| 5963 | static int | 6013 | static int |
| 5964 | xbm_scan (fp, sval, ival) | 6014 | xbm_scan (s, end, sval, ival) |
| 5965 | FILE *fp; | 6015 | char **s, *end; |
| 5966 | char *sval; | 6016 | char *sval; |
| 5967 | int *ival; | 6017 | int *ival; |
| 5968 | { | 6018 | { |
| 5969 | int c; | 6019 | int c; |
| 5970 | 6020 | ||
| 5971 | /* Skip white space. */ | 6021 | /* Skip white space. */ |
| 5972 | while ((c = fgetc (fp)) != EOF && isspace (c)) | 6022 | while (*s < end && (c = *(*s)++, isspace (c))) |
| 5973 | ; | 6023 | ; |
| 5974 | 6024 | ||
| 5975 | if (c == EOF) | 6025 | if (*s >= end) |
| 5976 | c = 0; | 6026 | c = 0; |
| 5977 | else if (isdigit (c)) | 6027 | else if (isdigit (c)) |
| 5978 | { | 6028 | { |
| 5979 | int value = 0, digit; | 6029 | int value = 0, digit; |
| 5980 | 6030 | ||
| 5981 | if (c == '0') | 6031 | if (c == '0' && *s < end) |
| 5982 | { | 6032 | { |
| 5983 | c = fgetc (fp); | 6033 | c = *(*s)++; |
| 5984 | if (c == 'x' || c == 'X') | 6034 | if (c == 'x' || c == 'X') |
| 5985 | { | 6035 | { |
| 5986 | while ((c = fgetc (fp)) != EOF) | 6036 | while (*s < end) |
| 5987 | { | 6037 | { |
| 6038 | c = *(*s)++; | ||
| 5988 | if (isdigit (c)) | 6039 | if (isdigit (c)) |
| 5989 | digit = c - '0'; | 6040 | digit = c - '0'; |
| 5990 | else if (c >= 'a' && c <= 'f') | 6041 | else if (c >= 'a' && c <= 'f') |
| @@ -5999,33 +6050,33 @@ xbm_scan (fp, sval, ival) | |||
| 5999 | else if (isdigit (c)) | 6050 | else if (isdigit (c)) |
| 6000 | { | 6051 | { |
| 6001 | value = c - '0'; | 6052 | value = c - '0'; |
| 6002 | while ((c = fgetc (fp)) != EOF | 6053 | while (*s < end |
| 6003 | && isdigit (c)) | 6054 | && (c = *(*s)++, isdigit (c))) |
| 6004 | value = 8 * value + c - '0'; | 6055 | value = 8 * value + c - '0'; |
| 6005 | } | 6056 | } |
| 6006 | } | 6057 | } |
| 6007 | else | 6058 | else |
| 6008 | { | 6059 | { |
| 6009 | value = c - '0'; | 6060 | value = c - '0'; |
| 6010 | while ((c = fgetc (fp)) != EOF | 6061 | while (*s < end |
| 6011 | && isdigit (c)) | 6062 | && (c = *(*s)++, isdigit (c))) |
| 6012 | value = 10 * value + c - '0'; | 6063 | value = 10 * value + c - '0'; |
| 6013 | } | 6064 | } |
| 6014 | 6065 | ||
| 6015 | if (c != EOF) | 6066 | if (*s < end) |
| 6016 | ungetc (c, fp); | 6067 | *s = *s - 1; |
| 6017 | *ival = value; | 6068 | *ival = value; |
| 6018 | c = XBM_TK_NUMBER; | 6069 | c = XBM_TK_NUMBER; |
| 6019 | } | 6070 | } |
| 6020 | else if (isalpha (c) || c == '_') | 6071 | else if (isalpha (c) || c == '_') |
| 6021 | { | 6072 | { |
| 6022 | *sval++ = c; | 6073 | *sval++ = c; |
| 6023 | while ((c = fgetc (fp)) != EOF | 6074 | while (*s < end |
| 6024 | && (isalnum (c) || c == '_')) | 6075 | && (c = *(*s)++, (isalnum (c) || c == '_'))) |
| 6025 | *sval++ = c; | 6076 | *sval++ = c; |
| 6026 | *sval = 0; | 6077 | *sval = 0; |
| 6027 | if (c != EOF) | 6078 | if (*s < end) |
| 6028 | ungetc (c, fp); | 6079 | *s = *s - 1; |
| 6029 | c = XBM_TK_IDENT; | 6080 | c = XBM_TK_IDENT; |
| 6030 | } | 6081 | } |
| 6031 | 6082 | ||
| @@ -6034,18 +6085,19 @@ xbm_scan (fp, sval, ival) | |||
| 6034 | 6085 | ||
| 6035 | 6086 | ||
| 6036 | /* Replacement for XReadBitmapFileData which isn't available under old | 6087 | /* Replacement for XReadBitmapFileData which isn't available under old |
| 6037 | X versions. FILE is the name of the bitmap file to read. Set | 6088 | X versions. CONTENTS is a pointer to a buffer to parse; END is the |
| 6038 | *WIDTH and *HEIGHT to the width and height of the image. Return in | 6089 | buffer's end. Set *WIDTH and *HEIGHT to the width and height of |
| 6039 | *DATA the bitmap data allocated with xmalloc. Value is non-zero if | 6090 | the image. Return in *DATA the bitmap data allocated with xmalloc. |
| 6040 | successful. */ | 6091 | Value is non-zero if successful. DATA null means just test if |
| 6092 | CONTENTS looks like an im-memory XBM file. */ | ||
| 6041 | 6093 | ||
| 6042 | static int | 6094 | static int |
| 6043 | xbm_read_bitmap_file_data (file, width, height, data) | 6095 | xbm_read_bitmap_data (contents, end, width, height, data) |
| 6044 | char *file; | 6096 | char *contents, *end; |
| 6045 | int *width, *height; | 6097 | int *width, *height; |
| 6046 | unsigned char **data; | 6098 | unsigned char **data; |
| 6047 | { | 6099 | { |
| 6048 | FILE *fp; | 6100 | char *s = contents; |
| 6049 | char buffer[BUFSIZ]; | 6101 | char buffer[BUFSIZ]; |
| 6050 | int padding_p = 0; | 6102 | int padding_p = 0; |
| 6051 | int v10 = 0; | 6103 | int v10 = 0; |
| @@ -6055,7 +6107,7 @@ xbm_read_bitmap_file_data (file, width, height, data) | |||
| 6055 | int LA1; | 6107 | int LA1; |
| 6056 | 6108 | ||
| 6057 | #define match() \ | 6109 | #define match() \ |
| 6058 | LA1 = xbm_scan (fp, buffer, &value) | 6110 | LA1 = xbm_scan (&s, end, buffer, &value) |
| 6059 | 6111 | ||
| 6060 | #define expect(TOKEN) \ | 6112 | #define expect(TOKEN) \ |
| 6061 | if (LA1 != (TOKEN)) \ | 6113 | if (LA1 != (TOKEN)) \ |
| @@ -6069,13 +6121,10 @@ xbm_read_bitmap_file_data (file, width, height, data) | |||
| 6069 | else \ | 6121 | else \ |
| 6070 | goto failure | 6122 | goto failure |
| 6071 | 6123 | ||
| 6072 | fp = fopen (file, "r"); | ||
| 6073 | if (fp == NULL) | ||
| 6074 | return 0; | ||
| 6075 | |||
| 6076 | *width = *height = -1; | 6124 | *width = *height = -1; |
| 6077 | *data = NULL; | 6125 | if (data) |
| 6078 | LA1 = xbm_scan (fp, buffer, &value); | 6126 | *data = NULL; |
| 6127 | LA1 = xbm_scan (&s, end, buffer, &value); | ||
| 6079 | 6128 | ||
| 6080 | /* Parse defines for width, height and hot-spots. */ | 6129 | /* Parse defines for width, height and hot-spots. */ |
| 6081 | while (LA1 == '#') | 6130 | while (LA1 == '#') |
| @@ -6098,6 +6147,8 @@ xbm_read_bitmap_file_data (file, width, height, data) | |||
| 6098 | 6147 | ||
| 6099 | if (*width < 0 || *height < 0) | 6148 | if (*width < 0 || *height < 0) |
| 6100 | goto failure; | 6149 | goto failure; |
| 6150 | else if (data == NULL) | ||
| 6151 | goto success; | ||
| 6101 | 6152 | ||
| 6102 | /* Parse bits. Must start with `static'. */ | 6153 | /* Parse bits. Must start with `static'. */ |
| 6103 | expect_ident ("static"); | 6154 | expect_ident ("static"); |
| @@ -6166,13 +6217,12 @@ xbm_read_bitmap_file_data (file, width, height, data) | |||
| 6166 | } | 6217 | } |
| 6167 | } | 6218 | } |
| 6168 | 6219 | ||
| 6169 | fclose (fp); | 6220 | success: |
| 6170 | return 1; | 6221 | return 1; |
| 6171 | 6222 | ||
| 6172 | failure: | 6223 | failure: |
| 6173 | 6224 | ||
| 6174 | fclose (fp); | 6225 | if (data && *data) |
| 6175 | if (*data) | ||
| 6176 | { | 6226 | { |
| 6177 | xfree (*data); | 6227 | xfree (*data); |
| 6178 | *data = NULL; | 6228 | *data = NULL; |
| @@ -6185,35 +6235,21 @@ xbm_read_bitmap_file_data (file, width, height, data) | |||
| 6185 | } | 6235 | } |
| 6186 | 6236 | ||
| 6187 | 6237 | ||
| 6188 | /* Load XBM image IMG which will be displayed on frame F from file | 6238 | /* Load XBM image IMG which will be displayed on frame F from buffer |
| 6189 | SPECIFIED_FILE. Value is non-zero if successful. */ | 6239 | CONTENTS. END is the end of the buffer. Value is non-zero if |
| 6240 | successful. */ | ||
| 6190 | 6241 | ||
| 6191 | static int | 6242 | static int |
| 6192 | xbm_load_image_from_file (f, img, specified_file) | 6243 | xbm_load_image (f, img, contents, end) |
| 6193 | struct frame *f; | 6244 | struct frame *f; |
| 6194 | struct image *img; | 6245 | struct image *img; |
| 6195 | Lisp_Object specified_file; | 6246 | char *contents, *end; |
| 6196 | { | 6247 | { |
| 6197 | int rc; | 6248 | int rc; |
| 6198 | unsigned char *data; | 6249 | unsigned char *data; |
| 6199 | int success_p = 0; | 6250 | int success_p = 0; |
| 6200 | Lisp_Object file; | ||
| 6201 | struct gcpro gcpro1; | ||
| 6202 | 6251 | ||
| 6203 | xassert (STRINGP (specified_file)); | 6252 | rc = xbm_read_bitmap_data (contents, end, &img->width, &img->height, &data); |
| 6204 | file = Qnil; | ||
| 6205 | GCPRO1 (file); | ||
| 6206 | |||
| 6207 | file = x_find_image_file (specified_file); | ||
| 6208 | if (!STRINGP (file)) | ||
| 6209 | { | ||
| 6210 | image_error ("Cannot find image file `%s'", specified_file, Qnil); | ||
| 6211 | UNGCPRO; | ||
| 6212 | return 0; | ||
| 6213 | } | ||
| 6214 | |||
| 6215 | rc = xbm_read_bitmap_file_data (XSTRING (file)->data, &img->width, | ||
| 6216 | &img->height, &data); | ||
| 6217 | if (rc) | 6253 | if (rc) |
| 6218 | { | 6254 | { |
| 6219 | int depth = DefaultDepthOfScreen (FRAME_X_SCREEN (f)); | 6255 | int depth = DefaultDepthOfScreen (FRAME_X_SCREEN (f)); |
| @@ -6245,7 +6281,7 @@ xbm_load_image_from_file (f, img, specified_file) | |||
| 6245 | if (img->pixmap == 0) | 6281 | if (img->pixmap == 0) |
| 6246 | { | 6282 | { |
| 6247 | x_clear_image (f, img); | 6283 | x_clear_image (f, img); |
| 6248 | image_error ("Unable to create X pixmap for `%s'", file, Qnil); | 6284 | image_error ("Unable to create X pixmap for `%s'", img->spec, Qnil); |
| 6249 | } | 6285 | } |
| 6250 | else | 6286 | else |
| 6251 | success_p = 1; | 6287 | success_p = 1; |
| @@ -6255,11 +6291,25 @@ xbm_load_image_from_file (f, img, specified_file) | |||
| 6255 | else | 6291 | else |
| 6256 | image_error ("Error loading XBM image `%s'", img->spec, Qnil); | 6292 | image_error ("Error loading XBM image `%s'", img->spec, Qnil); |
| 6257 | 6293 | ||
| 6258 | UNGCPRO; | ||
| 6259 | return success_p; | 6294 | return success_p; |
| 6260 | } | 6295 | } |
| 6261 | 6296 | ||
| 6262 | 6297 | ||
| 6298 | /* Value is non-zero if DATA looks like an in-memory XBM file. */ | ||
| 6299 | |||
| 6300 | static int | ||
| 6301 | xbm_file_p (data) | ||
| 6302 | Lisp_Object data; | ||
| 6303 | { | ||
| 6304 | int w, h; | ||
| 6305 | return (STRINGP (data) | ||
| 6306 | && xbm_read_bitmap_data (XSTRING (data)->data, | ||
| 6307 | (XSTRING (data)->data | ||
| 6308 | + STRING_BYTES (XSTRING (data))), | ||
| 6309 | &w, &h, NULL)); | ||
| 6310 | } | ||
| 6311 | |||
| 6312 | |||
| 6263 | /* Fill image IMG which is used on frame F with pixmap data. Value is | 6313 | /* Fill image IMG which is used on frame F with pixmap data. Value is |
| 6264 | non-zero if successful. */ | 6314 | non-zero if successful. */ |
| 6265 | 6315 | ||
| @@ -6276,26 +6326,60 @@ xbm_load (f, img) | |||
| 6276 | /* If IMG->spec specifies a file name, create a non-file spec from it. */ | 6326 | /* If IMG->spec specifies a file name, create a non-file spec from it. */ |
| 6277 | file_name = image_spec_value (img->spec, QCfile, NULL); | 6327 | file_name = image_spec_value (img->spec, QCfile, NULL); |
| 6278 | if (STRINGP (file_name)) | 6328 | if (STRINGP (file_name)) |
| 6279 | success_p = xbm_load_image_from_file (f, img, file_name); | 6329 | { |
| 6330 | Lisp_Object file; | ||
| 6331 | char *contents; | ||
| 6332 | int size; | ||
| 6333 | struct gcpro gcpro1; | ||
| 6334 | |||
| 6335 | file = x_find_image_file (file_name); | ||
| 6336 | GCPRO1 (file); | ||
| 6337 | if (!STRINGP (file)) | ||
| 6338 | { | ||
| 6339 | image_error ("Cannot find image file `%s'", file_name, Qnil); | ||
| 6340 | UNGCPRO; | ||
| 6341 | return 0; | ||
| 6342 | } | ||
| 6343 | |||
| 6344 | contents = slurp_file (XSTRING (file)->data, &size); | ||
| 6345 | if (contents == NULL) | ||
| 6346 | { | ||
| 6347 | image_error ("Error loading XBM image `%s'", img->spec, Qnil); | ||
| 6348 | UNGCPRO; | ||
| 6349 | return 0; | ||
| 6350 | } | ||
| 6351 | |||
| 6352 | success_p = xbm_load_image (f, img, contents, contents + size); | ||
| 6353 | UNGCPRO; | ||
| 6354 | } | ||
| 6280 | else | 6355 | else |
| 6281 | { | 6356 | { |
| 6282 | struct image_keyword fmt[XBM_LAST]; | 6357 | struct image_keyword fmt[XBM_LAST]; |
| 6283 | Lisp_Object data; | 6358 | Lisp_Object data; |
| 6359 | unsigned char *bitmap_data; | ||
| 6284 | int depth; | 6360 | int depth; |
| 6285 | unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); | 6361 | unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); |
| 6286 | unsigned long background = FRAME_BACKGROUND_PIXEL (f); | 6362 | unsigned long background = FRAME_BACKGROUND_PIXEL (f); |
| 6287 | char *bits; | 6363 | char *bits; |
| 6288 | int parsed_p; | 6364 | int parsed_p, height, width; |
| 6365 | int in_memory_file_p = 0; | ||
| 6366 | |||
| 6367 | /* See if data looks like an in-memory XBM file. */ | ||
| 6368 | data = image_spec_value (img->spec, QCdata, NULL); | ||
| 6369 | in_memory_file_p = xbm_file_p (data); | ||
| 6289 | 6370 | ||
| 6290 | /* Parse the list specification. */ | 6371 | /* Parse the image specification. */ |
| 6291 | bcopy (xbm_format, fmt, sizeof fmt); | 6372 | bcopy (xbm_format, fmt, sizeof fmt); |
| 6292 | parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm); | 6373 | parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm); |
| 6293 | xassert (parsed_p); | 6374 | xassert (parsed_p); |
| 6294 | 6375 | ||
| 6295 | /* Get specified width, and height. */ | 6376 | /* Get specified width, and height. */ |
| 6296 | img->width = XFASTINT (fmt[XBM_WIDTH].value); | 6377 | if (!in_memory_file_p) |
| 6297 | img->height = XFASTINT (fmt[XBM_HEIGHT].value); | 6378 | { |
| 6298 | xassert (img->width > 0 && img->height > 0); | 6379 | img->width = XFASTINT (fmt[XBM_WIDTH].value); |
| 6380 | img->height = XFASTINT (fmt[XBM_HEIGHT].value); | ||
| 6381 | xassert (img->width > 0 && img->height > 0); | ||
| 6382 | } | ||
| 6299 | 6383 | ||
| 6300 | BLOCK_INPUT; | 6384 | BLOCK_INPUT; |
| 6301 | 6385 | ||
| @@ -6310,46 +6394,51 @@ xbm_load (f, img) | |||
| 6310 | background = x_alloc_image_color (f, img, fmt[XBM_BACKGROUND].value, | 6394 | background = x_alloc_image_color (f, img, fmt[XBM_BACKGROUND].value, |
| 6311 | background); | 6395 | background); |
| 6312 | 6396 | ||
| 6313 | /* Set bits to the bitmap image data. */ | 6397 | if (in_memory_file_p) |
| 6314 | data = fmt[XBM_DATA].value; | 6398 | success_p = xbm_load_image (f, img, XSTRING (data)->data, |
| 6315 | if (VECTORP (data)) | 6399 | (XSTRING (data)->data |
| 6400 | + STRING_BYTES (XSTRING (data)))); | ||
| 6401 | else | ||
| 6316 | { | 6402 | { |
| 6317 | int i; | 6403 | if (VECTORP (data)) |
| 6318 | char *p; | 6404 | { |
| 6319 | int nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR; | 6405 | int i; |
| 6406 | char *p; | ||
| 6407 | int nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR; | ||
| 6320 | 6408 | ||
| 6321 | p = bits = (char *) alloca (nbytes * img->height); | 6409 | p = bits = (char *) alloca (nbytes * img->height); |
| 6322 | for (i = 0; i < img->height; ++i, p += nbytes) | 6410 | for (i = 0; i < img->height; ++i, p += nbytes) |
| 6411 | { | ||
| 6412 | Lisp_Object line = XVECTOR (data)->contents[i]; | ||
| 6413 | if (STRINGP (line)) | ||
| 6414 | bcopy (XSTRING (line)->data, p, nbytes); | ||
| 6415 | else | ||
| 6416 | bcopy (XBOOL_VECTOR (line)->data, p, nbytes); | ||
| 6417 | } | ||
| 6418 | } | ||
| 6419 | else if (STRINGP (data)) | ||
| 6420 | bits = XSTRING (data)->data; | ||
| 6421 | else | ||
| 6422 | bits = XBOOL_VECTOR (data)->data; | ||
| 6423 | |||
| 6424 | /* Create the pixmap. */ | ||
| 6425 | depth = DefaultDepthOfScreen (FRAME_X_SCREEN (f)); | ||
| 6426 | img->pixmap | ||
| 6427 | = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), | ||
| 6428 | FRAME_X_WINDOW (f), | ||
| 6429 | bits, | ||
| 6430 | img->width, img->height, | ||
| 6431 | foreground, background, | ||
| 6432 | depth); | ||
| 6433 | if (img->pixmap) | ||
| 6434 | success_p = 1; | ||
| 6435 | else | ||
| 6323 | { | 6436 | { |
| 6324 | Lisp_Object line = XVECTOR (data)->contents[i]; | 6437 | image_error ("Unable to create pixmap for XBM image `%s'", |
| 6325 | if (STRINGP (line)) | 6438 | img->spec, Qnil); |
| 6326 | bcopy (XSTRING (line)->data, p, nbytes); | 6439 | x_clear_image (f, img); |
| 6327 | else | ||
| 6328 | bcopy (XBOOL_VECTOR (line)->data, p, nbytes); | ||
| 6329 | } | 6440 | } |
| 6330 | } | 6441 | } |
| 6331 | else if (STRINGP (data)) | ||
| 6332 | bits = XSTRING (data)->data; | ||
| 6333 | else | ||
| 6334 | bits = XBOOL_VECTOR (data)->data; | ||
| 6335 | |||
| 6336 | /* Create the pixmap. */ | ||
| 6337 | depth = DefaultDepthOfScreen (FRAME_X_SCREEN (f)); | ||
| 6338 | img->pixmap | ||
| 6339 | = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), | ||
| 6340 | FRAME_X_WINDOW (f), | ||
| 6341 | bits, | ||
| 6342 | img->width, img->height, | ||
| 6343 | foreground, background, | ||
| 6344 | depth); | ||
| 6345 | if (img->pixmap) | ||
| 6346 | success_p = 1; | ||
| 6347 | else | ||
| 6348 | { | ||
| 6349 | image_error ("Unable to create pixmap for XBM image `%s'", | ||
| 6350 | img->spec, Qnil); | ||
| 6351 | x_clear_image (f, img); | ||
| 6352 | } | ||
| 6353 | 6442 | ||
| 6354 | UNBLOCK_INPUT; | 6443 | UNBLOCK_INPUT; |
| 6355 | } | 6444 | } |
| @@ -7175,42 +7264,6 @@ pbm_scan_number (s, end) | |||
| 7175 | } | 7264 | } |
| 7176 | 7265 | ||
| 7177 | 7266 | ||
| 7178 | /* Read FILE into memory. Value is a pointer to a buffer allocated | ||
| 7179 | with xmalloc holding FILE's contents. Value is null if an error | ||
| 7180 | occured. *SIZE is set to the size of the file. */ | ||
| 7181 | |||
| 7182 | static char * | ||
| 7183 | pbm_read_file (file, size) | ||
| 7184 | Lisp_Object file; | ||
| 7185 | int *size; | ||
| 7186 | { | ||
| 7187 | FILE *fp = NULL; | ||
| 7188 | char *buf = NULL; | ||
| 7189 | struct stat st; | ||
| 7190 | |||
| 7191 | if (stat (XSTRING (file)->data, &st) == 0 | ||
| 7192 | && (fp = fopen (XSTRING (file)->data, "r")) != NULL | ||
| 7193 | && (buf = (char *) xmalloc (st.st_size), | ||
| 7194 | fread (buf, 1, st.st_size, fp) == st.st_size)) | ||
| 7195 | { | ||
| 7196 | *size = st.st_size; | ||
| 7197 | fclose (fp); | ||
| 7198 | } | ||
| 7199 | else | ||
| 7200 | { | ||
| 7201 | if (fp) | ||
| 7202 | fclose (fp); | ||
| 7203 | if (buf) | ||
| 7204 | { | ||
| 7205 | xfree (buf); | ||
| 7206 | buf = NULL; | ||
| 7207 | } | ||
| 7208 | } | ||
| 7209 | |||
| 7210 | return buf; | ||
| 7211 | } | ||
| 7212 | |||
| 7213 | |||
| 7214 | /* Load PBM image IMG for use on frame F. */ | 7267 | /* Load PBM image IMG for use on frame F. */ |
| 7215 | 7268 | ||
| 7216 | static int | 7269 | static int |
| @@ -7242,7 +7295,7 @@ pbm_load (f, img) | |||
| 7242 | return 0; | 7295 | return 0; |
| 7243 | } | 7296 | } |
| 7244 | 7297 | ||
| 7245 | contents = pbm_read_file (file, &size); | 7298 | contents = slurp_file (XSTRING (file)->data, &size); |
| 7246 | if (contents == NULL) | 7299 | if (contents == NULL) |
| 7247 | { | 7300 | { |
| 7248 | image_error ("Error reading `%s'", file, Qnil); | 7301 | image_error ("Error reading `%s'", file, Qnil); |