Sub-pixel antialiasing report #1 [GSoC]

Blog post by Andrej Spielmann on Thu, 2008-06-26 14:06

The first month of GSoC coding period is almost over and it's time for a summary.
This month wasn't particularly easy. I was working hard to distribute my effort between Haiku and my exams accordingly. I must confess, I was probably doing more schoolwork than Haiku :-)
Nevertheless, I did make some progress and now I am very happy to announce some of the first actual results of my project!

Thanks to the great lucidity of the app server's and AGG's source codes, I have quickly become familiar with them and could start making the additions. I decided to begin by implementing sub-pixel antialiasing for untransformed text. This includes virtually all the text that one normally encounters around the system, in text editors or browsing the internet.
The internal part of the technology is now finished and it is already possible to have all the text in the system sub-pixel rendered. The first picture shows some text displayed in Haiku with its present gray-shade antialiasing and the second picture shows (almost) the same screen rendered with my implementation of sub-pixel antialiasing (click to see the full version and make sure you are viewing it in its full size).

The difference in the appearance of normal straight text is not particularly dramatic but I think that there is a significant improvement in the oblique font in the upper right window and the fancy font in the lower left window (Lucida Calligraphy).
I recommend using some magnifying software tool for studying the individual pixels of the characters :-)

I will now roughly draft some of the technical details.
The text rendering in Haiku uses the open source library Freetype for producing bitmaps of coverage values for each character. These bitmaps are now created with triple width and each of the values is interpreted as the coverage of one sub-pixel.
Of course, doing this would cause certain visible colour unbalance in the result. That can be cured by distributing the value of each pixel to some of its neighbours, which on the other hand introduces some blurriness. You can have this filtering done by Freetype, but I didn't find their implementation completely optimal.
This is because Haiku chooses to use strongly hinted characters, which means that they are snapped to the pixel grid, and so are some of their pronounced features (like the legs of an 'm', for example). Eventually, the effect of this is that almost every straight vertical line (in most fonts) is rendered precisely one or two whole pixels wide, covering precisely one or two whole pixels. Such lines then obviously don't need any colour filtering and applying it will actually make them blurrier.
My implementation of color filtering ignores such vertical lines and hence the characters are really sharp and crispy. Freetype's original colour filtering doesn't take this into account and neither does ClearType in Windows XP. So Haiku is actually, from this point of view, going to have much crispier text rendering than the standard these days!

I think (and so does my mentor Stephan, probably) that the most useful thing to do now would be to create a front-end for sub-pixel rendering - that means adding some options to the existing preferences applets. When that is done, sub-pixel rendering for untransformed fonts is ready for everyone and I will then start working on making it available for all vector graphics in general.
Another thing that I would like to look into is the possibility of (optionally?) using unhinted text, since I personally think it is a better approach which makes a much more effective use of the power of sub-pixels.

That's all for today. If anyone desperately yearns for having sub-pixel antialiasing Haiku right now just let me know and I can send you my app server source codes. But I optimistically think that it ought to be integrated into the main code trunk within one or two weeks :-)

Comments

Re: Sub-pixel antialiasing report #1 [GSoC]

Great report Andrej!

I believe sub-pixel antialiasing will greatly benefit the display of complex glyphs such as Japanese, Chinese, etc. I use Japanese quite a bit, so I am really looking forward to this feature making it into Haiku. ;)

Re: Sub-pixel antialiasing report #1 [GSoC]

Great work Andrej! On my CRT it doesn't make much difference, but on my LCD the characters are definately better defined. Particularly the font down left looks absolutely beautiful on my LCD. I was wondering though if there would be any way of changing the gamma setting for the font rendering? Also you mentioned that Haiku uses full hinting, is there any chance we could be able to set the hintstyle (slight, medium, full) in the font prefs? I understand that the latter two requests fall outside the scope of sub-pixel antialiasing but I figured I'd ask anyway :D

Re: Sub-pixel antialiasing report #1 [GSoC]

Yes, I'm definitely going to make it possible to choose the level of hinting. I will give a thought to the gamma setting as well.

Re: Sub-pixel antialiasing report #1 [GSoC]

Wonderful! Again, huge thanks for your great work Andrej! And if you find the time, please keep us updated :)

Re: Sub-pixel antialiasing report #1 [GSoC]

Very nice job! Keep up the great work!

Re: Sub-pixel antialiasing report #1 [GSoC]

I wonder if sub-pixel rendering only works at native resolution, and how that is handled?

Re: Sub-pixel antialiasing report #1 [GSoC]

I need my eyes checked.

I actually viewed both images on my 2 work LCD panels, my home CRT, and my MBP laptop, and I honesty cannot see the benefits.

I must be an old fart with bad eyesight :sob: But if all you young ones say that this is good, I'm all for it. And I'm only 38yo :)

Re: Sub-pixel antialiasing report #1 [GSoC]

Well, the CRT probably isn't going to show much benefit (unless it's trinitron perhaps) as subpixel rendering generally takes advantage of the 3-subpixel nature of a single full LCD pixel.

It is actually noticeable, but it's somewhat slight for people who don't care about such things...

The biggest difference is probably noticeable in the italicized/sheared lowercase letter "m" or "n"

for more information:

http://en.wikipedia.org/wiki/Subpixel_rendering

even more interesting subpixel rendering can be done with LCD panels containing 4-subpixels such as the OLPC

Re: Sub-pixel antialiasing report #1 [GSoC]

you and only about a billion other people, koki :)

Re: Sub-pixel antialiasing report #1 [GSoC]

Good work! Looks very promising, like you say the rendering of the cursive font is much better, looks absolutely beatiful on this screen (1680x1050 15" lcd)

Re: Sub-pixel antialiasing report #1 [GSoC]

This looks great. Good font rendering is important and this nails it!

Re: Sub-pixel antialiasing report #1 [GSoC]

I for sure can really tell the difference although it is a very fine difference. My first impression was that the old Haiku version was more blurry.

OT: This is IMHO how eye-candy should be; plain useful.

Re: Sub-pixel antialiasing report #1 [GSoC]

I can't unfortunately perceive differences and I used from magnifies glass 2x and 4x. Regards

Re: Sub-pixel antialiasing report #1 [GSoC]

It's not something you can see with "magnifying glass" (assuming you mean software to blow up the pixels on the screen) - as it makes use of the fractional pixels in an LCD display...

All you're likely to notice is that the edges of the glyphs are slightly colored reddish or bluish now as opposed to before to take advantage of the left and right subpixel colors.

Re: Sub-pixel antialiasing report #1 [GSoC]

Sub-pixel rendering is similar to Windows XP Cleartype or MacOS X Font Smoothing. You can try either of these to see the difference it makes.

Using Cleartype on a LCD display makes a huge difference that you'll notice. I use Cleartype on LCD displays because the text looks sharper. But I don't like using Cleartype on CRT because I believe it makes the fonts look a little blurry.

Check this image out:
http://en.wikipedia.org/wiki/Image:Subpixel_demonstration_%28Quartz%29.png

Rows 1&2 are regular method, rows 3&4 are sub-pixel.

The first column shows what is actually going on - how sub-pixel rendering works. The 3rd column shows what a person ends up seeing.

In the 3rd column, compare rows 1&2 vs 3&4 and you'll see that the last two rows ( sub-pixel ) look sharper.

Edit: above discussion was about sub-pixel rendering, but if you want to see sub-pixel anti-aliasing then look here for info:
http://en.wikipedia.org/wiki/Font_rasterization