diff options
Diffstat (limited to 'Build/source/libs/freetype2/freetype-src/src/smooth/ftsmooth.c')
-rw-r--r-- | Build/source/libs/freetype2/freetype-src/src/smooth/ftsmooth.c | 192 |
1 files changed, 118 insertions, 74 deletions
diff --git a/Build/source/libs/freetype2/freetype-src/src/smooth/ftsmooth.c b/Build/source/libs/freetype2/freetype-src/src/smooth/ftsmooth.c index 435854e6734..963435de150 100644 --- a/Build/source/libs/freetype2/freetype-src/src/smooth/ftsmooth.c +++ b/Build/source/libs/freetype2/freetype-src/src/smooth/ftsmooth.c @@ -31,12 +31,7 @@ static FT_Error ft_smooth_init( FT_Renderer render ) { - FT_Library library = FT_MODULE_LIBRARY( render ); - - - render->clazz->raster_class->raster_reset( render->raster, - library->raster_pool, - library->raster_pool_size ); + render->clazz->raster_class->raster_reset( render->raster, NULL, 0 ); return 0; } @@ -111,9 +106,6 @@ FT_Pos y_shift = 0; FT_Pos x_left, y_top; FT_Pos width, height, pitch; -#ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING - FT_Pos height_org, width_org; -#endif FT_Int hmul = ( mode == FT_RENDER_MODE_LCD ); FT_Int vmul = ( mode == FT_RENDER_MODE_LCD_V ); @@ -124,7 +116,6 @@ #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING - FT_Int lcd_extra = 0; FT_LcdFiveTapFilter lcd_weights = { 0 }; FT_Bool have_custom_weight = FALSE; FT_Bitmap_LcdFilterFunc lcd_filter_func = NULL; @@ -152,13 +143,12 @@ { /* * A per-font filter is set. It always uses the default 5-tap - * in-place FIR filter that needs 2 extra pixels. + * in-place FIR filter. */ ft_memcpy( lcd_weights, slot->face->internal->lcd_weights, FT_LCD_FILTER_FIVE_TAPS ); lcd_filter_func = ft_lcd_filter_fir; - lcd_extra = 2; } else { @@ -172,7 +162,6 @@ slot->library->lcd_weights, FT_LCD_FILTER_FIVE_TAPS ); lcd_filter_func = slot->library->lcd_filter_func; - lcd_extra = slot->library->lcd_extra; } #endif /*FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ @@ -201,6 +190,45 @@ /* taking into account the origin shift */ FT_Outline_Get_CBox( outline, &cbox ); +#ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING + + /* add minimal padding for LCD rendering */ + if ( hmul ) + { + cbox.xMax += 21; + cbox.xMin -= 21; + } + + if ( vmul ) + { + cbox.yMax += 21; + cbox.yMin -= 21; + } + +#else /* FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ + + /* add minimal padding for LCD filter depending on specific weights */ + if ( lcd_filter_func ) + { + if ( hmul ) + { + cbox.xMax += lcd_weights[4] ? 43 + : lcd_weights[3] ? 22 : 0; + cbox.xMin -= lcd_weights[0] ? 43 + : lcd_weights[1] ? 22 : 0; + } + + if ( vmul ) + { + cbox.yMax += lcd_weights[4] ? 43 + : lcd_weights[3] ? 22 : 0; + cbox.yMin -= lcd_weights[0] ? 43 + : lcd_weights[1] ? 22 : 0; + } + } + +#endif /* FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ + cbox.xMin = FT_PIX_FLOOR( cbox.xMin + x_shift ); cbox.yMin = FT_PIX_FLOOR( cbox.yMin + y_shift ); cbox.xMax = FT_PIX_CEIL( cbox.xMax + x_shift ); @@ -215,11 +243,6 @@ width = (FT_ULong)( cbox.xMax - cbox.xMin ) >> 6; height = (FT_ULong)( cbox.yMax - cbox.yMin ) >> 6; -#ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING - width_org = width; - height_org = height; -#endif - pitch = width; if ( hmul ) { @@ -230,26 +253,6 @@ if ( vmul ) height *= 3; -#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING - if ( lcd_filter_func ) - { - if ( hmul ) - { - x_shift += 64 * ( lcd_extra >> 1 ); - x_left -= lcd_extra >> 1; - width += 3 * lcd_extra; - pitch = FT_PAD_CEIL( width, 4 ); - } - - if ( vmul ) - { - y_shift += 64 * ( lcd_extra >> 1 ); - y_top += lcd_extra >> 1; - height += 3 * lcd_extra; - } - } -#endif - /* * XXX: on 16bit system, we return an error for huge bitmap * to prevent an overflow. @@ -353,57 +356,98 @@ #else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ - /* render outline into bitmap */ - error = render->raster_render( render->raster, ¶ms ); - if ( error ) - goto Exit; - - /* expand it horizontally */ - if ( hmul ) + if ( hmul ) /* lcd */ { - FT_Byte* line = bitmap->buffer; - FT_UInt hh; + FT_Byte* line; + FT_Byte* temp; + FT_Int i, j; - for ( hh = height_org; hh > 0; hh--, line += pitch ) - { - FT_UInt xx; - FT_Byte* end = line + width; + /* Render 3 separate monochrome bitmaps, shifting the outline */ + /* by 1/3 pixel. */ + width /= 3; + FT_Outline_Translate( outline, 21, 0 ); - for ( xx = width_org; xx > 0; xx-- ) - { - FT_UInt pixel = line[xx-1]; + error = render->raster_render( render->raster, ¶ms ); + if ( error ) + goto Exit; + + FT_Outline_Translate( outline, -21, 0 ); + bitmap->buffer += width; + + error = render->raster_render( render->raster, ¶ms ); + if ( error ) + goto Exit; + + FT_Outline_Translate( outline, -21, 0 ); + bitmap->buffer += width; + error = render->raster_render( render->raster, ¶ms ); + if ( error ) + goto Exit; - end[-3] = (FT_Byte)pixel; - end[-2] = (FT_Byte)pixel; - end[-1] = (FT_Byte)pixel; - end -= 3; + FT_Outline_Translate( outline, 21, 0 ); + 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. */ + + if ( FT_ALLOC( temp, (FT_ULong)pitch ) ) + goto Exit; + + for ( i = 0; i < height; i++ ) + { + line = bitmap->buffer + i * pitch; + for ( j = 0; j < width; j++ ) + { + temp[3 * j ] = line[j]; + temp[3 * j + 1] = line[j + width]; + temp[3 * j + 2] = line[j + width + width]; } + FT_MEM_COPY( line, temp, pitch ); } - } - /* expand it vertically */ - if ( vmul ) + FT_FREE( temp ); + } + else if ( vmul ) /* lcd_v */ { - FT_Byte* read = bitmap->buffer + ( height - height_org ) * pitch; - FT_Byte* write = bitmap->buffer; - FT_UInt hh; + /* Render 3 separate monochrome bitmaps, shifting the outline */ + /* by 1/3 pixel. Triple the pitch to render on each third row. */ + bitmap->pitch *= 3; + bitmap->rows /= 3; + FT_Outline_Translate( outline, 0, 21 ); + bitmap->buffer += 2 * pitch; - for ( hh = height_org; hh > 0; hh-- ) - { - ft_memcpy( write, read, pitch ); - write += pitch; + error = render->raster_render( render->raster, ¶ms ); + if ( error ) + goto Exit; - ft_memcpy( write, read, pitch ); - write += pitch; + FT_Outline_Translate( outline, 0, -21 ); + bitmap->buffer -= pitch; - ft_memcpy( write, read, pitch ); - write += pitch; - read += pitch; - } + error = render->raster_render( render->raster, ¶ms ); + if ( error ) + goto Exit; + + FT_Outline_Translate( outline, 0, -21 ); + bitmap->buffer -= pitch; + + error = render->raster_render( render->raster, ¶ms ); + if ( error ) + goto Exit; + + FT_Outline_Translate( outline, 0, 21 ); + + bitmap->pitch /= 3; + bitmap->rows *= 3; + } + else /* grayscale */ + { + error = render->raster_render( render->raster, ¶ms ); + if ( error ) + goto Exit; } #endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ |