Why is there always some noise in the freetype rendered text?

I am writing an opengl program that uses freetype2 as a mechanism for rendering text.

Using its sub-pixel visualization of the LCD, I found that there are always some noise pixels in the rendered result, why is this happening? Also, although the manual says that the LCD mode will generate a buffer that is a multiple of 3, I often find that the width is 3n + 1 or 3n + 2 and does not match face->glyph->bitmap->width .

enter image description here

+6
source share
2 answers

Actually, after several hours of trying and testing, I realized that rasterized glyph data has some irrelevant bytes called padding . As an illustration, the glyph data in the buffer is shown below: ( o / x are significant data, but not significant)

  0 1 2 3 4 5 6 7 0 oxoxox . . 1 xoxoxo . . 2 oxoxox . . 3 xoxoxo . . 4 oxoxox . . 

There are three numbers that describe the size of this buffer, the first two are obvious:

 rows = 5 //since there are 5 rows width = 6 //since each row has 6 bytes of data 

However, there is actually a third:

 pitch = 8 //the actual width of rows, including "padding" 

If you ignore this property of the buffer, as I do, and you are mistaken that width is the actual width, you will display a distorted or translated form of the glyph.

My understanding of this “add-on” is similar to Dayvat Pandya, this is compensation. However, this is not a compensation for parity (obviously, +2 does not change parity), by default it is compensation so that the actual width is a multiple of 4. But yes, you can change 4 to 2 or even 1. I assume by forming a data matrix with with a width of 4, it can be loaded faster, for example, to load in longint instead of byte .

Nevertheless, the insight of R.. really impressed me. I think you guys just can't understand that I can make such a basic mistake.

+3
source

I have never used the FreeType library, so I can’t speak from personal experience, but maybe this “noise” is due to the fact that the width of the text or the calculation of the coordinates of the upper left text are disabled by one?

+2
source

Source: https://habr.com/ru/post/888764/


All Articles