emacs-diffs
[Top][All Lists]
Advanced

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

master d5540d7dbc: Implement gamma-correction on Haiku


From: Po Lu
Subject: master d5540d7dbc: Implement gamma-correction on Haiku
Date: Wed, 18 May 2022 08:38:09 -0400 (EDT)

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

    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 a7f478acdf..910f630a50 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 8b6296e6ae..76a8569970 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 af20d1c11c..2db1e352ff 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'.  */



reply via email to

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