Includes FreeType code to do 4×4 oversampling
ÿþI find 4×4 oversampling to be even 
better than FreeType antialiasing.



"  4×4 oversampling will render a full 
pixel even when tiny parts of it are 
outside of the outline.

"  4×4 oversampling does not have the 
positional uncertainty of area 
matching, therefore multiple of the 
same outline on top of each other do 
not lose smoothness, and it is possible 
to stack rendered glyphs seamlessly.

"  4×4 oversampling has the same 
rasterizer as the bilevel renderer, 
making for consistent rendering, and 
has the exact same features such as 
dropout control.

"  4×4 oversampling is accurate 
anti-aliasing to what is used in a 
standard TrueType renderer, the classic 
GDI renderer.



How to do 4×4 oversampling?



"  Create hinted outline, like in 
bilevel rendering but with a grayscale 
GETINFO

"  Scale the outline four times 
horizontally and four times vertically

"  Render bilevel rendering



How to represent 4×4 oversampling in 
FreeType?



       FT_UInt     interpreter_version = 
TT_INTERPRETER_VERSION_35;

       FT_Property_Set(library, 
"truetype", "interpreter-version", 
&interpreter_version);

       if(FT_Get_Gasp(face, 
ppem)&FT_GASP_DO_GRAY){

              FT_Load_Glyph(face, glyph, 
FT_LOAD_NO_BITMAP|FT_LOAD_TARGET_NORMAL|FT_LOAD_NO_AUTOHINT);

              for(int_fast64_t i=0; 
i<face->glyph->outline.n_points; i++){

                     
face->glyph->outline.points[i].x *= 4;

                     
face->glyph->outline.points[i].y *= 4;

              }

              FT_Render_Glyph(face->glyph, 
FT_RENDER_MODE_MONO);

       }

       else{

              FT_Load_Glyph(face, glyph, 
FT_LOAD_TARGET_MONO|FT_LOAD_NO_AUTOHINT|FT_LOAD_RENDER|FT_LOAD_MONOCHROME);

       }



After FreeType rendering, how to stack 
4×4 oversampled glyphs?



"  The same as in bilevel rendering: use 
the or gate '|'

"  Discard pixels above font height 
boundaries (scaled four times)



After text line rendering, how to write 
the 4×4 oversampling line of text to 
pixels?



"  Find the amount of pixels in each 4×4 
square

"  Replace each 1 with 0

"  Convert foreground color and 
background color from sRGB to RGB 
(lookup table for which RGB value 
corresponds to each sRGB value)

"  Use linear interpolation assuming 
each 0 is background color and each 16 
is foreground color

"  Convert the resulting RGB colors to 
sRGB (lookup table for what is the 
first RGB value that corresponds to 
each sRGB value with eight step binary 
search)

Reply via email to