Link to home
Start Free TrialLog in
Avatar of dennis061698
dennis061698Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Reading & Loading a bitmap in DOS

How do I read and load a bitmap in DOS (Borland C++ 4.5 or 5.0).
I have set the Video Mode to 320x200x256.
ASKER CERTIFIED SOLUTION
Avatar of kinkajou
kinkajou

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kinkajou
kinkajou

Dennis,

To read in the image, you may need to uncompress the bitmap. Different bitmaps have different formats and methods of compression. Decompression information/algorithms for the most common formats (GIF, TIFF, BMP, PCX, PPM, etc) can be found on the web and you may even be able to find source code for the decompression. Simply, you would want to extract the palette from the bitmap header to set your video palette, examine the format header for the method of decompression and decompress the image setting each byte value from the uncompressed image in a char array that is the size of the product of the width of bitmap and the height of bitmap.

Once the image has been decompressed, you want to display it at the coordinate of your choice. The address of the video buffer is 0xA0000000L. You will need to offset from that address to acount for the coordinate position you want the bitmap to be displayed. Once you have calculated the position, you display each horizontal line of the bitmap, skip the space from the end of the bitmap to the right edge of the screen and the space from the left edge of the screen to the start of the bitmap, for all of the horizontal lines of the bit map. To diaplay a horizontal bitmap line, you must write each pixel for the line. To write a pixel you change the value of video memory to the value of your corresponding pixel in your char array.

#define SCREEN_WIDTH 320
#define BITMAP_WIDTH  to be filled in with bit map height
#define BITMAP_HEIGHT to be infilled in with bit map width
.
char bit_map_array[BITMAP_WIDTH*BITMAP_HEIGHT];
unsigned char far *video_buffer = 0xA00000000L;
unsigned char screen_offset,bitmap_offset;
.
screen_offset =  SCREEN_WIDTH*y_position_of_bitmap+x_position_of_bitmap;
bitmap_offset = BITMAP_WIDTH;
.

for (y = 0; y < bitmap_height; y++)
{
   for (x = 0; x < bitmap_width; x++)
   {
      video_buffer[screen_offset+x] = bit_map_array[bitmap_offset+x];
   }
   screen_offset += SCREEN_WIDTH;
   bitmap_offset += BITMAP_WIDTH;
}

I hope this isn't too confusing and helps you. Again, there are books that will discuss the palette setting and the bitmap displaying along with gaming concepts and graphics concepts. The "tricks of the game programming gurus" is an good guide.

Good Luck!
Kinkajou
One site that may have some helpful information for you as far as resources go.

http://hercule.csci.unt.edu/larc/
Avatar of dennis061698

ASKER

Thanks.
Your info helped alot, but there are still a couple of things that are confusing...
Couldn't you send me the program example from the book you mentioned concerning this?
I wish I could send the book's example but it is copyrighted and I read the copyright and it does not allow me to distribute the example. You could go to the local bookstore and copy it out of the book.You can check with your library for DOS graphics books.