Inverting Bitmaps

The Fastgraph bitmapped image display functions expect images to be stored starting with the bottom row and proceeding toward the top. This convention is often contrary to the "top to bottom" row order used in other graphics libraries. The fg_invert() function reverses the row order of bitmapped images, so a "top to bottom" image becomes a "bottom to top" image, or vice versa. This will often make it easier to import such images from other sources for use with the bitmapped image display functions. Note that fg_invert() does not change the bitmap orientation for these functions; it merely reverses the row order of the bitmap itself.

The fg_invert() function requires three parameters. The first is the name of the bitmap array; the resulting inverted image is stored in this same array. The second and third parameters respectively specify the bitmap width and height in bytes. For example, suppose we originally defined our 9x5 pixel 256-color triangle bitmap in top-down order. We could then use fg_invert() to convert the bitmap to the bottom-up orientation before displaying it with fg_drwimage():

C/C++:

BYTE Triangle[] = {
    0, 0, 0, 0,11, 0, 0, 0, 0,
    0, 0, 0,11,12,11, 0, 0, 0,
    0, 0,11,12,12,12,11, 0, 0,
    0,11,12,12,12,12,12,11, 0,
   11,11,11,11,11,11,11,11,11};
fg_move(156,101);
fg_invert(Triangle,9,5);
fg_drwimage(Triangle,9,5);

Delphi:

const
  Triangle : array [0..44] of byte = (
     0, 0, 0, 0,11, 0, 0, 0, 0,
     0, 0, 0,11,12,11, 0, 0, 0,
     0, 0,11,12,12,12,11, 0, 0,
     0,11,12,12,12,12,12,11, 0,
    11,11,11,11,11,11,11,11,11);
begin
  fg_move(156,101);
  fg_invert(Triangle,9,5);
  fg_drwimage(Triangle,9,5);

Visual Basic:

Dim Triangle(9 * 5) As Byte
Call fg_move(156, 101)
Call fg_invert(Triangle(0), 9, 5)
Call fg_drwimage(Triangle(0), 9, 5)

Because the fg_invert() bitmap width is specified in bytes, we can also use this function to invert any bitmap. However, it's often easier to use fg_invdcb() to invert direct color bitmaps. The fg_invdcb() function has the same parameters as fg_invert(), but of course the bitmap array holds a direct color bitmap, and the bitmap width is expressed in pixels, not bytes. For high color virtual buffers, the bitmap is stored two bytes per pixel, with each pixel in an encoded RGB format. For true color virtual buffers, the bitmap is stored three bytes per pixel, with the blue byte first, then the green byte, and finally the red.

Another use of fg_invert() and fg_invdcb() is to create inverted versions of any bitmap. This means you can create versions of bitmaps mirrored about the x axis, somewhat analogous to the way fg_revimage() and fg_revdcb() display images mirrored about the y axis.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.