From 4a01bf9bf24e45e1ba8950de7bc5d66ce899c7dd Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 24 Dec 2021 10:39:33 -0700 Subject: [PATCH] font: improve alpha channel in rasterizer Previously, we'd set it to 100% if any non-zero channel was present, but this resulted in stronger/darker outlines that were especially noticeable when the window background was transparent and over a bright background. This commit sets the alpha based on the coverage provided to us by freetype and looks better with and without a transparent window background. @dmfay: I think this might be behind what you noticed in your last comment on #1025. refs: #1325 --- wezterm-font/src/rasterizer/freetype.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wezterm-font/src/rasterizer/freetype.rs b/wezterm-font/src/rasterizer/freetype.rs index bdbfdc19b..c1bd323a5 100644 --- a/wezterm-font/src/rasterizer/freetype.rs +++ b/wezterm-font/src/rasterizer/freetype.rs @@ -139,7 +139,7 @@ impl FreeTypeRasterizer { rgba[dest_offset + (x * 4)] = gray; rgba[dest_offset + (x * 4) + 1] = gray; rgba[dest_offset + (x * 4) + 2] = gray; - rgba[dest_offset + (x * 4) + 3] = if gray == 0 { 0 } else { 0xff }; + rgba[dest_offset + (x * 4) + 3] = linear_gray; } } RasterizedGlyph { @@ -170,6 +170,8 @@ impl FreeTypeRasterizer { let green = data[src_offset + (x * 3) + 1]; let blue = data[src_offset + (x * 3) + 2]; + let linear_alpha = red.max(green).max(blue); + // Texture is SRGBA, which in OpenGL means // that the RGB values are gamma adjusted // non-linear values, but the A value is @@ -182,7 +184,7 @@ impl FreeTypeRasterizer { rgba[dest_offset + (x * 4)] = red; rgba[dest_offset + (x * 4) + 1] = green; rgba[dest_offset + (x * 4) + 2] = blue; - rgba[dest_offset + (x * 4) + 3] = if red | green | blue == 0 { 0 } else { 0xff }; + rgba[dest_offset + (x * 4) + 3] = linear_alpha; } }