summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2017-07-03 22:49:07 -0400
committerAlexei Podtelezhnikov <apodtele@gmail.com>2017-07-03 22:49:07 -0400
commitc56d8851ea987023cc73981a70d261b3f6427545 (patch)
treefdc5fffa739fd0cc4e98013138d47ee92d1a5325
parentca799e9be52526739691f120285a27b91fd15d68 (diff)
downloadfreetype2-c56d8851ea987023cc73981a70d261b3f6427545.tar.gz
* src/base/ftlcdfil.c (ft_lcd_filter_fir): Improve code.
-rw-r--r--ChangeLog6
-rw-r--r--src/base/ftlcdfil.c28
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 <apodtele@gmail.com>
+
+ * src/base/ftlcdfil.c (ft_lcd_filter_fir): Improve code.
+
2017-07-03 Werner Lemberg <wl@gnu.org>
[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] );
}
}
}