Alpha-blending in low colour depths
Wednesday, December 28, 2011 9:09:06 AM
The main reason to add support for alpha blending to wsdisplay was to give us relatively easy access to TrueType fonts - all anti-aliased fonts currently present in the NetBSD source tree were generated from TTF fonts found in pkgsrc with licenses that appear to allow redistribution of specific renderings. While freetype2 ( which is what the conversion utility uses ) can output monochrome bitmaps suitable for wsdisplay, the results look much better with anti-aliasing enabled.
Now we support some graphics hardware that doesn't support more than 8 bit colour, but which might be found in machines which are easily fast enough to do the alpha blending calculations by software, or graphics hardware that is just too slow when run in more than 8 bit, so we should be able to use the new fonts in 8 bit as well. There's prior art too, for example RISC OS supports anti-aliasing in a low as 16 colours ( that's 16 colours, not 16 bit ).
The solution is to simply use a fake 'true' colour map. In 8 bit we can use 3 bits for red, 3 bits for green and two for blue, which should be enough to make anti-aliased fonts look halfway decent. Rendering in 24 bit still looks an order of magnitude better but r3g3b2 doesn't look horrible either.
To get this to work rasops needs to know that the hardware colour map is r3g3b2 instead of ANSI colours in the first 16 palette entries - I added a flag which drivers can set to get the right devcmap. In order to test this out I added alpha blending support in 8bit colour to the r128fb driver, mostly because the hardware is relatively common in PowerMacs, the firmware always hands us 8 bit colour, and my Pismo was just sitting there waiting for some hackery. It's doing all calculations by software since we don't have any docs on the 3D engine, the 2D engine doesn't support alpha blending in any way and even if it did it probably wouldn't support it in 8 bit. Just like voyagerfb it still uses the blitter to draw characters so we don't have to scribble into video memory and stall the drawing engine.
The good news - it's pretty fast and looks better than bitmap fonts.
The bad news - you can immediately tell the difference to the same font rendered in 24 bit. Black on white looks nice but some other colour combinations not so much. Still lets us use the new fonts with usable results, which was the whole point of the exercise.
Now we support some graphics hardware that doesn't support more than 8 bit colour, but which might be found in machines which are easily fast enough to do the alpha blending calculations by software, or graphics hardware that is just too slow when run in more than 8 bit, so we should be able to use the new fonts in 8 bit as well. There's prior art too, for example RISC OS supports anti-aliasing in a low as 16 colours ( that's 16 colours, not 16 bit ).
The solution is to simply use a fake 'true' colour map. In 8 bit we can use 3 bits for red, 3 bits for green and two for blue, which should be enough to make anti-aliased fonts look halfway decent. Rendering in 24 bit still looks an order of magnitude better but r3g3b2 doesn't look horrible either.
To get this to work rasops needs to know that the hardware colour map is r3g3b2 instead of ANSI colours in the first 16 palette entries - I added a flag which drivers can set to get the right devcmap. In order to test this out I added alpha blending support in 8bit colour to the r128fb driver, mostly because the hardware is relatively common in PowerMacs, the firmware always hands us 8 bit colour, and my Pismo was just sitting there waiting for some hackery. It's doing all calculations by software since we don't have any docs on the 3D engine, the 2D engine doesn't support alpha blending in any way and even if it did it probably wouldn't support it in 8 bit. Just like voyagerfb it still uses the blitter to draw characters so we don't have to scribble into video memory and stall the drawing engine.
The good news - it's pretty fast and looks better than bitmap fonts.
The bad news - you can immediately tell the difference to the same font rendered in 24 bit. Black on white looks nice but some other colour combinations not so much. Still lets us use the new fonts with usable results, which was the whole point of the exercise.












