diff --git a/kitty/blit_fragment.glsl b/kitty/blit_fragment.glsl index e0a47ce60..74e243336 100644 --- a/kitty/blit_fragment.glsl +++ b/kitty/blit_fragment.glsl @@ -5,6 +5,16 @@ uniform sampler2D image; in vec2 texcoord; out vec4 color; +float linear2srgb(float x) { + // Linear to sRGB conversion. + float lower = 12.92 * x; + float upper = 1.055 * pow(x, 1.0f / 2.4f) - 0.055f; + + return mix(lower, upper, step(0.0031308f, x)); +} + + void main() { color = texture(image, texcoord); + color.a = linear2srgb(color.a); } diff --git a/kitty/cell_fragment.glsl b/kitty/cell_fragment.glsl index 8cdc388cf..2d2bec92c 100644 --- a/kitty/cell_fragment.glsl +++ b/kitty/cell_fragment.glsl @@ -240,9 +240,9 @@ void main() { #ifdef FOREGROUND final_color = calculate_foreground(); // pre-multiplied foreground - // This is the last pass, adjust alpha to compensate for gamma-incorrect - // blending in compositor: - final_color.a = linear2srgb(final_color.a); + // This is the last pass, called both with transparency and without but not in draw_cells_simple(). + // When transparent it is drawn into a framebuffer and linear2srgb() will be done + // when blitting that framebuffer. When not transparent there is not need to do linear2srgb() anyway. #endif }