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 2515

Summary: SDL_LoadBMP: wrong handling of BMP images that have BI_BITFILEDS compression
Product: SDL Reporter: spam
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: rpolzer
Version: HG 2.1   
Hardware: All   
OS: All   

Description spam 2014-04-27 09:06:31 UTC
There is a bug in SDL_LoadBMP when loading a BMP with BI_BITFIELDS compression.

The bug was introduced in:
http://hg.libsdl.org/SDL/rev/44dc7926f62d

The problem is that the SDL_RWseek on src file is called before
[ARGB]mask for BI_BITFILEDS is read and wrong values end up in
[ARGB]mask variables.
Comment 1 Rudolf Polzer 2014-10-10 09:18:37 UTC
I was just tracking down the same problem.

The issue is that the RGBA masks are actually part of struct BITMAPV4HEADER, and thus follow directly the biClrUsed value, instead of being behind the bitmap header struct.

However, the commit is correct for palette images - for these, the color table indeed follows the whole header.

As a solution, I suggest skipping over the whole header size AFTER reading the masks (if used). This will fix support for BMP formats v4 (since Win95) and v5 (since Win98).
Comment 2 Sam Lantinga 2014-10-11 07:01:35 UTC
Can you try the latest snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip

Thanks!
Comment 3 Rudolf Polzer 2014-10-13 08:47:47 UTC
Although I didn't get to checking it yet, I believe the change https://hg.libsdl.org/SDL/rev/08f3b56969b1 must fix the issue.
Comment 4 Ryan C. Gordon 2015-02-19 02:32:05 UTC
(In reply to Rudolf Polzer from comment #3)
> Although I didn't get to checking it yet, I believe the change
> https://hg.libsdl.org/SDL/rev/08f3b56969b1 must fix the issue.

Yes, that changeset should fix this specific issue.

--ryan.