* src/smooth/ftgrays.c: small optimization, the rasterizer now uses the render pool to store its state during its operation, this saves about 4 KB of heap for each FT_Library instance
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
diff --git a/ChangeLog b/ChangeLog
index 7ddb32c..f896fed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2007-01-04 David Turner <david@freetype.org>
+ * src/smooth/ftgrays.c: small optimization, the rasterizer now
+ uses the render pool to store its state during its operation,
+ this saves about 4 KB of heap for each FT_Library instance
+
* src/sfnt/sfobjs.c, src/sfnt/ttkern.c, src/sfnt/ttkern.h,
src/sfnt/ttmtx.c, src/sfnt/ttsbit.c, src/sfnt/ttsbit.h,
src/truetype/ttpload.c, include/freetype/config/ftoption.h:
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index e616795..dce27b0 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -169,13 +169,13 @@
#ifndef FT_STATIC_RASTER
-#define RAS_ARG PRaster raster
-#define RAS_ARG_ PRaster raster,
+#define RAS_ARG PWorker worker
+#define RAS_ARG_ PWorker worker,
-#define RAS_VAR raster
-#define RAS_VAR_ raster,
+#define RAS_VAR worker
+#define RAS_VAR_ worker,
-#define ras (*raster)
+#define ras (*worker)
#else /* FT_STATIC_RASTER */
@@ -186,7 +186,7 @@
#define RAS_VAR /* empty */
#define RAS_VAR_ /* empty */
- static TRaster ras;
+ static TWorker ras;
#endif /* FT_STATIC_RASTER */
@@ -260,7 +260,7 @@
} TCell;
- typedef struct TRaster_
+ typedef struct TWorker_
{
TCoord ex, ey;
TPos min_ex, max_ex;
@@ -299,7 +299,6 @@
int conic_level;
int cubic_level;
- void* memory;
ft_jmp_buf jump_buffer;
void* buffer;
@@ -308,9 +307,21 @@
PCell* ycells;
int ycount;
+ } TWorker, *PWorker;
+
+
+ typedef struct TRaster_
+ {
+ void* buffer;
+ long buffer_size;
+ int band_size;
+ void* memory;
+ PWorker worker;
+
} TRaster, *PRaster;
+
/*************************************************************************/
/* */
/* Initialize the cells table. */
@@ -672,7 +683,7 @@
ras.cover += delta;
ey1 += incr;
- gray_set_cell( raster, ex, ey1 );
+ gray_set_cell( &ras, ex, ey1 );
delta = (int)( first + first - ONE_PIXEL );
area = (TArea)two_fx * delta;
@@ -682,7 +693,7 @@
ras.cover += delta;
ey1 += incr;
- gray_set_cell( raster, ex, ey1 );
+ gray_set_cell( &ras, ex, ey1 );
}
delta = (int)( fy2 - ONE_PIXEL + first );
@@ -1044,32 +1055,31 @@
static int
gray_move_to( const FT_Vector* to,
- FT_Raster raster )
+ PWorker worker )
{
TPos x, y;
/* record current cell, if any */
- gray_record_cell( (PRaster)raster );
+ gray_record_cell( worker );
/* start to a new position */
x = UPSCALE( to->x );
y = UPSCALE( to->y );
- gray_start_cell( (PRaster)raster, TRUNC( x ), TRUNC( y ) );
+ gray_start_cell( worker, TRUNC( x ), TRUNC( y ) );
- ((PRaster)raster)->x = x;
- ((PRaster)raster)->y = y;
+ worker->x = x;
+ worker->y = y;
return 0;
}
static int
gray_line_to( const FT_Vector* to,
- FT_Raster raster )
+ PWorker worker )
{
- gray_render_line( (PRaster)raster,
- UPSCALE( to->x ), UPSCALE( to->y ) );
+ gray_render_line( worker, UPSCALE( to->x ), UPSCALE( to->y ) );
return 0;
}
@@ -1077,9 +1087,9 @@
static int
gray_conic_to( const FT_Vector* control,
const FT_Vector* to,
- FT_Raster raster )
+ PWorker worker )
{
- gray_render_conic( (PRaster)raster, control, to );
+ gray_render_conic( worker, control, to );
return 0;
}
@@ -1088,9 +1098,9 @@
gray_cubic_to( const FT_Vector* control1,
const FT_Vector* control2,
const FT_Vector* to,
- FT_Raster raster )
+ PWorker worker )
{
- gray_render_cubic( (PRaster)raster, control1, control2, to );
+ gray_render_cubic( worker, control1, control2, to );
return 0;
}
@@ -1099,10 +1109,10 @@
gray_render_span( int y,
int count,
const FT_Span* spans,
- PRaster raster )
+ PWorker worker )
{
unsigned char* p;
- FT_Bitmap* map = &raster->target;
+ FT_Bitmap* map = &worker->target;
/* first of all, compute the scanline offset */
@@ -1766,6 +1776,7 @@
{
const FT_Outline* outline = (const FT_Outline*)params->source;
const FT_Bitmap* target_map = params->target;
+ PWorker worker;
if ( !raster || !raster->buffer || !raster->buffer_size )
@@ -1782,6 +1793,8 @@
outline->contours[outline->n_contours - 1] + 1 )
return ErrRaster_Invalid_Outline;
+ worker = raster->worker;
+
/* if direct mode is not set, we must have a target bitmap */
if ( ( params->flags & FT_RASTER_FLAG_DIRECT ) == 0 )
{
@@ -1824,6 +1837,8 @@
ras.outline = *outline;
ras.num_cells = 0;
ras.invalid = 1;
+ ras.band_size = raster->band_size;
+ ras.num_gray_spans = 0;
if ( target_map )
ras.target = *target_map;
@@ -1837,7 +1852,7 @@
ras.render_span_data = params->user;
}
- return gray_convert_glyph( (PRaster)raster );
+ return gray_convert_glyph( worker );
}
@@ -1910,10 +1925,26 @@
PRaster rast = (PRaster)raster;
- if ( raster && pool_base && pool_size >= 4096 )
- gray_init_cells( rast, (char*)pool_base, pool_size );
+ if ( raster )
+ {
+ if ( pool_base && pool_size >= sizeof(TWorker) + 2048 )
+ {
+ PWorker worker = (PWorker) pool_base;
+
+ rast->worker = worker;
+ rast->buffer = pool_base + ((sizeof(TWorker) + sizeof(TCell)-1) & ~(sizeof(TCell)-1));
+ rast->buffer_size = (long)((pool_base + pool_size) - (char*)rast->buffer) & ~(sizeof(TCell)-1);
+ rast->band_size = (int)( rast->buffer_size/(sizeof(TCell)*8) );
- rast->band_size = (int)( ( pool_size / sizeof ( TCell ) ) / 8 );
+ gray_init_cells( RAS_VAR_ rast->buffer, rast->buffer_size );
+ }
+ else
+ {
+ rast->buffer = NULL;
+ rast->buffer_size = 0;
+ rast->worker = NULL;
+ }
+ }
}