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