Determining the Index Value of an RGB Value

Applications call GpiQueryColorIndex to find the closest match in a logical color table to an RGB value. This function finds the closest match for this RGB value in the physical color table, then finds the color in the logical color table closest to the color in the physical color table. The function returns the index value of that entry in the logical color table. The followiing figure is an example of how to determine which index value in the logical color table matches the RGB value for pink (0x00FF00FF), then uses that index entry to set the foreground color to pink for each of the primitive attributes.

#define INCL_GPILOGCOLORTABLE
#include <os2.h>

void fncCOLR03(void){
    LONG lIndex;                             /* Logical-color-table index */
    HPS hps;

    lIndex = GpiQueryColorIndex(hps, LCOLOPT_REALIZED, 0x00FF00FF);

    if ((lIndex >= 0) && (lIndex <= 15))     /* Check for valid index     */
        GpiSetColor(hps, lIndex);
} /* fncCOLR03 */


[Back: Determining the Color-Table Format and Index Values]
[Next: Setting the Primitive Color Attributes]