Пример #1
0
        internal static IconImage Parse(BinaryReader reader)
        {
            var infoHeader = BmpInfoHeader.Parse(reader);

            if (infoHeader.Compression != 0)
            {
                throw new NotSupportedException();
            }
            if (infoHeader.BitCount != 4)
            {
                throw new NotSupportedException();
            }

            var numColorTableEntries = (int)Math.Pow(2, infoHeader.BitCount);
            var colorTable           = BmpColorTable.Parse(reader, numColorTableEntries);

            var xorMask = BmpRasterData.Parse(reader, infoHeader.Width, infoHeader.Height / 2, infoHeader.BitCount);
            var andMask = BmpRasterData.Parse(reader, infoHeader.Width, infoHeader.Height / 2, 1);

            return(new IconImage
            {
                Header = infoHeader,
                ColorTable = colorTable,
                XorMask = xorMask,
                AndMask = andMask
            });
        }
Пример #2
0
        internal static IconImage Parse(BinaryReader reader)
        {
            var infoHeader = BmpInfoHeader.Parse(reader);

            if (infoHeader.Compression != 0)
            {
                throw new NotSupportedException();
            }

            int numColorTableEntries;

            switch (infoHeader.BitCount)
            {
            case 4:
            case 8:
                numColorTableEntries = (int)MathF.Pow(2, infoHeader.BitCount);
                break;

            case 24:
            case 32:
                numColorTableEntries = (int)infoHeader.ColorsUsed;
                break;

            default:
                throw new NotSupportedException();
            }

            var colorTable = BmpColorTable.Parse(reader, numColorTableEntries);

            var xorMask = BmpRasterData.Parse(reader, infoHeader.Width, infoHeader.Height / 2, infoHeader.BitCount);
            var andMask = BmpRasterData.Parse(reader, infoHeader.Width, infoHeader.Height / 2, 1);

            return(new IconImage
            {
                Header = infoHeader,
                ColorTable = colorTable,
                XorMask = xorMask,
                AndMask = andMask
            });
        }