Skip navigation
verpies
Currently Being Moderated

Invalid BMP Format with Alpha channel

Nov 15, 2010 5:25 PM

This post is directed to Adobe technical personnel and requires the knowledge of internal bitmap format structures.

CLAIM: Photoshop CS4 creates invalid file format when saving an image as  a Bitmap
(BMP) with Alpha Channels, in the advanced format A8 R8 G8 B8.

 

According to Microsoft documentation of the Bitmap (BMP) format, available at:

http://msdn.microsoft.com/en-us/library/dd183376%28VS.85%29.aspx

 

" If the biCompression member of the BITMAPINFOHEADER is BI_RGB, <...snip...> Each DWORD  in the bitmap array represents the relative intensities of blue, green,  and red, respectively, for a pixel. The high byte in each DWORD is not used..."

 

Yet, Photoshop CS4 saves Bitmaps with Alpha Channels in the advanced format A8 R8 G8 B8 in violation of this documentation.

 

Specifically, Photoshop CS4 writes:

1) BITMAPINFOHEADER of the size 0x28 bytes which is equal to sizeof(BITMAPINFOHEADER)

2) biCompression member of the BITMAPINFOHEADER is set to BI_RGB

3) The high byte in each DWORD of the pixel array is USED and contains the Alpha Channel values

4) There is no indication in the Bitmap headers of the presence of Alpha Channel data described in pt.3 above.

 

 

 

Proposed Solution:

1) Use BITMAPV4HEADER in lieu of BITMAPINFOHEADER because it contains a mandatory Alpha Channel bitmask.

    a) Alternatively use the proprietary Adobe header of the size 0x38 bytes, that Photoshop seems to be using in the wild.

2) Indicate the presence of the Alpha Channel by setting the bV4AlphaMask member of the BITMAPV4HEADER to an appropriate non-zero bitmask.

    a) Optionally indicate the presence of a valid bV4AlphaMask by setting the bV4V4Compression member, to BI_ALPHABITFIELDS

    b) Optionally set the bV4RedMask and bV4GreenMask and bV4BlueMask members to appropriate bitmasks

        and indicate this fact by setting the bV4V4Compression member to BI_BITFIELDS or to BI_ALPHABITFIELDS

 

NOTE: The Microsoft documentation, available at:

http://msdn.microsoft.com/en-us/library/dd183380%28VS.85%29.aspx

...states that:

"bV4AlphaMask - Color mask that specifies the alpha component of each pixel" irrespective of the value of bV4V4Compression member of the BITMAPV4HEADER.

The same is not true about the bV4RedMask and bV4GreenMask and bV4BlueMask members of the BITMAPV4HEADER, because these members are valid only when bV4V4Compression member is set to BI_BITFIELDS (or to BI_ALPHABITFIELDS in the wild).

Also, BITMAPV5HEADER can be used instead of BITMAPV4HEADER if advanced color profile needs to be embedded, but at the expense of increased file size.

 
Replies
  • Currently Being Moderated
    Nov 12, 2010 3:57 PM   in reply to verpies

    Have you talked to Microsoft about this?

    Microsoft requested the advanced formats, and verified the formats back when they were added (10 years ago, I've forgotten?).

     

    There is no "proprietary Adobe header" - everything we're writing is directly taken from the Microsoft documentation.

     

    Many other applications write BITMAPINFOHEADER, BI_RGB, and ARGB data.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2010 6:24 PM   in reply to verpies

    Again, there is no Adobe header, and no proprietary header involved (unless you consider Microsoft to be proprietary) -- everything we're writing came straight out of Microsoft's documentation.   Though I notice that you skipped the V2 and V3 headers.

     

    No, I'm not convinced, because I wrote the code in question using Microsoft documentation, at their request.

    And then Microsoft verified the results of our BMP files (all variations).

     

    You might need to do a little more searching, I know that Microsoft has simplified some of their BMP/BITMAPINFOHEADER documentation over the years - but the full documentation should still be available.

     

    We are using the BMP format correctly, according to the experts in the graphics and games groups at Microsoft.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2010 6:54 PM   in reply to Chris Cox

    Oh, and you might want to read http://en.wikipedia.org/wiki/BMP_file_format

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2010 8:48 PM   in reply to verpies

    From the Microsoft documentation (not sure if we changed the member names or not, but this is what is in my platform independent header):

     

    struct BITMAPV3INFOHEADER

    {

    uint32 biSize;

    int32 biWidth;

    int32 biHeight;

    uint16 biPlanes;

    uint16 biBitCount;

    uint32 biCompression;

    uint32 biSizeImage;

    uint32 biXPelsPerMeter;

    uint32 biYPelsPerMeter;

    uint32 biClrUsed;

    uint32 biClrImportant;

    /* new for V3 */

    uint32 biRedMask;

    uint32 biGreenMask;

    uint32 biBlueMask;

    uint32 biAlphaMask;

    };

    And Photoshop only writes 2 values for the size  (well, unless you could OS2 format): sizeof(BITMAPINFOHEADER) and sizeof(BITMAPV3INFOHEADER).

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2010 11:55 AM   in reply to verpies

    The V3 header WAS documented on MSDN and in Microsoft header files included with MSVC.    Microsoft does have a history of changing their documentation and sometimes losing details in the process.  I would not be surprised if this were another example.

     

    We found the exact same header used in BMP files from Microsoft, and in BMP files used in commercial games (yeah, I scavanged a bunch to make sure we could read them all).

     

    Again, Microsoft asked for these formats and tested our results before we shipped the software.  It's not like we're working outside of Microsoft's realm in any of this.

     

    Yes, some programs may only implement a subset of BMP support (heck, we don't even implement ALL the possible permutations).

    I'm not sure what you expect me to do about other applications not implementing parts of the BMP format that we do.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2010 11:59 AM   in reply to verpies

    The advanced BMP formats are game/3D oriented -- I wouldn't expect the simple image parsers from web browsers to display them.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2010 3:43 PM   in reply to verpies

    Admins can't insert any more HTML than you can.  There are limitations on the HTML accepted in the forum for formatting and security reasons.

     

    One more time: Photoshop's BMP implementation is working correctly as verified by Microsoft, and was written entirely using publicly available documentation from Microsoft.

     

    So far you have yet to demonstrate even a single bug, but have shown how you can accuse other developers based on your own lack of research.

    If you would like to ask questions and learn more, just ask.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2010 12:25 PM   in reply to verpies

    Yes, Photoshop implements more of the BMP spec. than some other applications.

    The advanced format support was requested by Microsoft to help game developers who use those advanced BMP options.

     

    You are not documenting incompatibilities -- but that Photoshop implements more than the other applications.  That is a given.

    Photoshop also implements many file formats that those other applications cannot read at all, and variants of other file formats that those applications cannot read as well.

    If you wanted to file a bug about that, wouldn't you file a bug with PowerPoint because it cannot read all valid BMP files, even though it is a Microsoft product?

     

     

    Yes, there are some ambiguities when reading a bitfields format BMP.  Photoshop tries to implement the bitfields reading as generally as possible, and that can lead to some empty alpha channel values depending on the bitfields options.  Image wise, the extra channel does no harm.  For round tripping purposes, the extra channel does no harm.  So, what is your point?

     

     

    Also, you seem to have transparency and alpha channels confused.  Alpha channels are any extra channel, and the term generally applies to channels that are not transparency/opacity.  Transparency is a specific meaning for a specific subset of possible alpha channels.

     

    And you might want to check the BMP documentation - it supports an extra channel, but assigns no meaning to that channel.  It is not transparency, and using it as transparency will cause problems with interoperability -- some apps use the channel for things other than transparency, and some games use it for other masks.

     

     

     

    You still seem to be approaching this all wrong.

    Instead of screaming BUG all the time, you should be asking questions, learning about the formats, learning about imaging and interoperability.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2010 5:25 PM   in reply to verpies

    Photoshop is a flagship graphics editor and I expect only perfection from it and adherence to current documentation.

    We adhere to standards and documentation.

    If another company loses part of their documentation, that does not change the standard or the fact that we are implementing what WAS documented.  Nor does that change the fact that we are reading and writing files that can be found elsewhere in the world (again, check the BMP files in some games).

    If Microsoft contacts us and gives a really good explanation for why we should no longer support the file format options that they previously asked us to support, and are used in the wild, then maybe we would reconsider.

     

    Photoshop is working reliably.  The fact that other programs are not able to read everything that Photoshop writes is not always a problem with Photoshop - it can mean (as in this case) that the other programs do not implement the full file format specification.   If you want another program to read the file format variants that it cannot read, you should file a bug report or feature request with the makers of that application. Asking Photoshop to not write a valid file is just, well, silly.

     

    How can you imply that "Error opening" an image created by Photoshop by major software is not an incompatibility?

    It is an incompatibility.  The other application is not compatible with the full BMP specification.  Photoshop implements more of the specification than the other program.  Again, that is not a problem with Photoshop.

     

    I cannot file a bug with PowerPoint team because they are coding according to current Microsoft's documentation - Photoshop is not.

    There are BMP files written to the Microsoft spec. which Microsoft cannot read. That is a bug in PowerPoint.  Microsoft has lost part of their documentation on the BMP format, and that is another bug for the MSDN team.

     

    Alpha blending is many times slower than normal blitting (sometimes requires a hard division by n^2-1

    1) We're talking about alpha channels, not transparency blending.  Alpha channels have nothing to do with transparency blending.

    2) only a beginner would use a divide instruction when you can use repiprocal multiplication to get the same answer faster and without the serialization of a divide instruction (and some compilers will do that automatically, if the optimizer is turned on).

     

    User confusion is the only good argument there.  And it's funny how the users who use these files all the time, haven't complained....

    Yeah, if I have some time I might see about cleaning up that code and removing the spurious alpha channel when possible.  But it's a low priority, because, again, it isn't harming anything.

     

     

    I'm not splitting hairs -- you are confusing the term alpha channel with transparency.  You keep using the term alpha channel as if it WERE transparency, which hasn't been the case for 25 years.  (historically it was true after the original Porter-Duff paper, but then the term alpha channel was used to mean additional channels of any content and even in the mid 80s images with "alpha channels" had things other than transparency in them)

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2011 7:05 PM   in reply to verpies

    Greetings,

     

    I came across this thread while writing a BMP filter.  But I didn't come across this variant of bitmap via Photoshop; rather, I created one using GIMP 2.7.1 (development version), with its Advanced Options on the BMP export and choosing 32 bits -> X8 R8 G8 B8.  GIMP 2.6.11 also can generate such files.  This development release is dated June 29, 2010, so it predates this thread at least; I don't if GIMP or Photoshop added the format first.  But there are at least two programs which can generate such files.

     

    I was able to duplicate the image-viewing issues with Opera (11.01 Windows and 11.00 Linux), Windows Picture and Fax Viewer, Visual Studio 2010, and Powerpoint 2007, and the success with Safari for Windows.  Irfanview was also able to view the image; Konqueror 4.5.4 could not.  Interestingly, Microsoft Paint XP was the closest of any of the not-quites, but it was not quite correct.

     

    At any rate the genie's out of the bag by now.   It doesn't look to be difficult to implement, so most likely with time more software will support it.  For that matter it might be fairly easy to add support to it to Firefox, Konqueror, and other open-source projects.

     

    I do appreciate the documentation on Wikipedia, though.  I was surprised to find the 56-bit header, too, expecting the 52-bit header without the alpha channel, which incidently is mentioned as the Windows NT (3.1?) version of BMP version 3 here.

     
    |
    Mark as:
  • Noel Carboni
    23,403 posts
    Dec 23, 2006
    Currently Being Moderated
    Mar 28, 2011 8:08 PM   in reply to verpies

    verpies wrote:

     

    Because of this undocumented header the following major software is incompatible with such bitmaps generated by Photoshop:

    http://1dollarsoftware.com/Photoshop32bpp_X8R8G8B8.bmp

     

    6) Internet Explorer 8.0.6001.18702 and v6.0.2900.5512 - Displays corrupted image. Note the little black artifact in upper right corner of the image.

     

    FYI, Internet Explorer 9.0.8112.16421 displays it just fine, without any artifact I can find.

     

    IE9BMP.jpg

     

    I really don't understand what the problem is here, nor why it rates so much discussion...  It's clear Photoshop reads/writes a whole bunch of formats, not all of which are accepted by all other applications.

     

    If you need a format that works across the board, can you not just choose a format that works with all of them?

     

    -Noel

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2011 9:01 PM   in reply to BMPFan007

    I was surprised to find the 56-bit header, too, expecting the 52-bit header without the alpha channel, which incidently is mentioned as the Windows NT (3.1?) version of BMP version 3 here.

    Ah, good.  Someone else copied the MSDN documentation before Microsoft lost it.

    I found several similar documents on other web sites -- looks like they were copied verbatim from one source.

     

    Without the MSDN documentation, I suspect that many file readers are going to fail to support that variant of BMP.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points