FreeType's 26.6 format - PaintLab/PixelFarm GitHub Wiki

FreeType's 26.6 format

from https://lists.nongnu.org/archive/html/freetype/2002-09/msg00080.html


Re: [Freetype] Why 26.6 ?

From: Laurent Lequenne

Subject: Re: [Freetype] Why 26.6 ?

Date: Thu, 19 Sep 2002 09:20:31 +0200

Thanks to the big boss :-)

----- Original Message ----- From: "David Turner" address@hidden To: address@hidden Sent: Thursday, September 19, 2002 1:09 AM Subject: Re: [Freetype] Why 26.6 ?

Hello,

Peter Montgomery wrote:

Hi,

Folks, you're getting things all mixed up. 26.6 refers to the placement of a pixel on a grid with fractional accuracy - in this case the fraction is 2 ^ 64. If the 26 refers to pixels (as opposed to inches, centimeters, etc) , this simply means that you can position text to any of 64 possible sub-pixel positions.

Levels of anti-aliasing has to do with sub-pixel positioning. You can position text to a fractional position and then render it as 1 bit per pixel monochrome. This will effectively round off your positioning to the nearest whole pixel, but you can still specify the positioning as a fractional pixel. If you render with 256 levels of gray, then you have that many levels of anti-aliasing available !

Think about it. Suppose that FreeType only allowed you to position text in whole pixel increments, but you rendered the text with 256 levels of anti-aliasing. Does that mean that suddenly the text would become monochrome? Of course not. The positioning accuracy and the anti-aliasing are completely different aspects of graphics that are not connected. In creating a graphics rendering system you can

1 - Have 256 levels of anti-aliasing and no fractional positioning

2 - No anti-aliasing with fractional positioning

3 - Both

4 - Neither

The choice is up to you when you design the renderer. Among other choices, FreeType happens to allow fractional positioning with 256 levels of anti-aliasing.

The sole relationship between anti-aliasing and sub-pixel positioning is that if you expect to see your fractional positioning, then you better have some anti-aliasing going on. FreeType uses 256 levels of grayscale anti-aliasing which is as much as virtually all common display systems on PCs allow.

Peter is right on topic. The 26.6 convention is necessary to implement TrueType hinting correctly (with the bytecode interpreter), so using 6 bits of fractional pixel units was a minimum. Experience shows that it is also largely sufficient to hint other kind of bezier curves, so it staid in FreeType.

And the reason why we don't use floats are multiple:

  • most embedded systems don't have efficient FPUs, so forget about using floats and doubles on these platforms

  • TrueType hinting requires and extensively uses 26.6 fixed point computations, using floats/doubles has strictly no advantage here, except slower operations, even on modern PCs

Hope this helps,

Thanks,
PeterM
⚠️ **GitHub.com Fallback** ⚠️