OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Working in PAL Or RGB Mode

A device-independent bitmap (DIB) can hold color values in two ways.

In palette mode, the DIB's color table contains indexes into a palette. The color values do not indicate any particular color themselves. The indexes must be cross-referenced to the corresponding palette entry in the currently realized palette. In RGB mode, each entry in the DIB's color table represents an actual RGB color value.

You can switch from RGB to palette mode by using these TDib functions:

bool ChangeModeToPal(const TPalette& pal);
bool ChangeModeToRGB(const TPalette& pal);

When you switch to palette mode using TDib::ChangeModetoPal, the TPalette & parameter is used as the DIB's palette. Each color used in the DIB is mapped to the palette and converted to a palette index. When you switch to RGB mode using TDib::ChangeModetoRGB, the TPalette & parameter is used to convert the current palette indexes to their RGB equivalents contained in the palette.

Working In RGB Mode

If you're working in RGB mode, you can use the following functions to access and modify the DIB's color table:

  • Retrieve any entry in the DIB's color table using theTDib::GetColor function. This function takes a single parameter, an int indicating the index of the color table entry. GetColor returns a TColor object.
  • Change any entry in the DIB's color table using theTDib::SetColor function. This function takes two parameters, an int indicating the index of the color table entry you want to change and a TColor containing the value to which you want to change the entry.
  • Match a TColor object to a color table entry by using the TDib::FindColor function. FindColor takes a single parameter, a TColor object, and searches through the DIB's color table until it finds an exact match for the TColor object. If it fails to find a match, FindColor returns -1.
  • Substitute one color for a color that currently exists in the DIB's color table using the TDib::MapColor function. This function takes three parameters, a TColor object containing the color to be replaced, a TColor object containing the new color to be placed in the color table, and a bool that indicates whether all occurrences of the second color should be replaced. If the third parameter is true, all color table entries that are equal to the first parameter are replaced by the second. If the third parameter is false, only the first color table entry that is equal to the first parameter is replaced. By default, the third parameter is false. The return value of this function indicates the total number of palette entries that were replaced.

For example, suppose you wanted to replace all occurrences of white in your DIB with light gray. The code would look something like this:

myDib->MapColor(TColor::LtGray, TColor::White, true);

Working In Palette Mode

If you're working in palette mode, you can use the following functions to access and modify the DIB's color table:

  • Retrieve the palette index of any color table entry using the TDib::GetIndex function. This function takes a single parameter, an int indicating the index of the color table entry. GetIndex returns a uint16 containing the palette index.
  • Change any entry in the DIB's color table using the TDib::SetIndex function. This function takes two parameters, an int indicating the index of the color table entry you want to change and a uint16 containing the palette index to which you want to change the entry.
  • Match a palette index to a color table entry by using the TDib::FindIndex function. FindIndex takes a single parameter, a uint16 and searches through the DIB's color table until it finds a match for the uint16. If it fails to find a match, FindIndex returns -1.
  • Substitute one color for a color that currently exists in the DIB's color table using the TDib::MapIndex function. This function takes three parameters, a uint16 indicating the index to be replaced, a uint16 indicating the new palette index to be placed in the color table, and a bool that indicates whether all occurrences of the second color should be replaced. If the third parameter is true, all color table entries that are equal to the first parameter are replaced by the second. If the third parameter is false, only the first color table entry that is equal to the first parameter is replaced. By default, the third parameter is false. The return value of this function indicates the total number of palette entries that were replaced.

See Also