| Previous | Table of Contents | Next |
The VESAPCX.C program displays PCX file version images on monitors controlled by display adapters that support VESA VBE version 1.2 or later. The specific monitor mode and PCX file are input arguments. PCX palette images can display on VBE packed pixel modes and 24-bit images can display on VBE direct color modes.
The program begins execution by verifying two input arguments exist. The first specifies the VBE mode the program should use and the second specifies the PCX filename the program should display. After verifying the display adapter provides VBE support, the program verifies the adapter supports the specific VBE mode. If the mode is not supported, the program exits with an error message. Otherwise, the program sets the requested VBE mode.
If the mode is a packed pixel mode, DisplayDefaultPaletteDiagonally() displays the default VGA palette across each line starting with palette entry zero in scan line zero, column zero. Whenever a display line is not completely filled after reaching palette entry 255, the program continues filling the line starting from value zero. When a line is finally filled, the next line is filled starting with a palette value one greater than the line above it started with. This gives the appearance of diagonal colored lines which slope from the upper right to the lower left. Eventually, the initial screen fills with colored diagonal lines. The program then continues displaying more scan lines by invoking SetDisplayStartLine() which performs a vertical scroll. SetDisplayStartLine() therefore provides a working example of memory scrolling which is also useful for horizontal scrolling.
The VESAPCX.C program now attempts to display the selected PCX file by calling DisplayPcxFile(). DisplayPcxFile() opens the file. ValidatePcxFileHeader() validates the file has a valid PCX header and attempts to load RGB gamma correction values from a file named gamma.val. If the file does not have a valid PCX header, DisplayPcxFile() returns. Otherwise, DisplayPcxFile() resets the screen to the desired mode, setting the clear video memory flag so the VBE support clears the screen.
DisplayPcxFile() now tests to see if the image has one display plane (palette). If so, the VESA VBE mode must be packed pixel and an error occurs if not. Alternately, the image may have more than one display plane (three for direct color images), and the VESA VBE mode must be a direct color mode. PresentDirectColorPcxImage() presents direct color images and PresentColorPalettePcxImage() presents palette images.
PresentDirectColorPcxImage() presents the direct color image, correcting the bit depth if necessary. It then displays a sharpened color image by converting the color information into luminance information and sharpening the luminance data. The resulting color information is converted back to color information using a proportional intensity scaling approach.
PresentColorPalettePcxImage() first displays the palette image and then presents the R, G, B, C, M, and Y color information in isolation by successively invoking DisplayRgbPlanes(). DisplayRgbPlanes() displays the image after stripping unwanted color plane information from the original palette. PresentColorPalettePcxImage() last checks to see whether the gamma correction values loaded correctly and performs an image gamma correction if so. PresentColorPalettePcxImage() returns to DisplayPcxFile() which then invokes PerformColorSpaceManipulation().
PerformColorSpaceManipulation() performs numerous color image manipulations in HLS, HSV, and HSI color space by invoking PerformHlsColorSpaceManipulation(), PerformHsvColorSpace Manipulation(), and PerformHsiColorSpaceManipulation(), respectively. Using each of these color spaces, the palette entry hues are first rotated 360 degrees, then the saturation varies from zero to a factor of three of the original value, and the intensity varies from a gamma value of 0.5 to nearly 2. The screen output provides a visual example of many concepts this book discusses, such as non-uniform color space side effects that appear as various image pixels suddenly becoming brighter with hue changes.
PresentColorPalettePcxImage() finally ends after presenting the original image again, followed by the gamma corrected version.
The RGB24TO8.C program displays 24-bit color images using two crude image quantization approaches described in detail in Chapter 15. The first approach constructs an RGB palette using the three high-order bits for the red intensity, the middle three bits for green intensities, and the two low-order bits for blue intensities. SetR3G3B2Palette() initializes the palette by distributing the individual primary RGB components intensities uniformly (red and green use intensity values 0, 32, 64, 96, 128, 160, 192, and 224, while blue uses intensity values 0, 64, 128, and 192) and gamma correcting the resulting palette.
The second approach assigns numbers of uniformly distributed primary color intensities rather than palette entry bit positions. SetMorphsPalette() uses seven uniformly distributed intensities for red, nine for green, and four for blue. This assigns 252 color combinations (7 x 9 x 4), using palette entries zero through 251. The remaining four intensity assignments for palette entries 252 through 255 are (60, 60, 60), (120, 120, 120), (180, 180, 180), and (240, 240, 240), respectively, which provide some monochromatic gray values.
In both approaches RGB24TO8.C attempts to minimize quantization errors by calculating the minimum Euclidean distance within RGB space and discarding any errors. A more refined approach would disperse the RGB component error to nearby pixels component values, similar to digital halftone error diffusion approaches. This is left as a reader exercise.
The WU_QNT.C program is the original implementation of Dr. Xiaolin Wus color quantization program for Sun Microsystems workstations. The WDS_QNT.C program is an MS-DOS derivative version of the WU_QNT.C program.
| Previous | Table of Contents | Next |