Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed










Rev Author Line No. Line
4349 Serge 1
2
"http://www.w3.org/TR/html4/loose.dtd">
3
4
5
6
FreeType-2.5.0 API Reference
7
32
33
34
 
35
[Index]
36
37
[TOC]
38

FreeType-2.5.0 API Reference

39
 
40

41
LCD Filtering
42
43

Synopsis

44
45
FT_LcdFilterFT_Library_SetLcdFilterWeights
46
FT_Library_SetLcdFilter
47


48
 
49
50

The FT_Library_SetLcdFilter API can be used to specify a low-pass filter which is then applied to LCD-optimized bitmaps generated through FT_Render_Glyph. This is useful to reduce color fringes which would occur with unfiltered rendering.

51

Note that no filter is active by default, and that this function is not implemented in default builds of the library. You need to #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your ‘ftoption.h’ file in order to activate it.

52

FreeType generates alpha coverage maps, which are linear by nature. For instance, the value 0x80 in bitmap representation means that (within numerical precision) 0x80/0xff fraction of that pixel is covered by the glyph's outline. The blending function for placing text over a background is

53
54
  dst = alpha * src + (1 - alpha) * dst    ,
55
56

which is known as OVER. However, when calculating the output of the OVER operator, the source colors should first be transformed to a linear color space, then alpha blended in that space, and transformed back to the output color space.

57

When linear light blending is used, the default FIR5 filtering weights (as given by FT_LCD_FILTER_DEFAULT) are no longer optimal, as they have been designed for black on white rendering while lacking gamma correction. To preserve color neutrality, weights for a FIR5 filter should be chosen according to two free parameters ‘a’ and ‘c’, and the FIR weights should be

58
59
  [a - c, a + c, 2 * a, a + c, a - c]    .
60
61

This formula generates equal weights for all the color primaries across the filter kernel, which makes it colorless. One suggested set of weights is

62
63
  [0x10, 0x50, 0x60, 0x50, 0x10]    ,
64
65

where ‘a’ has value 0x30 and ‘b’ value 0x20. The weights in filter may have a sum larger than 0x100, which increases coloration slightly but also improves contrast.

66

67
68

FT_LcdFilter

69
70
Defined in FT_LCD_FILTER_H (freetype/ftlcdfil.h).
71

72
73
 
74
  typedef enum  FT_LcdFilter_
75
  {
76
    FT_LCD_FILTER_NONE    = 0,
77
    FT_LCD_FILTER_DEFAULT = 1,
78
    FT_LCD_FILTER_LIGHT   = 2,
79
    FT_LCD_FILTER_LEGACY  = 16,
80
 
81
    FT_LCD_FILTER_MAX   /* do not remove */
82
 
83
  } FT_LcdFilter;
84
 
85

86
87

A list of values to identify various types of LCD filters.

88

89
values
90

91
92
FT_LCD_FILTER_NONE
93

Do not perform filtering. When used with subpixel rendering, this results in sometimes severe color fringes.

94
95
FT_LCD_FILTER_DEFAULT
96

The default filter reduces color fringes considerably, at the cost of a slight blurriness in the output.

97
98
FT_LCD_FILTER_LIGHT
99

The light filter is a variant that produces less blurriness at the cost of slightly more color fringes than the default one. It might be better, depending on taste, your monitor, or your personal vision.

100
101
FT_LCD_FILTER_LEGACY
102

This filter corresponds to the original libXft color filter. It provides high contrast output but can exhibit really bad color fringes if glyphs are not extremely well hinted to the pixel grid. In other words, it only works well if the TrueType bytecode interpreter is enabled and high-quality hinted fonts are used.

103

This filter is only provided for comparison purposes, and might be disabled or stay unsupported in the future.

104
105
106
107
since
108

2.3.0

109
110
111

112
[Index]
113
114
[TOC]
115
 
116
117

FT_Library_SetLcdFilter

118
119
Defined in FT_LCD_FILTER_H (freetype/ftlcdfil.h).
120

121
122
 
123
  FT_EXPORT( FT_Error )
124
  FT_Library_SetLcdFilter( FT_Library    library,
125
                           FT_LcdFilter  filter );
126
 
127

128
129

This function is used to apply color filtering to LCD decimated bitmaps, like the ones used when calling FT_Render_Glyph with FT_RENDER_MODE_LCD or FT_RENDER_MODE_LCD_V.

130

131
input
132

133
134
library
135

A handle to the target library instance.

136
137
filter
138

The filter type.

139

You can use FT_LCD_FILTER_NONE here to disable this feature, or FT_LCD_FILTER_DEFAULT to use a default filter that should work well on most LCD screens.

140
141
142
143
return
144

FreeType error code. 0 means success.

145
146
note
147

This feature is always disabled by default. Clients must make an explicit call to this function with a ‘filter’ value other than FT_LCD_FILTER_NONE in order to enable it.

148

Due to PATENTS covering subpixel rendering, this function doesn't do anything except returning ‘FT_Err_Unimplemented_Feature’ if the configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not defined in your build of the library, which should correspond to all default builds of FreeType.

149

The filter affects glyph bitmaps rendered through FT_Render_Glyph, FT_Outline_Get_Bitmap, FT_Load_Glyph, and FT_Load_Char.

150

It does not affect the output of FT_Outline_Render and FT_Outline_Get_Bitmap.

151

If this feature is activated, the dimensions of LCD glyph bitmaps are either larger or taller than the dimensions of the corresponding outline with regards to the pixel grid. For example, for FT_RENDER_MODE_LCD, the filter adds up to 3 pixels to the left, and up to 3 pixels to the right.

152

The bitmap offset values are adjusted correctly, so clients shouldn't need to modify their layout and glyph positioning code when enabling the filter.

153
154
since
155

2.3.0

156
157
158

159
[Index]
160
161
[TOC]
162
 
163
164

FT_Library_SetLcdFilterWeights

165
166
Defined in FT_LCD_FILTER_H (freetype/ftlcdfil.h).
167

168
169
 
170
  FT_EXPORT( FT_Error )
171
  FT_Library_SetLcdFilterWeights( FT_Library      library,
172
                                  unsigned char  *weights );
173
 
174

175
176

Use this function to override the filter weights selected by FT_Library_SetLcdFilter. By default, FreeType uses the quintuple (0x00, 0x55, 0x56, 0x55, 0x00) for FT_LCD_FILTER_LIGHT, and (0x10, 0x40, 0x70, 0x40, 0x10) for FT_LCD_FILTER_DEFAULT and FT_LCD_FILTER_LEGACY.

177

178
input
179

180
181
library
182

A handle to the target library instance.

183
184
weights
185

A pointer to an array; the function copies the first five bytes and uses them to specify the filter weights.

186
187
188
189
return
190

FreeType error code. 0 means success.

191
192
note
193

Due to PATENTS covering subpixel rendering, this function doesn't do anything except returning ‘FT_Err_Unimplemented_Feature’ if the configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not defined in your build of the library, which should correspond to all default builds of FreeType.

194

This function must be called after FT_Library_SetLcdFilter to have any effect.

195
196
since
197

2.4.0

198
199
200

201
[Index]
202
203
[TOC]
204
 
205
206