/// <summary> /// Decodes the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <returns>This.</returns> public override FileBase Decode(Stream stream) { Header = FileHeader.Read(stream); ScreenDescriptor = LogicalScreenDescriptor.Read(stream); if (ScreenDescriptor.GlobalColorTablePresent) { ColorTable = ColorTable.Read(stream, ScreenDescriptor.GlobalColorTableSize); } var Flag = stream.ReadByte(); while (Flag != SectionTypes.Terminator) { if (Flag == SectionTypes.ImageLabel) { Frames.Add(Frame.Read(stream, ColorTable, GraphicsControlExtension, ScreenDescriptor, Frames)); } else if (Flag == SectionTypes.ExtensionIntroducer) { var Label = (SectionTypes)stream.ReadByte(); if (Label == SectionTypes.GraphicControlLabel) { GraphicsControlExtension = GraphicsControl.Read(stream); } else if (Label == SectionTypes.CommentLabel) { Comment.Read(stream); } else if (Label == SectionTypes.ApplicationExtensionLabel) { ApplicationExtension.Read(stream); } else if (Label == SectionTypes.PlainTextLabel) { PlainText.Read(stream); } } else if (Flag == SectionTypes.EndIntroducer) { break; } Flag = stream.ReadByte(); } return(this); }
/// <summary> /// Loads the animation. /// </summary> /// <param name="animation">The animation.</param> /// <param name="quantizedImage">The quantized image.</param> private void LoadAnimation(Animation animation, QuantizedImage quantizedImage) { var TempImage = animation[0]; var TransparencyIndex = quantizedImage.TransparentIndex; Header = new FileHeader(); ScreenDescriptor = new LogicalScreenDescriptor(TempImage, TransparencyIndex, BitDepth); Frames.Add(new Frame(TempImage, quantizedImage, BitDepth, animation.Delay)); if (animation.Count > 1) { AppExtension = new ApplicationExtension(animation.RepeatCount, animation.Count); for (int x = 1; x < animation.Count; ++x) { quantizedImage = Quantizer.Quantize(animation[x], Quality); TempImage = animation[x]; Frames.Add(new Frame(TempImage, quantizedImage, BitDepth, animation.Delay)); } } }