[smooth] Implement minimal dynamic padding for LCD filtering. Extra bitmap padding for LCD filtering depends on the filter. The default 5-tap filter needs 2 extra subpixels. The light 3-tap filter needs only 1 extra subpixel. This space could be already available due to rounding. In order to optimize the padding, we now expand CBox for the given filter weights before rounding. This change breakes current Skia (and Firefox). * include/freetype/internal/ftobjs.h (FT_LibraryRec) [FT_CONFIG_OPTION_SUBPIXEL_RENDERING]: Remove `lcd_extra' field. * src/base/ftlcdfil.c (FT_Library_SetLcdFilterWeights, FT_Library_SetLcdFilter): Remove `lcd_extra' initializations. * src/smooth/ftsmooth.c (ft_smooth_render_generic): Implement dymanic LCD padding.
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 176 177 178 179 180 181 182 183 184 185 186
diff --git a/ChangeLog b/ChangeLog
index c784122..5e41f88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2017-05-20 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [smooth] Implement minimal dynamic padding for LCD filtering.
+
+ Extra bitmap padding for LCD filtering depends on the filter. The
+ default 5-tap filter needs 2 extra subpixels. The light 3-tap filter
+ needs only 1 extra subpixel. This space could be already available
+ due to rounding. In order to optimize the padding, we now expand
+ CBox for the given filter weights before rounding.
+
+ This change breakes current Skia (and Firefox).
+
+ * include/freetype/internal/ftobjs.h (FT_LibraryRec)
+ [FT_CONFIG_OPTION_SUBPIXEL_RENDERING]: Remove `lcd_extra' field.
+
+ * src/base/ftlcdfil.c (FT_Library_SetLcdFilterWeights,
+ FT_Library_SetLcdFilter): Remove `lcd_extra' initializations.
+
+ * src/smooth/ftsmooth.c (ft_smooth_render_generic): Implement dymanic
+ LCD padding.
+
2017-05-15 Werner Lemberg <wl@gnu.org>
[sfnt] Return proper scaling values for SBIX bitmaps.
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index 06b6597..73961b9 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -864,9 +864,6 @@ FT_BEGIN_HEADER
/* lcd_filter :: If subpixel rendering is activated, the */
/* selected LCD filter mode. */
/* */
- /* lcd_extra :: If subpixel rendering is activated, the number */
- /* of extra pixels needed for the LCD filter. */
- /* */
/* lcd_weights :: If subpixel rendering is activated, the LCD */
/* filter weights, if any. */
/* */
@@ -902,7 +899,6 @@ FT_BEGIN_HEADER
#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
FT_LcdFilter lcd_filter;
- FT_Int lcd_extra; /* number of extra pixels */
FT_LcdFiveTapFilter lcd_weights; /* filter weights, if any */
FT_Bitmap_LcdFilterFunc lcd_filter_func; /* filtering callback */
#endif
diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c
index 611b39f..65dbf34 100644
--- a/src/base/ftlcdfil.c
+++ b/src/base/ftlcdfil.c
@@ -296,7 +296,6 @@
ft_memcpy( library->lcd_weights, weights, FT_LCD_FILTER_FIVE_TAPS );
library->lcd_filter_func = ft_lcd_filter_fir;
- library->lcd_extra = 2;
return FT_Err_Ok;
}
@@ -319,7 +318,6 @@
{
case FT_LCD_FILTER_NONE:
library->lcd_filter_func = NULL;
- library->lcd_extra = 0;
break;
case FT_LCD_FILTER_DEFAULT:
@@ -327,7 +325,6 @@
default_weights,
FT_LCD_FILTER_FIVE_TAPS );
library->lcd_filter_func = ft_lcd_filter_fir;
- library->lcd_extra = 2;
break;
case FT_LCD_FILTER_LIGHT:
@@ -335,7 +332,6 @@
light_weights,
FT_LCD_FILTER_FIVE_TAPS );
library->lcd_filter_func = ft_lcd_filter_fir;
- library->lcd_extra = 2;
break;
#ifdef USE_LEGACY
@@ -343,7 +339,6 @@
case FT_LCD_FILTER_LEGACY:
case FT_LCD_FILTER_LEGACY1:
library->lcd_filter_func = _ft_lcd_filter_legacy;
- library->lcd_extra = 0;
break;
#endif
diff --git a/src/smooth/ftsmooth.c b/src/smooth/ftsmooth.c
index cd7a87b..061d251 100644
--- a/src/smooth/ftsmooth.c
+++ b/src/smooth/ftsmooth.c
@@ -119,7 +119,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;
@@ -147,13 +146,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
{
@@ -167,7 +165,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 */
@@ -196,6 +193,28 @@
/* taking into account the origin shift */
FT_Outline_Get_CBox( outline, &cbox );
+#ifdef 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[0] ? 43
+ : lcd_weights[1] ? 22 : 0;
+ cbox.yMin -= lcd_weights[4] ? 43
+ : lcd_weights[3] ? 22 : 0;
+ }
+ }
+#endif
+
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 );
@@ -225,26 +244,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.