Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Finding bits of Bitmap

  1. #1
    Guest

    Finding bits of Bitmap

    Hi,

    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?

    Cheers

    Alkon

  2. #2
    Junior Member Newbie
    Join Date
    May 2003
    Location
    Coimbatore,TN,India
    Posts
    5

    Re: Finding bits of Bitmap

    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.
    balchandran

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    England
    Posts
    9

    Re: Finding bits of Bitmap

    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?

    Allen

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    England
    Posts
    9

    Re: Finding bits of Bitmap

    erm...still trying...could you send the code?

    How do I set up the INFOHEADER? Looking @ MSDN there are a few versions

    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

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    England
    Posts
    9

    Re: Finding bits of Bitmap

    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:

    Cheers

  6. #6
    Junior Member Newbie
    Join Date
    May 2003
    Location
    Coimbatore,TN,India
    Posts
    5

    Re: Finding bits of Bitmap

    biSizeImage =
    ((((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)
    balchandran

  7. #7
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    England
    Posts
    9

    Re: Finding bits of Bitmap

    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?

    Cheers

  8. #8
    Junior Member Newbie
    Join Date
    May 2003
    Location
    Coimbatore,TN,India
    Posts
    5

    Re: Finding bits of Bitmap

    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
    balchandran

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •