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

Converting Bitmaps

This topic is 6118 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

This bitmap converting stuff is really perplexing me. I''m trying to convert a 24-bit bitmap buffer to a 32-bit bitmap buffer, but the output is horribly distorted. Here''s the code I have so far:

CImage::Convert24To32 (	UCHAR* uchBuffer_,
						UINT* uiBuffer_,
						const unsigned int c_uiWidth_,
						const unsigned int c_uiHeight_)
	// temporary colour holders, speed things up and make

	// the code more readable

	UCHAR	uchBlue,

	// convert each pixel in the buffer to 16-bit

	for (unsigned int y = 0; y < c_uiHeight_; y++)
		for (unsigned int x = 0; x < c_uiWidth_; x ++)
			// as always, the colours are stored backwards.

			// extract them

			uchBlue		= uchBuffer_[3*(x + y * c_uiWidth_)];

			uchGreen	= uchBuffer_[3*(x + y * c_uiWidth_) + 1];

			uchRed		= uchBuffer_[3*(x + y * c_uiWidth_) + 2];

			// construct the 32-bit value at the correct

			// address in the 32-bit buffer

			uiBuffer_[(x + y * c_uiWidth_)] = (UINT)RGB_32(0, uchRed, uchGreen, uchBlue);

Obviously un-optimised. Note that I am trying to convert bitmap buffers here, not video buffers (essentially the same except for video pitch). I copy the resulting buffer to the display using tested functions, so that''s not the problem. I don''t want to use the Windows utility functions, because then you don''t learn anything! Thanks for your help. The_Minister 1C3-D3M0N Interactive

Share this post

Link to post
Share on other sites
Without reading your code my first guess would be that you forgot that every line in a bitmap is dword aligned...

"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album

Share this post

Link to post
Share on other sites
The bitmap I am testing is 128 by 128... widely used multiples of 8, 16 and 32. But that would only make a difference once copied to the display and is a requirement of DirectX, not of bitmaps. It should still display something that remotely resembles the initial picture.

Please take a closer look at my code. I''ve been trying to solve this since the beginning of the month and I''m no closer.

1C3-D3M0N Interactive

Share this post

Link to post
Share on other sites