Esempio n. 1
0
        public static IImage ImageFromBytes(byte[] bytes)
        {
            var parser = new BinaryParser(bytes);

            if (parser.Int16BE() != 474)
            {
                throw new InvalidDataException("invalid header");
            }
            var    storage = parser.Byte();
            IImage image   = ImageFromBytesPerPixel(parser.Byte());

            if (image == null)
            {
                throw new InvalidDataException("invalid bpc");
            }
            var dimension = parser.UInt16BE();

            image.Width    = parser.UInt16BE();
            image.Height   = parser.UInt16BE();
            image.Channels = parser.UInt16BE();
            if (dimension != 3)
            {
                image.Channels = 1;
            }
            parser.Position += 92;
            var colormap = parser.Int32BE();

            if (colormap != 0)
            {
                throw new NotSupportedException("unsupported colormap");
            }
            parser.Position += 404;
            switch (storage)
            {
            case 0: ParseVerbatim(image, parser); break;

            case 1: ParseRLE(image, parser); break;

            default:
                throw new InvalidDataException("invalid storage value");
            }
            return(image);
        }
Esempio n. 2
0
 internal override ushort UInt16(BinaryParser bp) => bp.UInt16BE();