internal void Read(GifReader reader, GifLogicalScreenDescriptorBlock gifLogicalScreenDescriptorBlock) { bytes = reader.ReadBytes(gifLogicalScreenDescriptorBlock.GlobalColorTableSize * 3); //byte[] globalColorTableBuffer = reader.ReadBytes(globalColorTableSize * 3); //globalColorTable = new Color[globalColorTableSize]; //int baseIndex = 0; //for (UInt16 colorIndex = 0; colorIndex < globalColorTableSize; colorIndex++) //{ // globalColorTable[colorIndex] = Color.FromArgb(globalColorTableBuffer[baseIndex], globalColorTableBuffer[baseIndex + 1], globalColorTableBuffer[baseIndex + 2]); // baseIndex += 3; //} }
internal GifGlobalColorTableBlock(GifReader reader, GifLogicalScreenDescriptorBlock gifLogicalScreenDescriptorBlock) : base(GifBlockType.GlobalColorTable) { Read(reader, gifLogicalScreenDescriptorBlock); }
public void Read(Stream stream) { blocks.Clear(); // reader GifReader reader = new GifReader(stream); // Header AddBlock(new GifHeaderBlock(reader)); // Logical Screen Descriptor GifLogicalScreenDescriptorBlock gifLogicalScreenDescriptorBlock = new GifLogicalScreenDescriptorBlock(reader); AddBlock(gifLogicalScreenDescriptorBlock); // Global Color Table if (gifLogicalScreenDescriptorBlock.GlobalColorTableFlag) { AddBlock(new GifGlobalColorTableBlock(reader, gifLogicalScreenDescriptorBlock)); } // Segments while (true) { Byte identifier = reader.ReadByte(); switch (identifier) { // Frames case 0x2C: GifImageDescriptorBlock gifImageDescriptorBlock = new GifImageDescriptorBlock(reader); AddBlock(gifImageDescriptorBlock); if (gifImageDescriptorBlock.LocalColorTableFlag) { AddBlock(new GifLocalColorTableBlock(reader, gifImageDescriptorBlock)); } AddBlock(new GifTableBasedImageDataBlock(reader)); break; // Extensions case 0x21: Byte label = reader.ReadByte(); switch (label) { case 0xF9: AddBlock(new GifGraphicControExtensionBlock(reader)); break; case 0xFE: AddBlock(new GifCommentExtensionBlock(reader)); break; case 0x01: AddBlock(new GifPlainTextExtensionBlock(reader)); break; case 0xFF: AddBlock(GifApplicationExtensionBlock.Create(reader)); break; default: AddBlock(new GifExtensionBlock(label, reader)); break; } break; // Trailer case 0x3B: AddBlock(new GifTrailerBlock()); return; default: throw new Exception("Unknown segment identifier: 0x" + identifier.ToString("X2")); } } }
static private void DumpBlock(GifBlock gifBlock) { GifExtensionBlock gifUnknownBlock = gifBlock as GifExtensionBlock; if (gifUnknownBlock != null) { Console.WriteLine("\tLength:\t\t\t\t" + gifUnknownBlock.Bytes.Length); } GifHeaderBlock gifHeaderBlock = gifBlock as GifHeaderBlock; if (gifHeaderBlock != null) { Console.WriteLine("\tVersion:\t\t\t" + gifHeaderBlock.Version); } GifLogicalScreenDescriptorBlock gifLogicalScreenDescriptorBlock = gifBlock as GifLogicalScreenDescriptorBlock; if (gifLogicalScreenDescriptorBlock != null) { Console.WriteLine("\tWidth:\t\t\t\t" + gifLogicalScreenDescriptorBlock.Width); Console.WriteLine("\tHeight:\t\t\t\t" + gifLogicalScreenDescriptorBlock.Height); Console.WriteLine("\tGlobalColorTableFlag:\t\t" + gifLogicalScreenDescriptorBlock.GlobalColorTableFlag); Console.WriteLine("\tColorResolution:\t\t" + gifLogicalScreenDescriptorBlock.ColorResolution); Console.WriteLine("\tGlobalColorTableSorted:\t\t" + gifLogicalScreenDescriptorBlock.GlobalColorTableSorted); Console.WriteLine("\tGlobalColorTableSize:\t\t" + gifLogicalScreenDescriptorBlock.GlobalColorTableSize); Console.WriteLine("\tBackgroundColorIndex:\t\t" + gifLogicalScreenDescriptorBlock.BackgroundColorIndex); Console.WriteLine("\tPixelAspectRatio:\t\t" + gifLogicalScreenDescriptorBlock.PixelAspectRatio); } GifGlobalColorTableBlock gifGlobalColorTableBlock = gifBlock as GifGlobalColorTableBlock; if (gifGlobalColorTableBlock != null) { Console.WriteLine("\tLength:\t\t\t\t" + gifGlobalColorTableBlock.Bytes.Length); } GifImageDescriptorBlock gifImageDescriptorBlock = gifBlock as GifImageDescriptorBlock; if (gifImageDescriptorBlock != null) { Console.WriteLine("\tLeft:\t\t\t\t" + gifImageDescriptorBlock.Left); Console.WriteLine("\tTop:\t\t\t\t" + gifImageDescriptorBlock.Top); Console.WriteLine("\tWidth:\t\t\t\t" + gifImageDescriptorBlock.Width); Console.WriteLine("\tHeight:\t\t\t\t" + gifImageDescriptorBlock.Height); Console.WriteLine("\tInterlaced:\t\t\t" + gifImageDescriptorBlock.Interlaced); Console.WriteLine("\tLocalColorTableFlag:\t\t" + gifImageDescriptorBlock.LocalColorTableFlag); Console.WriteLine("\tLocalColorTableSorted:\t\t" + gifImageDescriptorBlock.LocalColorTableSorted); Console.WriteLine("\tLocalColorTableSize:\t\t" + gifImageDescriptorBlock.LocalColorTableSize); } GifLocalColorTableBlock gifLocalColorTableBlock = gifBlock as GifLocalColorTableBlock; if (gifLocalColorTableBlock != null) { Console.WriteLine("\tLength:\t\t\t\t" + gifLocalColorTableBlock.Bytes.Length); } GifTableBasedImageDataBlock gifTableBasedImageDataBlock = gifBlock as GifTableBasedImageDataBlock; if (gifTableBasedImageDataBlock != null) { Console.WriteLine("\tLzwMinimumCodeSize:\t\t" + gifTableBasedImageDataBlock.LzwMinimumCodeSize); Console.WriteLine("\tLength:\t\t\t\t" + gifTableBasedImageDataBlock.ImageData.Length); } GifGraphicControExtensionBlock gifGraphicControExtensionBlock = gifBlock as GifGraphicControExtensionBlock; if (gifGraphicControExtensionBlock != null) { Console.WriteLine("\tDisposalMethod:\t\t\t" + gifGraphicControExtensionBlock.DisposalMethod + " (" + (int)gifGraphicControExtensionBlock.DisposalMethod + ")"); Console.WriteLine("\tUserInputExpected:\t\t" + gifGraphicControExtensionBlock.UserInputExpected); Console.WriteLine("\tTransparency:\t\t\t" + gifGraphicControExtensionBlock.Transparency); Console.WriteLine("\tDelay:\t\t\t\t" + gifGraphicControExtensionBlock.Delay); Console.WriteLine("\tTransparencyIndex:\t\t" + gifGraphicControExtensionBlock.TransparencyIndex); } GifCommentExtensionBlock gifCommentExtensionBlock = gifBlock as GifCommentExtensionBlock; if (gifCommentExtensionBlock != null) { Console.WriteLine("\tComment:\t\t\t" + gifCommentExtensionBlock.Comment); } GifPlainTextExtensionBlock gifPlainTextExtensionBlock = gifBlock as GifPlainTextExtensionBlock; if (gifPlainTextExtensionBlock != null) { Console.WriteLine("\tLeft:\t\t\t\t" + gifPlainTextExtensionBlock.Left); Console.WriteLine("\tTop:\t\t\t\t" + gifPlainTextExtensionBlock.Top); Console.WriteLine("\tWidth:\t\t\t\t" + gifPlainTextExtensionBlock.Width); Console.WriteLine("\tHeight:\t\t\t\t" + gifPlainTextExtensionBlock.Height); Console.WriteLine("\tCellWidth:\t\t\t" + gifPlainTextExtensionBlock.CellWidth); Console.WriteLine("\tCellHeight:\t\t\t" + gifPlainTextExtensionBlock.CellHeight); Console.WriteLine("\tForegroundColor:\t\t" + gifPlainTextExtensionBlock.ForegroundColor); Console.WriteLine("\tBackgroundColor:\t\t" + gifPlainTextExtensionBlock.BackgroundColor); Console.WriteLine("\tText:\t\t\t" + gifPlainTextExtensionBlock.Text); } GifApplicationExtensionBlock gifApplicationExtensionBlock = gifBlock as GifApplicationExtensionBlock; if (gifApplicationExtensionBlock != null) { Console.WriteLine("\tApplicationIdentifier:\t\t" + gifApplicationExtensionBlock.ApplicationIdentifier); Console.WriteLine("\tApplicationAuthenticationCode:\t" + gifApplicationExtensionBlock.ApplicationAuthenticationCode); } GifNetscapeLoopingApplicationExtensionBlock gifNetscapeExtensionBlock = gifBlock as GifNetscapeLoopingApplicationExtensionBlock; if (gifNetscapeExtensionBlock != null) { Console.WriteLine("\tLoopCount:\t\t\t" + gifNetscapeExtensionBlock.LoopCount); } GifNetscapeBufferingApplicationExtensionBlock gifNetscapeBufferingExtensionBlock = gifBlock as GifNetscapeBufferingApplicationExtensionBlock; if (gifNetscapeBufferingExtensionBlock != null) { Console.WriteLine("\tBufferSize:\t\t\t" + gifNetscapeBufferingExtensionBlock.BufferSize); } GifAnimextsLoopingApplicationExtensionBlock gifAnimextsLoopingExtensionBlock = gifBlock as GifAnimextsLoopingApplicationExtensionBlock; if (gifAnimextsLoopingExtensionBlock != null) { Console.WriteLine("\tLoopCount:\t\t\t" + gifAnimextsLoopingExtensionBlock.LoopCount); } }