8
votes

I'm currently doing some image manipulation stuff in C# and I'm confused about the Bgr32 Pixel format. The following descriptions are from microsoft msdn: http://msdn.microsoft.com/en-us/library/system.windows.media.pixelformats(v=vs.110).aspx

  1. Bgr24 is a sRGB format with 24 bits per pixel (BPP). Each color channel (blue, green, and red) is allocated 8 bits per pixel (BPP). ✓
  2. Bgra32 is a sRGB format with 32 bits per pixel (BPP). Each channel (blue, green, red, and alpha) is allocated 8 bits per pixel (BPP). ✓
  3. Bgr32 is a sRGB format with 32 bits per pixel (BPP). Each color channel (blue, green, and red) is allocated 8 bits per pixel (BPP). -> (⊙.☉)? WTF

3 channels each 8 bits -> 3x8bit = 24bit

What is/are the last channel/the remaining 8bits for?

Thanks in advance

1
I've added a link that shows you the benefit of going PGBRA, it's not obvious at first but once you grasp the concept you will probably never go back :Daybe

1 Answers

6
votes

It is not used but having a color represented as an integer has practical reasons whether for reading or writing, it is aligned.

In the end it represents a 24 bit color and the closest type to represent it being a 32 bit integer. It would be a little weird to represent such color with two integers: a 16 bit (short) integer and an 8 bit (byte) integer.

Now 25% of space is not used, which is a waste ultimately.

Compared to RGB24 it makes more sense to use it in the way that a color is represented by one integer where as on the former it is necessarily 3 bytes. Obviously you have to unpack it to get the different components but these operations are really cheap today.

Personally I would use RGB24 only if there are memory constraints or any other type of constraint such as hardware for instance. Anything else I'd go RGBA and even PBGRA since it has many benefits such as transparency and spares extra calculations during blitting operations and better blending for transparent contours.

For the benefits such representation can offer to you I'd suggest you to take a look at this question : Pre-multiplied alpha compositing (take a look at the results I've posted)