16- to 24-bit conversion
Hello,
I''m trying to hone my DirectDraw skills. I guess I''m not trying hard enough Can anyone lend a hand in converting the following code (16-bit) to support 24-bit mode?
USHORT *srcPtr, *destPtr; // Working pointers
// Extract bitmap data
srcPtr = (USHORT *)bitmap->buffer + cy * bitmap->bitmapInfoHeader.biWidth + cx;
// Assign a pointer to the memory surface for manipulation
destPtr = (USHORT *)ddsd.lpSurface;
int bytesPerLine = (sprite->width + sprite->widthFill) * 2;
// 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 += (sprite->width + sprite->widthFill);
srcPtr += bitmap->bitmapInfoHeader.biWidth;
}
Thanks a ton guys!
Silly boy :D
Billy
BillyB@mrsnj.com -> if you have any questions.
ps. It appeared your code was incorrect for even 16-bit images... maybe i''m just missing something :D
USHORT *srcPtr, *destPtr;char BytesPerPixel = bitmap->bitmapInfoHeader.biBitCount>>3; //I think that''s it''s name, other wise change it to whatever bitsperpixel is.//Extract bitmap datasrcPtr = (USHORT *)bitmap->buffer + cy*bitmap->bitmapInfoHeader.biWidth + cx;//Should this be biWidth*2 and cx*2 if it''s 16 bit?//If so, just use biWidth*BytesPerPixel and cx*BytesPerPixeldstPtr= (USHORT *)ddsd.lpSurface;int bytesPerLine = (sprite->width + sprite->widthFill)*BytesPerPixel; //Bytes per pixel...for (int indexY = 0; indexY < sprite->height; ++indexY){ memcpy(destPtr, srcPtr, bytesPerLine);}destPtr += (sprite->width + sprite->widthFill);//Should this be *2? If so, change to *BytesPerPixelsrcPtr += bitmap->bitmapInfoHeader.biWidth;//Same with this? Should it have been *2? chante to *BytesPerPixel if so.
Billy
BillyB@mrsnj.com -> if you have any questions.
ps. It appeared your code was incorrect for even 16-bit images... maybe i''m just missing something :D
Thanks for your quick reply Billy-
This is what I changed my code to:
USHORT *srcPtr, *destPtr; // Working pointers
// Extract bitmap data
srcPtr = (USHORT *)bitmap->buffer + cy * bitmap->bitmapInfoHeader.biWidth + cx;
// Assign a pointer to the memory surface for manipulation
destPtr = (USHORT *)ddsd.lpSurface;
int bytesPerLine = (sprite->width + sprite->widthFill) * 24 >> 3;
// 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 += (sprite->width + sprite->widthFill);
srcPtr += bitmap->bitmapInfoHeader.biWidth;
}
But I still can''t get it to work. Did I miss something? I know for sure that the bitmap I''m loading is 24 bpp.
BTW- what did you see wrong with my 16-bit code?
Thanks again,
Jon
This is what I changed my code to:
USHORT *srcPtr, *destPtr; // Working pointers
// Extract bitmap data
srcPtr = (USHORT *)bitmap->buffer + cy * bitmap->bitmapInfoHeader.biWidth + cx;
// Assign a pointer to the memory surface for manipulation
destPtr = (USHORT *)ddsd.lpSurface;
int bytesPerLine = (sprite->width + sprite->widthFill) * 24 >> 3;
// 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 += (sprite->width + sprite->widthFill);
srcPtr += bitmap->bitmapInfoHeader.biWidth;
}
But I still can''t get it to work. Did I miss something? I know for sure that the bitmap I''m loading is 24 bpp.
BTW- what did you see wrong with my 16-bit code?
Thanks again,
Jon
OK, I think I''m starting to actually figure this out.
I read that in 24-bit mode, you must copy each color separately. I changed my code to the following, but I don''t know how to actually write the pixel (the destination would be destPtr + indexY * pitch + indexX * 3 + 0, I think):
--------------------------
// Assign a pointer to the memory surface for manipulations
UCHAR *destPtr = (UCHAR *)ddsd.lpSurface;
int pitch = bitmap->bitmapInfoHeader.biWidth * 3;
// Iterate through each scanline and copy bitmap
for (int indexY = 0; indexY < sprite->height; indexY++)
{
for (int indexX = 0; indexX < bitmap->bitmapInfoHeader.biWidth; indexX++)
{
// Get BGR values
UCHAR *blue = bitmap->buffer + indexY * pitch + indexX * 3 + 0,
*green = bitmap->buffer + indexY * pitch + indexX * 3 + 1,
*red = bitmap->buffer + indexY * pitch + indexX * 3 + 2;
// Write the pixel
}
}
---------------------
Does anyone know how to write the pixel?
Thanks a million!
I read that in 24-bit mode, you must copy each color separately. I changed my code to the following, but I don''t know how to actually write the pixel (the destination would be destPtr + indexY * pitch + indexX * 3 + 0, I think):
--------------------------
// Assign a pointer to the memory surface for manipulations
UCHAR *destPtr = (UCHAR *)ddsd.lpSurface;
int pitch = bitmap->bitmapInfoHeader.biWidth * 3;
// Iterate through each scanline and copy bitmap
for (int indexY = 0; indexY < sprite->height; indexY++)
{
for (int indexX = 0; indexX < bitmap->bitmapInfoHeader.biWidth; indexX++)
{
// Get BGR values
UCHAR *blue = bitmap->buffer + indexY * pitch + indexX * 3 + 0,
*green = bitmap->buffer + indexY * pitch + indexX * 3 + 1,
*red = bitmap->buffer + indexY * pitch + indexX * 3 + 2;
// Write the pixel
}
}
---------------------
Does anyone know how to write the pixel?
Thanks a million!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement