diff options
author | Gokul Krishnan <gk7huki@gmail.com> | 2016-05-25 22:24:00 +0000 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2016-12-19 18:30:51 +0100 |
commit | cd302dd3005733e235292711a6e5763711cf5895 (patch) | |
tree | c155e5f7d3622036908223935a502a1991cab5a7 | |
parent | 69962e278fb03c572c06d2a5c08c20574db922cf (diff) | |
download | gdk-pixbuf-cd302dd3005733e235292711a6e5763711cf5895.tar.gz |
bmp: Add support for BMP headers with bitmask
Header size 52 and 56 failed to load before this patch.
https://bugzilla.gnome.org/show_bug.cgi?id=766890
-rw-r--r-- | gdk-pixbuf/io-bmp.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/gdk-pixbuf/io-bmp.c b/gdk-pixbuf/io-bmp.c index b896a0349..f78c092b6 100644 --- a/gdk-pixbuf/io-bmp.c +++ b/gdk-pixbuf/io-bmp.c @@ -298,6 +298,18 @@ static gboolean DecodeHeader(unsigned char *BFH, unsigned char *BIH, State->Header.height = lsb_32 (&BIH[8]); State->Header.depth = lsb_16 (&BIH[14]); State->Compressed = lsb_32 (&BIH[16]); + } else if (State->Header.size == 56) { + /* BMP v3 with RGBA bitmasks */ + State->Header.width = lsb_32 (&BIH[4]); + State->Header.height = lsb_32 (&BIH[8]); + State->Header.depth = lsb_16 (&BIH[14]); + State->Compressed = lsb_32 (&BIH[16]); + } else if (State->Header.size == 52) { + /* BMP v3 with RGB bitmasks */ + State->Header.width = lsb_32 (&BIH[4]); + State->Header.height = lsb_32 (&BIH[8]); + State->Header.depth = lsb_16 (&BIH[14]); + State->Compressed = lsb_32 (&BIH[16]); } else if (State->Header.size == 40) { /* BMP v3 */ State->Header.width = lsb_32 (&BIH[4]); @@ -495,9 +507,10 @@ static gboolean DecodeHeader(unsigned char *BFH, unsigned char *BIH, State->BufferSize = State->LineWidth; } } else if (State->Compressed == BI_BITFIELDS) { - if (State->Header.size == 108 || State->Header.size == 124) + if (State->Header.size == 52 || State->Header.size == 56 || + State->Header.size == 108 || State->Header.size == 124) { - /* v4 and v5 have the bitmasks in the header */ + /* extended v3, v4 and v5 have the bitmasks in the header */ if (!decode_bitmasks (&BIH[40], State, error)) { State->read_state = READ_STATE_ERROR; return FALSE; @@ -607,8 +620,8 @@ decode_bitmasks (guchar *buf, find_bits (State->g_mask, &State->g_shift, &State->g_bits); find_bits (State->b_mask, &State->b_shift, &State->b_bits); - /* v4 and v5 have an alpha mask */ - if (State->Header.size == 108 || State->Header.size == 124) { + /* extended v3, v4 and v5 have an alpha mask */ + if (State->Header.size == 56 || State->Header.size == 108 || State->Header.size == 124) { buf += 4; State->a_mask = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); find_bits (State->a_mask, &State->a_shift, &State->a_bits); |