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
This commit is contained in:
1 parent
88b8cb3e21
commit
4a01bf9bf2
1 file changed
+4
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user