Browse Source

Added Skip extension to support streams that cannot seek.

af/merge-core
dirk 9 years ago
parent
commit
c188e5aa79
  1. 25
      src/ImageSharp/Common/Extensions/StreamExtensions.cs
  2. 6
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  3. 2
      src/ImageSharp/Formats/Png/PngDecoderCore.cs

25
src/ImageSharp/Common/Extensions/StreamExtensions.cs

@ -0,0 +1,25 @@
// <copyright file="StreamExtensions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System.IO;
internal static class StreamExtensions
{
public static void Skip(this Stream stream, int count)
{
if (stream.CanSeek)
{
stream.Position += count;
}
else
{
byte[] foo = new byte[count];
stream.Read(foo, 0, count);
}
}
}
}

6
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -59,7 +59,7 @@ namespace ImageSharp.Formats
this.currentStream = stream;
// Skip the identifier
this.currentStream.Seek(6, SeekOrigin.Current);
this.currentStream.Skip(6);
this.ReadLogicalScreenDescriptor();
if (this.logicalScreenDescriptor.GlobalColorTableFlag)
@ -192,13 +192,13 @@ namespace ImageSharp.Formats
/// <param name="length">The number of bytes to skip.</param>
private void Skip(int length)
{
this.currentStream.Seek(length, SeekOrigin.Current);
this.currentStream.Skip(length);
int flag;
while ((flag = this.currentStream.ReadByte()) != 0)
{
this.currentStream.Seek(flag, SeekOrigin.Current);
this.currentStream.Skip(flag);
}
}

2
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -116,7 +116,7 @@ namespace ImageSharp.Formats
{
Image<TColor, TPacked> currentImage = image;
this.currentStream = stream;
this.currentStream.Seek(8, SeekOrigin.Current);
this.currentStream.Skip(8);
bool isEndChunkReached = false;

Loading…
Cancel
Save