[base] API for Harmony LCD rendering. This introduces `FT_Library_SetLcdGeometry' for setting up arbitrary LCD subpixel geometry including non-striped patterns. * src/base/ftlcdfil.c (FT_Library_SetLcdGeometry): New function. * include/freetype/ftlcdfil.h: Document it. * include/freetype/freetype.h: Minor. * include/freetype/ftchapters.h: Minor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
diff --git a/ChangeLog b/ChangeLog
index db224a2..93c1d51 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2018-06-07 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [base] API for Harmony LCD rendering.
+
+ This introduces `FT_Library_SetLcdGeometry' for setting up arbitrary
+ LCD subpixel geometry including non-striped patterns.
+
+ * src/base/ftlcdfil.c (FT_Library_SetLcdGeometry): New function.
+ * include/freetype/ftlcdfil.h: Document it.
+ * include/freetype/freetype.h: Minor.
+ * include/freetype/ftchapters.h: Minor.
+
2018-06-06 Werner Lemberg <wl@gnu.org>
ftcolor.h: Redesign API.
@@ -5,7 +17,7 @@
While going to implement it I noticed that I need access to most of
the `CPAL' elements; I thus plan to add a `cpal' field to
`TT_FaceRec', which makes most of the previously suggested API
- functions obsolete because the fields will be directly accessable.
+ functions obsolete because the fields will be directly accessible.
2018-06-06 Parth Wazurkar <parthwazurkar@gmail.com>
@@ -657,7 +669,7 @@
The CPack definitions have been cleaned up, the `make dist' has been
removed. Source packages generated with CPack don't contain Autotools
- files and aren't used by the maintainters anyway.
+ files and aren't used by the maintainers anyway.
On Windows, src/base/ftver.rc is compiled to decorate the library with
version and copyright information.
@@ -1872,7 +1884,7 @@
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3514.
- * src/raster/ftrend1.c (ft_raster1_render): Exlicitly signed height.
+ * src/raster/ftrend1.c (ft_raster1_render): Explicitly signed height.
* src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto.
* src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Explicitly unsigned
subtraction.
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 736c251..2b41381 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -3500,7 +3500,7 @@ FT_BEGIN_HEADER
* with subpixel-rendered glyphs to prevent color-fringing! A
* subpixel-rendered glyph must first be filtered with a filter that
* gives equal weight to the three color primaries and does not
- * exceed a sum of 0x100, see section @lcd_filtering. Then the
+ * exceed a sum of 0x100, see section @lcd_rendering. Then the
* only difference to gray linear blending is that subpixel-rendered
* linear blending is done 3~times per pixel: red foreground subpixel
* to red background subpixel and so on for green and blue.
diff --git a/include/freetype/ftchapters.h b/include/freetype/ftchapters.h
index 0bb8229..f220e4b 100644
--- a/include/freetype/ftchapters.h
+++ b/include/freetype/ftchapters.h
@@ -120,7 +120,7 @@
* gzip
* lzw
* bzip2
- * lcd_filtering
+ * lcd_rendering
*
*/
diff --git a/include/freetype/ftlcdfil.h b/include/freetype/ftlcdfil.h
index ce5ea35..2989ceb 100644
--- a/include/freetype/ftlcdfil.h
+++ b/include/freetype/ftlcdfil.h
@@ -36,28 +36,29 @@ FT_BEGIN_HEADER
/***************************************************************************
*
* @section:
- * lcd_filtering
+ * lcd_rendering
*
* @title:
- * LCD Filtering
+ * Subpixel Rendering
*
* @abstract:
- * Remove color fringes of subpixel-rendered bitmaps.
+ * API to control subpixel rendering.
*
* @description:
+ * FreeType provides two alternative subpixel rendering technologies.
* Should you #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your
- * `ftoption.h', 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.
+ * `ftoption.h', this enables patented ClearType-style rendering.
+ * Otherwise, Harmony LCD rendering is enabled. These technologies are
+ * controlled differently and API described below, although always
+ * available, performs its function when appropriate method is enabled
+ * and does nothing otherwise.
*
* 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~3. Using the
* subpixels coverages unfiltered can create severe color fringes
* especially when rendering thin features. Indeed, to produce
- * black-on-white text, the color components must be dimmed equally.
+ * black-on-white text, the nearby color subpixels must be dimmed equally.
*
* A good 5-tap FIR filter should be applied to subpixel coverages
* regardless of pixel boundaries and should have these properties:
@@ -72,31 +73,54 @@ FT_BEGIN_HEADER
* 3) It should be normalized, meaning 2a~+ 2b~+ c~=~1.0 to maintain
* overall brightness.
*
- * Use the @FT_Library_SetLcdFilter API to specify a low-pass filter,
- * which is then applied to subpixel-rendered bitmaps generated through
- * @FT_Render_Glyph. The filter affects glyph bitmaps rendered through
- * @FT_Render_Glyph, @FT_Load_Glyph, and @FT_Load_Char. It does _not_
- * affect the output of @FT_Outline_Render and @FT_Outline_Get_Bitmap.
- *
- * 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
- * @FT_RENDER_MODE_LCD, the filter adds 2~subpixels to the left, and
+ * The distribution of density values by the color-balanced filter assumes
+ * alpha blending is done in linear space; only then color artifacts
+ * cancel out. Boxy 3-tap filter {0, 1/3, 1/3, 1/3, 0} is sharper but is
+ * less forgiving of non-ideal gamma curves of a screen (viewing angles!),
+ * beveled filters are fuzzier but more tolerant.
+ *
+ * Use the @FT_Library_SetLcdFilter or @FT_Library_SetLcdFilterWeights
+ * API to specify a low-pass filter, which is then applied to
+ * subpixel-rendered bitmaps generated through @FT_Render_Glyph.
+ *
+ * Harmony LCD rendering is suitable to panels with any regular subpixel
+ * structure, not just monitors with 3 color striped subpixels, as long as
+ * the color subpixels have fixed positions relative to the pixel center.
+ * In this case, each color channel is then rendered separately after
+ * shifting the outline opposite to the subpixel shift so that the
+ * coverage maps are aligned. This method is immune to color fringes
+ * because the shifts do not change integral coverage.
+ *
+ * The subpixel geometry must be specified by xy-coordinates for each
+ * subpixel. By convention they may come in the RGB order:
+ *
+ * {{-1/3, 0}, {0, 0}, {1/3, 0}} for hRGB striped panel (default),
+ * {{1/3, 0}, {0, 0}, {-1/3, 0}} for hBGR striped panel,
+ * {{0, 1/3}, {0, 0}, {0, -1/3}} for vRGB striped panel,
+ * {{-1/6, 1/4}, {-1/6, -1/4}, {1/3, 0}} for a certain PenTile panel.
+ *
+ * Use the @FT_Library_SetLcdGeometry API to specify subpixel positions.
+ * If one follows the RGB order convention, the same order applies
+ * to the resulting @FT_PIXEL_MODE_LCD and @FT_PIXEL_MODE_LCD_V bitmaps.
+ * Note, however, that the coordinate frame for the latter must be rotated
+ * clockwise. Harmony with default LCD geometry is equivalent to
+ * ClearType with light filter.
+ *
+ * As a result of ClearType filtering or Harmony rendering, the dimensions
+ * of LCD bitmaps can be either wider or taller than the dimensions of
+ * the corresponding outline with regard to the pixel grid. For example,
+ * for @FT_RENDER_MODE_LCD, the filter adds 2~subpixels to the left, and
* 2~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.
*
- * Only filtering along with gamma-corrected alpha blending can completely
- * remove color fringes. Boxy 3-tap filter {0, 1/3, 1/3, 1/3, 0} is
- * sharper but is less forgiving of non-ideal gamma curves of a screen
- * (viewing angles!), beveled filters are fuzzier but more tolerant.
- *
- * Each of the 3~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.
+ * The ClearType and Harmony rendering is applicable to glyph bitmaps
+ * rendered through @FT_Render_Glyph, @FT_Load_Glyph, and @FT_Load_Char.
+ * @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V and these technologies do
+ * not apply to @FT_Outline_Render and @FT_Outline_Get_Bitmap directly.
+ * Each of the 3~alpha values (subpixels) must by 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.
*/
@@ -247,6 +271,53 @@ FT_BEGIN_HEADER
typedef FT_Byte FT_LcdFiveTapFilter[FT_LCD_FILTER_FIVE_TAPS];
+ /**************************************************************************
+ *
+ * @func:
+ * FT_Library_SetLcdGeometry
+ *
+ * @description:
+ * This function can be used to modify default positions of color
+ * subpixels, which controls Harmony LCD rendering.
+ *
+ * @input:
+ * library ::
+ * A handle to the target library instance.
+ *
+ * sub ::
+ * A pointer to an array of 3 vectors in 26.6 fractional pixel format;
+ * the function modifies the default values, see the note below.
+ *
+ * @return:
+ * FreeType error code. 0~means success.
+ *
+ * @note:
+ * Subpixel geometry examples:
+ *
+ * - {{-21, 0}, {0, 0}, {21, 0}} is the default, corresponding 3 color
+ * stripes shifted by a third of a pixel. This could be an RGB panel.
+ *
+ * - {{21, 0}, {0, 0}, {-21, 0}} looks the same as the default but
+ * can specify a BGR panel instead, while keeping the bitmap in the same
+ * RGB888 format.
+ *
+ * - {{0, 21}, {0, 0}, {0, -21}} is the vertical RGB, but the bitmap
+ * stays RGB888 as a result.
+ *
+ * - {{-11, 16}, {-11, -16}, {22, 0}} is a certain PenTile arrangement.
+ *
+ * This function does nothing and returns `FT_Err_Unimplemented_Feature'
+ * in the context of ClearType-style subpixel rendering when
+ * FT_CONFIG_OPTION_SUBPIXEL_RENDERING is defined in your build of the
+ * library.
+ *
+ * @since:
+ * 2.10.0
+ */
+ FT_EXPORT( FT_Error )
+ FT_Library_SetLcdGeometry( FT_Library library,
+ FT_Vector sub[3] );
+
/* */
diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c
index 341fae6..65eff93 100644
--- a/src/base/ftlcdfil.c
+++ b/src/base/ftlcdfil.c
@@ -285,6 +285,8 @@
#endif /* USE_LEGACY */
+ /* documentation in ftlcdfil.h */
+
FT_EXPORT_DEF( FT_Error )
FT_Library_SetLcdFilterWeights( FT_Library library,
unsigned char *weights )
@@ -302,6 +304,8 @@
}
+ /* documentation in ftlcdfil.h */
+
FT_EXPORT_DEF( FT_Error )
FT_Library_SetLcdFilter( FT_Library library,
FT_LcdFilter filter )
@@ -351,6 +355,17 @@
return FT_Err_Ok;
}
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_Library_SetLcdGeometry( FT_Library library,
+ FT_Vector* sub )
+ {
+ FT_UNUSED( library );
+ FT_UNUSED( sub );
+
+ return FT_THROW( Unimplemented_Feature );
+ }
+
#else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
/* add padding to accommodate outline shifts */
@@ -399,6 +414,24 @@
return FT_THROW( Unimplemented_Feature );
}
+
+ /* documentation in ftlcdfil.h */
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_Library_SetLcdGeometry( FT_Library library,
+ FT_Vector sub[3] )
+ {
+ if ( !library )
+ return FT_THROW( Invalid_Library_Handle );
+
+ if ( !sub )
+ return FT_THROW( Invalid_Argument );
+
+ ft_memcpy( library->lcd_geometry, sub, 3 * sizeof( FT_Vector ) );
+
+ return FT_THROW( Unimplemented_Feature );
+ }
+
#endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */