Skip to main content
gamedev.net
🔒 Locked

bitmap-loadfunction fails

Started by Merwin van Dijk Apr 11, 2002 at 9:18 AM 1 replies 800+ views
Original Post
Merwin van Dijk
Merwin van Dijk
I've made a class named CBmp which has a member-function that loads the bmp-image from the hard disk to an offscreen-surface. The function can load a part of a .bmp -image. This functions has 5 parameters. One to give the name of the file, Two to parameters to give coordinates of the left bottom of the picture and two paramters for the picture width and height. Everything in my fucntion succeeds until my functions tries to copy the actually image. Here you can see a part of the function: prototype: BOOL CBmp::Load(char * filename, int x, int y, int t_width, int t_height) part that fails to copy the image to an offscreen surface: if(ok){ // try to move pointer to the left bottom of the image SetFilePointer(hFile, (y-1)*width_mul4+x, NULL, FILE_CURRENT); dest=(BYTE *)ddsd.lpSurface; ok=image->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) == DD_OK; for(int i=0; i < height && ok; i++){ ok=ok && ReadFile(hFile, dest, width, &nr_bytes_read, NULL)!=0; // next row dest+=ddsd.lPitch; // skip the number of bytes that aren't part of the part that must be load SetFilePointer(hFile, skip_bytes, NULL, FILE_CURRENT); } image->Unlock(NULL); } I think an explanation of some var's might be helpful: width_mul4 = an integer with get's the value of the next multiple from 4 of the width of the image; dest = destination (the offscreen surface); image = pointer to an IDrectDrawSurface4 skip_bytes = width_mul4 - width, number of unimportant bytes of the image any help would be welcome... Merwin [edited by - Merwin van Dijk on April 11, 2002 12:36:08 PM] [edited by - Merwin van Dijk on April 11, 2002 12:36:53 PM] [edited by - Merwin van Dijk on April 11, 2002 1:14:25 PM] [edited by - Merwin van Dijk on April 11, 2002 1:15:43 PM] [edited by - Merwin van Dijk on April 11, 2002 1:36:15 PM] [edited by - Merwin van Dijk on April 11, 2002 1:37:03 PM] [edited by - Merwin van Dijk on April 11, 2002 6:10:14 PM]
Zeke
Zeke
Firstly is there a reason you are setting the file pointer to the end of the image (well end minus a row)? I dont think it matters but just out of curiosity why are you doing that?

Secondly i dont understand the (y-1)*width_mul4+x part. To get the pointer to the position you are after would be:

if x is the width
Currentpos+(x*bpp)*y-1;

or if x is the width in bytes:
Currentpos+(x*bpp)*y-1;

I think so anyway.

Another thing is where is the code that actually copies the data onto the surface?
Shouldnt there be a

memcpy(dest, pbitmapdata, LengthOfRow);
pbitmapdata-=LengthOfRow;

in there somewhere?


or is this the part you omitted.

Im not too familiar anymore with ddraw but if you think it might help I can show you how to copy a bitmap to a different chink of memory (if you see what I mean) cos that is all surfaces are right? a linear chunk of memory?


Edit:
Having read what I just wrote im not sure i have been of any use whatsoever but in case you think I might have come close please ask me to clairfy my ramblings


[edited by - Zeke on April 11, 2002 1:06:49 PM]
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Merwin van Dijk
Merwin van Dijk
Fist of all, I've made a few small changes in my first post. Second I think it will help a lot if I give some more explanation of the source code.

(y-1)*width_mul4+x:
The load function can load a part of .bmp-file. The x and y -coordinates together with the width and height determine the part of the image that must be load. After the fileheader, infoheader and the palette has been loaded, the first byte is the most left and low pixel of the image (at least, this is what I think, can someone confirm this?). Thus the part of the image below y can be skipped. So (y-1)*width_mul4+x determine's where exactly is the first byte of the most left pixel on the bottom.

ReadFile(hFile, dest, width, &nr_bytes_read, NULL)!=0; :
Maybe I'm wrong, but I think that the ReadFile function copies the data from the hard disk to the surface; dest is a pointer to the surface and hFile a handle to the bmp-file.

If someone can determine of the above assumption's are true or false it may help a lot.

PS: I think my english in this reply is far from perfect but I hope that at least the intention is clear.





[edited by - Merwin van Dijk on April 11, 2002 1:53:00 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.