(BMP): refined detection of bitmaps with alpha channel.

This commit is contained in:
morkt 2016-07-26 07:05:02 +04:00
parent 1922c42ae2
commit 5a858cf42d

View File

@ -49,17 +49,20 @@ namespace GameRes
public override ImageData Read (Stream file, ImageMetaData info) public override ImageData Read (Stream file, ImageMetaData info)
{ {
var bmp_info = info as BmpMetaData; var bmp_info = info as BmpMetaData;
if (bmp_info != null && file.CanSeek if (bmp_info != null && file.CanSeek)
&& info.Width * info.Height * (uint)info.BPP/8 + bmp_info.HeaderLength == bmp_info.ImageLength)
{ {
if (0x20 == info.BPP) uint bmp_length = info.Width * info.Height * (uint)info.BPP/8 + bmp_info.HeaderLength;
if (bmp_length == bmp_info.ImageLength || bmp_length+2 == bmp_info.ImageLength)
{ {
return ReadBitmapBGRA (file, bmp_info); if (0x20 == info.BPP)
} {
else if (0x18 == info.BPP return ReadBitmapBGRA (file, bmp_info);
&& (bmp_info.ImageLength + info.Width * info.Height) == file.Length) }
{ else if (0x18 == info.BPP
return ReadBitmapWithAlpha (file, bmp_info); && (bmp_info.ImageLength + info.Width * info.Height) == file.Length)
{
return ReadBitmapWithAlpha (file, bmp_info);
}
} }
} }
var decoder = new BmpBitmapDecoder (file, var decoder = new BmpBitmapDecoder (file,