Gamma CorrectionA gamma correction transform adjusts the overall brightness of an image. It does this by first normalizing a pixel's RGB color components from integer values between 0 and 255 to real numbers between 0.0 and 1.0. Next it raises the normalized value to a specified power, called the gamma value. Finally, it transforms the resulting value back to an integer component between 0 and 255. Gamma values between 0.0 and 1.0 will lighten an image, while gamma values greater than 1.0 will darken it. The gamma correction transform is closely related to adjusting the brightness control on a monitor, or to the exposure time in photography. The fg_gammadcb() function applies a gamma correction transform to a direct color bitmap, so it can only be used when a high color or true color virtual buffer is active. The first fg_gammadcb() parameter is the name of the array containing the direct color bitmap to be transformed, and the second parameter is the name of the array that will receive the transformed direct color bitmap (these two parameters can be the same array). The next parameter is the floating point gamma value, and the final fg_gammadcb() parameter specifies the size of each bitmap in pixels. The code snippets shown here illustrate how we can apply a gamma correction transform, with a gamma value of 0.6, to an 80x50 true color bitmap:
C/C++:
Delphi:
Visual Basic:
The fg_gammavb() function applies a gamma correction transform to a rectangular region of the active virtual buffer. The region's lower left corner is at the current graphics position. Like fg_gammadcb(), you can only use fg_gammavb() with direct color virtual buffers. The first fg_gammavb() parameter defines the gamma value, and its last two parameters specify the width and height (in pixels) of the rectangular area to transform within the active virtual buffer. The code snippets shown here illustrate how we can apply a gamma correction transform, with a gamma value of 0.6, to the upper left 80x50 region in the active virtual buffer: C/C++ and Delphi: fg_move(0,49); fg_gammavb(0.6,80,50); Visual Basic: Call fg_move(0, 49) Call fg_gammavb(0.6, 80, 50) The fg_gammargb() function applies a gamma correction transform to a series of RGB color triples. Its first parameter is the name of the array containing the RGB color components, arranged as three-byte RGB triples. The next parameter is the gamma value, and the final parameter is the number of RGB triples to transform. The code snippets shown here illustrate how we can apply a gamma correction transform, with a gamma value of 0.6, to the non-system colors (colors 10 to 246) in the active logical palette:
C/C++:
Delphi:
Visual Basic:
If we're using a 256-color virtual buffer, the above sequences immediately change the colors of all pixels displayed in the application's client area if a palette-based display driver is active. If a high color or true color display driver is being used, the pixel colors will change the next time we blit the virtual buffer contents to the client area with fg_vbpaste() or fg_vbscale().
|
 
copyright 2001 Ted Gruber Software, Inc.