View Full Version : Finding bits of Bitmap
I am trying to find the bits of a bit map so I can mess with the Alpha values.
I have seen this done using oleLoadPicturePath - Nehe style but I do not want to use this as it seems to be overkill when LoadImage will do...is there a simplier way to do it i.e. using GetDIBits?
05-15-2003, 02:38 AM
GetDIBits(...) will work fine.
For storing alpha values a 32 bit pixel format is needed. But GetDIBits(...) failed when I tested by setting 32 to the pixelbits member of the BITMAPINFOHEADER structure . Precise results were obtained
by setting 24 to the pixelbits member and then expanding to output byte array to
32 bit pixel format.
If you need any more help i can send the working code.
05-15-2003, 03:53 AM
That's probably why it isn't currently working then!
So I have to read in my BMP file, then call GetDIBits using a BITMAPINFO structure with a depth of 24bits and then add in the extra Alpha bits?
05-15-2003, 07:46 AM
erm...still trying...could you send the code?
How do I set up the INFOHEADER? Looking @ MSDN there are a few versions http://www.opengl.org/discussion_boards/ubb/smile.gif
Mine keeps giving me errors...I think it maybe to do with my buffer area - i.e. where the bits are stored after reading them.
Dunno though http://www.opengl.org/discussion_boards/ubb/smile.gif
05-15-2003, 08:11 AM
Ok got it now...went onto MSDN online and found some useful stuff on there...
can anyone explain what the hell is going on here though?
biSizeImage = ((((biWidth * biBitCount) + 31) &
~31) >> 3) * biHeight:
05-15-2003, 09:22 AM
((((biWidth * biBitCount) + 31) &
~31) >> 3) * biHeight:
The above mentioned statement is for calculating the imagesize in terms of bytes.
In terms of bytes the row length of bitmap must always be a multiple of four and to set this often extra padding bytes are added at the end of the row.
The row length with padding bytes is calculated as follows
((((biWidth * biBitCount) + 31) & ~31) >> 3)
05-15-2003, 02:14 PM
Ok, so I have my bytes...
As I understand it the whole bitmaps bits are in a DWORD array. Each "RGB" chunk can be retrieved by "casting" each element into a BYTE, thus giving 4 BYTES to each DWORD element in the array...I think...with it in the order BGRA instead of the standard RGBA.
Now when for a test I copy these values into another array and pass this to glTexImage2D and this works. So I though it would be cool to re-arrange the bits so they are RGBA by simply copying B -> temp and then R -> B and finally temp -> R, i.e. swap R and B via a temp variable...this don't work.
Also it seems that what I thought was the alpha BYTE...pun not intended...is not the case!
Could anyone explain how the BYTES are arranged? Or am I way off the mark here?
05-16-2003, 12:09 AM
The bitmap bits out of GetDIBits(...) is stored only in the BYTE array and not in a DWORD array. The values from the BYTE array can be easiy copied into the second BYTE array without any typecasing. Only the red and blue values have to be swapped
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.