Browse Source

Avoid encoding the same image twice

pull/2173/head
Brian Popow 4 years ago
parent
commit
7d0838f97c
  1. 2
      tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs
  2. 29
      tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
  3. 5
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

2
tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs

@ -5,7 +5,7 @@ using SixLabors.ImageSharp.Formats.Webp.Lossy;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.WebP
namespace SixLabors.ImageSharp.Tests.Formats.Webp
{
[Trait("Format", "Webp")]
public class Vp8ResidualTests

29
tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs

@ -269,9 +269,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
}
[Theory]
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, false)]
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, true)]
public void Encode_Lossy_WithAlpha_Works<TPixel>(TestImageProvider<TPixel> provider, bool compressed)
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, false, 64020)]
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, true, 16200)]
public void Encode_Lossy_WithAlpha_Works<TPixel>(TestImageProvider<TPixel> provider, bool compressed, int expectedFileSize)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
@ -281,33 +281,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
};
using Image<TPixel> image = provider.GetImage();
image.VerifyEncoder(
string encodedFile = image.VerifyEncoder(
provider,
"webp",
$"with_alpha_compressed_{compressed}",
encoder,
ImageComparer.Tolerant(0.04f),
referenceDecoder: new MagickReferenceDecoder());
}
[Theory]
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32)]
public void Encode_Lossy_WithCompressedAlpha_AlphaShouldBeSmaller<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
{
FileFormat = WebpFileFormatType.Lossy,
UseAlphaCompression = true
};
using Image<TPixel> image = provider.GetImage();
using (var memoryStream = new MemoryStream())
{
image.SaveAsWebp(memoryStream, encoder);
int size = memoryStream.ToArray().Length;
Assert.True(size < 16300);
}
int encodedBytes = File.ReadAllBytes(encodedFile).Length;
Assert.True(encodedBytes <= expectedFileSize);
}
[Theory]

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

@ -661,7 +661,8 @@ namespace SixLabors.ImageSharp.Tests
/// Loads the expected image with a reference decoder + compares it to <paramref name="image"/>.
/// Also performs a debug save using <see cref="ImagingTestCaseUtility.SaveTestOutputFile{TPixel}"/>.
/// </summary>
internal static void VerifyEncoder<TPixel>(
/// <returns>The path to the encoded output file.</returns>
internal static string VerifyEncoder<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
string extension,
@ -687,6 +688,8 @@ namespace SixLabors.ImageSharp.Tests
ImageComparer comparer = customComparer ?? ImageComparer.Exact;
comparer.VerifySimilarity(encodedImage, image);
}
return actualOutputFile;
}
internal static AllocatorBufferCapacityConfigurator LimitAllocatorBufferCapacity<TPixel>(

Loading…
Cancel
Save