Sign in to follow this  
m4ster

24BPP Bitmap-16BPP Surface SOLVED

Recommended Posts

Hi, At the moment I'm trying to load a 24bpp bitmap and convert it to a 16bpp Image(5R6G5B). But every time I try to start my programm windows gives me a critical error. Plz help my guys, otherwise I'm going to die... (xD) Here's the convert part...
for(int cY=0; cY < ddsd.dwHeight; cY++)
{
	for(int cX=0; cX < ddsd.dwWidth; cX++)
		{
		BYTE red   = pbyImage[(cY*nBMPPitch+cX)*3+0],
		     green = pbyImage[(cY*nBMPPitch+cX)*3+1],
		     blue  = pbyImage[(cY*nBMPPitch+cX)*3+2];

		pwSurface[cY*ddsd.lPitch/2+cX] = _RGB16BIT565(red,green,blue);
	}
}



And here is the macro definition
#define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 5) + ((b & 31) << 11))



[Edited by - m4ster on June 14, 2006 12:52:08 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try:

BYTE red = pbyImage[cY*nBMPPitch+cX*3+0],
green = pbyImage[cY*nBMPPitch+cX*3+1],
blue = pbyImage[cY*nBMPPitch+cX*3+2];



If that doesn't work, try running in a debugger and provide us with more info...

Share this post


Link to post
Share on other sites
Also
*((Uint16*)(pwSurface + (cY*ddsd.lPitch)+(cX*2))) = _RGB16BIT565(red,green,blue);
I am assuming:
ddsd.lPitch is the pitch of the 16bit surface
pwSurface is declared as an 8bit pointer

Share this post


Link to post
Share on other sites
Hey,

Thanks, Jack Sotac answer helped me a lot...

I made the mistake not to devide the Pitch by 2

Yours sinserelly
Damien K.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this