Browse Source

Ensure pixel is assigned and add encoded comparison and

pull/527/head
James Jackson-South 8 years ago
parent
commit
1e4b61db52
  1. 2
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  2. 20
      tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs
  3. 37
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  4. 2
      tests/Images/External

2
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
{
ref TPixel entry = ref Unsafe.Add(ref paletteRef, i);
entry.ToRgb24(ref rgb);
Unsafe.Add(ref rgb24Ref, i);
Unsafe.Add(ref rgb24Ref, i) = rgb;
}
writer.Write(colorTable.Array, 0, colorTableLength);

20
tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs

@ -2,11 +2,11 @@
// Licensed under the Apache License, Version 2.0.
using System.IO;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Quantization;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit;
// ReSharper disable InconsistentNaming
@ -15,6 +15,7 @@ namespace SixLabors.ImageSharp.Tests
public class GifEncoderTests
{
private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32;
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.001F);
[Theory]
[WithTestPatternImages(100, 100, TestPixelTypes)]
@ -23,7 +24,22 @@ namespace SixLabors.ImageSharp.Tests
{
using (Image<TPixel> image = provider.GetImage())
{
provider.Utility.SaveTestOutputFile(image, "gif", new GifEncoder());
var encoder = new GifEncoder()
{
// Use the palette quantizer without dithering to ensure results
// are consistant
Quantizer = new PaletteQuantizer(false)
};
// Always save as we need to compare the encoded output.
provider.Utility.SaveTestOutputFile(image, "gif", encoder);
}
// Compare encoded result
string path = provider.Utility.GetTestOutputFileName("gif", null, true);
using (var encoded = Image.Load(path))
{
encoded.CompareToReferenceOutput(ValidatorComparer, provider, null, "gif");
}
}

37
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -87,6 +87,37 @@ namespace SixLabors.ImageSharp.Tests
return image;
}
/// <summary>
/// Saves the image only when not running in the CI server.
/// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam>
/// <param name="image">The image</param>
/// <param name="provider">The image provider</param>
/// <param name="encoder">The image encoder</param>
/// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
/// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the output file name.</param>
public static Image<TPixel> DebugSave<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
IImageEncoder encoder,
object testOutputDetails = null,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
if (TestEnvironment.RunsOnCI)
{
return image;
}
// We are running locally then we want to save it out
provider.Utility.SaveTestOutputFile(
image,
encoder: encoder,
testOutputDetails: testOutputDetails,
appendPixelTypeToFileName: appendPixelTypeToFileName);
return image;
}
public static Image<TPixel> DebugSaveMultiFrame<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
@ -168,7 +199,7 @@ namespace SixLabors.ImageSharp.Tests
provider,
testOutputDetails,
extension,
appendPixelTypeToFileName))
appendPixelTypeToFileName))
{
comparer.VerifySimilarity(referenceImage, image);
}
@ -272,7 +303,7 @@ namespace SixLabors.ImageSharp.Tests
}
Image<TPixel> firstTemp = temporaryFrameImages[0];
var result = new Image<TPixel>(firstTemp.Width, firstTemp.Height);
foreach (Image<TPixel> fi in temporaryFrameImages)
@ -345,7 +376,7 @@ namespace SixLabors.ImageSharp.Tests
{
return CompareToOriginal(image, provider, ImageComparer.Tolerant());
}
public static Image<TPixel> CompareToOriginal<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,

2
tests/Images/External

@ -1 +1 @@
Subproject commit 5a66c9c6da02bf27345f90adc05d415c0d0450ea
Subproject commit 01af5f36912ec7080cae3187a48905d1e54f6ea7
Loading…
Cancel
Save