From 2fe4d93624e3b1084a12bba27e6ff9a212fc8117 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 14 Feb 2022 01:34:09 +0000 Subject: [PATCH] Fix wide fringe bitmap processing on Haiku * src/haiku_support.cc (BBitmap_import_mono_bits): Rewrite to use ImportBits. (BBitmap_import_fringe_bitmap): New function. * src/haiku_support.h: Update prototypes. * src/haikuterm.c (haiku_define_fringe_bitmap): Pass entire short array to BBitmap_import_fringe_bitmap instead. --- src/haiku_support.cc | 29 ++++++++++++++++++++++++----- src/haiku_support.h | 4 ++++ src/haikuterm.c | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 5feb56b9f97..ced680d2e53 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -2187,21 +2187,40 @@ BView_mouse_moved (void *view, int x, int y, uint32_t transit) } } -/* Import BITS into BITMAP using the B_GRAY1 colorspace. */ +/* Import fringe bitmap (short array, low bit rightmost) BITS into + BITMAP using the B_GRAY1 colorspace. */ void -BBitmap_import_mono_bits (void *bitmap, void *bits, int wd, int h) +BBitmap_import_fringe_bitmap (void *bitmap, unsigned short *bits, int wd, int h) { BBitmap *bmp = (BBitmap *) bitmap; unsigned char *data = (unsigned char *) bmp->Bits (); - unsigned short *bts = (unsigned short *) bits; + int i; - for (int i = 0; i < (h * (wd / 8)); i++) + for (i = 0; i < h; i++) { - *((unsigned short *) data) = bts[i]; + if (wd <= 8) + data[0] = bits[i] & 0xff; + else + { + data[1] = bits[i] & 0xff; + data[0] = bits[i] >> 8; + } + data += bmp->BytesPerRow (); } } +void +BBitmap_import_mono_bits (void *bitmap, void *bits, int wd, int h) +{ + BBitmap *bmp = (BBitmap *) bitmap; + + if (wd % 8) + wd += 8 - (wd % 8); + + bmp->ImportBits (bits, wd / 8 * h, wd / 8, 0, B_GRAY1); +} + /* Make a scrollbar at X, Y known to the view VIEW. */ void BView_publish_scroll_bar (void *view, int x, int y, int width, int height) diff --git a/src/haiku_support.h b/src/haiku_support.h index e6560f401ac..c9035d3dc0d 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -631,6 +631,10 @@ extern "C" extern void BView_mouse_up (void *view, int x, int y); + extern void + BBitmap_import_fringe_bitmap (void *bitmap, unsigned short *bits, + int wd, int h); + extern void BBitmap_import_mono_bits (void *bitmap, void *bits, int wd, int h); diff --git a/src/haikuterm.c b/src/haikuterm.c index f129eba0ccc..9d128f6a6a8 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -2293,7 +2293,7 @@ haiku_define_fringe_bitmap (int which, unsigned short *bits, } fringe_bmps[which] = BBitmap_new (wd, h, 1); - BBitmap_import_mono_bits (fringe_bmps[which], bits, wd, h); + BBitmap_import_fringe_bitmap (fringe_bmps[which], bits, wd, h); } static void -- 2.39.5