freetype
[Top][All Lists]
Advanced

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

Re: [ft] monochrome bitmaps


From: T. Horsnell
Subject: Re: [ft] monochrome bitmaps
Date: Wed, 07 Jan 2009 11:32:44 +0000
User-agent: Thunderbird 2.0.0.18 (X11/20081119)

Werner LEMBERG wrote:
Can someone tell me how freetype's monochrome bitmaps are organised
please.  I'm trying to use FT_RENDER_MODE_MONO to generate a 1-bit
monochrome bitmap using docs/tutorial/example.c program.  I presume
8 bits get packed into one byte of the image-area, but what's the
bit ordering?  which bit of image[0][0] corresponds to bit 0 if the
monochrome bitmap?

Please look up the documentation of the FT_Pixel_Mode enumeration.

Do I need to make use of FT_LOAD_MONOCHROME somewhere?

Yes; you should use the load flags FT_LOAD_MONOCHROME and
FT_LOAD_TARGET_MONO (or FT_RENDER_MODE_MONO if you render the glyph
later).


     Werner

Werner, thanks for this, but two more questions:

Is is possible to suppress anti-aliasing but still use the
grey-level rendering? I ultimately want a monochrome
rendering but I prefer to work with byte-maps
rather than bit-maps whilst assembling an image
from rendered chars, and then convert to a bitmap at the end.
I thought there may be a speed gain if I dont need
anti-aliasing.

Secondly, I'm afraid I still dont understand FreeType's
monochrome bitmaps. I have the following test program
which renders a single char in monochrome and prints
the resulting bitmap:


#include <ft2build.h>
#include FT_FREETYPE_H
#include <stdio.h>


main()
{
FT_UInt                 glyph_index;
FT_Error                error;
FT_Face                 face;
FT_Library              library;
FT_GlyphSlot            slot;
FT_Bitmap               bitmap;
unsigned char*          bufptr;
int                     i;
char                    c='l';

if (error=FT_Init_FreeType(&library) != 0)
  {
  printf("FT_Init_FreeType error=%i\n",error);
  exit(0);
  }

if (error=FT_New_Face(library, "/usr/share/fonts/freefonts/FreeSans.ttf", 0, 
&face) != 0)
  {
  printf("FT_New_Face error=%i\n",error);
  exit(0);
  }

if (error=FT_Set_Char_Size(face, 20*64, 0, 100, 0) !=0)
  {
  printf("FT_Set_Char_Size error=%i\n",error);
  exit(0);
  }

glyph_index=FT_Get_Char_Index(face,c);
slot=face->glyph;

if (error=FT_Load_Glyph(face, glyph_index, 
FT_LOAD_MONOCHROME|FT_LOAD_TARGET_MONO) != 0)
  {
  printf("FT_Load_Glyph 2 error=%i\n",error);
  exit(0);
  }
if (error=FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO) != 0)
  {
  printf("FT_Render_Glyph 2 error=%i\n",error);
  exit(0);
  }

printf("rows=%i cols=%i 
mode=%i\n",slot->bitmap.rows,slot->bitmap.width,slot->bitmap.pixel_mode);
bufptr=slot->bitmap.buffer;
for (i=0; i<(slot->bitmap.rows*slot->bitmap.width)/8; i++)  
printf("%x\n",*bufptr++);
}


It yields the following output:

rows=20 cols=2 mode=1
c0
0
c0
0
c0


I looked at the documentation for FT_Pixel_Mode enumeration
as you suggested, but dont understand this output. The 'l'
character in this sanserif font should have 40 bits set (20*2),
so what are all the zeros? Are the bits organised in rows
such that each row of bits starts in a new byte?
And is there a pad byte at the end of each row?

Cheers,
Terry










reply via email to

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