From: Po Lu Date: Sun, 8 May 2022 06:27:13 +0000 (+0800) Subject: Fix file-based stipple on NS X-Git-Tag: emacs-29.0.90~1910^2~913 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=144e9f9b6a376ec0349557ef10a6c133228cda26;p=emacs.git Fix file-based stipple on NS * src/image.c (image_create_bitmap_from_file) [HAVE_NS]: Fix loading XBM data from file. --- 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