Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
(uint)width,
(uint)height,
hasAlpha,
alphaData,
alphaData.Slice(0, alphaDataSize),
this.alphaCompression && alphaCompressionSucceeded);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/ImageSharp.Tests/Formats/WebP/Vp8LHistogramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
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()
Expand Down
2 changes: 1 addition & 1 deletion tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand Down
18 changes: 14 additions & 4 deletions tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;

Expand Down Expand Up @@ -268,9 +269,9 @@ public void Encode_Lossy_WithDifferentMethodsAndQuality_Works<TPixel>(TestImageP
}

[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()
Expand All @@ -280,7 +281,16 @@ public void Encode_Lossy_WithAlpha_Works<TPixel>(TestImageProvider<TPixel> provi
};

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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public MagickReferenceDecoder()

public MagickReferenceDecoder(bool validate) => this.validate = validate;

public static MagickReferenceDecoder Instance { get; } = new MagickReferenceDecoder();
public static MagickReferenceDecoder Instance { get; } = new();

private static void FromRgba32Bytes<TPixel>(Configuration configuration, Span<byte> rgbaBytes, IMemoryGroup<TPixel> destinationGroup)
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel<TPixel>
Expand Down
5 changes: 4 additions & 1 deletion tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ internal static void VerifyOperation<TPixel>(
/// 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,
Expand All @@ -687,6 +688,8 @@ internal static void VerifyEncoder<TPixel>(
ImageComparer comparer = customComparer ?? ImageComparer.Exact;
comparer.VerifySimilarity(encodedImage, image);
}

return actualOutputFile;
}

internal static AllocatorBufferCapacityConfigurator LimitAllocatorBufferCapacity<TPixel>(
Expand Down