256-Color BitmapsBecause they are simplest, let's first discuss 256-color bitmaps. You can think of a 256-color bitmap as a rectangular grid of pixels with values between 0 and 255. The corresponding color in the active logical palette determines the colors in which bitmap pixels are displayed. For example, if the logical palette defines color 24 as yellow, then bitmap pixels whose value is 24 will be yellow. You can use 256-color bitmaps with palette-based and direct color virtual buffers. For direct color virtual buffers, 256-color bitmaps use the virtual palette instead of the logical palette to associate colors with the bitmap pixels. Let's begin with a simple triangle image:
The triangle's perimeter is a different color than its interior pixels, and to use this image with Fastgraph, we must inscribe the triangle in a rectangular area. Our triangle is nine pixels wide at its base and five pixels high. The pixels indicated by an asterisk (*) are the triangle's perimeter, while those indicated by an x represent its interior points. We need to distinguish between these pixels because they will be different colors. The pixels shown as periods (.) are not part of the triangle itself but are transparent pixels required to make the image rectangular. Before we can display the triangle image as a 256-color bitmap, we must specify the color value for each pixel in the bitmap. Let's suppose we want the triangle's perimeter pixels to be blue, and the interior pixels to be green. If we're using the default logical palette, blue is color 11 and green is color 12. Most Fastgraph bitmap display functions treat color 0 as transparent, so we'll set all the pixels outside the actual triangle to zero. The resulting bitmap is shown here.
Our triangle is nine pixels wide and five pixels high, for a total of 45 pixels. Because each pixel is a value between 0 and 255, we need an array of at least 45 bytes to hold the bitmap, with each byte of the array holding one pixel from the bitmap. The first element of a bitmap array represents the lower left corner of the image. The subscript progression then continues to the right until reaching the end of the first row. It then resumes at the leftmost pixel of the second row and continues to the right until the end of that row. It continues in this manner for all remaining rows. Assuming subscripts begin at zero, the subscript order for our 9x5 triangle image would thus be:
And we could store the 256-color bitmap in an array like this:
C/C++:
Delphi:
Because programs usually access 256-color bitmaps in bytes, it's best to store them in byte arrays.
|
 
copyright 2001 Ted Gruber Software, Inc.