public void TestPackedValue() { Assert.Equal(0, GifGraphicControlExtension.GetPackedValue(GifDisposalMethod.Unspecified, false, false)); Assert.Equal(11, GifGraphicControlExtension.GetPackedValue(GifDisposalMethod.RestoreToBackground, true, true)); Assert.Equal(4, GifGraphicControlExtension.GetPackedValue(GifDisposalMethod.NotDispose, false, false)); Assert.Equal(14, GifGraphicControlExtension.GetPackedValue(GifDisposalMethod.RestoreToPrevious, true, false)); }
private static ImageBehavior.FrameMetadata GetFrameMetadata(GifFrame gifMetadata) { GifImageDescriptor descriptor = gifMetadata.Descriptor; ImageBehavior.FrameMetadata frameMetadata = new ImageBehavior.FrameMetadata() { Left = descriptor.Left, Top = descriptor.Top, Width = descriptor.Width, Height = descriptor.Height, Delay = TimeSpan.FromMilliseconds(100.0), DisposalMethod = ImageBehavior.FrameDisposalMethod.None }; GifGraphicControlExtension controlExtension = gifMetadata.Extensions.OfType <GifGraphicControlExtension>().FirstOrDefault <GifGraphicControlExtension>(); if (controlExtension != null) { if (controlExtension.Delay != 0) { frameMetadata.Delay = TimeSpan.FromMilliseconds((double)controlExtension.Delay); } frameMetadata.DisposalMethod = (ImageBehavior.FrameDisposalMethod)controlExtension.DisposalMethod; } return(frameMetadata); }
public static GifExtension ReadExtension(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly) { //Note: at this point, the Extension Introducer (0x21) has already been read var label = stream.ReadByte(); if (label < 0) { throw GifHelpers.UnexpectedEndOfStreamException(); } switch (label) { case GifGraphicControlExtension.ExtensionLabel: return(GifGraphicControlExtension.ReadGraphicsControl(stream)); case GifCommentExtension.ExtensionLabel: return(GifCommentExtension.ReadComment(stream)); case GifPlainTextExtension.ExtensionLabel: return(GifPlainTextExtension.ReadPlainText(stream, controlExtensions, metadataOnly)); case GifApplicationExtension.ExtensionLabel: return(GifApplicationExtension.ReadApplication(stream)); default: throw GifHelpers.UnknownExtensionTypeException(label); } }
private void DisposePreviousFrame(GifFrame currentFrame) { GifFrame previousFrame = this._previousFrame; GifGraphicControlExtension controlExtension = previousFrame != null ? previousFrame.GraphicControl : null; if (controlExtension != null) { switch (controlExtension.DisposalMethod) { case GifFrameDisposalMethod.RestoreBackground: this.ClearArea((IGifRect)this._previousFrame.Descriptor); break; case GifFrameDisposalMethod.RestorePrevious: Animator.CopyToBitmap(this._previousBackBuffer, this._bitmap, 0, this._previousBackBuffer.Length); break; } } GifGraphicControlExtension graphicControl = currentFrame.GraphicControl; if (graphicControl == null || graphicControl.DisposalMethod != GifFrameDisposalMethod.RestorePrevious) { return; } Animator.CopyFromBitmap(this._previousBackBuffer, this._bitmap, 0, this._previousBackBuffer.Length); }
private static Dictionary <int, Animator.GifPalette> CreatePalettes(GifDataStream metadata) { Dictionary <int, Animator.GifPalette> dictionary = new Dictionary <int, Animator.GifPalette>(); Color[] colorArray = (Color[])null; if (metadata.Header.LogicalScreenDescriptor.HasGlobalColorTable) { colorArray = (Color[])Enumerable.ToArray <Color>(Enumerable.Select <GifColor, Color>(metadata.GlobalColorTable, (Func <GifColor, Color>)(gc => Color.FromArgb(byte.MaxValue, gc.R, gc.G, gc.B)))); } for (int index = 0; index < metadata.Frames.Count; ++index) { GifFrame frame = metadata.Frames[index]; Color[] colors = colorArray; if (frame.Descriptor.HasLocalColorTable) { colors = (Color[])Enumerable.ToArray <Color>(Enumerable.Select <GifColor, Color>(frame.LocalColorTable, (Func <GifColor, Color>)(gc => Color.FromArgb(byte.MaxValue, gc.R, gc.G, gc.B)))); } int?transparencyIndex = new int?(); GifGraphicControlExtension graphicControl = frame.GraphicControl; if (graphicControl != null && graphicControl.HasTransparency) { transparencyIndex = new int?(graphicControl.TransparencyIndex); } dictionary[index] = new Animator.GifPalette(transparencyIndex, colors); } return(dictionary); }
public static GifGraphicControlExtension ReadGraphicsControl(Stream stream) { var ext = new GifGraphicControlExtension(); ext.Read(stream); return(ext); }
private static TimeSpan GetFrameDelay(GifFrame frame) { GifGraphicControlExtension graphicControl = frame.GraphicControl; if (graphicControl != null && graphicControl.Delay != 0) { return(TimeSpan.FromMilliseconds((double)graphicControl.Delay)); } return(TimeSpan.FromMilliseconds(100.0)); }