From d5540d7dbcee2a35dc928670ac210c5ffb909a75 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 18 May 2022 12:36:50 +0000 Subject: [PATCH] Implement gamma-correction on Haiku * src/dispextern.h: Add `gamma_correct' prototype on Haiku as well. * src/haikufns.c (gamma_correct): New function. * src/haikuterm.c (haiku_defined_color): Gamma-correct colors if their pixels are being allocated. --- src/dispextern.h | 3 +++ src/haikufns.c | 16 ++++++++++++++++ src/haikuterm.c | 9 ++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/dispextern.h b/src/dispextern.h index a7f478acdf8..910f630a50c 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3615,6 +3615,9 @@ void gamma_correct (struct frame *, XColor *); #ifdef HAVE_NTGUI void gamma_correct (struct frame *, COLORREF *); #endif +#ifdef HAVE_HAIKU +void gamma_correct (struct frame *, Emacs_Color *); +#endif #ifdef HAVE_WINDOW_SYSTEM diff --git a/src/haikufns.c b/src/haikufns.c index 8b6296e6ae1..76a8569970a 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -268,6 +268,22 @@ haiku_set_tab_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) haiku_change_tab_bar_height (f, nlines * FRAME_LINE_HEIGHT (f)); } +void +gamma_correct (struct frame *f, Emacs_Color *color) +{ + if (f->gamma) + { + color->red = (pow (color->red / 65535.0, f->gamma) + * 65535.0 + 0.5); + color->green = (pow (color->green / 65535.0, f->gamma) + * 65535.0 + 0.5); + color->blue = (pow (color->blue / 65535.0, f->gamma) + * 65535.0 + 0.5); + color->pixel = RGB_TO_ULONG (color->red / 256, + color->green / 256, + color->blue / 256); + } +} int haiku_get_color (const char *name, Emacs_Color *color) diff --git a/src/haikuterm.c b/src/haikuterm.c index af20d1c11c8..2db1e352ffb 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -575,7 +575,14 @@ static bool haiku_defined_color (struct frame *f, const char *name, Emacs_Color *color, bool alloc, bool make_index) { - return !haiku_get_color (name, color); + int rc; + + rc = !haiku_get_color (name, color); + + if (rc && f->gamma && alloc) + gamma_correct (f, color); + + return rc; } /* Adapted from xterm `x_draw_box_rect'. */ -- 2.39.2