From 230891d9f33644146cf1e962824618256374eadc Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sat, 25 Jun 2022 07:34:43 +0000 Subject: [PATCH] Implement image transform smoothing on Haiku * src/dispextern.h (struct image): New field `use_bilinear_filtering'. * src/haiku_draw_support.cc (BView_DrawBitmap): Accept it. * src/haiku_support.h: Update prototypes. * src/haikuterm.c (haiku_draw_image_glyph_string): * src/image.c (image_set_transform): Set it. --- src/dispextern.h | 4 ++++ src/haiku_draw_support.cc | 11 ++++++++--- src/haiku_support.h | 2 +- src/haikuterm.c | 3 ++- src/image.c | 7 ++++++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/dispextern.h b/src/dispextern.h index 170641f1ba9..9dec8b7d129 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3090,6 +3090,10 @@ struct image /* The original width and height of the image. */ int original_width, original_height; + + /* Whether or not bilinear filtering should be used to "smooth" the + image. */ + bool use_bilinear_filtering; #endif /* Colors allocated for this image, if any. Allocated via xmalloc. */ diff --git a/src/haiku_draw_support.cc b/src/haiku_draw_support.cc index 768ffdabf82..e2025ed68d4 100644 --- a/src/haiku_draw_support.cc +++ b/src/haiku_draw_support.cc @@ -280,14 +280,19 @@ hsl_color_rgb (double h, double s, double l, uint32_t *rgb) void BView_DrawBitmap (void *view, void *bitmap, int x, int y, int width, int height, int vx, int vy, int vwidth, - int vheight) + int vheight, bool use_bilinear_filtering) { BView *vw = get_view (view); BBitmap *bm = (BBitmap *) bitmap; vw->SetDrawingMode (B_OP_OVER); - vw->DrawBitmap (bm, BRect (x, y, x + width - 1, y + height - 1), - BRect (vx, vy, vx + vwidth - 1, vy + vheight - 1)); + if (!use_bilinear_filtering) + vw->DrawBitmap (bm, BRect (x, y, x + width - 1, y + height - 1), + BRect (vx, vy, vx + vwidth - 1, vy + vheight - 1)); + else + vw->DrawBitmap (bm, BRect (x, y, x + width - 1, y + height - 1), + BRect (vx, vy, vx + vwidth - 1, vy + vheight - 1), + B_FILTER_BITMAP_BILINEAR); vw->SetDrawingMode (B_OP_COPY); } diff --git a/src/haiku_support.h b/src/haiku_support.h index fcdf6bcb154..7585b62a064 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -558,7 +558,7 @@ extern void BView_StrokeLine (void *, int, int, int, int); extern void BView_CopyBits (void *, int, int, int, int, int, int, int, int); extern void BView_InvertRect (void *, int, int, int, int); extern void BView_DrawBitmap (void *, void *, int, int, int, int, int, int, - int, int); + int, int, bool); extern void BView_DrawBitmapWithEraseOp (void *, void *, int, int, int, int); extern void BView_DrawBitmapTiled (void *, void *, int, int, int, int, int, int, int, int); diff --git a/src/haikuterm.c b/src/haikuterm.c index 7c307afa32e..f50f6b34bda 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -1738,7 +1738,8 @@ haiku_draw_image_glyph_string (struct glyph_string *s) s->img->original_height, 0, 0, s->img->original_width, - s->img->original_height); + s->img->original_height, + s->img->use_bilinear_filtering); if (mask) be_draw_image_mask (mask, view, 0, 0, diff --git a/src/image.c b/src/image.c index 5e98945df50..fcf5e97b0b1 100644 --- a/src/image.c +++ b/src/image.c @@ -2563,6 +2563,7 @@ image_set_transform (struct frame *f, struct image *img) img->original_width = img->width; img->original_height = img->height; + img->use_bilinear_filtering = false; memcpy (&img->transform, identity, sizeof identity); #endif @@ -2604,7 +2605,7 @@ image_set_transform (struct frame *f, struct image *img) /* Determine flipping. */ flip = !NILP (image_spec_value (img->spec, QCflip, NULL)); -# if defined USE_CAIRO || defined HAVE_XRENDER || defined HAVE_NS +# if defined USE_CAIRO || defined HAVE_XRENDER || defined HAVE_NS || defined HAVE_HAIKU /* We want scale up operations to use a nearest neighbor filter to show real pixels instead of munging them, but scale down operations to use a blended filter, to avoid aliasing and the like. @@ -2618,6 +2619,10 @@ image_set_transform (struct frame *f, struct image *img) smoothing = !NILP (s); # endif +#ifdef HAVE_HAIKU + img->use_bilinear_filtering = smoothing; +#endif + /* Perform scale transformation. */ matrix3x3 matrix -- 2.39.5