January 29, 2016

Bitmap Loader++ : Turbo C++


    Bitmap is a raster graphics image file format with the extensions of .BMP or .DIB  (Device Independent Bitmap) used in Microsoft Windows  and  OS/2 operating systems. The file  format can be stored  uncompressed and some, like GIF, are difficult to decompress. 

The Bitmap Loader++ program shows how you can easily load bitmap images in a C++ program (in Turbo C++). The Bitmap Loader++ program supports 256-color bitmaps; it has a 54-byte header followed by a 1024-byte palette table. After that is the actual bitmap, which starts at the lower-left hand corner. In this program I have used VGA’s graphics mode, Mode 13h.





What is VGA Mode 13h?


Mode 13h is by far simplest mode to use. It is a 256 color mode with a 320x200 resolution (320 columns and 200 rows of pixels). In Mode 13h, one byte represents one pixel on the screen. Since this is a 256-color mode, each pixel represents 8 bits (28=256) or one byte, so the memory needed is 320*200 or 64,000 bytes. This memory is located at segment 0xA000 in the computer’s memory. Simply writing to that area in memory will write to the screen.

How to set Video mode?


To set the video mode, call interrupt 0x10 (BIOS video functions) with 0(zero) in the AH register and the desired mode number (mode 13h) in the AL register.

Example :

void SetGraphicsMode()
{
      _AH = 0;
     _AL = 0x13;
    geninterrupt(0x10);
}

How to set text mode?


To return to the normal text mode before your program ends, simply set AH to 0, set AL to 3 hex, and call interrupt 0x10.

Example :

void SetTextMode()
 {
                  _AH = 0;
                  _AL = 0x03;
                  geninterrupt(0x10);   
  }

How to plot pixels?

To plot pixels use pokeb() function.

Syntax:

pokeb(unsigned segment, unsigned offset, char value);

Pokeb stores the byte value at the memory location segment.

Example :

void Putpixel (int x, int y, char color)
{
     pokeb(0xA000,(y*320)+x,color);
}

Here, 0xA000 is Video segment and 320 is the width of screen.


Screenshots

 

  The following screenshots show you how this program works :

Bitmap Loader++ - Output

Bitmap Loader++ - Output

Bitmap Loader++ - Output

Bitmap Loader++ - Output



Download

 

Click here to view and download the source code of Bitmap Loader++ (51 KB).  

Click here to download the executable file of Bitmap Loader++ (49 KB) (Please note that it is a 16-bit executable and will not run on 64-bit systems).





No comments:

Post a Comment