Photo-Inversion

The simplest of Fastgraph's image processing transforms is photo-inversion. A photo-inversion transform replaces each RGB color component in an image with its grayscale opposite (the grayscale opposite of a color component C is 255-C). The resulting image looks like a photographic negative.

The fg_photodcb() function applies a photo-inversion transform to a direct color bitmap, so it can only be used when a high color or true color virtual buffer is active. The first fg_photodcb() parameter is the name of the array containing the direct color bitmap to be transformed, and the second parameter is the name of the array that will receive the transformed direct color bitmap (these two parameters can be the same array). The final fg_photodcb() parameter specifies the size of each bitmap in pixels. The code snippets shown here illustrate how we can apply a photo-inversion transform to an 80x50 true color bitmap:

C/C++:

BYTE Original[80*50*3];
BYTE Transformed[80*50*3];
fg_photodcb(Original,Transformed,80*50);

Delphi:

Original : array [1..80*50*3] of byte;
Transformed : array [1..80*50*3] of byte;
fg_photodcb(Original,Transformed,80*50);

Visual Basic:

Option Base 1
Dim Original(80*50*3) As Byte
Dim Transformed(80*50*3) As Byte
Call fg_photodcb(Original(1), Transformed(1), 80 * 50)

Recall that each pixel in a true color bitmap requires three bytes, so the size of each array is 80*50*3 bytes.

The fg_photovb() function applies a photo-inversion transform to a rectangular region of the active virtual buffer. The region's lower left corner is at the current graphics position. Like fg_photodcb(), you can only use fg_photovb() with direct color virtual buffers. The fg_photovb() function has two parameters that specify the width and height (in pixels) of the rectangular area to transform within the active virtual buffer. The code snippets shown here illustrate how we can apply a photo-inversion transform to the upper left 80x50 region in the active virtual buffer:

C/C++ and Delphi:

fg_move(0,49);
fg_photovb(80,50);
Visual Basic:
Call fg_move(0, 49)
Call fg_photovb(80, 50)

The fg_photorgb() function applies a photo-inversion transform to a series of RGB color triples. The first of its two parameters is the name of the array containing the RGB color components, arranged as three-byte RGB triples. The second parameter specifies the number of RGB triples to transform. The code snippets shown here illustrate how we can apply a photo-inversion transform to the non-system colors (colors 10 to 246) in the active logical palette:

C/C++:

BYTE RGBvalues[236*3];
fg_getdacs(10,236,RGBvalues);
fg_photorgb(RGBvalues,236);
fg_setdacs(10,236,RGBvalues);

Delphi:

RGBvalues : array [1..236*3] of byte;
fg_getdacs(10,236,RGBvalues);
fg_photorgb(RGBvalues,236);
fg_setdacs(10,236,RGBvalues);

Visual Basic:

Option Base 1
Dim RGBvalues(236 * 3) As Byte
Call fg_getdacs(10,236,RGBvalues(1))
Call fg_photorgb(RGBvalues(1),236)
Call fg_setdacs(10,236,RGBvalues(1))

If we're using a 256-color virtual buffer, the above sequences immediately change the colors of all pixels displayed in the application's client area if a palette-based display driver is active. If a high color or true color display driver is being used, the pixel colors will change the next time we blit the virtual buffer contents to the client area with fg_vbpaste() or fg_vbscale().

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.