private static async Task <Animator> CreateAsync(Stream sourceStream, Uri sourceUri, RepeatBehavior repeatBehavior, Image image) { Stream stream = sourceStream.AsBuffered(); GifDataStream metadata = await GifDataStream.ReadAsync(stream); return(new Animator(stream, sourceUri, metadata, repeatBehavior, image)); }
internal static async Task<TAnimator> CreateAsyncCore<TAnimator>( Stream sourceStream, Func<GifDataStream, TAnimator> create) where TAnimator : Animator { var metadata = await GifDataStream.ReadAsync(sourceStream); return create(metadata); }
internal static async Task <TAnimator> CreateAsyncCore <TAnimator>( Stream sourceStream, Func <GifDataStream, TAnimator> create) where TAnimator : Animator { if (!sourceStream.CanSeek) { throw new ArgumentException("The stream is not seekable"); } sourceStream.Seek(0, SeekOrigin.Begin); var metadata = await GifDataStream.ReadAsync(sourceStream); return(create(metadata)); }
private static async Task DecompressAllFramesAsync(string path) { using var fileStream = File.OpenRead(path); var gif = await GifDataStream.ReadAsync(fileStream); for (int i = 0; i < gif.Frames.Count; i++) { var frame = gif.Frames[i]; fileStream.Seek(frame.ImageData.CompressedDataStartOffset, SeekOrigin.Begin); using var ms = new MemoryStream(); await GifHelpers.CopyDataBlocksToStreamAsync(fileStream, ms); using var lzwStream = new LzwDecompressStream(ms.GetBuffer(), frame.ImageData.LzwMinimumCodeSize); using var indOutStream = File.OpenWrite($"{path}.{i}.ind"); await lzwStream.CopyToAsync(indOutStream); } }
private static async Task TestLzwDecompressionAsync(string path) { using (var fileStream = File.OpenRead(path)) { var gif = await GifDataStream.ReadAsync(fileStream); var firstFrame = gif.Frames[0]; fileStream.Seek(firstFrame.ImageData.CompressedDataStartOffset, SeekOrigin.Begin); using (var ms = new MemoryStream()) { await GifHelpers.CopyDataBlocksToStreamAsync(fileStream, ms); using (var lzwStream = new LzwDecompressStream(ms.GetBuffer(), firstFrame.ImageData.LzwMinimumCodeSize)) using (var indOutStream = File.OpenWrite(path + ".ind")) { await lzwStream.CopyToAsync(indOutStream); } } } }