We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2714 - 32-bit BMPs with alpha channel saved with GIMP 2.8 not handled correctly
Summary: 32-bit BMPs with alpha channel saved with GIMP 2.8 not handled correctly
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.1
Hardware: x86_64 Windows 8
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
: 3156 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-09-03 05:57 UTC by Wei Mingzhi
Modified: 2015-10-19 13:34 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wei Mingzhi 2014-09-03 05:57:07 UTC
From GIMP source code:

gimp-2.8.14/plug-ins/file-bmp/bmp.h:


extern struct Bitmap_File_Head_Struct
{
  gchar    zzMagic[2];  /* 00 "BM" */
  gulong   bfSize;      /* 02 */
  gushort  zzHotX;      /* 06 */
  gushort  zzHotY;      /* 08 */
  gulong   bfOffs;      /* 0A */
  gulong   biSize;      /* 0E */
} Bitmap_File_Head;

extern struct Bitmap_Head_Struct
{
  glong    biWidth;     /* 12 */
  glong    biHeight;    /* 16 */
  gushort  biPlanes;    /* 1A */
  gushort  biBitCnt;    /* 1C */
  gulong   biCompr;     /* 1E */
  gulong   biSizeIm;    /* 22 */
  gulong   biXPels;     /* 26 */
  gulong   biYPels;     /* 2A */
  gulong   biClrUsed;   /* 2E */
  gulong   biClrImp;    /* 32 */
  guint32  masks[4];    /* 36 */
} Bitmap_Head;

However currently SDL2 does not use the "masks" field in Bitmap_Head_Struct struct (which contains the masks for R/G/B/A channels).

Not sure if what the GIMP is doing is standard behavior though (cannot find documentation about this one, and M$ does not use the "masks" field), also I can manually hack the BMP file by putting the masks to where SDL2 uses to make it work with SDL2 so this should be considered as a minor issue.
Comment 1 Ryan C. Gordon 2014-09-05 04:59:42 UTC
I ran into this a few weeks ago and put a hack into SDL, but this is a clear explanation of what would need to change to make a proper fix.

Stealing this bug.

--ryan.
Comment 2 Ryan C. Gordon 2014-09-08 04:32:13 UTC
(In reply to Ryan C. Gordon from comment #1)
> I ran into this a few weeks ago and put a hack into SDL, but this is a clear
> explanation of what would need to change to make a proper fix.
> 
> Stealing this bug.
> 
> --ryan.

So what we do is look for a 40-byte BITMAPINFOHEADER (and if the reported size of this header is more than 40 bytes, we throw away the difference by seeking over it).

Gimp's extra field we're ignoring is because they write out a BITMAPV5INFOHEADER. v2 added the RGB masks, v3 added alpha.

I'm cleaning this up a little in SDL now.

--ryan.
Comment 3 Ryan C. Gordon 2014-09-08 05:47:53 UTC
Ok, my totally incorrect hack is gone, and this is fixed properly in https://hg.libsdl.org/SDL/rev/08f3b56969b1 ...let me know if this gives you further grief.

--ryan.
Comment 4 Wei Mingzhi 2014-09-08 12:40:51 UTC
cool :)
thanks.
Comment 5 Rubinson Ivan 2015-10-19 13:34:43 UTC
*** Bug 3156 has been marked as a duplicate of this bug. ***