[smooth] Formalize Harmony LCD rendering. This generalizes magic outline shifts that make Harmony LCD rendering work in terms of precise two-dimensional RGB subpixel positions. These coordinates are now set in time of the `smooth' module initialization and later used to shift a glyph outline for rendering. FT_RENDER_MODE_LCD and FT_RENDER_MODE_LCD_V use the same coordinates. The letter, however, rotates them before using. The LCD bitmap padding is also calculated using these coordinates. * include/freetype/internal/ftobjs.h (FT_LibraryRec): New array field `lcd_geometry'. * src/base/ftlcdfil.c (ft_lcd_padding): Reworked. * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Updated accordingly. * src/smooth/ftsmooth.c [!FT_CONFIG_OPTION_SUBPIXEL_RENDERING] (ft_smooth_init): Initialize `lcd_geometry'. (ft_smooth_render_generic): Formalize outline shifts.
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
diff --git a/ChangeLog b/ChangeLog
index 789ac94..7c19448 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2018-05-24 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [smooth] Formalize Harmony LCD rendering.
+
+ This generalizes magic outline shifts that make Harmony LCD
+ rendering work in terms of precise two-dimensional RGB subpixel
+ positions. These coordinates are now set in time of the `smooth'
+ module initialization and later used to shift a glyph outline for
+ rendering. FT_RENDER_MODE_LCD and FT_RENDER_MODE_LCD_V use the same
+ coordinates. The letter, however, rotates them before using.
+ The LCD bitmap padding is also calculated using these coordinates.
+
+ * include/freetype/internal/ftobjs.h (FT_LibraryRec): New array field
+ `lcd_geometry'.
+ * src/base/ftlcdfil.c (ft_lcd_padding): Reworked.
+ * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Updated accordingly.
+
+ * src/smooth/ftsmooth.c [!FT_CONFIG_OPTION_SUBPIXEL_RENDERING]
+ (ft_smooth_init): Initialize `lcd_geometry'.
+ (ft_smooth_render_generic): Formalize outline shifts.
+
2018-05-22 Werner Lemberg <wl@gnu.org>
[truetype] Reject elements of composites with invalid glyph indices.
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index a8d987f..77f5dc4 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -270,11 +270,11 @@ FT_BEGIN_HEADER
FT_CMap_Done( FT_CMap cmap );
- /* adds LCD padding to Min and Max boundaries */
+ /* add LCD padding to CBox */
FT_BASE( void )
- ft_lcd_padding( FT_Pos* Min,
- FT_Pos* Max,
- FT_GlyphSlot slot );
+ ft_lcd_padding( FT_BBox* cbox,
+ FT_GlyphSlot slot,
+ FT_Render_Mode mode );
#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
@@ -350,8 +350,8 @@ FT_BEGIN_HEADER
/* */
/* lcd_weights :: */
/* lcd_filter_func :: */
- /* If subpixel rendering is activated, the LCD filtering weights */
- /* and callback function. */
+ /* These fields specify the LCD filtering weights and callback */
+ /* function for ClearType-style subpixel rendering. */
/* */
/* refcount :: */
/* A counter initialized to~1 at the time an @FT_Face structure is */
@@ -868,11 +868,15 @@ FT_BEGIN_HEADER
/* interpreter. Currently, only the TrueType */
/* bytecode debugger uses this. */
/* */
- /* lcd_weights :: If subpixel rendering is activated, the LCD */
- /* filter weights, if any. */
+ /* lcd_weights :: The LCD filter weights for ClearType-style */
+ /* subpixel rendering. */
/* */
- /* lcd_filter_func :: If subpixel rendering is activated, the LCD */
- /* filtering callback function. */
+ /* lcd_filter_func :: The LCD filtering callback function for */
+ /* for ClearType-style subpixel rendering. */
+ /* */
+ /* lcd_geometry :: This array specifies LCD subpixel geometry */
+ /* and controls Harmony LCD rendering technique, */
+ /* alternative to ClearType. */
/* */
/* pic_container :: Contains global structs and tables, instead */
/* of defining them globally. */
@@ -904,6 +908,8 @@ FT_BEGIN_HEADER
#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
FT_LcdFiveTapFilter lcd_weights; /* filter weights, if any */
FT_Bitmap_LcdFilterFunc lcd_filter_func; /* filtering callback */
+#else
+ FT_Vector lcd_geometry[3]; /* RGB subpixel positions */
#endif
FT_Int refcount;
diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c
index 8d314df..213f3f1 100644
--- a/src/base/ftlcdfil.c
+++ b/src/base/ftlcdfil.c
@@ -34,9 +34,9 @@
/* add padding according to filter weights */
FT_BASE_DEF (void)
- ft_lcd_padding( FT_Pos* Min,
- FT_Pos* Max,
- FT_GlyphSlot slot )
+ ft_lcd_padding( FT_BBox* cbox,
+ FT_GlyphSlot slot,
+ FT_Render_Mode mode )
{
FT_Byte* lcd_weights;
FT_Bitmap_LcdFilterFunc lcd_filter_func;
@@ -56,10 +56,20 @@
if ( lcd_filter_func == ft_lcd_filter_fir )
{
- *Min -= lcd_weights[0] ? 43 :
- lcd_weights[1] ? 22 : 0;
- *Max += lcd_weights[4] ? 43 :
- lcd_weights[3] ? 22 : 0;
+ if ( mode == FT_RENDER_MODE_LCD )
+ {
+ cbox->xMin -= lcd_weights[0] ? 43 :
+ lcd_weights[1] ? 22 : 0;
+ cbox->xMax += lcd_weights[4] ? 43 :
+ lcd_weights[3] ? 22 : 0;
+ }
+ else if ( mode == FT_RENDER_MODE_LCD_V )
+ {
+ cbox->yMin -= lcd_weights[0] ? 43 :
+ lcd_weights[1] ? 22 : 0;
+ cbox->yMax += lcd_weights[4] ? 43 :
+ lcd_weights[3] ? 22 : 0;
+ }
}
}
@@ -343,16 +353,28 @@
#else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
- /* add padding according to accommodate outline shifts */
+ /* add padding to accommodate outline shifts */
FT_BASE_DEF (void)
- ft_lcd_padding( FT_Pos* Min,
- FT_Pos* Max,
- FT_GlyphSlot slot )
+ ft_lcd_padding( FT_BBox* cbox,
+ FT_GlyphSlot slot,
+ FT_Render_Mode mode )
{
- FT_UNUSED( slot );
+ FT_Vector* sub = slot->library->lcd_geometry;
- *Min -= 21;
- *Max += 21;
+ if ( mode == FT_RENDER_MODE_LCD )
+ {
+ cbox->xMin -= FT_MAX( FT_MAX( sub[0].x, sub[1].x ), sub[2].x );
+ cbox->xMax -= FT_MIN( FT_MIN( sub[0].x, sub[1].x ), sub[2].x );
+ cbox->yMin -= FT_MAX( FT_MAX( sub[0].y, sub[1].y ), sub[2].y );
+ cbox->yMax -= FT_MIN( FT_MIN( sub[0].y, sub[1].y ), sub[2].y );
+ }
+ else if ( mode == FT_RENDER_MODE_LCD_V )
+ {
+ cbox->xMin -= FT_MAX( FT_MAX( sub[0].y, sub[1].y ), sub[2].y );
+ cbox->xMax -= FT_MIN( FT_MIN( sub[0].y, sub[1].y ), sub[2].y );
+ cbox->yMin += FT_MIN( FT_MIN( sub[0].x, sub[1].x ), sub[2].x );
+ cbox->yMax += FT_MAX( FT_MAX( sub[0].x, sub[1].x ), sub[2].x );
+ }
}
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index d7768dd..2cd0c92 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -397,12 +397,12 @@
case FT_RENDER_MODE_LCD:
pixel_mode = FT_PIXEL_MODE_LCD;
- ft_lcd_padding( &cbox.xMin, &cbox.xMax, slot );
+ ft_lcd_padding( &cbox, slot, mode );
goto Round;
case FT_RENDER_MODE_LCD_V:
pixel_mode = FT_PIXEL_MODE_LCD_V;
- ft_lcd_padding( &cbox.yMin, &cbox.yMax, slot );
+ ft_lcd_padding( &cbox, slot, mode );
goto Round;
case FT_RENDER_MODE_NORMAL:
diff --git a/src/smooth/ftsmooth.c b/src/smooth/ftsmooth.c
index 497926e..3813251 100644
--- a/src/smooth/ftsmooth.c
+++ b/src/smooth/ftsmooth.c
@@ -30,6 +30,22 @@
static FT_Error
ft_smooth_init( FT_Renderer render )
{
+
+#ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
+
+ FT_Vector* sub = render->root.library->lcd_geometry;
+
+
+ /* set up default subpixel geometry for striped RGB panels. */
+ sub[0].x = -21;
+ sub[0].y = 0;
+ sub[1].x = 0;
+ sub[1].y = 0;
+ sub[2].x = 21;
+ sub[2].y = 0;
+
+#endif
+
render->clazz->raster_class->raster_reset( render->raster, NULL, 0 );
return 0;
@@ -234,33 +250,33 @@
unsigned int width = bitmap->width;
int pitch = bitmap->pitch;
+ FT_Vector* sub = slot->library->lcd_geometry;
- /* Render 3 separate monochrome bitmaps, shifting the outline */
- /* by 1/3 pixel. */
- width /= 3;
- bitmap->buffer += width;
+ /* Render 3 separate monochrome bitmaps, shifting the outline. */
+ width /= 3;
+ FT_Outline_Translate( outline, -sub[0].x, -sub[0].y );
error = render->raster_render( render->raster, ¶ms );
if ( error )
goto Exit;
- FT_Outline_Translate( outline, -21, 0 );
- x_shift -= 21;
bitmap->buffer += width;
-
+ FT_Outline_Translate( outline, sub[0].x - sub[1].x, sub[0].y - sub[1].y );
error = render->raster_render( render->raster, ¶ms );
if ( error )
goto Exit;
- FT_Outline_Translate( outline, 42, 0 );
- x_shift += 42;
- bitmap->buffer -= 2 * width;
-
+ bitmap->buffer += width;
+ FT_Outline_Translate( outline, sub[1].x - sub[2].x, sub[1].y - sub[2].y );
error = render->raster_render( render->raster, ¶ms );
if ( error )
goto Exit;
+ x_shift -= sub[2].x;
+ y_shift -= sub[2].y;
+ bitmap->buffer -= 2 * width;
+
/* XXX: Rearrange the bytes according to FT_PIXEL_MODE_LCD. */
/* XXX: It is more efficient to render every third byte above. */
@@ -285,34 +301,36 @@
{
int pitch = bitmap->pitch;
+ FT_Vector* sub = slot->library->lcd_geometry;
- /* Render 3 separate monochrome bitmaps, shifting the outline */
- /* by 1/3 pixel. Triple the pitch to render on each third row. */
+
+ /* Render 3 separate monochrome bitmaps, shifting the outline. */
+ /* Notice that the subpixel geometry vectors are rotated. */
+ /* Triple the pitch to render on each third row. */
bitmap->pitch *= 3;
bitmap->rows /= 3;
- bitmap->buffer += pitch;
-
+ FT_Outline_Translate( outline, -sub[0].y, sub[0].x );
error = render->raster_render( render->raster, ¶ms );
if ( error )
goto Exit;
- FT_Outline_Translate( outline, 0, 21 );
- y_shift += 21;
bitmap->buffer += pitch;
-
+ FT_Outline_Translate( outline, sub[0].y - sub[1].y, sub[1].x - sub[0].x );
error = render->raster_render( render->raster, ¶ms );
if ( error )
goto Exit;
- FT_Outline_Translate( outline, 0, -42 );
- y_shift -= 42;
- bitmap->buffer -= 2 * pitch;
-
+ bitmap->buffer += pitch;
+ FT_Outline_Translate( outline, sub[1].y - sub[2].y, sub[2].x - sub[1].x );
error = render->raster_render( render->raster, ¶ms );
if ( error )
goto Exit;
+ x_shift -= sub[2].y;
+ y_shift += sub[2].x;
+ bitmap->buffer -= 2 * pitch;
+
bitmap->pitch /= 3;
bitmap->rows *= 3;
}