This topic is 5050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Alright, I have a loadBMP function, but it doesn't actually load the BMP for some reason. the function and everything is contained in a header, which is included in Unit1.cpp this is how I use it...
...
BITMAP_FILE bitmap;
....

I trace through, and it errors out at the line indicated
if(bitmap->bitmapinfoheader.biBitCount == 8 || bitmap->bitmapinfoheader.biBitCount == 16 ||
{
//delete the alst image if there was one
if(bitmap->buffer)
delete bitmap->buffer;

//allocate the memory for the image

{
//close the file
_lclose(file_handle);

//return error
return(0);
}

}
else
{
//WOW! Serious error!
return(0);<<<-------------- THIS LINE <<----------
}


I check the value of biSizeImage and its 24.....So why doesn't that fit the clause in the if statment? All that happens is that I get the message saying It wasn't loaded(at the indicated line). Any ideas? I've attached the header file below Many thanks
//this was taken from André LaMoth's "Tricks of the windows game programming gurus"
//p.346  2nd Revision

//NOTE:
//assumes your not stupid and arn't asking it to load a non-BMP file. the code is commented out for that

#include "Unit1.h"
#define BITMAP_ID            0x4D42 // universal id for a bitmap
#define MAX_COLORS_PALETTE   256

//////container structure for bitmap files///////////////////////////////////////
typedef struct BITMAP_FILE_TAG
{
PALETTEENTRY     palette[256];      // we will store the palette here
UCHAR            *buffer;           // this is a pointer to the data

} BITMAP_FILE, *BITMAP_FILE_PTR;

// PROTOTYPES  //////////////////////////////////////////////

int Flip_Bitmap(UCHAR *image, int bytes_per_line, int height);

{
//this function opens a *.BMP file

int file_handle; //the file handle
int i; //looping var

UCHAR *temp_buffer = NULL; //used to convert 24 bit images to 16bit
OFSTRUCT file_data; // file data information

//open file if it exists
return(0); //Opening failed

/*    //TEST IF THIS IS A BITMAP FILE
{
//this definatly isn't a bitmap, so lets unload 'er
_lclose(file_handle);

//return error
return(0);
}   */

//NOW LOAD THE COLOR PALETTE IF THERE IS ONE
{

//Now set all the flags in the palette correctly and fix the reversed BGR RGBQUAD
for(i = 0; i < MAX_COLORS_PALETTE; i++)
{
int temp_color = bitmap->palette.peRed;
bitmap->palette.peRed = bitmap->palette.peBlue;
bitmap->palette.peBlue = temp_color;

bitmap->palette.peFlags = PC_NOCOLLAPSE;
}
}

//image data

// 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 image

{
//delete the alst image if there was one
if(bitmap->buffer)
delete bitmap->buffer;

//allocate the memory for the image

{
//close the file
_lclose(file_handle);

//return error
return(0);
}

}
else
{
//WOW! Serious error!
return(0);
}

//close the file
_lclose(file_handle);

//flip the bitmap
Flip_Bitmap(bitmap->buffer,

// return success
return(1);
}

{
// this function releases all memory associated with "bitmap"
if (bitmap->buffer)
{
// release memory
delete (bitmap->buffer);

// reset pointer
bitmap->buffer = NULL;

} // end if

// return success
return(1);

}

//// FLIP ///////////////////////////////////////////////////////

int Flip_Bitmap(UCHAR *image, int bytes_per_line, int height)
{
// this function is used to flip bottom-up .BMP images

UCHAR *buffer; // used to perform the image processing
int index;     // looping index

// allocate the temporary buffer
if (!(buffer = (UCHAR *)malloc(bytes_per_line*height)))
return(0);

// copy image to work area
memcpy(buffer,image,bytes_per_line*height);

// flip vertically
for (index=0; index < height; index++)
memcpy(&#8465;[((height-1) - index)*bytes_per_line], &buffer[index*bytes_per_line], bytes_per_line);

// release the memory
free(buffer);

// return success
return(1);

}


[Edited by - Coder on September 19, 2004 11:49:35 PM]

##### Share on other sites
Yea, I remember having problems with that function, too...

Are you using DirectDraw7, or just that loader function? If you are still using DD7, you may want to consider upgrading to DX9. Even though DirectDraw has been deprecated in DirectX9, D3DX still has all the functionality that you need for 2D apps (to draw a texture to screen, just use ID3DXSprite). It will take some effort on your part to move up, but the benefits are well worth it.

If you upgrade, you can simply use D3DXCreateTextureFromFile() to load all of your images - .bmp, .dds, .hdr, .jpg, .png, and .tga (just to name a few).

##### Share on other sites
Well since I'm using Lamoth's book, I would kinda like to keep it simple for my first DX app, then move up to 3D when I read his 3D book. =) Are there any tutorials about what you suggested? Also, do you have any idea whats wrong with that function? because it *should* work, but it doesn't....:(

thanks

Ya, i'm using DirectDraw 7 interfaces atm. 32-bit. Using that function to load the file, then puting it on a surface, the blting it to the backbuffer

##### Share on other sites
I guess I just really don't see the point in spending a lot of time learning old technology just to learn it, considering you aren't going to use it again. Also, Lamoth's 3D book teaches you a lot of stuff that is cool to know, but you don't *really* need to know it. Direct3D already handles a lot, so you don't need to spend your time re-inventing the wheel.

I understand where you're coming from, because Lamoth's 3D book does go over a lot of graphics theory, which you do need to know (you will definetly struggle without it). However, you don't need to read a 1000 page book on DirectDraw7 and a 1500 page book on software renderering to grasp the concept of a matrix [wink].

If you want to learn 3D, I'd say just go for it. Download the new SDK and check out some of the great tutorial sites listed here (DrunkenHyena and Andy Pike are especially good).

If you want a really good book to help you out on the graphics theory side, I recommend Real-Time Rendering. It rocks. Also, MathWorld is great for that kind of stuff.

##### Share on other sites

and

Then check the following:

- The image data starts at BITMAPFILEINFO::bfOffBits, using 'EOF - BITMAPINFOHEADER::biSizeImage' is unreliable.
- Check your image compression is BI_RGB first, and that your bitmaps are uncompressed and sensible colour depths.
- BITMAPINFOHEADER might be susceptible to compiler packing & realignment; try reading it in element-wise or make your own structure.
- Bitmap rows are padded if the width isn't a multiple of 4, you'll have to read them in line-by line if this is the case.
- Bitmaps are stored upside-down.

Jans.

##### Share on other sites
Quote:
 Original post by circlesoftIf you want to learn 3D, I'd say just go for it.

aye, I *do* want to learn 3D, but I also want to learn 2D, and I already have the book, so I might as well finish 'er!

Alright, can you supply a method? ;)

But my code *should* work tho. I read the stuff on MSDN, and everything *looks* in order....

I also have a flip function, so that if the BMP is upsidedown, it doesn't matter...

Sigma

##### Share on other sites
Opps....that was me, sorry for the confusion

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002051
×