Imported Upstream version 2.9.1
[platform/upstream/freetype2.git] / docs / reference / ft2-lcd_filtering.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "https://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>FreeType-2.9.1 API Reference</title>
7 <style type="text/css">
8   a:link { color: #0000EF; }
9   a:visited { color: #51188E; }
10   a:hover { color: #FF0000; }
11
12   body { font-family: Verdana, Geneva, Arial, Helvetica, serif;
13          color: #000000;
14          background: #FFFFFF;
15          width: 87%;
16          margin: auto; }
17
18   div.section { width: 75%;
19                 margin: auto; }
20   div.section hr { margin: 4ex 0 1ex 0; }
21   div.section h4 { background-color: #EEEEFF;
22                    font-size: medium;
23                    font-style: oblique;
24                    font-weight: bold;
25                    margin: 3ex 0 1.5ex 9%;
26                    padding: 0.3ex 0 0.3ex 1%; }
27   div.section p { margin: 1.5ex 0 1.5ex 10%; }
28   div.section pre { margin: 3ex 0 3ex 9%;
29                     background-color: #D6E8FF;
30                     padding: 2ex 0 2ex 1%; }
31   div.section table.fields { width: 90%;
32                              margin: 1.5ex 0 1.5ex 10%; }
33   div.section table.toc { width: 95%;
34                           margin: 1.5ex 0 1.5ex 5%; }
35   div.timestamp { text-align: center;
36                   font-size: 69%;
37                   margin: 1.5ex 0 1.5ex 0; }
38
39   h1 { text-align: center; }
40   h3 { font-size: medium;
41        margin: 4ex 0 1.5ex 0; }
42
43   p { text-align: justify; }
44
45   pre.colored { color: blue; }
46
47   span.keyword { font-family: monospace;
48                  text-align: left;
49                  white-space: pre;
50                  color: darkblue; }
51
52   table.fields td.val { font-weight: bold;
53                         text-align: right;
54                         width: 30%;
55                         vertical-align: baseline;
56                         padding: 1ex 1em 1ex 0; }
57   table.fields td.desc { vertical-align: baseline;
58                          padding: 1ex 0 1ex 1em; }
59   table.fields td.desc p:first-child { margin: 0; }
60   table.fields td.desc p { margin: 1.5ex 0 0 0; }
61   table.index { margin: 6ex auto 6ex auto;
62                 border: 0;
63                 border-collapse: separate;
64                 border-spacing: 1em 0.3ex; }
65   table.index tr { padding: 0; }
66   table.index td { padding: 0; }
67   table.index-toc-link { width: 100%;
68                          border: 0;
69                          border-spacing: 0;
70                          margin: 1ex 0 1ex 0; }
71   table.index-toc-link td.left { padding: 0 0.5em 0 0.5em;
72                                  font-size: 83%;
73                                  text-align: left; }
74   table.index-toc-link td.middle { padding: 0 0.5em 0 0.5em;
75                                    font-size: 83%;
76                                    text-align: center; }
77   table.index-toc-link td.right { padding: 0 0.5em 0 0.5em;
78                                   font-size: 83%;
79                                   text-align: right; }
80   table.synopsis { margin: 6ex auto 6ex auto;
81                    border: 0;
82                    border-collapse: separate;
83                    border-spacing: 2em 0.6ex; }
84   table.synopsis tr { padding: 0; }
85   table.synopsis td { padding: 0; }
86   table.toc td.link { width: 30%;
87                       text-align: right;
88                       vertical-align: baseline;
89                       padding: 1ex 1em 1ex 0; }
90   table.toc td.desc { vertical-align: baseline;
91                       padding: 1ex 0 1ex 1em;
92                       text-align: left; }
93   table.toc td.desc p:first-child { margin: 0;
94                                     text-align: left; }
95   table.toc td.desc p { margin: 1.5ex 0 0 0;
96                         text-align: left; }
97
98 </style>
99 </head>
100 <body>
101
102 <table class="index-toc-link"><tr><td class="left">[<a href="ft2-index.html">Index</a>]</td><td class="right">[<a href="ft2-toc.html">TOC</a>]</td></tr></table>
103 <h1>FreeType-2.9.1 API Reference</h1>
104
105 <h1 id="lcd_filtering">LCD Filtering</h1>
106 <h2>Synopsis</h2>
107 <table class="synopsis">
108 <tr><td><a href="#FT_LcdFilter">FT_LcdFilter</a></td><td><a href="#FT_Library_SetLcdFilterWeights">FT_Library_SetLcdFilterWeights</a></td></tr>
109 <tr><td><a href="#FT_Library_SetLcdFilter">FT_Library_SetLcdFilter</a></td><td></td></tr>
110 </table>
111
112
113 <p>Should you #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your &lsquo;ftoption.h&rsquo;, which enables patented ClearType-style rendering, the LCD-optimized glyph bitmaps should be filtered to reduce color fringes inherent to this technology. The default FreeType LCD rendering uses different technology, and API described below, although available, does nothing.</p>
114 <p>ClearType-style LCD rendering exploits the color-striped structure of LCD pixels, increasing the available resolution in the direction of the stripe (usually horizontal RGB) by a factor of&nbsp;3. Since these subpixels are color pixels, using them unfiltered creates severe color fringes. Use the <a href="ft2-lcd_filtering.html#FT_Library_SetLcdFilter">FT_Library_SetLcdFilter</a> API to specify a low-pass filter, which is then applied to subpixel-rendered bitmaps generated through <a href="ft2-base_interface.html#FT_Render_Glyph">FT_Render_Glyph</a>. The filter sacrifices some of the higher resolution to reduce color fringes, making the glyph image slightly blurrier. Positional improvements will remain.</p>
115 <p>A filter should have two properties:</p>
116 <p>1) It should be normalized, meaning the sum of the 5&nbsp;components should be 256 (0x100). It is possible to go above or under this target sum, however: going under means tossing out contrast, going over means invoking clamping and thereby non-linearities that increase contrast somewhat at the expense of greater distortion and color-fringing. Contrast is better enhanced through stem darkening.</p>
117 <p>2) It should be color-balanced, meaning a filter &lsquo;{&nbsp;a, b, c, b, a&nbsp;}&rsquo; where a&nbsp;+ b&nbsp;=&nbsp;c. It distributes the computed coverage for one subpixel to all subpixels equally, sacrificing some won resolution but drastically reducing color-fringing. Positioning improvements remain! Note that color-fringing can only really be minimized when using a color-balanced filter and alpha-blending the glyph onto a surface in linear space; see <a href="ft2-base_interface.html#FT_Render_Glyph">FT_Render_Glyph</a>.</p>
118 <p>Regarding the form, a filter can be a &lsquo;boxy&rsquo; filter or a &lsquo;beveled&rsquo; filter. Boxy filters are sharper but are less forgiving of non-ideal gamma curves of a screen (viewing angles!), beveled filters are fuzzier but more tolerant.</p>
119 <p>Examples:</p>
120 <p>- [0x10 0x40 0x70 0x40 0x10] is beveled and neither balanced nor normalized.</p>
121 <p>- [0x1A 0x33 0x4D 0x33 0x1A] is beveled and balanced but not normalized.</p>
122 <p>- [0x19 0x33 0x66 0x4c 0x19] is beveled and normalized but not balanced.</p>
123 <p>- [0x00 0x4c 0x66 0x4c 0x00] is boxily beveled and normalized but not balanced.</p>
124 <p>- [0x00 0x55 0x56 0x55 0x00] is boxy, normalized, and almost balanced.</p>
125 <p>- [0x08 0x4D 0x56 0x4D 0x08] is beveled, normalized and, almost balanced.</p>
126 <p>The filter affects glyph bitmaps rendered through <a href="ft2-base_interface.html#FT_Render_Glyph">FT_Render_Glyph</a>, <a href="ft2-base_interface.html#FT_Load_Glyph">FT_Load_Glyph</a>, and <a href="ft2-base_interface.html#FT_Load_Char">FT_Load_Char</a>. It does <i>not</i> affect the output of <a href="ft2-outline_processing.html#FT_Outline_Render">FT_Outline_Render</a> and <a href="ft2-outline_processing.html#FT_Outline_Get_Bitmap">FT_Outline_Get_Bitmap</a>.</p>
127 <p>If this feature is activated, the dimensions of LCD glyph bitmaps are either wider or taller than the dimensions of the corresponding outline with regard to the pixel grid. For example, for <a href="ft2-base_interface.html#FT_Render_Mode">FT_RENDER_MODE_LCD</a>, the filter adds 3&nbsp;subpixels to the left, and 3&nbsp;subpixels to the right. The bitmap offset values are adjusted accordingly, so clients shouldn't need to modify their layout and glyph positioning code when enabling the filter.</p>
128 <p>It is important to understand that linear alpha blending and gamma correction is critical for correctly rendering glyphs onto surfaces without artifacts and even more critical when subpixel rendering is involved.</p>
129 <p>Each of the 3&nbsp;alpha values (subpixels) is independently used to blend one color channel. That is, red alpha blends the red channel of the text color with the red channel of the background pixel. The distribution of density values by the color-balanced filter assumes alpha blending is done in linear space; only then color artifacts cancel out.</p>
130
131 <div class="section">
132 <h3 id="FT_LcdFilter">FT_LcdFilter</h3>
133 <p>Defined in FT_LCD_FILTER_H (freetype/ftlcdfil.h).</p>
134 <pre>
135   <span class="keyword">typedef</span> <span class="keyword">enum</span>  FT_LcdFilter_
136   {
137     <a href="ft2-lcd_filtering.html#FT_LCD_FILTER_NONE">FT_LCD_FILTER_NONE</a>    = 0,
138     <a href="ft2-lcd_filtering.html#FT_LCD_FILTER_DEFAULT">FT_LCD_FILTER_DEFAULT</a> = 1,
139     <a href="ft2-lcd_filtering.html#FT_LCD_FILTER_LIGHT">FT_LCD_FILTER_LIGHT</a>   = 2,
140     <a href="ft2-lcd_filtering.html#FT_LCD_FILTER_LEGACY1">FT_LCD_FILTER_LEGACY1</a> = 3,
141     <a href="ft2-lcd_filtering.html#FT_LCD_FILTER_LEGACY">FT_LCD_FILTER_LEGACY</a>  = 16,
142
143     FT_LCD_FILTER_MAX   /* do not remove */
144
145   } <b>FT_LcdFilter</b>;
146 </pre>
147
148 <p>A list of values to identify various types of LCD filters.</p>
149
150 <h4>values</h4>
151 <table class="fields">
152 <tr><td class="val" id="FT_LCD_FILTER_NONE">FT_LCD_FILTER_NONE</td><td class="desc">
153 <p>Do not perform filtering. When used with subpixel rendering, this results in sometimes severe color fringes.</p>
154 </td></tr>
155 <tr><td class="val" id="FT_LCD_FILTER_DEFAULT">FT_LCD_FILTER_DEFAULT</td><td class="desc">
156 <p>The default filter reduces color fringes considerably, at the cost of a slight blurriness in the output.</p>
157 <p>It is a beveled, normalized, and color-balanced five-tap filter that is more forgiving to screens with non-ideal gamma curves and viewing angles. Note that while color-fringing is reduced, it can only be minimized by using linear alpha blending and gamma correction to render glyphs onto surfaces. The default filter weights are [0x08 0x4D 0x56 0x4D 0x08].</p>
158 </td></tr>
159 <tr><td class="val" id="FT_LCD_FILTER_LIGHT">FT_LCD_FILTER_LIGHT</td><td class="desc">
160 <p>The light filter is a variant that is sharper at the cost of slightly more color fringes than the default one.</p>
161 <p>It is a boxy, normalized, and color-balanced three-tap filter that is less forgiving to screens with non-ideal gamma curves and viewing angles. This filter works best when the rendering system uses linear alpha blending and gamma correction to render glyphs onto surfaces. The light filter weights are [0x00 0x55 0x56 0x55 0x00].</p>
162 </td></tr>
163 <tr><td class="val" id="FT_LCD_FILTER_LEGACY">FT_LCD_FILTER_LEGACY</td><td class="desc">
164 <p>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 <b>and</b> high-quality hinted fonts are used.</p>
165 <p>This filter is only provided for comparison purposes, and might be disabled or stay unsupported in the future.</p>
166 </td></tr>
167 <tr><td class="val" id="FT_LCD_FILTER_LEGACY1">FT_LCD_FILTER_LEGACY1</td><td class="desc">
168 <p>For historical reasons, the FontConfig library returns a different enumeration value for legacy LCD filtering. To make code work that (incorrectly) forwards FontConfig's enumeration value to <a href="ft2-lcd_filtering.html#FT_Library_SetLcdFilter">FT_Library_SetLcdFilter</a> without proper mapping, it is thus easiest to have another enumeration value, which is completely equal to &lsquo;FT_LCD_FILTER_LEGACY&rsquo;.</p>
169 </td></tr>
170 </table>
171
172 <h4>since</h4>
173 <p>2.3.0 (&lsquo;FT_LCD_FILTER_LEGACY1&rsquo; since 2.6.2)</p>
174
175 <hr>
176 <table class="index-toc-link"><tr><td class="left">[<a href="ft2-index.html">Index</a>]</td><td class="middle">[<a href="#">Top</a>]</td><td class="right">[<a href="ft2-toc.html">TOC</a>]</td></tr></table></div>
177
178 <div class="section">
179 <h3 id="FT_Library_SetLcdFilter">FT_Library_SetLcdFilter</h3>
180 <p>Defined in FT_LCD_FILTER_H (freetype/ftlcdfil.h).</p>
181 <pre>
182   FT_EXPORT( <a href="ft2-basic_types.html#FT_Error">FT_Error</a> )
183   <b>FT_Library_SetLcdFilter</b>( <a href="ft2-base_interface.html#FT_Library">FT_Library</a>    library,
184                            <a href="ft2-lcd_filtering.html#FT_LcdFilter">FT_LcdFilter</a>  filter );
185 </pre>
186
187 <p>This function is used to apply color filtering to LCD decimated bitmaps, like the ones used when calling <a href="ft2-base_interface.html#FT_Render_Glyph">FT_Render_Glyph</a> with <a href="ft2-base_interface.html#FT_Render_Mode">FT_RENDER_MODE_LCD</a> or <a href="ft2-base_interface.html#FT_Render_Mode">FT_RENDER_MODE_LCD_V</a>.</p>
188
189 <h4>input</h4>
190 <table class="fields">
191 <tr><td class="val" id="library">library</td><td class="desc">
192 <p>A handle to the target library instance.</p>
193 </td></tr>
194 <tr><td class="val" id="filter">filter</td><td class="desc">
195 <p>The filter type.</p>
196 <p>You can use <a href="ft2-lcd_filtering.html#FT_LcdFilter">FT_LCD_FILTER_NONE</a> here to disable this feature, or <a href="ft2-lcd_filtering.html#FT_LcdFilter">FT_LCD_FILTER_DEFAULT</a> to use a default filter that should work well on most LCD screens.</p>
197 </td></tr>
198 </table>
199
200 <h4>return</h4>
201 <p>FreeType error code. 0&nbsp;means success.</p>
202
203 <h4>note</h4>
204 <p>This feature is always disabled by default. Clients must make an explicit call to this function with a &lsquo;filter&rsquo; value other than <a href="ft2-lcd_filtering.html#FT_LcdFilter">FT_LCD_FILTER_NONE</a> in order to enable it.</p>
205 <p>Due to <b>PATENTS</b> covering subpixel rendering, this function doesn't do anything except returning &lsquo;FT_Err_Unimplemented_Feature&rsquo; 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.</p>
206
207 <h4>since</h4>
208 <p>2.3.0</p>
209
210 <hr>
211 <table class="index-toc-link"><tr><td class="left">[<a href="ft2-index.html">Index</a>]</td><td class="middle">[<a href="#">Top</a>]</td><td class="right">[<a href="ft2-toc.html">TOC</a>]</td></tr></table></div>
212
213 <div class="section">
214 <h3 id="FT_Library_SetLcdFilterWeights">FT_Library_SetLcdFilterWeights</h3>
215 <p>Defined in FT_LCD_FILTER_H (freetype/ftlcdfil.h).</p>
216 <pre>
217   FT_EXPORT( <a href="ft2-basic_types.html#FT_Error">FT_Error</a> )
218   <b>FT_Library_SetLcdFilterWeights</b>( <a href="ft2-base_interface.html#FT_Library">FT_Library</a>      library,
219                                   <span class="keyword">unsigned</span> <span class="keyword">char</span>  *weights );
220
221
222   /*
223    * @type:
224    *   FT_LcdFiveTapFilter
225    *
226    * @description:
227    *   A <span class="keyword">typedef</span> for passing the five LCD filter weights to
228    *   @<a href="ft2-base_interface.html#FT_Face_Properties">FT_Face_Properties</a> within an @<a href="ft2-base_interface.html#FT_Parameter">FT_Parameter</a> structure.
229    *
230    * @since:
231    *   2.8
232    *
233    */
234 #define FT_LCD_FILTER_FIVE_TAPS  5
235
236   <span class="keyword">typedef</span> <a href="ft2-basic_types.html#FT_Byte">FT_Byte</a>  FT_LcdFiveTapFilter[FT_LCD_FILTER_FIVE_TAPS];
237 </pre>
238
239 <p>This function can be used to enable LCD filter with custom weights, instead of using presets in <a href="ft2-lcd_filtering.html#FT_Library_SetLcdFilter">FT_Library_SetLcdFilter</a>.</p>
240
241 <h4>input</h4>
242 <table class="fields">
243 <tr><td class="val" id="library">library</td><td class="desc">
244 <p>A handle to the target library instance.</p>
245 </td></tr>
246 <tr><td class="val" id="weights">weights</td><td class="desc">
247 <p>A pointer to an array; the function copies the first five bytes and uses them to specify the filter weights.</p>
248 </td></tr>
249 </table>
250
251 <h4>return</h4>
252 <p>FreeType error code. 0&nbsp;means success.</p>
253
254 <h4>note</h4>
255 <p>Due to <b>PATENTS</b> covering subpixel rendering, this function doesn't do anything except returning &lsquo;FT_Err_Unimplemented_Feature&rsquo; 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.</p>
256 <p>LCD filter weights can also be set per face using <a href="ft2-base_interface.html#FT_Face_Properties">FT_Face_Properties</a> with <a href="ft2-parameter_tags.html#FT_PARAM_TAG_LCD_FILTER_WEIGHTS">FT_PARAM_TAG_LCD_FILTER_WEIGHTS</a>.</p>
257
258 <h4>since</h4>
259 <p>2.4.0</p>
260
261 <hr>
262 <table class="index-toc-link"><tr><td class="left">[<a href="ft2-index.html">Index</a>]</td><td class="middle">[<a href="#">Top</a>]</td><td class="right">[<a href="ft2-toc.html">TOC</a>]</td></tr></table></div>
263
264 </body>
265 </html>