Class LcdFilter
The five-tap filter LCD text spreads each subpixel's coverage with, across the subpixel and its two neighbours on each side. The weights add up to 256. A wider filter has softer colour fringes; a narrower one is sharper and more coloured.
public sealed class LcdFilter : IEquatable<LcdFilter>
- Inheritance
-
LcdFilter
- Implements
- Inherited Members
Examples
// GDI+ ClearType's look: its filter (an even spread over three subpixels), no smoothing along the stripes, and the text
// gamma that then matched GDI+'s weight for a white Trebuchet MS label at 16 pixels.
var gdiPlus = new CanvasOptions
{
PixelGeometry = PixelGeometry.RgbHorizontal,
LcdFilter = LcdFilter.Gdi,
LcdSampling = LcdSampling.Gdi,
TextGamma = 1.25f,
};
var label = new Font(face, 16) { Hinting = FontHinting.Light, Edging = FontEdging.Lcd, Subpixel = false };
using (RasterCanvas<Rgb8> canvas = button.CreateCanvas(gdiPlus))
{
canvas.DrawText("Start the course", new Vector2(40, 26), label, Rgba8.White);
}
// Softer fringes: a balanced filter and half the colour of full ClearType.
var soft = new CanvasOptions { PixelGeometry = PixelGeometry.RgbHorizontal, LcdFilter = LcdFilter.Balanced, ClearTypeLevel = 0.5f };
// Or weights of your own, normalised to add up to 256.
var custom = new CanvasOptions { PixelGeometry = PixelGeometry.RgbHorizontal, LcdFilter = LcdFilter.Custom(1, 3, 4, 3, 1) };
Properties
Balanced
Gets a colour-balanced filter: 8, 77, 86, 77, 8, as FreeType's default LCD filter is described.
public static LcdFilter Balanced { get; }
Property Value
Default
Gets Egami's filter since 2.7.2 and the default: 16, 64, 96, 64, 16 (1, 4, 6, 4, 1 over 16).
public static LcdFilter Default { get; }
Property Value
Gdi
Gets the filter that matches GDI and GDI+ ClearType as measured in 2.7.5: each subpixel's coverage spread evenly over it and its two neighbours. It has the same weights as Light (0, 85, 86, 85, 0) and equals it; the two names say why the weights are chosen.
public static LcdFilter Gdi { get; }
Property Value
Light
Gets a light three-tap filter: 0, 85, 86, 85, 0, a box over the subpixel and its two neighbours. Gdi has the same weights, and equals it.
public static LcdFilter Light { get; }
Property Value
Name
Gets the preset's name, or Custom.
public string Name { get; }
Property Value
Weights
Gets the five weights from the farthest left neighbour to the farthest right; they add up to 256.
public IReadOnlyList<int> Weights { get; }
Property Value
Methods
Custom(float, float, float, float, float)
A filter of five weights, normalised to add up to 256 (largest remainders rounding up).
public static LcdFilter Custom(float outerLeft, float left, float center, float right, float outerRight)
Parameters
outerLeftfloatThe weight two subpixels to the left.
leftfloatThe weight one subpixel to the left.
centerfloatThe subpixel's own weight.
rightfloatThe weight one subpixel to the right.
outerRightfloatThe weight two subpixels to the right.
Returns
- LcdFilter
The filter.
Exceptions
- ArgumentOutOfRangeException
A weight is negative or not finite, or they add up to 0.
Equals(LcdFilter?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(LcdFilter? other)
Parameters
otherLcdFilterAn object to compare with this object.
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.