Browse Source

bugfix in GifDecoderCore.Identity

af/merge-core
denisivan0v 8 years ago
parent
commit
35e2a08348
  1. 11
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 59
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  3. 1
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj

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

@ -180,17 +180,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
{
if (nextFlag == GifConstants.ImageLabel)
{
GifImageDescriptor imageDescriptor = this.ReadImageDescriptor();
// Determine the color table for this frame. If there is a local one, use it otherwise use the global color table.
if (imageDescriptor.LocalColorTableFlag)
{
int length = imageDescriptor.LocalColorTableSize * 3;
// Skip local color table block
this.Skip(length);
}
// Skip image block
this.Skip(0);
}

59
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -3,11 +3,19 @@
using System.IO;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
namespace SixLabors.ImageSharp.Tests
{
using System;
public class GeneralFormatTests : FileTestBase
{
[Theory]
@ -146,5 +154,56 @@ namespace SixLabors.ImageSharp.Tests
}
}
}
[Theory]
[InlineData(10, 10, "png")]
[InlineData(100, 100, "png")]
[InlineData(100, 10, "png")]
[InlineData(10, 100, "png")]
[InlineData(10, 10, "gif")]
[InlineData(100, 100, "gif")]
[InlineData(100, 10, "gif")]
[InlineData(10, 100, "gif")]
[InlineData(10, 10, "bmp")]
[InlineData(100, 100, "bmp")]
[InlineData(100, 10, "bmp")]
[InlineData(10, 100, "bmp")]
[InlineData(10, 10, "jpg")]
[InlineData(100, 100, "jpg")]
[InlineData(100, 10, "jpg")]
[InlineData(10, 100, "jpg")]
public void CanIdentifyImageLoadedFromBytes(int width, int height, string format)
{
using (Image<Rgba32> image = Image.LoadPixelData(new Rgba32[width * height], width, height))
{
using (var memoryStream = new MemoryStream())
{
image.Save(memoryStream, GetEncoder(format));
memoryStream.Position = 0;
var imageInfo = Image.Identify(memoryStream);
Assert.Equal(imageInfo.Width, width);
Assert.Equal(imageInfo.Height, height);
}
}
}
private static IImageEncoder GetEncoder(string format)
{
switch (format)
{
case "png":
return new PngEncoder();
case "gif":
return new GifEncoder();
case "bmp":
return new BmpEncoder();
case "jpg":
return new JpegEncoder();
default:
throw new ArgumentOutOfRangeException(nameof(format), format, null);
}
}
}
}

1
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -17,6 +17,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CoreCompat.System.Drawing" Version="1.0.0-beta006" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" />
<PackageReference Include="Moq" Version="4.7.137" />

Loading…
Cancel
Save