Jump to content

ABGR order BMP files lose alpha channel


Recommended Posts

I'm writing a BMP file from my app and trying to open it in .Net (4.2.13). I'm using the same DIB header format as is written by .Net (BITMAPV5HEADER). .Net specifies the RGBA channel masks in the header as R = 0x00ff000, G = 0x0000ff00, B = 0x000000ff, A = 0xff000000. When I write these masks to my header, .Net reads the file correctly, but my pixel data is in a different order, the red and blue colors are swapped. But the alpha channel is correct. If I change the header mask to get the correct color order [R = 0x0000000ff, B = 0x00ff0000], the colors come in the correctly, but the alpha channel data is ignored and all pixels have alpha 255. I can read my correct order BMP file into InkScape and it works fine, with the alpha channel correct. So this seems to be a .Net bug. I'm using all the other settings exactly as written by .Net, so DIB header bV5Compression is 3 (BI_BITFIELDS). If I hand edit a BMP file written by .Net to just swap the red and blue masks the same thing happens. When I open the edited BMP file in .Net, the alpha channel data is ignored and all texels have alpha = 255.

Link to comment
Share on other sites

So, just to correct some terminology: You're trying to work with BMP's that use RGBA order, but not having success unless things are done in BGRA order.

 

Have you thought about just using BGRA? Is there a specific reason you're doing RGBA? I just need some more context on your scenario.

 

Paint.NET uses WIC for reading and writing .BMPs, it's not reading and parsing the header directly. I suspect that RGBA order .BMPs will just have a lot of friction in the Windows ecosystem despite being correct as-per the BMP spec. 

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

My image is set up ready to create a Texture in OpenGL, and that needs RGBA order. To write the BMP file in BGRA order I would have to swizzle all the data. Not a big deal, but it seemed like it shouldn't be necessary as the DIB header supports a quite generic setup using the alpha masks. I guess WIC doesn't support the format generally. Seems odd that it reads the colors ok, but just ignores the alpha channel with RGBA and not in BGRA. Thanks anyway. I'll have to just swizzle the data.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...