emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7e6fa8ed38: Implement XBM images on Haiku


From: Po Lu
Subject: master 7e6fa8ed38: Implement XBM images on Haiku
Date: Thu, 17 Feb 2022 07:37:51 -0500 (EST)

branch: master
commit 7e6fa8ed385a9fc096f037bcea17c18220fa69f1
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Implement XBM images on Haiku
    
    * src/image.c (image_create_bitmap_from_data): Handle allocation
    failures on Haiku.
    (Create_Pixmap_From_Bitmap_Data): Implement for Haiku.
---
 src/image.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/image.c b/src/image.c
index 3c521e413a..e511326935 100644
--- a/src/image.c
+++ b/src/image.c
@@ -543,6 +543,10 @@ image_create_bitmap_from_data (struct frame *f, char *bits,
 
 #ifdef HAVE_HAIKU
   void *bitmap = BBitmap_new (width, height, 1);
+
+  if (!bitmap)
+    return -1;
+
   BBitmap_import_mono_bits (bitmap, bits, width, height);
 #endif
 
@@ -3815,6 +3819,21 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct 
image *img, char *data,
     convert_mono_to_color_image (f, img, fg, bg);
 #elif defined HAVE_NS
   img->pixmap = ns_image_from_XBM (data, img->width, img->height, fg, bg);
+#elif defined HAVE_HAIKU
+  img->pixmap = BBitmap_new (img->width, img->height, 0);
+
+  if (img->pixmap)
+    {
+      int bytes_per_line = (img->width + 7) / 8;
+
+      for (int y = 0; y < img->height; y++)
+       {
+         for (int x = 0; x < img->width; x++)
+           PUT_PIXEL (img->pixmap, x, y,
+                      (data[x / 8] >> (x % 8)) & 1 ? fg : bg);
+         data += bytes_per_line;
+       }
+    }
 #endif
 }
 
@@ -3999,6 +4018,7 @@ xbm_load_image (struct frame *f, struct image *img, char 
*contents, char *end)
 
   rc = xbm_read_bitmap_data (f, contents, end, &img->width, &img->height,
                             &data, 0);
+
   if (rc)
     {
       unsigned long foreground = img->face_foreground;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]