Archived

This topic is now archived and is closed to further replies.

monkey-poop

Copy Lines to Surface (32-bit)

Recommended Posts

Hello, I''m trying to copy lines from a 24-bit bitmap into a 32-bit surface. I made the following code to perform the conversion, but it always fails on the memcpy(). Does anyone see what I did wrong? UINT *srcPtr, *destPtr; // Working pointers // The pitch of the destination surface UINT nPitch = ddsd.lPitch >> 2; // Extract bitmap data srcPtr = (UINT *)bitmap->buffer + cx + cy * bitmap->bitmapInfoHeader.biWidth; // Assign a pointer to the memory surface for manipulation destPtr = (UINT *)ddsd.lpSurface; int bytesPerLine = (sprite->width + sprite->widthFill) * 4; // Iterate through each scanline and copy bitmap for (int indexY = 0; indexY < sprite->height; indexY++) { // Copy next line of data to destination memcpy (destPtr, srcPtr, bytesPerLine); // Advance pointers destPtr += nPitch; //(sprite->width + sprite->widthFill); srcPtr += bitmap->bitmapInfoHeader.biWidth; } Thanks a million!

Share this post


Link to post
Share on other sites
You''re exceeding the bounds of your source memory by giving the memcpy the size of the destination memory block which is bigger than the size of the source memory block.
You can''t do the copy on a line per line basis. You have to do it on a pixel by pixel basis.

Share this post


Link to post
Share on other sites
They may have the same size in pixels but not in byte. If you have a 24BPP bitmap and a 32BPP surface the latter one needs more bytes to save an image with the same dimensions and the pixels start at different offsets:
24BPP:
Pixel 0, Offset 0; Pixel 1, Offset 3;...
32BPP:
Pixel 0: Offset 0; Pixel 1, Offset 4;...

Do you know know why you have to copy the image pixel by pixel?

Share this post


Link to post
Share on other sites
I understand that 24-bit has three bytes per pixel and 32-bit has four. But I successfully made a line-by-line copy using similar code to copy a 24-bit bitmap to a 16-bit surface. How come the 16-bit version works but I can''t do the same thing in 32-bit mode? Would I have to switch the parameters the memcpy()?

Thanks...

Share this post


Link to post
Share on other sites