ReactOS 0.4.16-dev-2332-g4cba65d
ftlcdfil.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * ftlcdfil.h
4 *
5 * FreeType API for color filtering of subpixel bitmap glyphs
6 * (specification).
7 *
8 * Copyright (C) 2006-2020 by
9 * David Turner, Robert Wilhelm, and Werner Lemberg.
10 *
11 * This file is part of the FreeType project, and may only be used,
12 * modified, and distributed under the terms of the FreeType project
13 * license, LICENSE.TXT. By continuing to use, modify, or distribute
14 * this file you indicate that you have read the license and
15 * understand and accept it fully.
16 *
17 */
18
19
20#ifndef FTLCDFIL_H_
21#define FTLCDFIL_H_
22
23#include <freetype/freetype.h>
24#include <freetype/ftparams.h>
25
26#ifdef FREETYPE_H
27#error "freetype.h of FreeType 1 has been loaded!"
28#error "Please fix the directory search order for header files"
29#error "so that freetype.h of FreeType 2 is found first."
30#endif
31
32
34
35 /**************************************************************************
36 *
37 * @section:
38 * lcd_rendering
39 *
40 * @title:
41 * Subpixel Rendering
42 *
43 * @abstract:
44 * API to control subpixel rendering.
45 *
46 * @description:
47 * FreeType provides two alternative subpixel rendering technologies.
48 * Should you define `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` in your
49 * `ftoption.h` file, this enables ClearType-style rendering.
50 * Otherwise, Harmony LCD rendering is enabled. These technologies are
51 * controlled differently and API described below, although always
52 * available, performs its function when appropriate method is enabled
53 * and does nothing otherwise.
54 *
55 * ClearType-style LCD rendering exploits the color-striped structure of
56 * LCD pixels, increasing the available resolution in the direction of
57 * the stripe (usually horizontal RGB) by a factor of~3. Using the
58 * subpixels coverages unfiltered can create severe color fringes
59 * especially when rendering thin features. Indeed, to produce
60 * black-on-white text, the nearby color subpixels must be dimmed
61 * equally.
62 *
63 * A good 5-tap FIR filter should be applied to subpixel coverages
64 * regardless of pixel boundaries and should have these properties:
65 *
66 * 1. It should be symmetrical, like {~a, b, c, b, a~}, to avoid
67 * any shifts in appearance.
68 *
69 * 2. It should be color-balanced, meaning a~+ b~=~c, to reduce color
70 * fringes by distributing the computed coverage for one subpixel to
71 * all subpixels equally.
72 *
73 * 3. It should be normalized, meaning 2a~+ 2b~+ c~=~1.0 to maintain
74 * overall brightness.
75 *
76 * Boxy 3-tap filter {0, 1/3, 1/3, 1/3, 0} is sharper but is less
77 * forgiving of non-ideal gamma curves of a screen (and viewing angles),
78 * beveled filters are fuzzier but more tolerant.
79 *
80 * Use the @FT_Library_SetLcdFilter or @FT_Library_SetLcdFilterWeights
81 * API to specify a low-pass filter, which is then applied to
82 * subpixel-rendered bitmaps generated through @FT_Render_Glyph.
83 *
84 * Harmony LCD rendering is suitable to panels with any regular subpixel
85 * structure, not just monitors with 3 color striped subpixels, as long
86 * as the color subpixels have fixed positions relative to the pixel
87 * center. In this case, each color channel is then rendered separately
88 * after shifting the outline opposite to the subpixel shift so that the
89 * coverage maps are aligned. This method is immune to color fringes
90 * because the shifts do not change integral coverage.
91 *
92 * The subpixel geometry must be specified by xy-coordinates for each
93 * subpixel. By convention they may come in the RGB order: {{-1/3, 0},
94 * {0, 0}, {1/3, 0}} for standard RGB striped panel or {{-1/6, 1/4},
95 * {-1/6, -1/4}, {1/3, 0}} for a certain PenTile panel.
96 *
97 * Use the @FT_Library_SetLcdGeometry API to specify subpixel positions.
98 * If one follows the RGB order convention, the same order applies to the
99 * resulting @FT_PIXEL_MODE_LCD and @FT_PIXEL_MODE_LCD_V bitmaps. Note,
100 * however, that the coordinate frame for the latter must be rotated
101 * clockwise. Harmony with default LCD geometry is equivalent to
102 * ClearType with light filter.
103 *
104 * As a result of ClearType filtering or Harmony rendering, the
105 * dimensions of LCD bitmaps can be either wider or taller than the
106 * dimensions of the corresponding outline with regard to the pixel grid.
107 * For example, for @FT_RENDER_MODE_LCD, the filter adds 2~subpixels to
108 * the left, and 2~subpixels to the right. The bitmap offset values are
109 * adjusted accordingly, so clients shouldn't need to modify their layout
110 * and glyph positioning code when enabling the filter.
111 *
112 * The ClearType and Harmony rendering is applicable to glyph bitmaps
113 * rendered through @FT_Render_Glyph, @FT_Load_Glyph, @FT_Load_Char, and
114 * @FT_Glyph_To_Bitmap, when @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V
115 * is specified. This API does not control @FT_Outline_Render and
116 * @FT_Outline_Get_Bitmap.
117 *
118 * The described algorithms can completely remove color artefacts when
119 * combined with gamma-corrected alpha blending in linear space. Each of
120 * the 3~alpha values (subpixels) must by independently used to blend one
121 * color channel. That is, red alpha blends the red channel of the text
122 * color with the red channel of the background pixel.
123 */
124
125
126 /**************************************************************************
127 *
128 * @enum:
129 * FT_LcdFilter
130 *
131 * @description:
132 * A list of values to identify various types of LCD filters.
133 *
134 * @values:
135 * FT_LCD_FILTER_NONE ::
136 * Do not perform filtering. When used with subpixel rendering, this
137 * results in sometimes severe color fringes.
138 *
139 * FT_LCD_FILTER_DEFAULT ::
140 * This is a beveled, normalized, and color-balanced five-tap filter
141 * with weights of [0x08 0x4D 0x56 0x4D 0x08] in 1/256th units.
142 *
143 * FT_LCD_FILTER_LIGHT ::
144 * this is a boxy, normalized, and color-balanced three-tap filter with
145 * weights of [0x00 0x55 0x56 0x55 0x00] in 1/256th units.
146 *
147 * FT_LCD_FILTER_LEGACY ::
148 * FT_LCD_FILTER_LEGACY1 ::
149 * This filter corresponds to the original libXft color filter. It
150 * provides high contrast output but can exhibit really bad color
151 * fringes if glyphs are not extremely well hinted to the pixel grid.
152 * This filter is only provided for comparison purposes, and might be
153 * disabled or stay unsupported in the future. The second value is
154 * provided for compatibility with FontConfig, which historically used
155 * different enumeration, sometimes incorrectly forwarded to FreeType.
156 *
157 * @since:
158 * 2.3.0 (`FT_LCD_FILTER_LEGACY1` since 2.6.2)
159 */
160 typedef enum FT_LcdFilter_
161 {
167
168 FT_LCD_FILTER_MAX /* do not remove */
169
171
172
173 /**************************************************************************
174 *
175 * @function:
176 * FT_Library_SetLcdFilter
177 *
178 * @description:
179 * This function is used to change filter applied to LCD decimated
180 * bitmaps, like the ones used when calling @FT_Render_Glyph with
181 * @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V.
182 *
183 * @input:
184 * library ::
185 * A handle to the target library instance.
186 *
187 * filter ::
188 * The filter type.
189 *
190 * You can use @FT_LCD_FILTER_NONE here to disable this feature, or
191 * @FT_LCD_FILTER_DEFAULT to use a default filter that should work well
192 * on most LCD screens.
193 *
194 * @return:
195 * FreeType error code. 0~means success.
196 *
197 * @note:
198 * Since 2.10.3 the LCD filtering is enabled with @FT_LCD_FILTER_DEFAULT.
199 * It is no longer necessary to call this function explicitly except
200 * to choose a different filter or disable filtering altogether with
201 * @FT_LCD_FILTER_NONE.
202 *
203 * This function does nothing but returns `FT_Err_Unimplemented_Feature`
204 * if the configuration macro `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` is
205 * not defined in your build of the library.
206 *
207 * @since:
208 * 2.3.0
209 */
213
214
215 /**************************************************************************
216 *
217 * @function:
218 * FT_Library_SetLcdFilterWeights
219 *
220 * @description:
221 * This function can be used to enable LCD filter with custom weights,
222 * instead of using presets in @FT_Library_SetLcdFilter.
223 *
224 * @input:
225 * library ::
226 * A handle to the target library instance.
227 *
228 * weights ::
229 * A pointer to an array; the function copies the first five bytes and
230 * uses them to specify the filter weights in 1/256th units.
231 *
232 * @return:
233 * FreeType error code. 0~means success.
234 *
235 * @note:
236 * This function does nothing but returns `FT_Err_Unimplemented_Feature`
237 * if the configuration macro `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` is
238 * not defined in your build of the library.
239 *
240 * LCD filter weights can also be set per face using @FT_Face_Properties
241 * with @FT_PARAM_TAG_LCD_FILTER_WEIGHTS.
242 *
243 * @since:
244 * 2.4.0
245 */
248 unsigned char *weights );
249
250
251 /**************************************************************************
252 *
253 * @type:
254 * FT_LcdFiveTapFilter
255 *
256 * @description:
257 * A typedef for passing the five LCD filter weights to
258 * @FT_Face_Properties within an @FT_Parameter structure.
259 *
260 * @since:
261 * 2.8
262 *
263 */
264#define FT_LCD_FILTER_FIVE_TAPS 5
265
267
268
269 /**************************************************************************
270 *
271 * @function:
272 * FT_Library_SetLcdGeometry
273 *
274 * @description:
275 * This function can be used to modify default positions of color
276 * subpixels, which controls Harmony LCD rendering.
277 *
278 * @input:
279 * library ::
280 * A handle to the target library instance.
281 *
282 * sub ::
283 * A pointer to an array of 3 vectors in 26.6 fractional pixel format;
284 * the function modifies the default values, see the note below.
285 *
286 * @return:
287 * FreeType error code. 0~means success.
288 *
289 * @note:
290 * Subpixel geometry examples:
291 *
292 * - {{-21, 0}, {0, 0}, {21, 0}} is the default, corresponding to 3 color
293 * stripes shifted by a third of a pixel. This could be an RGB panel.
294 *
295 * - {{21, 0}, {0, 0}, {-21, 0}} looks the same as the default but can
296 * specify a BGR panel instead, while keeping the bitmap in the same
297 * RGB888 format.
298 *
299 * - {{0, 21}, {0, 0}, {0, -21}} is the vertical RGB, but the bitmap
300 * stays RGB888 as a result.
301 *
302 * - {{-11, 16}, {-11, -16}, {22, 0}} is a certain PenTile arrangement.
303 *
304 * This function does nothing and returns `FT_Err_Unimplemented_Feature`
305 * in the context of ClearType-style subpixel rendering when
306 * `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` is defined in your build of the
307 * library.
308 *
309 * @since:
310 * 2.10.0
311 */
314 FT_Vector sub[3] );
315
316 /* */
317
318
320
321#endif /* FTLCDFIL_H_ */
322
323
324/* END */
FT_Library library
Definition: cffdrivr.c:660
#define FT_END_HEADER
Definition: ftheader.h:57
#define FT_BEGIN_HEADER
Definition: ftheader.h:37
FT_LcdFilter_
Definition: ftlcdfil.h:161
@ FT_LCD_FILTER_LIGHT
Definition: ftlcdfil.h:164
@ FT_LCD_FILTER_LEGACY1
Definition: ftlcdfil.h:165
@ FT_LCD_FILTER_MAX
Definition: ftlcdfil.h:168
@ FT_LCD_FILTER_LEGACY
Definition: ftlcdfil.h:166
@ FT_LCD_FILTER_DEFAULT
Definition: ftlcdfil.h:163
@ FT_LCD_FILTER_NONE
Definition: ftlcdfil.h:162
FT_Library_SetLcdFilter(FT_Library library, FT_LcdFilter filter)
Definition: ftlcdfil.c:407
FT_Library_SetLcdGeometry(FT_Library library, FT_Vector sub[3])
Definition: ftlcdfil.c:420
#define FT_LCD_FILTER_FIVE_TAPS
Definition: ftlcdfil.h:264
FT_Library_SetLcdFilterWeights(FT_Library library, unsigned char *weights)
Definition: ftlcdfil.c:396
FT_BEGIN_HEADER enum FT_LcdFilter_ FT_LcdFilter
FT_Byte FT_LcdFiveTapFilter[FT_LCD_FILTER_FIVE_TAPS]
Definition: ftlcdfil.h:266
unsigned char FT_Byte
Definition: fttypes.h:154
int FT_Error
Definition: fttypes.h:299
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
const GLbyte * weights
Definition: glext.h:6523
#define FT_EXPORT(x)