Modifying a Logical Palette

Once you realize a logical palette, fg_setrgb() and fg_setdacs() let you modify its colors. The two functions differ in that fg_setrgb() changes a single color in the logical palette, while fg_setdacs() changes one or more consecutive colors. If a palette-based display driver is active, the effect of each function is immediate, meaning if we change a color definition, pixels of the color will immediately change to the new color. This is true for pixels in the active window, and for pixels in inactive windows mapped to that color. Neither function has any effect unless a logical palette is active.

The fg_setrgb() function has four integer parameters. The first specifies the color being changed (more accurately, the color index in the active logical palette), and the last three specify that color's new red, green, and blue color components. Each color component is between 0 and 255. For example, if we set up a default logical palette with fg_defpal(), color 10 will be black (that is, its red, green, and blue color components are all zero). If we want to change all color 10 pixels from black to white (red, green, and blue are all 255), we could use fg_setrgb() as shown here:

C/C++ and Delphi:

fg_setrgb(10,255,255,255);

Visual Basic:

Call fg_setrgb(10, 255, 255, 255)

If you want to change two or more consecutive colors in a logical palette, the fg_setdacs() function is more efficient than multiple calls to fg_setrgb(). This function takes the same parameters as fg_logpal() -- a starting color number, the number of colors to change, and a byte array containing that many sets of RGB color components. For example, we could make the first 16 non-system colors (colors 10 to 25) black with this code:

C/C++:

char Black[16*3];
memset(Black,0,16*3);
fg_setdacs(10,16,Black);

Delphi:

var
  Black : array [1..16*3] of byte;
begin
  FillChar(Black,16*3,0);
  fg_setdacs(10,16,Black);

Visual Basic:

Dim Black(16 * 3) As Byte
Erase Black
Call fg_setdacs(10, 16, Black(0))

Note that each fg_setrgb() and fg_setdacs() color component is a value between 0 and 255 (in fact, this is true for all Fastgraph for Windows functions that use RGB color components). This differs from Fastgraph for DOS, where color components range from 0 to 63 in 256-color graphics modes. If you are converting an application from DOS to Windows and you have an array containing DOS color component values, you can convert them with fg_mapdacs(). This function has three parameters: the byte array containing the "0 to 63" color components, the byte array to receive the "0 to 255" converted components (which must be at least as large as the first array), and the number of sets of color components to convert. You can specify the same array for both source and destination. For example, after this call to fg_mapdacs()

C/C++:

char RGBvalues[6] = {0,21,21, 0,63,63};
fg_mapdacs(RGBvalues,RGBvalues,2);

Delphi:

const
  RGBvalues : array [1..6] of byte = (0,21,21, 0,63,63);
begin
  fg_mapdacs(RGBvalues,RGBvalues,2);

Visual Basic:

Dim RGBvalues(6) As Byte
RGBvalues(0) = 0: RGBvalues(1) = 21: RGBvalues(2) = 21
RGBvalues(3) = 0: RGBvalues(4) = 63: RGBvalues(5) = 63
Call fg_mapdacs(RGBvalues(0), RGBvalues(0), 2)

the RGBvalues array would contain two sets of converted RGB color components, (0,85,85) and (0,255,255).

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.