[smooth] Shrink bisection stack. The convergence of Bézier flatteners is fast with the deviation from straight line being assymptotically cut 4-fold on each bisection. This justifies smaller bisection stack size. * src/smooth/ftgrays.c (gray_TWorker): Remove common `bez_stack'. (gray_render_conic): Create and use conic `bez_stack'. Move back the band analysis from... (gray_conic_to): ... here. (gray_render_cubic): Create and use cubic `bez_stack'. Move back the band analysis from... (gray_cubic_to): ... here. (gray_move_to): Updated.
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
diff --git a/ChangeLog b/ChangeLog
index abd36ed..f6c4b0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2016-05-26 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [smooth] Shrink bisection stack.
+
+ The convergence of Bézier flatteners is fast with the deviation
+ from straight line being assymptotically cut 4-fold on each bisection.
+ This justifies smaller bisection stack size.
+
+ * src/smooth/ftgrays.c (gray_TWorker): Remove common `bez_stack'.
+ (gray_render_conic): Create and use conic `bez_stack'. Move back the
+ band analysis from...
+ (gray_conic_to): ... here.
+ (gray_render_cubic): Create and use cubic `bez_stack'. Move back the
+ band analysis from...
+ (gray_cubic_to): ... here.
+ (gray_move_to): Updated.
+
2016-05-25 Werner Lemberg <wl@gnu.org>
[autofit] Fixes for Armenian and Gujarati ranges.
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index c69a184..bee4043 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -434,8 +434,6 @@ typedef ptrdiff_t FT_PtrDist;
TPos x, y;
- FT_Vector bez_stack[32 * 3 + 1];
-
FT_Outline outline;
FT_Bitmap target;
FT_BBox clip_box;
@@ -1064,12 +1062,34 @@ typedef ptrdiff_t FT_PtrDist;
static void
- gray_render_conic( RAS_ARG )
+ gray_render_conic( RAS_ARG_ const FT_Vector* control,
+ const FT_Vector* to )
{
+ FT_Vector bez_stack[16 * 2 + 1]; /* enough to accommodate bisections */
+ FT_Vector* arc = bez_stack;
TPos dx, dy;
- int draw, split, level;
- FT_Vector* arc = ras.bez_stack;
+ int draw, split;
+
+ arc[0].x = UPSCALE( to->x );
+ arc[0].y = UPSCALE( to->y );
+ arc[1].x = UPSCALE( control->x );
+ arc[1].y = UPSCALE( control->y );
+ arc[2].x = ras.x;
+ arc[2].y = ras.y;
+
+ /* short-cut the arc that crosses the current band */
+ if ( ( TRUNC( arc[0].y ) >= ras.max_ey &&
+ TRUNC( arc[1].y ) >= ras.max_ey &&
+ TRUNC( arc[2].y ) >= ras.max_ey ) ||
+ ( TRUNC( arc[0].y ) < ras.min_ey &&
+ TRUNC( arc[1].y ) < ras.min_ey &&
+ TRUNC( arc[2].y ) < ras.min_ey ) )
+ {
+ ras.x = arc[0].x;
+ ras.y = arc[0].y;
+ return;
+ }
dx = FT_ABS( arc[2].x + arc[0].x - 2 * arc[1].x );
dy = FT_ABS( arc[2].y + arc[0].y - 2 * arc[1].y );
@@ -1078,19 +1098,17 @@ typedef ptrdiff_t FT_PtrDist;
/* We can calculate the number of necessary bisections because */
/* each bisection predictably reduces deviation exactly 4-fold. */
-
- level = 0;
+ /* Even 32-bit deviation would vanish after 16 bisections. */
+ draw = 1;
while ( dx > ONE_PIXEL / 4 )
{
- dx >>= 2;
- level++;
+ dx >>= 2;
+ draw <<= 1;
}
/* We use decrement counter to count the total number of segments */
/* to draw starting from 2^level. Before each draw we split as */
/* many times as there are trailing zeros in the counter. */
-
- draw = 1 << level;
do
{
split = 1;
@@ -1137,14 +1155,41 @@ typedef ptrdiff_t FT_PtrDist;
static void
- gray_render_cubic( RAS_ARG )
+ gray_render_cubic( RAS_ARG_ const FT_Vector* control1,
+ const FT_Vector* control2,
+ const FT_Vector* to )
{
- FT_Vector* arc = ras.bez_stack;
+ FT_Vector bez_stack[16 * 3 + 1]; /* enough to accommodate bisections */
+ FT_Vector* arc = bez_stack;
TPos dx, dy, dx_, dy_;
TPos dx1, dy1, dx2, dy2;
TPos L, s, s_limit;
+ arc[0].x = UPSCALE( to->x );
+ arc[0].y = UPSCALE( to->y );
+ arc[1].x = UPSCALE( control2->x );
+ arc[1].y = UPSCALE( control2->y );
+ arc[2].x = UPSCALE( control1->x );
+ arc[2].y = UPSCALE( control1->y );
+ arc[3].x = ras.x;
+ arc[3].y = ras.y;
+
+ /* short-cut the arc that crosses the current band */
+ if ( ( TRUNC( arc[0].y ) >= ras.max_ey &&
+ TRUNC( arc[1].y ) >= ras.max_ey &&
+ TRUNC( arc[2].y ) >= ras.max_ey &&
+ TRUNC( arc[3].y ) >= ras.max_ey ) ||
+ ( TRUNC( arc[0].y ) < ras.min_ey &&
+ TRUNC( arc[1].y ) < ras.min_ey &&
+ TRUNC( arc[2].y ) < ras.min_ey &&
+ TRUNC( arc[3].y ) < ras.min_ey ) )
+ {
+ ras.x = arc[0].x;
+ ras.y = arc[0].y;
+ return;
+ }
+
for (;;)
{
/* Decide whether to split or draw. See `Rapid Termination */
@@ -1190,7 +1235,7 @@ typedef ptrdiff_t FT_PtrDist;
gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
- if ( arc == ras.bez_stack )
+ if ( arc == bez_stack )
return;
arc -= 3;
@@ -1220,8 +1265,8 @@ typedef ptrdiff_t FT_PtrDist;
gray_start_cell( RAS_VAR_ TRUNC( x ), TRUNC( y ) );
- worker->x = x;
- worker->y = y;
+ ras.x = x;
+ ras.y = y;
return 0;
}
@@ -1240,27 +1285,7 @@ typedef ptrdiff_t FT_PtrDist;
const FT_Vector* to,
gray_PWorker worker )
{
- FT_Vector* arc = ras.bez_stack;
-
-
- arc[0].x = UPSCALE( to->x );
- arc[0].y = UPSCALE( to->y );
- arc[1].x = UPSCALE( control->x );
- arc[1].y = UPSCALE( control->y );
- arc[2].x = ras.x;
- arc[2].y = ras.y;
-
- /* short-cut the arc that crosses the current band */
- if ( ( TRUNC( arc[0].y ) >= ras.max_ey &&
- TRUNC( arc[1].y ) >= ras.max_ey &&
- TRUNC( arc[2].y ) >= ras.max_ey ) ||
- ( TRUNC( arc[0].y ) < ras.min_ey &&
- TRUNC( arc[1].y ) < ras.min_ey &&
- TRUNC( arc[2].y ) < ras.min_ey ) )
- gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
- else
- gray_render_conic( RAS_VAR );
-
+ gray_render_conic( RAS_VAR_ control, to );
return 0;
}
@@ -1271,31 +1296,7 @@ typedef ptrdiff_t FT_PtrDist;
const FT_Vector* to,
gray_PWorker worker )
{
- FT_Vector* arc = ras.bez_stack;
-
-
- arc[0].x = UPSCALE( to->x );
- arc[0].y = UPSCALE( to->y );
- arc[1].x = UPSCALE( control2->x );
- arc[1].y = UPSCALE( control2->y );
- arc[2].x = UPSCALE( control1->x );
- arc[2].y = UPSCALE( control1->y );
- arc[3].x = ras.x;
- arc[3].y = ras.y;
-
- /* short-cut the arc that crosses the current band */
- if ( ( TRUNC( arc[0].y ) >= ras.max_ey &&
- TRUNC( arc[1].y ) >= ras.max_ey &&
- TRUNC( arc[2].y ) >= ras.max_ey &&
- TRUNC( arc[3].y ) >= ras.max_ey ) ||
- ( TRUNC( arc[0].y ) < ras.min_ey &&
- TRUNC( arc[1].y ) < ras.min_ey &&
- TRUNC( arc[2].y ) < ras.min_ey &&
- TRUNC( arc[3].y ) < ras.min_ey ) )
- gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
- else
- gray_render_cubic( RAS_VAR );
-
+ gray_render_cubic( RAS_VAR_ control1, control2, to );
return 0;
}