Browse Source

Merge branch 'main' into js/decoder-options

pull/2180/head
James Jackson-South 4 years ago
parent
commit
c823323d44
  1. 2
      src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs
  2. 3
      tests/ImageSharp.Tests/Formats/WebP/Vp8LHistogramTests.cs
  3. 2
      tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs
  4. 18
      tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
  5. 2
      tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs
  6. 3
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

2
src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs

@ -382,7 +382,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
(uint)width,
(uint)height,
hasAlpha,
alphaData,
alphaData.Slice(0, alphaDataSize),
this.alphaCompression && alphaCompressionSucceeded);
}

3
tests/ImageSharp.Tests/Formats/WebP/Vp8LHistogramTests.cs

@ -7,8 +7,9 @@ using SixLabors.ImageSharp.Formats.Webp.Lossless;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.WebP
namespace SixLabors.ImageSharp.Tests.Formats.Webp
{
[Trait("Format", "Webp")]
public class Vp8LHistogramTests
{
private static void RunAddVectorTest()

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

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

@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs;
using Xunit;
using static SixLabors.ImageSharp.Tests.TestImages.Webp;
@ -268,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()
@ -280,7 +281,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
};
using Image<TPixel> image = provider.GetImage();
image.VerifyEncoder(provider, "webp", $"with_alpha_compressed_{compressed}", encoder, ImageComparer.Tolerant(0.04f));
string encodedFile = image.VerifyEncoder(
provider,
"webp",
$"with_alpha_compressed_{compressed}",
encoder,
ImageComparer.Tolerant(0.04f),
referenceDecoder: new MagickReferenceDecoder());
int encodedBytes = File.ReadAllBytes(encodedFile).Length;
Assert.True(encodedBytes <= expectedFileSize);
}
[Theory]

2
tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
public MagickReferenceDecoder(bool validate) => this.validate = validate;
public static MagickReferenceDecoder Instance { get; } = new MagickReferenceDecoder();
public static MagickReferenceDecoder Instance { get; } = new();
public override Image<TPixel> DecodeSpecialized<TPixel>(MagickReferenceDecoderOptions options, Stream stream, CancellationToken cancellationToken)
{

3
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,

Loading…
Cancel
Save