Example: Image Processing

The ImgProc example is a simple image processing program that illustrates each of Fastgraph's one-to-one image transforms on BMP, JPEG, or PCX files. ImgProc has a File menu with items for opening an image file, saving a transformed image, displaying image file details, and exiting. It also has an Edit menu with items for a one-level undo, restoring the original image, and applying each of the four transforms. ImgProc uses the versions of the image transform functions that apply the transform to the active virtual buffer.

ImgProc uses three 24-bit true color virtual buffers. One virtual buffer, referenced by the handle hVB, contains the working copy of the image. All image transforms are applied to this buffer. Another virtual buffer keeps the previous version of the image for the undo operation, and another buffer holds the original image. All three buffers are initially 32x32 pixels, but are re-created in the program's SwitchBuffers() function so they are the same size as the image, just as we did in the Image example.

The OpenClick() function is called in response to clicking the File|Open menu item. OpenClick() displays an Open File dialog box for entering a BMP, JPEG, or PCX file name. It then verifies that the file really is one of the supported image file types. If it is, we obtain the image dimensions, call SwitchBuffers() to create new virtual buffers of that size, and then display the image. OpenClick() then uses fg_copypage() to keep a copy of the original image in another virtual buffer. Finally, OpenClick() enables the other items on the File menu and the image processing items on the Edit menu.

The four image processing items on the Edit menu all call separate action functions to apply the transform to the working copy of the image. The Contrast Enhancement item applies a contrast enhancement transform with lower bound 63 and upper bound 192, while the Gamma Correction item applies a gamma correction transform with a gamma value of 0.45 (in a commercial application, of course, you would want to make these values variable). The Grayscale and Photo-Inversion items apply those transforms. Once we apply any transform, the action functions display the transformed image with fg_vbscale() and then enable the Edit|Undo and Edit|Restore Original menu items.

C/C++ version

C++Builder version

Delphi version

Visual Basic version

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.