Borland Online And The Cobb Group Present:


November, 1994 - Vol. 1 No. 11

Letters - Determining video bit-depth from a Windows application

I'm writing a Windows application that displays some complex images from PCX files. To maintain the highest possible image quality, I've created both 16-color and 256-color versions of each image. (I've had unpredictable results displaying 256-color graphics on a 16-color system.)

However, I need to have my program determine the bit-depth of the current video system. To do this, I'm calling the Windows API function GetDeviceCaps().

Using the constant BITSPIXEL as the second parameter seems to work correctly for 256-color mode, but it returns a 1 for 16-color systems. Am I calling this function with the wrong constant, or should I use a different API function?

James Martinez

St. Charles, Illinois

James, you're calling the function correctly, and it's the right one to use. Unfortunately, there's more to bit-depth in Windows video than this one value.

Back when CGA video was the standard, there were four variables to contend with: the Red, Blue, and Green color bits and the High/Low Intensity bit. By combining these four bits, you could create only 16 colors (High intensity Green, Low intensity Green, High intensity Green and Red, and so on). The four variables became known as color planes.

With the advent of EGA/VGA, the number of possible colors expanded somewhat through the use of separate intensity bits for each color. For instance, it became possible to create a color using High intensity Red and Low intensity Green (Brown).

For compatibility reasons, though, the video card manufacturers decided not to define as part of the available color palette most of the variations that mixed High and Low intensity colors. This resulted in 16 available colors, even though 64 colors were possible (3 color bits + 3 intensity bits = 26 colors).

Finally, SVGA systems introduced eight bits of intensity information for each color. Since the concept of a color plane doesn't describe the capabilities of this type of system, the eight bits of information for each color have become known as the bits-per-pixel values.

To determine the actual bit-depth of a given video system, you must check both the bits-per-pixel value (for SVGA systems) and the number of color planes (for EGA/VGA systems). A simple solution is to retrieve both values and multiply them. This calculation is valid because an EGA/VGA system will return 1 for the bits-per-pixel value, and an SVGA system will return 1 for the color planes value.

To apply this to your program, add the following code to your main window procedure (assuming that hWnd is the window handle):

HDC currentDC = GetDC(hWnd);
int bitdepth = GetDeviceCaps(currentDC, 
                             BITSPIXEL) 
    * GetDeviceCaps(currentDC, PLANES);

This code simply gets currentDC (the current device context) from the window handle and then queries Windows for the BITSPIXEL (bits-per-pixel) and PLANES (number of color planes) values for the current video system by using the GetDeviceCaps() API function.

Return to the Borland C++ Developer's Journal index

Subscribe to the Borland C++ Developer's Journal


Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.