ReadUnpack() public method

Reads packed bytes with specified count.
public ReadUnpack ( int count ) : byte[]
count int /// Bytes count. ///
return byte[]
示例#1
0
        /// <param name="stream">
        /// Stream containing ILBM image data.
        /// </param>
        public ILBMImage(Stream stream)
        {
            //BinaryReader reader = new BinaryReader(stream, Encoding.ASCII);
            //ReadNext(reader);

            IFFReader reader = new IFFReader(stream);
            var file = reader.ReadFileHeader();
            if(file.FormatID != "PBM ")
            {
                throw new NotSupportedException("This is not supported IBLM file.");
            }

            foreach(IFFChunk chunk in reader.ReadAll())
            {
                switch(chunk.TypeID)
                {
                    case "BMHD":
                        Width = reader.ReadInt16();
                        Height = reader.ReadInt16();
                        PosX = reader.ReadInt16();
                        PosY = reader.ReadInt16();
                        NumPlanes = reader.ReadByte();
                        Mask = reader.ReadByte();
                        Compression = reader.ReadByte();
                        Padding = reader.ReadByte();
                        Transparent = reader.ReadInt16();
                        AspectRatio = reader.ReadInt16();
                        PageWidth = reader.ReadInt16();
                        PageHeight = reader.ReadInt16();
                        break;
                    case "CMAP":
                        Color[] pal = new Color[chunk.Length/3];
                        for(int i = 0; i < pal.Length; i++)
                        {
                            byte R = reader.ReadByte();
                            byte G = reader.ReadByte();
                            byte B = reader.ReadByte();
                            pal[i] = Color.FromArgb(R, G, B);
                        }
                        Palette = ImagePalette.Create(pal);
                        break;
                    case "GRAB":
                        HotspotX = reader.ReadInt16();
                        HotspotY = reader.ReadInt16();
                        break;
                    case "CRNG":
                        if(ColorRanges == null)ColorRanges = new List<ColorRange>();
                        ColorRanges.Add(new ColorRange(reader));
                        break;
                    case "TINY":
                        short width = reader.ReadInt16();
                        short height = reader.ReadInt16();
                        byte[] tiny;
                        if(Compression == 1)
                        {
                            tiny = reader.ReadUnpack(chunk.Length-4);
                        }else{
                            tiny = reader.ReadBytes(chunk.Length-4);
                        }
                        Tiny = new TinyImage(width, height, tiny);
                        break;
                    case "BODY":
                        if(Compression == 1)
                        {
                            ImageData = reader.ReadUnpack(chunk.Length);
                        }else{
                            ImageData = reader.ReadBytes(chunk.Length);
                        }
                        break;
                }
            }
        }