internal static async Task <GifBlock> ReadAsync(Stream stream, IEnumerable <GifExtension> controlExtensions) { int blockId = await stream.ReadByteAsync().ConfigureAwait(false); if (blockId < 0) { throw new EndOfStreamException(); } return(blockId switch { GifExtension.ExtensionIntroducer => await GifExtension.ReadAsync(stream, controlExtensions).ConfigureAwait(false), GifFrame.ImageSeparator => await GifFrame.ReadAsync(stream, controlExtensions).ConfigureAwait(false), GifTrailer.TrailerByte => await GifTrailer.ReadAsync().ConfigureAwait(false), _ => throw GifHelpers.UnknownBlockTypeException(blockId), });
internal static async Task<GifBlock> ReadAsync(Stream stream, IEnumerable<GifExtension> controlExtensions) { int blockId = await stream.ReadByteAsync().ConfigureAwait(false); if (blockId < 0) throw GifHelpers.UnexpectedEndOfStreamException(); switch (blockId) { case GifExtension.ExtensionIntroducer: return await GifExtension.ReadAsync(stream, controlExtensions).ConfigureAwait(false); case GifFrame.ImageSeparator: return await GifFrame.ReadAsync(stream, controlExtensions).ConfigureAwait(false); case GifTrailer.TrailerByte: return await GifTrailer.ReadAsync().ConfigureAwait(false); default: throw GifHelpers.UnknownBlockTypeException(blockId); } }
private async Task ReadFramesAsync(Stream stream) { List <GifFrame> frames = new List <GifFrame>(); List <GifExtension> controlExtensions = new List <GifExtension>(); List <GifExtension> specialExtensions = new List <GifExtension>(); GifBlock gifBlock; do { gifBlock = await GifBlock.ReadAsync(stream, (IEnumerable <GifExtension>) controlExtensions).ConfigureAwait(false); if (gifBlock.Kind == GifBlockKind.GraphicRendering) { controlExtensions = new List <GifExtension>(); } if (gifBlock is GifFrame) { frames.Add((GifFrame)gifBlock); } else if (gifBlock is GifExtension) { GifExtension gifExtension = (GifExtension)gifBlock; switch (gifExtension.Kind) { case GifBlockKind.Control: controlExtensions.Add(gifExtension); continue; case GifBlockKind.SpecialPurpose: specialExtensions.Add(gifExtension); continue; default: continue; } } }while (!(gifBlock is GifTrailer)); this.Frames = (IList <GifFrame>)frames.AsReadOnly(); this.Extensions = (IList <GifExtension>)specialExtensions.AsReadOnly(); }
internal static async Task <GifBlock> ReadAsync(Stream stream, IEnumerable <GifExtension> controlExtensions) { int blockId = await stream.ReadByteAsync(new CancellationToken()).ConfigureAwait(false); if (blockId < 0) { throw GifHelpers.UnexpectedEndOfStreamException(); } switch (blockId) { case 33: return((GifBlock)await GifExtension.ReadAsync(stream, controlExtensions).ConfigureAwait(false)); case 44: return((GifBlock)await GifFrame.ReadAsync(stream, controlExtensions).ConfigureAwait(false)); case 59: return((GifBlock)await GifTrailer.ReadAsync().ConfigureAwait(false)); default: throw GifHelpers.UnknownBlockTypeException(blockId); } }