GrayscaleA grayscale transform converts a color image to its grayscale equivalent. It does this by calculating a luminance value L for each pixel from its RGB color components:
and then setting each of the pixel's RGB components to L. Because the three factors in the above equation sum to 1, applying a grayscale transform to a grayscale image has no effect. The fg_graydcb() function applies a grayscale 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_graydcb() 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 final fg_graydcb() parameter specifies the size of each bitmap in pixels. The code snippets shown here illustrate how we can apply a grayscale transform to an 80x50 true color bitmap:
C/C++:
Delphi:
Visual Basic:
The fg_grayvb() function applies a grayscale transform to a rectangular region of the active virtual buffer. The region's lower left corner is at the current graphics position. Like fg_graydcb(), you can only use fg_grayvb() with direct color virtual buffers. The fg_grayvb() function has two parameters that 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 grayscale transform to the upper left 80x50 region in the active virtual buffer:
C/C++ and Delphi:
Visual Basic:
The fg_grayrgb() function applies a grayscale transform to a series of RGB color triples. The first of its two parameters is the name of the array containing the RGB color components, arranged as three-byte RGB triples. The second parameter specifies the number of RGB triples to transform. The code snippets shown here illustrate how we can apply a grayscale transform 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.