int Scan_Image_Bitmap(BITMAP_FILE_PTR bitmap, // bitmap file to scan image data from
LPDIRECTDRAWSURFACE4 lpdds, // surface to hold data
int cx, int cy) // cell to scan image from
{
// this function extracts a bitmap out of a bitmap file
UCHAR *source_ptr, // working pointers
*dest_ptr;
DDSURFACEDESC2 ddsd; // direct draw surface description
// get the addr to destination surface memory
// set size of the structure
ddsd.dwSize = sizeof(ddsd);
// lock the display surface
lpdds->Lock(NULL,
&ddsd,
DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL);
// compute position to start scanning bits from
cx = cx*(ddsd.dwWidth+1) + 1;
cy = cy*(ddsd.dwHeight+1) + 1;
gwidth = ddsd.dwWidth;
gheight = ddsd.dwHeight;
// extract bitmap data
source_ptr = bitmap->buffer + cy*bitmap->bitmapinfoheader.biWidth+cx;
// assign a pointer to the memory surface for manipulation
dest_ptr = (UCHAR *)ddsd.lpSurface;
// iterate thru each scanline and copy bitmap
for (int index_y=0; index_y < ddsd.dwHeight; index_y++)
{
// copy next line of data to destination
memcpy(dest_ptr, source_ptr, ddsd.dwWidth);
// advance pointers
dest_ptr += (ddsd.dwWidth);
source_ptr += bitmap->bitmapinfoheader.biWidth;
} // end for index_y
// unlock the surface
lpdds->Unlock(NULL);
// return success
return(1);
} // end Scan_Image_Bitmap
Sorry if I haven''t described the problem properly, but as I said, those who have TOTWPG should know what I mean. Thanks for any help .
Insomnia
TOWTPG - erm, buggy demos?
Hey all,
I''ve recently migrated from DOS to Win32 programming (mainly because djgpp doesn''t work anymore... grumble), and it''s all going fine. I''ve been bashing out a few functions to make my DirectX life easier, and today got on to getting a fully working bitmap loading system. I''ve been pretty much following Lamothe''s code, although adapting it in places and making functions to suit my needs. Loading the bitmap and unloading the bitmap is all fine, as is creating new surfaces. The problem comes with copying a bitmap to a LPDIRECTDRAW7 surface. The resulting surface comes out mangled, to say the least. Not a very technical description, but it''s the best I can do . I''m working with 8bit bitmaps here, by the way. It''s not that i''m implementing the functions wrong, because Lamothe''s demo7_13.exe, in which he uses the function to scan a bitmap into three surfaces has the same problem... the guy''s own bloody demos don''t even work properly! Anyway, the long and short of it is, i''m stuck.
I''ll post the code from his version, although I find it rather hard to read with his comments in odd places. I''ve no idea why it doesn''t work, but then i''ve never done anything with graphics before (used allegro in the old days, ya see ). I''m guessing those who have TOTWPG have run into this problem before, and I guess you''ll have solved it too . Here''s his function:
Insomnia
February 12, 2001 01:04 PM
I have not had any problems with Lamothe''s code. Are you sure it is not your code. He uses dx6.1, maybe it has something to do with that.
I think this has been covered on the message board recently, try searching. If I remember correcly changing all ddsd.dwWidth to ddsd.dwPitch fixed it.
Micah
Micah
Anon Poster: Nope, it wasn''t because of my code. That''s why I posted his funciton, because HIS demo suffered the same problem.
MicahJon: Thankyou . It was a case of changing the dwWidth to lPitch after all. I suppose I should have figured that one out... thanks though .
Cheers all !
Insomnia
MicahJon: Thankyou . It was a case of changing the dwWidth to lPitch after all. I suppose I should have figured that one out... thanks though .
Cheers all !
Insomnia
Insomnia
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement