freetype
[Top][All Lists]
Advanced

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

Re: [ft] Determining pixel dimensions for bitmap


From: Marco Wertz
Subject: Re: [ft] Determining pixel dimensions for bitmap
Date: Sun, 2 Nov 2014 11:41:38 +0100

> > when using FT_Outline_Get_BBox() to get the dimensions of the
> > outline, the values are all in the 26.6 fixed point format. How do I
> > determine the optimal pixel size for a bitmap to pass to
> > FT_Outline_Get_Bitmap() so that the outline fits *exactly* into the
> > bitmap dimensions?
> >
> > The obvious approach would be something like this:
> >
> > width = bbox.xMax - bbox.xMin;
> > height = bbox.yMax - bbox.yMin;
> >
> > pixelwidth = width >> 6;
> > pixelheight = height >> 6;
> >
> > if((width & 0x3f) > 31) pixelwidth++;
> > if((height & 0x3f) > 31) pixelheight++;
> >
> > This will add another pixel in case the fractional part of the 26.6
> > fixed point value is >= 0.5. But I'm not sure if this is the right
> > approach....
> 
> Yes, this looks good.

Actually, it doesn't work for all outlines. I have an outline here for
which (bbox.yMax - bbox.yMin) is 23448, i.e. the integer part is 366 and
the fractional part is 24. As the fractional part is less than 0.5, I
do not add another row. So the bitmap I pass to FT_Outline_Get_Bitmap()
has 366 rows. This, however, is not enough as the topmost row is missing.
FT_Outline_Get_Bitmap() actually draws 367 rows for this outline although
the fractional part is less than 0.5.

What's the recommended way of dealing with this behaviour? Should I always
allocate one row and one column more if the fractional part is != 0? But this
might lead to empty rows/columns, doesn't it? What's the suggested way of
dealing with this problem? I'd like my bitmap to have the *exact* size
of the shape, i.e. without an empty rows or columns.

How can I achieve this? I could of course always add the additional column/row
and then check for empty rows and columns and clip them but that's some
unnecessary overhead if you ask me.

Marco



reply via email to

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