From c56d8851ea987023cc73981a70d261b3f6427545 Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Mon, 3 Jul 2017 22:49:07 -0400 Subject: [PATCH] * src/base/ftlcdfil.c (ft_lcd_filter_fir): Improve code. --- ChangeLog | 6 +++++- src/base/ftlcdfil.c | 28 ++++++++-------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index c6e8229af..8b2d72275 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-07-03 Alexei Podtelezhnikov + + * src/base/ftlcdfil.c (ft_lcd_filter_fir): Improve code. + 2017-07-03 Werner Lemberg [truetype] Integer overflow. @@ -112,7 +116,7 @@ [base, smooth] LCD filtering cleanups. - * src/base/ftlcdlil.c (ft_lcd_filter_fir, _ft_lcd_filter_legacy): + * src/base/ftlcdfil.c (ft_lcd_filter_fir, _ft_lcd_filter_legacy): Clean up, start filtering from the bottom-left origin. * src/smooth/ftsmooth.c (ft_smooth_render_generic): Updated. diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c index 6d35e35cb..60c813fd9 100644 --- a/src/base/ftlcdfil.c +++ b/src/base/ftlcdfil.c @@ -29,6 +29,8 @@ /* define USE_LEGACY to implement the legacy filter */ #define USE_LEGACY +#define FT_SHIFTCLAMP( x ) ( x >>= 8, (FT_Byte)( x > 255 ? 255 : x ) ) + /* FIR filter used by the default and light filters */ FT_BASE( void ) ft_lcd_filter_fir( FT_Bitmap* bitmap, @@ -80,18 +82,11 @@ fir[3] = fir[4] + weights[3] * val; fir[4] = weights[4] * val; - fir[0] >>= 8; - fir[0] |= (FT_UInt)-(FT_Int)( fir[0] >> 8 ); - line[xx - 2] = (FT_Byte)fir[0]; + line[xx - 2] = FT_SHIFTCLAMP( fir[0] ); } - fir[1] >>= 8; - fir[1] |= (FT_UInt)-(FT_Int)( fir[1] >> 8 ); - line[xx - 2] = (FT_Byte)fir[1]; - - fir[2] >>= 8; - fir[2] |= (FT_UInt)-(FT_Int)( fir[2] >> 8 ); - line[xx - 1] = (FT_Byte)fir[2]; + line[xx - 2] = FT_SHIFTCLAMP( fir[1] ); + line[xx - 1] = FT_SHIFTCLAMP( fir[2] ); } } @@ -130,18 +125,11 @@ fir[3] = fir[4] + weights[3] * val; fir[4] = weights[4] * val; - fir[0] >>= 8; - fir[0] |= (FT_UInt)-(FT_Int)( fir[0] >> 8 ); - col[pitch * 2] = (FT_Byte)fir[0]; + col[pitch * 2] = FT_SHIFTCLAMP( fir[0] ); } - fir[1] >>= 8; - fir[1] |= (FT_UInt)-(FT_Int)( fir[1] >> 8 ); - col[pitch * 2] = (FT_Byte)fir[1]; - - fir[2] >>= 8; - fir[2] |= (FT_UInt)-(FT_Int)( fir[2] >> 8 ); - col[pitch] = (FT_Byte)fir[2]; + col[pitch * 2] = FT_SHIFTCLAMP( fir[1] ); + col[pitch] = FT_SHIFTCLAMP( fir[2] ); } } }