Microsoft Windows CE 3.0  

Matching True RGB Colors to the Frame Buffer's Color Space

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Applications often need to find out how a true RGB color (RGB 888) will be mapped into a frame buffer's color space when the display device is not in RGB 888 mode. For example, imagine you're working on an application that will run in 16- and 24-bit RGB display modes. You know that when the art was created, a color was reserved for use as a transparent blitting color key; for the sake of argument, it is a 24-bit color such as RGB(128,64,255). Because your application will also run in a 16-bit RGB mode, you need a way to find out how this 24-bit color key maps into the color space that the frame buffer uses when it's running in a 16-bit RGB mode.

Although DirectDraw does not perform color matching services for you, there are ways to calculate how your color key will be mapped in the frame buffer. These methods can be pretty complicated. For most purposes, you can use the GDI built-in color matching services, combined with the DirectDraw direct frame buffer access, to determine how a color value maps into a different color space. In fact, the Ddutil.cpp source file included in the DirectX examples of the Platform SDK includes a sample function called DDColorMatchthat performs this task. The DDColorMatchsample function performs the following main tasks:

  1. Retrieves the color value of a pixel in a surface at 0,0.
  2. Calls the Win32 SetPixelfunction, using a COLORREFstructure that describes your 24-bit RGB color.
  3. Uses DirectDraw to lock the surface, getting a pointer to the frame buffer memory.
  4. Retrieves the actual color value from the frame buffer (set by GDI in Step 2) and unlocks the surface
  5. Resets the pixel at 0,0 to its original color using SetPixel.

    The process used by the DDColorMatchsample function is not fast; it isn't intended to be. However, it provides a reliable way to determine how a color will be mapped across different RGB color spaces. For more information, see the source code for DDColorMatchin the Ddutil.cpp source file.

    Note   Because the SetPixelGDI function only accepts a COLORREFstructure on input, this technique only works for matching RGB 888 colors to the frame buffer's pixel format. If your application needs to match colors of another pixel format, you should translate them to RGB 888 before using this technique or query the primary surface for its pixel format and match colors manually.


     Last updated on Tuesday, May 18, 2004

    © 2004 Microsoft Corporation. All rights reserved.