int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename){// this function opens a bitmap file and loads the data into bitmapint file_handle, // the file handle index; // looping indexUCHAR *temp_buffer = NULL; // used to convert 24 bit images to 16 bitOFSTRUCT file_data; // the file data information// open the file if it existsif ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1) return(0);// now load the bitmap file header_lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));// test if this is a bitmap fileif (bitmap->bitmapfileheader.bfType!=BITMAP_ID) { // close the file _lclose(file_handle); // return error return(0); } // end if// now we know this is a bitmap, so read in all the sections// first the bitmap infoheader// now load the bitmap file header_lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));// now load the color palette if there is oneif (bitmap->bitmapinfoheader.biBitCount == 8) { _lread(file_handle, &bitmap->palette,256*sizeof(PALETTEENTRY)); // now set all the flags in the palette correctly and fix the reversed // BGR RGBQUAD data format for (index=0; index < 256; index++) { // reverse the red and green fields int temp_color = bitmap->palette[index].peRed; bitmap->palette[index].peRed = bitmap->palette[index].peBlue; bitmap->palette[index].peBlue = temp_color; // always set the flags word to this bitmap->palette[index].peFlags = PC_NOCOLLAPSE; } // end for index } // end if// finally the image data itself lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);// now read in the image, if the image is 8 or 16 bit then simply read it// but if its 24 bit then read it into a temporary area and then convert// it to a 16 bit imageif (bitmap->bitmapinfoheader.biBitCount==8 | | bitmap->bitmapinfoheader.biBitCount==16) { // delete the last image if there was one if (bitmap->buffer) free(bitmap->buffer); // allocate the memory for the image if (!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage))) { // close the file _lclose(file_handle); // return error return(0); } // end if // now read it in _lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage); } // end ifelse { // this must be a 24 bit image, load it in and convert it to 16 bit// printf("\nconverting 24 bit image..."); // allocate temporary buffer if (!(temp_buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage))) { // close the file _lclose(file_handle); // return error return(0); } // end if // allocate final 16 bit storage buffer if (!(bitmap->buffer=(UCHAR *)malloc(2*bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight))) { // close the file _lclose(file_handle); // release working buffer free(temp_buffer); // return error return(0); } // end if // now read it in _lread(file_handle,temp_buffer,bitmap->bitmapinfoheader.biSizeImage); // now convert each 24 bit RGB value into a 16 bit value for (index=0; indexbitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++) { // extract RGB components (in BGR order), note the scaling UCHAR blue = (temp_buffer[index*3 + 0] >> 3), green = (temp_buffer[index*3 + 1] >> 3), red = (temp_buffer[index*3 + 2] >> 3); // build up 16 bit color word USHORT color = _RGB16BIT(red,green,blue); // write color to buffer ((USHORT *)bitmap->buffer)[index] = color; } // end for index // finally write out the correct number of bits bitmap->bitmapinfoheader.biBitCount=16; } // end if#if 0// write the file info out printf("\nfilename:%s \nsize=%d \nwidth=%d \nheight=%d \nbitsperpixel=%d \ncolors=%d \nimpcolors=%d", filename, bitmap->bitmapinfoheader.biSizeImage, bitmap->bitmapinfoheader.biWidth, bitmap->bitmapinfoheader.biHeight, bitmap->bitmapinfoheader.biBitCount, bitmap->bitmapinfoheader.biClrUsed, bitmap->bitmapinfoheader.biClrImportant);#endif// close the file_lclose(file_handle);// flip the bitmapFlip_Bitmap(bitmap->buffer, bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/8), bitmap->bitmapinfoheader.biHeight);// return successreturn(1);} // end Load_Bitmap_File
Please help me! I''ve been having this problem for 2 weeks already, and I can''t fix it!
Thanks in advance.
still have graphics problems
Hi,
I still have major graphics problems. Below I have posted all of my comments from the XGames3D forum, wehere no one has been able to help me yet.
Hi,
I''ve developed a very crude tile based scrolling graphics engine using the GPDumb engine from WGPFD.
However, I''m having problems with the graphics for my tiles. The bottom half of each tile is either showing the negative values of the colours, or sometimes it shows a bit of a different image loaded into my program (using BOBs). The other BOB works perfectly. I think that this may have to do with memory allocation or something like that... Anyone have any ideas?
Hmmm, that''s interesting.
I discovered something very strange:
I tried running a different game I was working on, and instead of displaying my image normally (128*128 with normal colors), I got a 32*32 image which was half the tile I am using and half part of the sprite I''m using (this sprite is what I get now for the bottom half of my tile). The funny thing is that these programs aren''t in the same directory, and neither are the images! Some other apps using bitmaps work fine.
I don''t really understand why only the tiles get cut up. My 8 bit sprite bitmap loads perfectly, and it''s loaded with the same procedure. I always use the function provided by Andrew in WGPFD, and it''s always worked.
I understand what you say, but I don''t know what I can do, because if th memory would be allocated for 16Bit images, then none of the images should have worked.
Thanks for your help.
I figured out now that if I load a new bitmap into the program, it doesn''t display the image it''s supposed to, but rather part of the messed up tile. Why? Why? Why???
Here''s the code for bitmap file loading:
--------------------Help Needed!Turn-based 20th century strategy wargameTitle still to be determined
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement