Oops! I think the old code was correct! Here, everything but the
last loop is handled – you always have full multiples of 8:
for ( j = source->width >> 3; j > 0; j-- )
[...]
Later on the remaining pixels are handled:
j = source->width & 7;
[...]
Here's a new patch.
Werner
======================================================================
--- ftbitmap.c.old 2009-07-31 18:45:18.000000000 +0200
+++ ftbitmap.c 2010-03-16 09:22:13.000000000 +0100
@@ -1,27 +1,27 @@
/***************************************************************************/
/*
*/
/* ftbitmap.c
*/
/*
*/
/* FreeType utility functions for bitmaps (body).
*/
/*
*/
-/* Copyright 2004, 2005, 2006, 2007, 2008, 2009 by
*/
+/* Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010 by
*/
/* David Turner, Robert Wilhelm, and Werner Lemberg.
*/
/*
*/
/* This file is part of the FreeType project, and may only be used,
*/
/* modified, and distributed under the terms of the FreeType project
*/
/* license, LICENSE.TXT. By continuing to use, modify, or distribute
*/
/* this file you indicate that you have read the license and
*/
/* understand and accept it fully.
*/
/*
*/
/***************************************************************************/
#include <ft2build.h>
#include FT_BITMAP_H
#include FT_IMAGE_H
#include FT_INTERNAL_OBJECTS_H
static
const FT_Bitmap null_bitmap = { 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -435,63 +435,64 @@
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int i;
target->num_grays = 2;
for ( i = source->rows; i > 0; i-- )
{
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[0] = ( val & 0x80 ) ? 0xFF : 0;
+ tt[1] = ( val & 0x40 ) ? 0xFF : 0;
+ tt[2] = ( val & 0x20 ) ? 0xFF : 0;
+ tt[3] = ( val & 0x10 ) ? 0xFF : 0;
+ tt[4] = ( val & 0x08 ) ? 0xFF : 0;
+ tt[5] = ( val & 0x04 ) ? 0xFF : 0;
+ tt[6] = ( val & 0x02 ) ? 0xFF : 0;
+ tt[7] = ( val & 0x01 ) ? 0xFF : 0;
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);
+ tt[0] = ( val & 0x80 ) ? 0xFF : 0;
+
val <<= 1;
tt += 1;
}
}
s += source->pitch;
t += target->pitch;
}
}
break;
case FT_PIXEL_MODE_GRAY:
case FT_PIXEL_MODE_LCD:
case FT_PIXEL_MODE_LCD_V:
{
FT_Int width = source->width;
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int s_pitch = source->pitch;
@@ -517,101 +518,106 @@
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int i;
target->num_grays = 4;
for ( i = source->rows; i > 0; i-- )
{
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 ) );
+ tt[0] = (FT_Byte)( ( ( val & 0xC0 ) >> 6 ) * 0x55 );
+ tt[1] = (FT_Byte)( ( ( val & 0x30 ) >> 4 ) * 0x55 );
+ tt[2] = (FT_Byte)( ( ( val & 0x0C ) >> 2 ) * 0x55 );
+ tt[3] = (FT_Byte)( ( ( val & 0x03 ) ) * 0x55 );
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 );
+ tt[0] = (FT_Byte)( ( ( val & 0xC0 ) >> 6 ) * 0x55 );
val <<= 2;
tt += 1;
}
}
s += source->pitch;
t += target->pitch;
}
}
break;
case FT_PIXEL_MODE_GRAY4:
{
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int i;
target->num_grays = 16;
for ( i = source->rows; i > 0; i-- )
{
FT_Byte* ss = s;
FT_Byte* tt = t;
FT_Int j;
/* get the full bytes */
for ( j = source->width >> 1; j > 0; j-- )
{
FT_Int val = ss[0];
- tt[0] = (FT_Byte)( ( val & 0xF0 ) >> 4 );
- tt[1] = (FT_Byte)( ( val & 0x0F ) );
+ tt[0] = (FT_Byte)( ( ( val & 0xF0 ) >> 4 ) * 0x11 );
+ tt[1] = (FT_Byte)( ( ( val & 0x0F ) ) * 0x11 );
ss += 1;
tt += 2;
}
if ( source->width & 1 )
- tt[0] = (FT_Byte)( ( ss[0] & 0xF0 ) >> 4 );
+ {
+ FT_Int val = ss[0];
+
+
+ tt[0] = (FT_Byte)( ( ( val & 0xF0 ) >> 4 ) * 0x11 );
+ }
s += source->pitch;
t += target->pitch;
}
}
break;
default:
;
}
return error;
}
/* documentation is in ftbitmap.h */
FT_EXPORT_DEF( FT_Error )
FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot )