public GifImageDescriptor ReadImageDescriptor() { AssertToken(Token.ImageDescriptor); imageDescriptor.left = currentStream.ReadInt16LittleEndian(); imageDescriptor.top = currentStream.ReadInt16LittleEndian(); imageDescriptor.width = currentStream.ReadInt16LittleEndian(); imageDescriptor.height = currentStream.ReadInt16LittleEndian(); var flags = currentStream.ReadByte8(); imageDescriptor.localColorTableSize = BitUtils.GetColorTableSize(flags.GetBitsFromByte(0, 3)); imageDescriptor.isInterlaced = flags.GetBitFromByte(6); imageDescriptor.hasLocalColorTable = flags.GetBitFromByte(7); if (imageDescriptor.hasLocalColorTable) { nextPaletteIsGlobal = false; SetCurrentToken(Token.Palette); } else { SetCurrentToken(Token.Image); } return(imageDescriptor); }
/// <summary> /// Read gif header /// </summary> /// <returns>Data of gif header</returns> /// <exception cref="ArgumentException">If file is not gif file</exception> public GifHeader ReadHeader() { AssertToken(Token.Header); // Header headerStartPosition = currentStream.Position; firstFrameStartPosition = -1; currentStream.Read(headerBuffer, 0, headerBuffer.Length); if (BitUtils.CheckString(headerBuffer, "GIF87a")) { header.version = GifVersion.Gif87a; } else if (BitUtils.CheckString(headerBuffer, "GIF89a")) { header.version = GifVersion.Gif89a; } else { throw new ArgumentException("Invalid or corrupted Gif file"); } // Screen descriptor header.width = currentStream.ReadInt16LittleEndian(); header.height = currentStream.ReadInt16LittleEndian(); var flags = currentStream.ReadByte8(); header.globalColorTableSize = BitUtils.GetColorTableSize(flags.GetBitsFromByte(0, 3)); header.sortColors = flags.GetBitFromByte(3); header.colorResolution = flags.GetBitsFromByte(4, 3); header.hasGlobalColorTable = flags.GetBitFromByte(7); header.transparentColorIndex = currentStream.ReadByte8(); header.pixelAspectRatio = currentStream.ReadByte8(); canvas.SetSize(header.width, header.height); if (header.hasGlobalColorTable) { SetCurrentToken(Token.Palette); nextPaletteIsGlobal = true; } else { DetermineNextToken(); } return(header); }