GNOME Bugzilla – Bug 678250
Reading 32-bit RGBX BMP Files: Transparency Turns into Cyan
Last modified: 2012-06-21 00:43:04 UTC
When reading a 32-bit RGBX Windows Bitmap file the pixels with the RGBA values 0,0,0,0 turn into 0,255,255,255. Color Space information does not affect the results. See also the attachment to this bug report. This bug can be reproduced the following way: - Export an image containing an alpha channel as 32-bit RGBX Windows Bitmap (BMP) - Import the bitmap file again into GIMP.
Created attachment 216604 [details] XCF File with Original image and image after BMP Export/Import
I've found a few mistakes in file: http://git.gnome.org/browse/gimp/tree/plug-ins/file-bmp/bmp-write.c Inside write_image(), the code: case RGBX_8888: buf[0] = 0; buf[3] = *temp++; buf[2] = *temp++; buf[1] = *temp++; should be replaced by: case RGBX_8888: buf[2] = *temp++; buf[1] = *temp++; buf[0] = *temp++; buf[3] = 0; And inside WriteBMP(), the code: switch (BMPSaveData.rgb_format) { default: case RGB_888: case RGBX_8888: Mask[0] = 0xff000000; Mask[1] = 0x00ff0000; Mask[2] = 0x0000ff00; Mask[3] = 0x00000000; break; case RGBA_8888: Mask[0] = 0xff000000; Mask[1] = 0x00ff0000; Mask[2] = 0x0000ff00; Mask[3] = 0x000000ff; break; should be replaced by: switch (BMPSaveData.rgb_format) { default: case RGB_888: case RGBX_8888: Mask[0] = 0x0000ff00; Mask[1] = 0x00ff0000; Mask[2] = 0xff000000; Mask[3] = 0x00000000; break; case RGBA_8888: Mask[0] = 0x0000ff00; Mask[1] = 0x00ff0000; Mask[2] = 0xff000000; Mask[3] = 0x000000ff; break; Sorry, I'm on Windows so I can't easily compile and try, etc.
I have attached a zip file below showing the results of your changes. The first change you suggest results in "RGBX changes1.bmp". The first change combined with the second change you suggest results in "RGBX changes2.bmp". Applying the second change only to bmp-write.c results in "RGBX changes3.bmp". And of course, there is "RGBX nochange.bmp" which is the bmp exported from a non-modified bmp-write.c.
Created attachment 216758 [details] Results of proposed changes in comment 2.
The patch I just uploaded in Bug 678252 should solve this issue. I am marking this bug report as a duplicate. *** This bug has been marked as a duplicate of bug 678252 ***
Just for info, there was a mistake (wrong endianness) in the fix I suggested above (comment 2). The code inside WriteBMP() should be: switch (BMPSaveData.rgb_format) { default: case RGB_888: case RGBX_8888: Mask[0] = 0x00ff0000; Mask[1] = 0x0000ff00; Mask[2] = 0x000000ff; Mask[3] = 0x00000000; break; case RGBA_8888: Mask[0] = 0x00ff0000; Mask[1] = 0x0000ff00; Mask[2] = 0x000000ff; Mask[3] = 0xff000000; break; The patch kindly generated by Bastian and attached to bug 678252, comment 6 was created using this fixed modification.