* src/raster/ftraster.c, src/smooth/ftgrays.c: small optimization, the rasterizers now uses the render pool to store their state during scanline convertion. this saves about 6 KB of heap space 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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
diff --git a/ChangeLog b/ChangeLog
index f896fed..fddf162 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,8 @@
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/raster/ftraster.c, src/smooth/ftgrays.c: small optimization, the
+ rasterizers now uses the render pool to store their state during scanline
+ convertion. this saves about 6 KB of heap space 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,
diff --git a/src/raster/ftraster.c b/src/raster/ftraster.c
index cb9f946..b90e332 100644
--- a/src/raster/ftraster.c
+++ b/src/raster/ftraster.c
@@ -378,19 +378,19 @@
#else /* FT_STATIC_RASTER */
-#define RAS_ARGS TRaster_Instance* raster,
-#define RAS_ARG TRaster_Instance* raster
+#define RAS_ARGS PWorker worker,
+#define RAS_ARG PWorker worker
-#define RAS_VARS raster,
-#define RAS_VAR raster
+#define RAS_VARS worker,
+#define RAS_VAR worker
-#define FT_UNUSED_RASTER FT_UNUSED( raster )
+#define FT_UNUSED_RASTER FT_UNUSED( worker )
#endif /* FT_STATIC_RASTER */
- typedef struct TRaster_Instance_ TRaster_Instance;
+ typedef struct TWorker_ TWorker, *PWorker;
/* prototypes used for sweep function dispatch */
@@ -422,7 +422,7 @@
/* at the top. Thus, their offset can be coded with less */
/* opcodes, and it results in a smaller executable. */
- struct TRaster_Instance_
+ struct TWorker_
{
Int precision_bits; /* precision related variables */
Int precision;
@@ -498,15 +498,11 @@
TBand band_stack[16]; /* band stack used for sub-banding */
Int band_top; /* band stack top */
- Int count_table[256]; /* Look-up table used to quickly count */
- /* set bits in a gray 2x2 cell */
-
- void* memory;
+ Int* count_table;
#ifdef FT_RASTER_OPTION_ANTI_ALIASING
- Byte grays[5]; /* Palette of gray levels used for */
- /* render. */
+ Byte* grays;
Byte gray_lines[RASTER_GRAY_LINES];
/* Intermediate table used to render the */
@@ -523,26 +519,30 @@
#endif /* FT_RASTER_ANTI_ALIASING */
-#if 0
- PByte flags; /* current flags table */
- PUShort outs; /* current outlines table */
- FT_Vector* coords;
+ };
- UShort nPoints; /* number of points in current glyph */
- Short nContours; /* number of contours in current glyph */
-#endif
- };
+ typedef struct TRaster_
+ {
+ char* buffer;
+ long buffer_size;
+ void* memory;
+ PWorker worker;
+ Int count_table[256]; /* Look-up table used to quickly count */
+ /* set bits in a gray 2x2 cell */
+ Byte grays[5];
+ Short gray_width;
+ } TRaster, *PRaster;
#ifdef FT_STATIC_RASTER
- static TRaster_Instance cur_ras;
+ static TWorker cur_ras;
#define ras cur_ras
#else
-#define ras (*raster)
+#define ras (*worker)
#endif /* FT_STATIC_RASTER */
@@ -3153,7 +3153,7 @@
static void
- ft_black_init( TRaster_Instance* raster )
+ ft_black_init( PRaster raster )
{
FT_UInt n;
FT_ULong c;
@@ -3169,7 +3169,7 @@
( ( c << 2 ) & 0x0030 ) |
(c & 0x0003 );
- ras.count_table[n] = (UInt)c;
+ raster->count_table[n] = (UInt)c;
}
#ifdef FT_RASTER_OPTION_ANTI_ALIASING
@@ -3178,7 +3178,7 @@
for ( n = 0; n < 5; n++ )
raster->grays[n] = n * 255 / 4;
- ras.gray_width = RASTER_GRAY_LINES / 2;
+ raster->gray_width = RASTER_GRAY_LINES / 2;
#endif
}
@@ -3195,7 +3195,7 @@
ft_black_new( void* memory,
FT_Raster *araster )
{
- static TRaster_Instance the_raster;
+ static TRaster the_raster;
*araster = (FT_Raster)&the_raster;
@@ -3218,11 +3218,11 @@
static int
- ft_black_new( FT_Memory memory,
- TRaster_Instance** araster )
+ ft_black_new( FT_Memory memory,
+ PRaster *araster )
{
- FT_Error error;
- TRaster_Instance* raster;
+ FT_Error error;
+ PRaster raster;
*araster = 0;
@@ -3239,7 +3239,7 @@
static void
- ft_black_done( TRaster_Instance* raster )
+ ft_black_done( PRaster raster )
{
FT_Memory memory = (FT_Memory)raster->memory;
FT_FREE( raster );
@@ -3250,21 +3250,32 @@
static void
- ft_black_reset( TRaster_Instance* raster,
- char* pool_base,
- long pool_size )
+ ft_black_reset( PRaster raster,
+ char* pool_base,
+ long pool_size )
{
- if ( (&ras) && pool_base && pool_size >= 4096 )
+ if ( raster )
{
- /* save the pool */
- ras.buff = (PLong)pool_base;
- ras.sizeBuff = ras.buff + pool_size / sizeof ( Long );
+ if ( pool_base && pool_size >= (long)sizeof(TWorker) + 2048 )
+ {
+ PWorker worker = (PWorker)pool_base;
+
+ raster->buffer = pool_base + ((sizeof(*worker) + 7) & ~7);
+ raster->buffer_size = ((pool_base + pool_size) - (char*)raster->buffer)/sizeof(Long);
+ raster->worker = worker;
+ }
+ else
+ {
+ raster->buffer = NULL;
+ raster->buffer_size = 0;
+ raster->worker = NULL;
+ }
}
}
static void
- ft_black_set_mode( TRaster_Instance* raster,
+ ft_black_set_mode( PRaster raster,
unsigned long mode,
const char* palette )
{
@@ -3273,11 +3284,11 @@
if ( mode == FT_MAKE_TAG( 'p', 'a', 'l', '5' ) )
{
/* set 5-levels gray palette */
- ras.grays[0] = palette[0];
- ras.grays[1] = palette[1];
- ras.grays[2] = palette[2];
- ras.grays[3] = palette[3];
- ras.grays[4] = palette[4];
+ raster->grays[0] = palette[0];
+ raster->grays[1] = palette[1];
+ raster->grays[2] = palette[2];
+ raster->grays[3] = palette[3];
+ raster->grays[4] = palette[4];
}
#else
@@ -3291,14 +3302,15 @@
static int
- ft_black_render( TRaster_Instance* raster,
+ ft_black_render( PRaster raster,
const FT_Raster_Params* params )
{
const FT_Outline* outline = (const FT_Outline*)params->source;
const FT_Bitmap* target_map = params->target;
+ PWorker worker;
- if ( !(&ras) || !ras.buff || !ras.sizeBuff )
+ if ( !raster || !raster->buffer || !raster->buffer_size )
return Raster_Err_Not_Ini;
/* return immediately if the outline is empty */
@@ -3311,6 +3323,8 @@
if ( outline->n_points != outline->contours[outline->n_contours - 1] + 1 )
return Raster_Err_Invalid;
+ worker = raster->worker;
+
/* this version of the raster does not support direct rendering, sorry */
if ( params->flags & FT_RASTER_FLAG_DIRECT )
return Raster_Err_Unsupported;
@@ -3321,6 +3335,14 @@
ras.outline = *outline;
ras.target = *target_map;
+ worker->count_table = raster->count_table;
+ worker->buff = (PLong) raster->buffer;
+ worker->sizeBuff = worker->buff + raster->buffer_size/sizeof(Long);
+#ifdef FT_RASTER_OPTION_ANTI_ALIASING
+ worker->grays = raster->grays;
+ worker->gray_width = raster->gray_width;
+#endif
+
return ( ( params->flags & FT_RASTER_FLAG_AA )
? Render_Gray_Glyph( RAS_VAR )
: Render_Glyph( RAS_VAR ) );
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index dce27b0..c38f42f 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -1834,6 +1834,8 @@
ras.clip_box.yMax = 32767L;
}
+ gray_init_cells( worker, raster->buffer, raster->buffer_size );
+
ras.outline = *outline;
ras.num_cells = 0;
ras.invalid = 1;
@@ -1927,7 +1929,7 @@
if ( raster )
{
- if ( pool_base && pool_size >= sizeof(TWorker) + 2048 )
+ if ( pool_base && pool_size >= (long)sizeof(TWorker) + 2048 )
{
PWorker worker = (PWorker) pool_base;
@@ -1935,8 +1937,6 @@
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) );
-
- gray_init_cells( RAS_VAR_ rast->buffer, rast->buffer_size );
}
else
{