GNOME Bugzilla – Bug 678248
Gimp reading 32-bit BMP files with BITMAPV5HEADER: Pixbuf ignores alpha channel
Last modified: 2012-06-20 16:46:34 UTC
Gimp can read and write 32-bit Windows Bitmap files. 32-bit BMP files are read using GDK, but GDK doesn't appear to read the 4th channel, hence ignoring transparency. This bug report is derived from bug 676219 and below I have quoted Jigebren who discovered that the issue lied within gdk-pixbuf: "In OneLine32(), we can see that the alpha component is simply overwritten with 0xff: for (i = 0; i < context->Header.width; i++) { *pixels++ = src[2]; *pixels++ = src[1]; *pixels++ = src[0]; *pixels++ = 0xff; src += 4; } Not to lose the alpha channel it should be: *pixels++ = src[2]; *pixels++ = src[1]; *pixels++ = src[0]; *pixels++ = src[3]; I don't know whether or not GDK is supposed to support alpha in BMP files. But as far as Gimp is concerned it sounds inconsistent not to be able to properly read again a file it has written itself..." (See also comment 10 in Bug 676219) I have submitted a patch with Jigebren's suggested changes to this bug report.
Created attachment 216601 [details] [review] Patch which fixes problems importing 32-bit RGBA V5 BMP files.
After second reading of: http://git.gnome.org/browse/gdk-pixbuf/tree/gdk-pixbuf/io-bmp.c it appears that the alpha channel is actually supported in BMP if bV5Compression is set to BI_BITFIELDS, which seems to be the less ambiguous way to support alpha channel in BMP. The issue still comes in fact from Gimp bmp-write.c module: Bug 678252 also prevents to save BMP using the BI_BITFIELDS format. But a buggy ARGB BMP file exported from Gimp and then fixed in an hexadecimal editor to set the BI_BITFIELDS and add the 4 Color masks is properly loaded by Gimp / GDK (with alpha channel). This bug report can safely be closed.