• ### Announcements

#### Archived

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

# Converting Bitmaps

## 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:
  void 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, uchGreen, uchRed; // 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 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 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.

The_Minister
1C3-D3M0N Interactive

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627636
• Total Posts
2978331

• 10
• 12
• 22
• 13
• 33