GNOME Bugzilla – Bug 678252
File-bmp: Color Space Information breaks BITMAPV5HEADER Structure
Last modified: 2012-10-08 02:24:59 UTC
This bug report is derived from Bug 676219. The bug was initially found by Jigebren: "- In the file "http://git.gnome.org/browse/gimp/tree/plug-ins/file-bmp/bmp-write.c" inside WriteBMP(), inside the "switch (BMPSaveData.rgb_format)" the "mask_info_size" is not set for case "RGBA_8888". This is later preventing the writing of the Mask info "if (mask_info_size > 0)", thus breaking the BITMAPV5HEADER structure in case the color_space_data are also written. So we should likely have: case RGBA_8888: BitsPerPixel = 32; mask_info_size = 16; break; instead of: case RGBA_8888: BitsPerPixel = 32; break; (Maybe this bad structure format could be a reason some apps fails reading a BMP image with color space information saved from Gimp BTW...)" I have attached the fix which Jigebren is suggesting above as a patch to this bug report.
Created attachment 216605 [details] [review] bmp-write.c with Jigebren's changes applied
The broken code above also prevents the use of BI_BITFIELDS format when a writing 32-bit BMP file, which later leads for example GDK to ignore the alpha channel (see Bug 678248). So I confirm the necessity of the fix above...
I have attached a zip file which shows the result of these changes alone ("changes1.bmp"). As you can see there is an alpha channel, but everything has turned pink and semi-transparent. This is the results regardless of whether colorspace information is written to the RGBA BMP or not. The zip also contains a file called "changes2.bmp". It shows the result if the changes above + the changes you suggest in Bug 678250 is applied to bmp-write.c. The exported bmp is now blue and still semi-transparent. The third file is called "no changes.bmp" and is created from a non-modified bmp-write.c.
Created attachment 216756 [details] Exported Results from Initial Changes
You should attach only the diff output of your changes as a patch, not the complete files. Please use either diff -u or git's diff command - the latter will also get you the proper attribution in the revision history if you add your name and mail address to your git setup.
Created attachment 216810 [details] [review] Patch for bmp-write.c which fixes writing 32-bit RGBA & RGBX Windows Bitmaps.
*** Bug 678250 has been marked as a duplicate of this bug. ***
A few info about the patch submitted by Bastian above (attachment 216810 [details] [review]). This path is a merge of the fix from bug 676219, comment 6 and bug 678250, comment 2. It fixes the following cases: - 32 bits BMP with alpha channel (RGBA_8888) were saved using BI_RGB instead of BI_BITFIELDS format (those corrupted BMP files could not be properly read by some softwares - including GIMP). - Exporting an image containing an alpha channel as a RGBX_8888 BMP was broken: channels were mixed in totally transparent areas. BTW, just for info I notice that though RGBX / RGBA names are used in the source code, the actual channel layout (and the options in GIMP interface) is XRGB / ARGB (or BGRX / BGRA, I'm not 100% sure).
This bug is fixed in the following commits. Note that Firefox still has a bug that it does not use the masks when parsing BMPs. Reporters please verify the fix. Resolving as FIXED, milestone 2.8. In master: commit 800f967930e360e86cbb15b6c4d1ae36443ac9c8 Author: Mukund Sivaraman <muks@banu.com> Date: Fri Sep 21 20:11:31 2012 +0530 file-bmp: Fix order of data in RGBA_8888 images See #678250, #678252, etc. for example bug reports. This fix should be sufficient in fixing BMP output, but it looks like some apps like Firefox have broken BMP loaders which do not care for the masks. We would have to change the masks for them. commit b100b14111725bf9ad7a48db096ae4ad65a81bc5 Author: Mukund Sivaraman <muks@banu.com> Date: Fri Sep 21 20:09:51 2012 +0530 file-bmp: All 16 and 32-bpp files need the masks to be written See #678250, #678252, etc. for example bug reports. In gimp-2-8: commit b38d44220f2eb47a2e2e7584850a99874242961b Author: Mukund Sivaraman <muks@banu.com> Date: Fri Sep 21 20:11:31 2012 +0530 file-bmp: Fix order of data in RGBA_8888 images See #678250, #678252, etc. for example bug reports. This fix should be sufficient in fixing BMP output, but it looks like some apps like Firefox have broken BMP loaders which do not care for the masks. We would have to change the masks for them. commit 2af0e143706128842cae71850f3aa2a3cd418bf7 Author: Mukund Sivaraman <muks@banu.com> Date: Fri Sep 21 20:09:51 2012 +0530 file-bmp: All 16 and 32-bpp files need the masks to be written See #678250, #678252, etc. for example bug reports.
*** Bug 676219 has been marked as a duplicate of this bug. ***