freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft-devel] FT_Bitmap_Convert and 1bpp bitmaps


From: Kamil Hornicek
Subject: [ft-devel] FT_Bitmap_Convert and 1bpp bitmaps
Date: Sun, 14 Mar 2010 01:58:18 +0100

Hi,
when trying to fix some alignment related issues in our project I stumbled upon FT_Bitmap_Convert. It works ok for FT_PIXEL_MODE_GRAY but I ran into problems with FT_PIXEL_MODE_MONO ie. 1bpp bitmaps.

The code for the actual conversion is as follows (ftbitmap.c ~ line 440):

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 );

... ...

First of all "source->width >> 3" is 0 for widths < 8 and the whole loop is skipped. So we need to make the condition j >= 0. Next thing is "tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 );" etc etc.. The corresponding bit is masked and shifted. But this way only the LSB is set. As the original bitmap was monochromatic I believe we need to set all 8 bits to 1 (setting the whole byte to 0xff) in case "val & 0x80" equals to 1 or set them to 0 otherwise.

I modified the code like this and got my code working:

         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 ) ? 0xff : 0);
           tt[1] = (FT_Byte)( ( val & 0x40 ) ? 0xff : 0);
           tt[2] = (FT_Byte)( ( val & 0x20 ) ? 0xff : 0);
           tt[3] = (FT_Byte)( ( val & 0x10 ) ? 0xff : 0);
           tt[4] = (FT_Byte)( ( val & 0x08 ) ? 0xff : 0);
           tt[5] = (FT_Byte)( ( val & 0x04 ) ? 0xff : 0);
           tt[6] = (FT_Byte)( ( val & 0x02 ) ? 0xff : 0);
           tt[7] = (FT_Byte)( ( val & 0x01 ) ? 0xff : 0);

There's of course a possibility I missed something fundamental and in that case I apologize and would like to ask for some info that would point me in the right direction.

Regards,
Kamil Hornicek




reply via email to

[Prev in Thread] Current Thread [Next in Thread]