Direct Color Bitmap Translation

The structure of a direct color bitmap depends on the color depth and pixel format of the active virtual buffer. When using a high color virtual buffer, a DCB must be a series of two-byte values, with each pixel encoded in the 5/6/5 or 5/5/5 RGB format. For true color virtual buffers, a DCB is a series of three-byte RGB values, stored blue byte first, then green byte, then red.

Sometimes you may need to translate direct color bitmaps between different formats. The fg_transdcb() function translates direct color bitmaps between 5/5/5 high color, 5/6/5 high color, and true color formats. Its first two parameters are the names of the array containing the original bitmap and the name of the array to receive the converted bitmap. The next two parameters respectively define the color depth in bits per pixel of these two bitmaps. A color depth of 15 means 5/5/5 high color, 16 means 5/6/5 high color, and 24 means true color. The last fg_transdcb() parameter specifies the bitmap size in pixels.

The Dcb example stores a 40x20 high color bitmap in the Bird array, with each pixel hard-coded as a 5/6/5 RGB value. This is guaranteed to work for native Fastgraph applications because they always use the 5/6/5 high color pixel format. DirectX implementations, however, can use either the 5/6/5 or a 5/5/5 high color format. If you create a DirectX version of the Dcb example and run it on a system whose DirectX drivers require the 5/5/5 high color format, the program's colors will be wrong.

We can solve this problem with fg_gethcbpp() and fg_transdcb(). The fg_gethcbpp() function returns the color depth Fastgraph is using for high color virtual buffers. In Fastgraph's native libraries, fg_gethcbpp() will always return 16. But in the DirectX libraries, it will return 16 if DirectX is using the 5/6/5 high color pixel format, or 15 if DirectX is using the 5/5/5 format. Hence we can add the following code at the end of the Dcb WM_CREATE handler to translate the Bird bitmap to the 5/5/5 format if necessary:


if (fg_gethcbpp() == 15)


if (fg_gethcbpp() = 15) then

Visual Basic:

If fg_gethcbpp() = 15 Then
   Call fg_transdcb(Bird(0), Bird(0), 16, 15, 40 * 20)

In the above code snippets, we store the translated DCB in the same array as the original DCB. We can do this when translating between 5/5/5 and 5/6/5 high color formats, or when translating from true color to a high color format. We must use different bitmap arrays when translating high color to true color.

The fg_transdcb() function does not translate 256-color bitmaps to a direct color format. You can do this by displaying a 256-color bitmap in a direct color virtual buffer with fg_putimage() and then retrieving the resulting image as a direct color bitmap with fg_getdcb().

<< Prev

Next >>

Fastgraph Home Page


copyright 2001 Ted Gruber Software, Inc.