adding missing file
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
diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c
new file mode 100644
index 0000000..ae1a221
--- /dev/null
+++ b/src/base/ftlcdfil.c
@@ -0,0 +1,169 @@
+#include <ft2build.h>
+#include FT_LCD_FILTER_H
+#include FT_IMAGE_H
+#include FT_INTERNAL_OBJECTS_H
+
+#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
+
+ /* this function will be invoked from within the smooth
+ * rasterizer
+ */
+ static void
+ _ft_lcd_filter( FT_Bitmap* bitmap,
+ FT_Render_Mode mode,
+ FT_Byte* weights )
+ {
+ FT_UInt width = (FT_UInt) bitmap->width;
+ FT_UInt height = (FT_UInt) bitmap->rows;
+
+ /* horizontal in-place FIR filter */
+ if ( mode == FT_RENDER_MODE_LCD && width >= 4 )
+ {
+ FT_Byte* line = bitmap->buffer;
+
+ for ( ; height > 0; height--, line += bitmap->pitch )
+ {
+ FT_UInt fir[5];
+ FT_UInt val1, xx;
+
+ val1 = line[0];
+ fir[0] = weights[2]*val1;
+ fir[1] = weights[3]*val1;
+ fir[2] = weights[4]*val1;
+ fir[3] = 0;
+ fir[4] = 0;
+
+
+ val1 = line[1];
+ fir[0] += weights[1]*val1;
+ fir[1] += weights[2]*val1;
+ fir[2] += weights[3]*val1;
+ fir[3] += weights[4]*val1;
+
+ for ( xx = 2; xx < width; xx++ )
+ {
+ FT_UInt val, pix;
+
+ val = line[xx];
+ pix = fir[0] + weights[0]*val;
+ fir[0] = fir[1] + weights[1]*val;
+ fir[1] = fir[2] + weights[2]*val;
+ fir[2] = fir[3] + weights[3]*val;
+ fir[3] = weights[4]*val;
+
+ pix >>= 8;
+ pix |= -(pix >> 8);
+ line[xx-2] = (FT_Byte)pix;
+ }
+
+ {
+ FT_UInt pix;
+
+ pix = fir[0] >> 8;
+ pix |= -(pix >> 8);
+ line[xx-2] = (FT_Byte)pix;
+
+ pix = fir[1] >> 8;
+ pix |= -(pix >> 8);
+ line[xx-1] = (FT_Byte)pix;
+ }
+ }
+ }
+ /* vertical in-place FIR filter */
+ else if ( mode == FT_RENDER_MODE_LCD_V && height >= 4 )
+ {
+ FT_Byte* column = bitmap->buffer;
+ FT_Int pitch = bitmap->pitch;
+
+ for ( ; width > 0; width--, column++ )
+ {
+ FT_Byte* col = column;
+ FT_UInt fir[5];
+ FT_UInt val1, yy;
+
+ val1 = col[0];
+ fir[0] = weights[2]*val1;
+ fir[1] = weights[3]*val1;
+ fir[2] = weights[4]*val1;
+ fir[3] = 0;
+ fir[4] = 0;
+ col += pitch;
+
+ val1 = col[0];
+ fir[0] += weights[1]*val1;
+ fir[1] += weights[2]*val1;
+ fir[2] += weights[3]*val1;
+ fir[3] += weights[4]*val1;
+ col += pitch;
+
+ for ( yy = 2; yy < height; yy++ )
+ {
+ FT_UInt val, pix;
+
+ val = col[0];
+ pix = fir[0] + weights[0]*val;
+ fir[0] = fir[1] + weights[1]*val;
+ fir[1] = fir[2] + weights[2]*val;
+ fir[2] = fir[3] + weights[3]*val;
+ fir[3] = weights[4]*val;
+
+ pix >>= 8;
+ pix |= -(pix >> 8);
+ col[-2*pitch] = (FT_Byte)pix;
+ col += pitch;
+ }
+
+ {
+ FT_UInt pix;
+
+ pix = fir[0] >> 8;
+ pix |= -(pix >> 8);
+ col[-2*pitch] = (FT_Byte)pix;
+
+ pix = fir[1] >> 8;
+ pix |= -(pix >> 8);
+ col[-pitch] = (FT_Byte)pix;
+ }
+ }
+ }
+ }
+
+
+ FT_EXPORT( FT_Error )
+ FT_Library_SetLcdFilter( FT_Library library,
+ const FT_Byte* filter_weights )
+ {
+ static const FT_Byte default_filter[5] = { 0x10, 0x40, 0x70, 0x40, 0x10 };
+
+ if ( library == NULL )
+ return FT_Err_Invalid_Argument;
+
+ if ( filter_weights == FT_LCD_FILTER_NONE )
+ {
+ library->lcd_filter = NULL;
+ return 0;
+ }
+
+ if ( filter_weights == FT_LCD_FILTER_DEFAULT )
+ filter_weights = default_filter;
+
+ memcpy( library->lcd_filter_weights, filter_weights, 5 );
+ library->lcd_filter = _ft_lcd_filter;
+
+ return 0;
+ }
+
+#else
+
+ FT_EXPORT( FT_Error )
+ FT_Library_SetLcdFilter( FT_Library library,
+ const FT_Byte* filter_weights )
+ {
+ FT_UNUSED(library);
+ FT_UNUSED(filter_weights);
+
+ return FT_Err_Unimplemented_Feature;
+ }
+
+
+#endif