Cell extraction
Hi all
This is my first posting to this message board, so be gentle!
I have some artwork that is stored in a 640X400 .bmp file. I have it templated at 72X72, i.e., the artwork is in cells that are 72X72 pixels. I am unable to extract the artwork using the following function. In order to get the bitmap stored in cell 0,0 I seem to have to give the coordinates 1,1.
If someone could tell me what is going wrong, I am a newbie to game programming, I would appreciate it.
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.lPitch);
source_ptr += bitmap->bitmapinfoheader.biWidth;
} // end for index_y
// unlock the surface
lpdds->Unlock(NULL);
// return success
return(1);
} // end Scan_Image_Bitmap
Thanks,
Don Cathcart
Donald Cathcart
Donald Cathcart
Ok, I don''t have a complete answer, but here are some general hints:
If your bitmap is 640x400 (or anything else for that matter), and your artwork is 72x72 (or anything else), then you can get the index in the bitmap buffer using cx * 72 + (cy * 640 * 72), provided that the bitmap buffer is top to bottom. Don''t forget to check if cx and cy are in the valid range (in this example, cx < 8 (=640\72), and cy < 5 (=400\72)).
If you load a bitmap from file, you have to keep in mind that bitmaps are usually bottom up, which means that the bottom scan line comes first in the buffer, and then goes to the top of the bitmap. Pixels in a scanline are left to right.
I hope this can get you in the right direction.
Erik
If your bitmap is 640x400 (or anything else for that matter), and your artwork is 72x72 (or anything else), then you can get the index in the bitmap buffer using cx * 72 + (cy * 640 * 72), provided that the bitmap buffer is top to bottom. Don''t forget to check if cx and cy are in the valid range (in this example, cx < 8 (=640\72), and cy < 5 (=400\72)).
If you load a bitmap from file, you have to keep in mind that bitmaps are usually bottom up, which means that the bottom scan line comes first in the buffer, and then goes to the top of the bitmap. Pixels in a scanline are left to right.
I hope this can get you in the right direction.
Erik
April 05, 2000 04:04 PM
You need to make sure that you are using the correct source and dest
pitches. We can''t tell from your code if your bitmap is, for example,
24-bit, and your surface is 16-bit, or anything.
pitches. We can''t tell from your code if your bitmap is, for example,
24-bit, and your surface is 16-bit, or anything.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement