summaryrefslogtreecommitdiff
path: root/src/image.c
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-05-08 14:27:13 +0800
committerPo Lu <luangruo@yahoo.com>2022-05-08 14:28:41 +0800
commit144e9f9b6a376ec0349557ef10a6c133228cda26 (patch)
treef57338f0ddb68eda8e1dcb417cb2e24de248d06d /src/image.c
parenta85e30516e543081d0197b9975fa9ba143426b6f (diff)
downloademacs-144e9f9b6a376ec0349557ef10a6c133228cda26.tar.gz
Fix file-based stipple on NS
* src/image.c (image_create_bitmap_from_file) [HAVE_NS]: Fix loading XBM data from file.
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/image.c b/src/image.c
index f3b47f7cccb..6cd0aa48cfc 100644
--- a/src/image.c
+++ b/src/image.c
@@ -611,7 +611,7 @@ image_create_bitmap_from_data (struct frame *f, char *bits,
return id;
}
-#ifdef HAVE_HAIKU
+#if defined HAVE_HAIKU || defined HAVE_NS
static char *slurp_file (int, ptrdiff_t *);
static Lisp_Object image_find_image_fd (Lisp_Object, int *);
static bool xbm_read_bitmap_data (struct frame *, char *, char *,
@@ -630,11 +630,36 @@ image_create_bitmap_from_file (struct frame *f, Lisp_Object file)
#endif
#ifdef HAVE_NS
- ptrdiff_t id;
- void *bitmap = ns_image_from_file (file);
+ ptrdiff_t id, size;
+ int fd, width, height, rc;
+ char *contents, *data;
+ void *bitmap;
+
+ if (!STRINGP (image_find_image_fd (file, &fd)))
+ return -1;
+
+ contents = slurp_file (fd, &size);
+
+ if (!contents)
+ return -1;
+
+ rc = xbm_read_bitmap_data (f, contents, contents + size,
+ &width, &height, &data, 0);
+
+ if (!rc)
+ {
+ xfree (contents);
+ return -1;
+ }
+
+ bitmap = ns_image_from_XBM (data, width, height, 0, 0);
if (!bitmap)
+ {
+ xfree (contents);
+ xfree (data);
return -1;
+ }
id = image_allocate_bitmap_record (f);
dpyinfo->bitmaps[id - 1].img = bitmap;
@@ -643,6 +668,9 @@ image_create_bitmap_from_file (struct frame *f, Lisp_Object file)
dpyinfo->bitmaps[id - 1].depth = 1;
dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap);
dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap);
+
+ xfree (contents);
+ xfree (data);
return id;
#endif