* src/base/ftbitmap.c (FT_Bitmap_Convert): small improvements to the conversion function (mainly stupid optimization, because I like these... shame on me) * src/base/Jamfile: adding ftbitmap.c to the list of compiled files
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 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
diff --git a/ChangeLog b/ChangeLog
index 68d13d2..ac8f8c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,12 @@
dynamic array when loading a glyph from a PFR font. This fixes
bug #11921
+ * src/base/ftbitmap.c (FT_Bitmap_Convert): small improvements to the
+ conversion function (mainly stupid optimization, because I like
+ these... shame on me)
+
+ * src/base/Jamfile: adding ftbitmap.c to the list of compiled files
+
2005-02-10 Werner Lemberg <wl@gnu.org>
* builds/unix/freetype-config.in: Add new flag `--ftversion' to
diff --git a/src/base/Jamfile b/src/base/Jamfile
index f46e9b4..b00c7c9 100644
--- a/src/base/Jamfile
+++ b/src/base/Jamfile
@@ -10,7 +10,7 @@ SubDir FT2_TOP $(FT2_SRC_DIR) base ;
if $(FT2_MULTI)
{
_sources = ftutil ftdbgmem ftstream ftcalc fttrigon ftgloadr ftoutln
- ftobjs ftnames ftrfork ;
+ ftobjs ftnames ftrfork ;
}
else
{
@@ -24,7 +24,7 @@ SubDir FT2_TOP $(FT2_SRC_DIR) base ;
#
Library $(FT2_LIB) : ftsystem.c ftinit.c ftglyph.c ftmm.c ftbdf.c
ftbbox.c ftdebug.c ftxf86.c fttype1.c ftpfr.c
- ftstroke.c ftwinfnt.c ftotval.c ;
+ ftstroke.c ftwinfnt.c ftotval.c ftbitmap.c ;
# Add Macintosh-specific file to the library when necessary.
#
diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c
index ea62aa2..1ad4556 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -46,8 +46,6 @@
{
FT_Error error = FT_Err_Ok;
FT_Memory memory;
- FT_Int i, j, old_size;
- FT_Byte *s, *ss, *t, *tt;
if ( !library )
@@ -61,174 +59,201 @@
case FT_PIXEL_MODE_GRAY:
case FT_PIXEL_MODE_GRAY2:
case FT_PIXEL_MODE_GRAY4:
- old_size = target->rows * target->pitch;
+ {
+ FT_Int pad;
+ FT_Long old_size;
+
+ old_size = target->rows * target->pitch;
+ if ( old_size < 0 )
+ old_size = -old_size;
+
+ target->pixel_mode = FT_PIXEL_MODE_GRAY;
+ target->rows = source->rows;
+ target->width = source->width;
- target->pixel_mode = FT_PIXEL_MODE_GRAY;
- target->rows = source->rows;
- target->width = source->width;
- target->pitch = ( source->width + alignment - 1 )
- / alignment * alignment;
+ pad = 0;
+ if ( alignment > 0 )
+ {
+ pad = source->width % alignment;
+ if ( pad != 0 )
+ pad = alignment - pad;
+ }
- if ( target->rows * target->pitch > old_size )
- if ( FT_QREALLOC( target->buffer,
+ target->pitch = source->width + pad;
+
+ if ( target->rows * target->pitch > old_size &&
+ FT_QREALLOC( target->buffer,
old_size, target->rows * target->pitch ) )
return error;
-
+ }
break;
default:
error = FT_Err_Invalid_Argument;
}
- s = source->buffer;
- t = target->buffer;
-
switch ( source->pixel_mode )
{
case FT_PIXEL_MODE_MONO:
- target->num_grays = 2;
-
- for ( i = 0; i < source->rows; i++ )
{
- ss = s;
- tt = t;
+ FT_Byte* s = source->buffer;
+ FT_Byte* t = target->buffer;
+ FT_Int i;
- /* get the full bytes */
- for ( j = 0; j < ( source->width >> 3 ); j++ )
- {
- *(tt++) = (FT_Byte)( ( *ss & 0x80 ) >> 7 );
- *(tt++) = (FT_Byte)( ( *ss & 0x40 ) >> 6 );
- *(tt++) = (FT_Byte)( ( *ss & 0x20 ) >> 5 );
- *(tt++) = (FT_Byte)( ( *ss & 0x10 ) >> 4 );
- *(tt++) = (FT_Byte)( ( *ss & 0x08 ) >> 3 );
- *(tt++) = (FT_Byte)( ( *ss & 0x04 ) >> 2 );
- *(tt++) = (FT_Byte)( ( *ss & 0x02 ) >> 1 );
- *(tt++) = (FT_Byte)( *ss & 0x01 );
-
- ss++;
- }
+ target->num_grays = 2;
- /* get remaining pixels (if any) */
- switch ( source->width & 7 )
+ for ( i = source->rows; i > 0; i-- )
{
- case 7:
- *(tt++) = (FT_Byte)( ( *ss & 0x80 ) >> 7 );
- /* fall through */
- case 6:
- *(tt++) = (FT_Byte)( ( *ss & 0x40 ) >> 6 );
- /* fall through */
- case 5:
- *(tt++) = (FT_Byte)( ( *ss & 0x20 ) >> 5 );
- /* fall through */
- case 4:
- *(tt++) = (FT_Byte)( ( *ss & 0x10 ) >> 4 );
- /* fall through */
- case 3:
- *(tt++) = (FT_Byte)( ( *ss & 0x08 ) >> 3 );
- /* fall through */
- case 2:
- *(tt++) = (FT_Byte)( ( *ss & 0x04 ) >> 2 );
- /* fall through */
- case 1:
- *(tt++) = (FT_Byte)( ( *ss & 0x02 ) >> 1 );
- /* fall through */
- case 0:
- break;
+ FT_Byte* ss = s;
+ FT_Byte* tt = t;
+ FT_Int j;
+
+ /* get the full bytes */
+ for ( j = source->width >> 3; j > 0; j-- )
+ {
+ FT_Int val = ss[0]; /* avoid a byte->int cast on each line */
+
+ tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 );
+ tt[1] = (FT_Byte)( ( val & 0x40 ) >> 6 );
+ tt[2] = (FT_Byte)( ( val & 0x20 ) >> 5 );
+ tt[3] = (FT_Byte)( ( val & 0x10 ) >> 4 );
+ tt[4] = (FT_Byte)( ( val & 0x08 ) >> 3 );
+ tt[5] = (FT_Byte)( ( val & 0x04 ) >> 2 );
+ tt[6] = (FT_Byte)( ( val & 0x02 ) >> 1 );
+ tt[7] = (FT_Byte)( val & 0x01 );
+
+ tt += 8;
+ ss += 1;
+ }
+
+ /* get remaining pixels (if any) */
+ j = source->width & 7;
+ if ( j > 0 )
+ {
+ FT_Int val = *ss;
+
+ for ( ; j > 0; j-- )
+ {
+ tt[0] = (FT_Byte)(( val & 0x80 ) >> 7);
+ val <<= 1;
+ tt += 1;
+ }
+ }
+
+ s += source->pitch;
+ t += target->pitch;
}
-
- s += source->pitch;
- t += target->pitch;
}
break;
- case FT_PIXEL_MODE_GRAY:
- target->num_grays = 256;
- for ( i = 0; i < source->rows; i++ )
+ case FT_PIXEL_MODE_GRAY:
{
- ss = s;
- tt = t;
+ FT_Int width = source->width;
+ FT_Byte* s = source->buffer;
+ FT_Byte* t = target->buffer;
+ FT_Int s_pitch = source->pitch;
+ FT_Int t_pitch = target->pitch;
+ FT_Int i;
- for ( j = 0; j < source->width; j++ )
- *(tt++) = *(ss++);
+ target->num_grays = 256;
+
+ for ( i = source->rows; i > 0; i-- )
+ {
+ FT_ARRAY_COPY( t, s, width );
- s += source->pitch;
- t += target->pitch;
+ s += s_pitch;
+ t += t_pitch;
+ }
}
break;
- case FT_PIXEL_MODE_GRAY2:
- target->num_grays = 4;
- for ( i = 0; i < source->rows; i++ )
+ case FT_PIXEL_MODE_GRAY2:
{
- ss = s;
- tt = t;
+ FT_Byte* s = source->buffer;
+ FT_Byte* t = target->buffer;
+ FT_Int i;
- /* get the full bytes */
- for ( j = 0; j < ( source->width >> 2 ); j++ )
- {
- *(tt++) = (FT_Byte)( ( *ss & 0xC0 ) >> 6 );
- *(tt++) = (FT_Byte)( ( *ss & 0x30 ) >> 4 );
- *(tt++) = (FT_Byte)( ( *ss & 0x0C ) >> 2 );
- *(tt++) = (FT_Byte)( *ss & 0x03 );
+ target->num_grays = 4;
- ss++;
- }
-
- /* get remaining pixels (if any) */
- switch ( source->width & 3 )
+ for ( i = source->rows; i > 0; i-- )
{
- case 3:
- *(tt++) = (FT_Byte)( ( *ss & 0xC0 ) >> 6 );
- /* fall through */
- case 2:
- *(tt++) = (FT_Byte)( ( *ss & 0x30 ) >> 4 );
- /* fall through */
- case 1:
- *(tt++) = (FT_Byte)( ( *ss & 0x0C ) >> 2 );
- /* fall through */
- case 0:
- break;
+ FT_Byte* ss = s;
+ FT_Byte* tt = t;
+ FT_Int j;
+
+ /* get the full bytes */
+ for ( j = source->width >> 2; j > 0; j-- )
+ {
+ FT_Int val = ss[0];
+
+ tt[0] = (FT_Byte)( (val & 0xC0) >> 6 );
+ tt[1] = (FT_Byte)( (val & 0x30) >> 4 );
+ tt[2] = (FT_Byte)( (val & 0x0C) >> 2 );
+ tt[3] = (FT_Byte)( (val & 0x03) );
+
+ ss += 1;
+ tt += 4;
+ }
+
+ j = source->width & 3;
+ if ( j > 0 )
+ {
+ FT_Int val = ss[0];
+
+ for ( ; j > 0; j-- )
+ {
+ tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
+ val <<= 2;
+ tt += 1;
+ }
+ }
+
+ s += source->pitch;
+ t += target->pitch;
}
-
- s += source->pitch;
- t += target->pitch;
}
break;
- case FT_PIXEL_MODE_GRAY4:
- target->num_grays = 16;
- for ( i = 0; i < source->rows; i++ )
+ case FT_PIXEL_MODE_GRAY4:
{
- ss = s;
- tt = t;
+ FT_Byte* s = source->buffer;
+ FT_Byte* t = target->buffer;
+ FT_Int i;
- /* get the full bytes */
- for ( j = 0; j < ( source->width >> 1 ); j++ )
+ target->num_grays = 16;
+
+ for ( i = source->rows; i > 0; i-- )
{
- *(tt++) = (FT_Byte)( ( *ss & 0xF0 ) >> 4 );
- *(tt++) = (FT_Byte)( *ss & 0x0F );
+ FT_Byte* ss = s;
+ FT_Byte* tt = t;
+ FT_Int j;
- ss++;
- }
+ /* get the full bytes */
+ for ( j = source->width >> 1; j > 0; j-- )
+ {
+ FT_Int val = ss[0];
- /* get remaining pixels (if any) */
- switch ( source->width & 1 )
- {
- case 1:
- *(tt++) = (FT_Byte)( ( *ss & 0xF0 ) >> 4 );
- /* fall through */
- case 0:
- break;
- }
+ tt[0] = (FT_Byte)( (val & 0xF0) >> 4 );
+ tt[1] = (FT_Byte)( (val & 0x0F) );
- s += source->pitch;
- t += target->pitch;
+ ss += 1;
+ tt += 2;
+ }
+
+ if ( source->width & 1 )
+ tt[0] = (FT_Byte)( ( ss[0] & 0xF0 ) >> 4 );
+
+ s += source->pitch;
+ t += target->pitch;
+ }
}
break;
+ default:
+ ;
}
return error;