kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.15k stars 972 forks source link

Add Option to Enable Gamma-Corrected/SRGB Rendering #5850

Closed ewhac closed 1 year ago

ewhac commented 1 year ago

Is your feature request related to a problem? Please describe. *[NOTE: I am not trying to start a fight about mathematically or perceptually correct rendering -- a fight that appears to inevitably break out whenever the topic of gamma-corrected font rendering is raised.]*

On X11 systems, even the best fixed-width outline fonts look thin and anemic. Vertical stems in particular are dim.

Based on my own admittedly spotty and subjective research, the problem appears to be that gamma correction is not applied when rendering anti-aliased fonts.

Describe the solution you'd like A configuration option in Kitty that will enable gamma-corrected or SRGB rendering.

Describe alternatives you've considered Applying a gamma correction to the X display, either via xgamma or via xrandr. However, this will affect the entire display, leaving everything (subjectively) too bright.

Additional context I applied the following patch to Kitty:

diff --git a/kitty/gl.c b/kitty/gl.c
index 21435bd0..c667ef05 100644
--- a/kitty/gl.c
+++ b/kitty/gl.c
@@ -64,6 +64,7 @@ gl_init() {
             fatal("OpenGL version is %d.%d, version >= 3.3 required for kitty", gl_major, gl_minor);
         }
     }
+    glEnable (GL_FRAMEBUFFER_SRGB);
 }

 void

Here are the results. Note that how these images appear to you will be affected by your own monitor's gamma settings, your desktop/display server gamma settings, and your browser's rendering. In my case:

The font being used is Iosevka Extended v17, font size 9. The first image is from stock Kitty; the second is with the patch applied. Pay particular attention to the vertical stems, such as in lower-case 'm', 'n', and 'l':

Screenshot_2023-01-03_11-29-58 Screenshot_2023-01-03_11-30-17

Personally, I find the second image far more readable, and the stroke widths more uniform.

This solution, of course, has side-effects, most notably on color themes. Here's Neovim running inside both Kittys, editing a Python file with the Dracula theme:

Screenshot_2023-01-03_11-32-11 Screenshot_2023-01-03_11-32-26

The font rendering looks great, but now all the colors are far too bright. So anyone using this option would have to "un-gamma" their various color themes.

Further Reading: Freetype.org: On Slight Hinting, Proper Text Rendering, Stem Darkening and LCD Filters. This article is about eight years old, but is still largely relevant, and helps illustrate that rendering anti-aliased fonts well isn't so simple.

ewhac commented 1 year ago

Furhter further reading (turns out it's a deep topic):

page-down commented 1 year ago

I see there seems to be an open PR (5423) discussing this. You might want to try it.

kovidgoyal commented 1 year ago

dup of #5423

ewhac commented 1 year ago

dup of #5423

(visits PR) (pulls PR into working tree) (fixes merge conflicts) (builds)

Oooo! Lovely! I'll have that; thanks!