shithub: freetype+ttf2subf

Download patch

ref: c56d8851ea987023cc73981a70d261b3f6427545
parent: ca799e9be52526739691f120285a27b91fd15d68
author: Alexei Podtelezhnikov <[email protected]>
date: Mon Jul 3 18:49:07 EDT 2017

* src/base/ftlcdfil.c (ft_lcd_filter_fir): Improve code.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-07-03  Alexei Podtelezhnikov  <[email protected]>
+
+	* src/base/ftlcdfil.c (ft_lcd_filter_fir): Improve code.
+
 2017-07-03  Werner Lemberg  <[email protected]>
 
 	[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.
--- 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] );
       }
     }
   }