Converting Palette-Based Image Files

The fish tank program uses PCX files to hold the background image and sprites. Because of the way fg_showpcx() performs color reduction in Fastgraph for Windows, problems can arise if you use more than one palette-based image file with 256-color virtual buffers.

Consider the case of a game in which you have one PCX file for the background and a second PCX file for the sprites that you'll display against that background. To avoid color problems in DOS, we would either have the two PCX files use the same palette, or else reserve specific colors for the sprites and then not use those colors in the background image. With either strategy, we'll most likely encounter problems because Fastgraph for Windows could produce different palettes for each image after applying the color reduction.

To illustrate this problem, suppose our two PCX files each used a palette in which color 60 was red. If the background image included pixels of some color less than 60 that weren't in the sprite image (or if such a color were eliminated from the sprite image during the color reduction process), color 60 pixels would be mapped to a lower-numbered color in the sprite image. For example, let's suppose we let fg_showpcx() perform color reduction when loading the background image into a virtual buffer. This, of course, will reduce the image to 236 non-system colors and set up these colors in the active logical palette -- no problem when we display the background image. Now if we use fg_showpcx() to load the sprite image into another virtual buffer, its colors will be different from the reduced palette of the background image. If our color 60 sprite pixels remapped to, say, color 58, they won't appear red when we display them against the background.

The easiest solution to this problem is to use the WinPal and WinMatch utilities. WinPal reduces a palette-based BMP or PCX file to 236 colors (if necessary) and remaps the color indices to avoid using the Windows system colors. WinMatch matches the palette in one image file to that of another. We can run WinPal on both PCX files, then run WinMatch to match the palette of the color-reduced sprite PCX file to that of the color-reduced background PCX file. After this, we'll have two color-reduced PCX files that use the same palette, and the palette would not use any Windows system colors. When you display such image files with fg_showpcx() or fg_showbmp(), be sure to specify the FG_KEEPCOLORS flag to disable color reduction.

If the two PCX files originally used the same palette, we can also solve this problem by combining the two PCX files into a single PCX file. For example, suppose we had two 320x200 PCX files. We could create a 320x400 PCX file, with the upper half containing one image and the lower half containing the other. The fg_showpcx() color reduction will then apply to the entire image, so naturally their colors would be compatible afterward.

Of course, the best solution to this problem is just to avoid using the Windows system colors altogether in your image files. If this is feasible, you can display all palette-based image files with color reduction disabled, and probably save yourself a few headaches along the way.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.