Ejemplo n.º 1
0
 public GifFrame()
 {
     _bounds = new Rectangle();
     _colourTable = null;
     _subBlocks = null;
     _extensionOrNull = null;
 }
Ejemplo n.º 2
0
        private void ReadHeaderFromFile(BinaryReader reader)
        {
            byte[] header = reader.ReadBytes(_headerMagic.Length);

            if (!ByteUtilities.CompareBytes(header, _headerMagic))
            {
                throw new FormatException(
                    "The expected header was not found; the file is not a valid GIF file.");
            }

            _width = reader.ReadUInt16();
            _height = reader.ReadUInt16();
            byte flags = reader.ReadByte();
            _backgroundColourIndex = reader.ReadByte();
            _pixelAspectRatio = reader.ReadByte();

            bool hasGlobalColourTable = (flags & 0x80) != 0;
            _colourResolutionBits = 1 + (flags & 0x70) >> 4;
            _colourTableIsSorted = (flags & 0x08) != 0;
            int sizeOfGlobalColourTable = 1 << (1 + (flags & 0x07));

            if (hasGlobalColourTable)
            {
                _colourTable = new GifColourTable();
                _colourTable.ReadFromFile(reader, sizeOfGlobalColourTable);
            }
            else
            {
                _colourTable = null;
            }
        }
Ejemplo n.º 3
0
        internal void ReadImageDescriptorFromFile(BinaryReader reader, GifGraphicsControlExtension extensionOrNull)
        {
            _extensionOrNull = extensionOrNull;

            _bounds.X = (int)reader.ReadUInt16();
            _bounds.Y = (int)reader.ReadUInt16();
            _bounds.Width = (int)reader.ReadUInt16();
            _bounds.Height = (int)reader.ReadUInt16();

            byte flags = reader.ReadByte();

            bool hasLocalColourTable = (flags & 0x80) != 0;
            _isInterlaced = (flags & 0x40) != 0;
            _isSorted = (flags & 0x20) != 0;
            int sizeOfLocalColourTable = 1 << (1 + (flags & 0x07));

            if (hasLocalColourTable)
            {
                _colourTable = new GifColourTable();
                _colourTable.ReadFromFile(reader, sizeOfLocalColourTable);
            }
            else
            {
                _colourTable = null;
            }

            ReadImageDataFromFile(reader);
        }