Jump to content
  • Advertisement

Archived

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

monkey-poop

16- to 24-bit conversion

This topic is 6068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Silly boy :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 data

srcPtr = (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*BytesPerPixel


dstPtr= (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 *BytesPerPixel

srcPtr += 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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!