Displaying Monochrome Bitmaps

The fg_drawmap() function displays monochrome bitmaps in 256-color or direct color virtual buffers. Its first parameter is the name of the bitmap array, the second is the width of the bitmap in bytes, and the last is the height of the bitmap in pixels. The fg_drawmap() function displays the image in the current color, with its lower left corner at the graphics cursor position in the active virtual buffer.

Suppose we want to display the triangle monochrome bitmap in the middle of a 320x200 virtual buffer, just as we did using a 256-color bitmap. To do this, its lower left corner must be at the screen space position (156,101). The following code will accomplish this:

C/C++:

BYTE Perimeter[] =
  {0xFF,0x80,0x41,0x00,0x22,0x00,0x14,0x00,0x08,0x00};
BYTE Interior[] =
  {0x00,0x00,0x3E,0x00,0x1C,0x00,0x08,0x00,0x00,0x00};
fg_move(156,101);
fg_setcolor(11);
fg_drawmap(Perimeter,2,5);
fg_setcolor(12);
fg_drawmap(Interior,2,5);

Delphi:

const
  Perimeter : array [1..10] of byte =
    ($FF,$80,$41,$00,$22,$00,$14,$00,$08,$00);
  Interior : array [1..10] of byte =
    ($00,$00,$3E,$00,$1C,$00,$08,$00,$00,$00);
begin
  fg_move(156,101);
  fg_setcolor(11);
  fg_drawmap(Perimeter,2,5);
  fg_setcolor(12);
  fg_drawmap(Interior,2,5);

Visual Basic:

Dim Perimeter(10) As Byte, Interior(10) As Byte
Perimeter(0) = &HFF: Perimeter(1) = &H80
Perimeter(2) = &H41: Perimeter(3) = &H0
Perimeter(4) = &H22: Perimeter(5) = &H0
Perimeter(6) = &H14: Perimeter(7) = &H0
Perimeter(8) = &H8: Perimeter(9) = &H0
Interior(0) = &H0: Interior(1) = &H0: Interior(2) = &H3E
Interior(3) = &H0: Interior(4) = &H1C: Interior(5) = &H0
Interior(6) = &H8: Interior(7) = &H0: Interior(8) = &H0
Interior(9) = &H0
Call fg_move(156, 101)
Call fg_setcolor(11)
Call fg_drawmap(Perimeter(0), 2, 5)
Call fg_setcolor(12)
Call fg_drawmap(Interior(0), 2, 5)

Note that we need two calls to fg_drawmap(), one for each color in the image, and how we use fg_setcolor() before each call to fg_drawmap() to define the current color. The result is a triangle with a blue perimeter and green interior.

Like fg_drwimage(), fg_drawmap() does not perform clipping when displaying an image. If you want to display a monochrome bitmapped image constrained by the current clipping limits, use fg_clipmap() instead of fg_drawmap(). The fg_clipmap() function takes the same three parameters as fg_drawmap().

The different color bitmaps used by fg_drawmap() do not all have to be the same size. In our triangle example, the perimeter is 9 pixels wide by 5 pixels high, but the interior is only 5 pixels wide by 3 pixels high. Hence, the bitmap for the interior pixels only requires one byte for each of its three rows, so we can store it in a three-byte array that would look like this:

[2]

08

[1]

1C

[0]

3E

We could then use this code to display the triangle bitmaps:

C/C++:

BYTE Perimeter[] = 
  {0xFF,0x80,0x41,0x00,0x22,0x00,0x14,0x00,0x08,0x00};
BYTE Interior[] =
  {0x3E,0x1C,0x08};
fg_move(156,101);
fg_setcolor(11);
fg_drawmap(Perimeter,2,5);
fg_move(156,100);
fg_setcolor(12);
fg_drawmap(Interior,1,3);

Delphi:

const
  Perimeter : array [1..10] of byte =
    ($FF,$80,$41,$00,$22,$00,$14,$00,$08,$00);
  Interior : array [1..3] of byte =
    ($3E,$1C,$08);
begin
  fg_move(156,101);
  fg_setcolor(11);
  fg_drawmap(Perimeter,2,5);
  fg_move(156,100);
  fg_setcolor(12);
  fg_drawmap(Interior,1,3);

Visual Basic:

Dim Perimeter(10) As Byte, Interior(3) As Byte
Perimeter(0) = &HFF: Perimeter(1) = &H80
Perimeter(2) = &H41: Perimeter(3) = &H0
Perimeter(4) = &H22: Perimeter(5) = &H0
Perimeter(6) = &H14: Perimeter(7) = &H0
Perimeter(8) = &H8: Perimeter(9) = &H0
Interior(0) = &H3E: Interior(1) = &H1C: Interior(2) = &H8
Call fg_move(156, 101)
Call fg_setcolor(11)
Call fg_drawmap(Perimeter(0), 2, 5)
Call fg_move(156, 100)
Call fg_setcolor(12)
Call fg_drawmap(Interior(0), 1, 3)

In this example, the time required to execute the second call to fg_move() may not be worth the saving of 7 bytes of bitmap array. When array space is critical, or when the images are larger, the use of smaller bitmaps for certain colors may be more valuable.

Yet another possibility for this example would be to shift the elements of the interior bitmap two pixels to the left. In this way, the bitmap would be aligned against the left side of the array, as the perimeter bitmap is. The three values comprising the interior bitmap would then become F8, 70, and 20. We also would need to change the x coordinate in the second call to fg_move() from 156 to 158.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.