Self-written bitmap ignores alpha value if it is 0

0

I am writing a program that outputs a list of RGBA values to a bitmap image. It seems to work fine, except when alpha is 0. When alpha is 0, alpha seems to be ignored instead of transparent. When alpha is 0x01 though, everything seems to be fine.

Currently the file has the following format:

  • BMP header [14 bytes]
  • BITMAPV5HEADER [124 bytes]
  • image data [262 144 bytes]

The BMP header has the following values:

  • magic number: "BM" [2 bytes]
  • file size: 262282 [4 bytes]
  • padding: 0 [4 bytes]
  • data-offset: 138 [4 bytes]

The BITMAPV5HEADER has the following values:

  • size of header: 124 [4 bytes]
  • width: 256 [4 bytes]
  • height: 256 [4 bytes]
  • number of colour planes: 1 [2 bytes]
  • number of bits per pixel: 32 [2 bytes]
  • compression method: 3 (BI_BITFIELDS) [4 bytes]
  • size of image data: 0 [4 bytes] (0 should be allowed, but putting 256 * 256 * 4 has exact same result.)
  • Horizontal resolution: 4724 [4 bytes] (I'll admit I have no idea what this is and copied it from a different BMP file.)
  • Vertical resolution: 4724 [4 bytes] (same as above)
  • Number of colours in pallete: 0 [4 bytes] (0 = all)
  • Number of important colours: 0 [4 bytes] (0 = all)
  • redmask: 0x0000FF00 [4 bytes]
  • greenmask: 0x00FF0000 [4 bytes]
  • bluemask: 0xFF000000 [4 bytes]
  • alphamask: 0x000000FF [4 bytes]
  • colour space: 'Win ' [4 bytes] ('sRGB' gives same result.)
  • padding: 0 [9 * 4 bytes] (This data should be meaningless in colourspace sRGB/Win)
  • Toned response curve for red: 0 [4 bytes] (This data should be meaningless in colourspace sRGB/Win)
  • Toned response curve for green: 0 [4 bytes] (This data should be meaningless in colourspace sRGB/Win)
  • Toned response curve for blue: 0 [4 bytes] (This data should be meaningless in colourspace sRGB/Win)
  • Embedded profile data: 0 [3*4 bytes]

image data has the following values is just 256 * 256 times 0x31BC5B00 (RRGGBBAA) written in file as 0x005BBC31 (AABBGGRR).

bmp
asked on Stack Overflow Nov 28, 2020 by AceCrow

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0