Image File Colors

Like virtual buffers, image files are either palette-based or direct color. In general, image files that support up to 256 colors are palette-based, while 24-bit image files are direct color. Palette-based image files contain their own color or palette information that defines the actual colors used in the image. Fastgraph's image display functions can display palette-based images using either these colors, or whatever colors are currently in effect. Displaying images in the current colors is useful if you have many images that all use the same palette (because you only need to define the colors when displaying the first such image). You can display palette-based image files in any virtual buffer, but you can display direct color image files in direct color virtual buffers only.

When you display a palette-based image in a 256-color virtual buffer, Fastgraph normally updates the logical palette with the colors defined in the image palette so the image appears in its intended colors (and if necessary performs color reduction and remapping to avoid using the Windows system colors). However, this does have the side effect of changing the colors of other pixels already on the screen. For example, suppose we're displaying a 100x100 PCX file in a 640x480 virtual buffer, so the PCX image obviously won't cover the entire buffer. Before we display the image, we might fill the buffer with pixels of the same color, let's say color 25 (which is white by default). After displaying the image, the color 25 pixels outside the 100x100 image area will change from white to whatever color 25 is in the PCX palette.

Ideally, you'll want image files to use the same palette to avoid this problem, but sometimes this just isn't possible. One common solution is to "split" the image palette into two or more distinct groups of colors. For example, we might use a PCX file for a background, then display animated objects (sprites) against that background. We could design our background images to use, say, colors 42 to 245 and our sprites to use colors 10 to 41. Each PCX background would then use the sprite colors for its first 32 non-system palette entries, but the remaining 204 palette entries (42 to 245) would use the same colors as the background images. Then when we change backgrounds, the sprite colors remain intact.

Another solution is to use a direct color virtual buffer instead of a palette-based virtual buffer. By default, when we display a palette-based image in a direct color buffer, Fastgraph sets the virtual palette colors to the colors defined in the image palette. Changing the virtual palette does not affect pixels already drawn in those colors.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.