Flarg -- Daniel Wexler's Corner

Frame Buffer C Library

Sunday, July 15, 2001

This library is out-of-date.

Under XFree86, extensions are now available to set the color LUTs in a device independent manner.  I'm leaving this library in the public domain because it is interesting that newer graphics cards can be manipulated just like the original PC VGA tables, and because it was the first GPL (only?) code released by PDI. 

The FB C library, distributed under the GNU Public License, contains utility routines for setting the hardware color lookup tables. These routines can be useful for developing a color calibration system. Two example programs are included: fb_gamma which sets the LUTs to a specified gamma curve, and fb_flash, which sets the LUTs to random values.

Download a gzip'ed tar file of the FB library and programs.

Update: Although these routines and functions still work, I believe there is more formalized support through X extensions that are supported by both the NVidia and ATI cards.

The library provides the following two primary routines:

int FB_set_luts(short red[256], short grn[256], short blu[256]);
int FB_set_gamma(double gamma);

The library has been tested under Red Hat using a GeForce2 card, under IRIX on an SGI O2, and on an HP Linux box using an FX/5 card. No other platforms have been tested, nor are any other platforms supported. Please feel free to add support for additional platforms and contact me with patches.

Warning! On all platforms, setting the hardware LUTs will change the look of all the windows on your screen. This makes these tools somewhat dangerous since they can make your windowing system unusable if used improperly. For this reason, the programs must be run with superuser permissions on most machines.

Programs

Fb_gamma is a quick and dirty program for setting the gamma curve on your monitor. This is not a substitution for correct calibration, but it can be useful when you don't have the tools to develop a complete calibration system. You can specify a gamma exponent, and the program will set the LUTs to display the corresponding gamma curve.

The fb_flash program can be quite useful when developing graphics applications. It will set the LUTs to complete random colors, which makes your monitor look like a bad LSD trip. This is strangely useful when examining the alpha layer of a rendered image where fb_flash can help pinpoint holes in the mask, or dithering problems in the color channels. Thanks to Thad Beier for the original idea and early versions of this tool.

Color Calibration

Developing a complete color calibration system requires some programming and a nice photometer. To callibrate your system, you must first determine the display curve for your monitor. This can be done with a light meter that reads gray levels from the screen. For example, you might display a 25% gray, 50% gray and 75% gray images and read the actually displayed values using the light meter. From this information you can build a response curve for your monitor. Then, given a certain target profile, say a linear response or perhaps a respnse curve that mimics a specific film stock, you can build a set of LUTs using the inverse of the monitor reponse curve and your target response curve. Once computed, the LUTs are then set using the FB_set_luts() function in the FB library.