public void Encode_Lossy_WithAlpha_Works <TPixel>(TestImageProvider <TPixel> provider, bool compressed) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy, UseAlphaCompression = compressed }; using Image <TPixel> image = provider.GetImage(); image.VerifyEncoder(provider, "webp", $"with_alpha_compressed_{compressed}", encoder, ImageComparer.Tolerant(0.04f)); }
public void Encode_Lossy_WorksWithTestPattern <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { using Image <TPixel> image = provider.GetImage(); var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy }; image.VerifyEncoder(provider, "webp", string.Empty, encoder, ImageComparer.Tolerant(0.04f)); }
public void Encode_Lossless_WithPalette_Works <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless, Quality = 100, Method = WebpEncodingMethod.BestQuality }; using Image <TPixel> image = provider.GetImage(); image.VerifyEncoder(provider, "webp", string.Empty, encoder); }
public static void RunEncodeLossy_WithPeakImage() { var provider = TestImageProvider <Rgba32> .File(TestImageLossyFullPath); using Image <Rgba32> image = provider.GetImage(); var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy }; image.VerifyEncoder(provider, "webp", string.Empty, encoder, ImageComparer.Tolerant(0.04f)); }
public void Encode_Lossless_WithDifferentQuality_Works <TPixel>(TestImageProvider <TPixel> provider, int quality) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless, Quality = quality }; using Image <TPixel> image = provider.GetImage(); string testOutputDetails = string.Concat("lossless", "_q", quality); image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); }
public void Encode_Lossy_WithDifferentSpatialNoiseShapingStrength_Works <TPixel>(TestImageProvider <TPixel> provider, int snsStrength) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy, SpatialNoiseShaping = snsStrength }; using Image <TPixel> image = provider.GetImage(); string testOutputDetails = string.Concat("lossy", "_sns", snsStrength); image.VerifyEncoder(provider, "webp", testOutputDetails, encoder, customComparer: GetComparer(75)); }
public void Encode_Lossless_OneByOnePixel_Works() { // Just make sure, encoding 1 pixel by 1 pixel does not throw an exception. using var image = new Image <Rgba32>(1, 1); var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless }; using (var memStream = new MemoryStream()) { image.SaveAsWebp(memStream, encoder); } }
public void Encode_Lossy_WithDifferentMethodsAndQuality_Works <TPixel>(TestImageProvider <TPixel> provider, WebpEncodingMethod method, int quality) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy, Method = method, Quality = quality }; using Image <TPixel> image = provider.GetImage(); string testOutputDetails = string.Concat("lossy", "_m", method, "_q", quality); image.VerifyEncoder(provider, "webp", testOutputDetails, encoder, customComparer: GetComparer(quality)); }
public void Encode_Lossless_WithPreserveTransparentColor_Works <TPixel>(TestImageProvider <TPixel> provider, WebpEncodingMethod method) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless, Method = method, TransparentColorMode = WebpTransparentColorMode.Preserve }; using Image <TPixel> image = provider.GetImage(); string testOutputDetails = string.Concat("lossless", "_m", method); image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); }
public void Encode_Lossless_WithNearLosslessFlag_Works <TPixel>(TestImageProvider <TPixel> provider, int nearLosslessQuality) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless, NearLossless = true, NearLosslessQuality = nearLosslessQuality }; using Image <TPixel> image = provider.GetImage(); string testOutputDetails = string.Concat("nearlossless", "_q", nearLosslessQuality); image.VerifyEncoder(provider, "webp", testOutputDetails, encoder, customComparer: GetComparer(nearLosslessQuality)); }
public void Encode_Lossless_WithBestQuality_HasExpectedSize <TPixel>(TestImageProvider <TPixel> provider, int expectedBytes) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless, Method = WebpEncodingMethod.BestQuality }; using Image <TPixel> image = provider.GetImage(); using var memoryStream = new MemoryStream(); image.Save(memoryStream, encoder); Assert.Equal(memoryStream.Length, expectedBytes); }
public void Encode_PreserveRatio <TPixel>(TestImageProvider <TPixel> provider, WebpFileFormatType expectedFormat) where TPixel : unmanaged, IPixel <TPixel> { var options = new WebpEncoder(); using Image <TPixel> input = provider.GetImage(); using var memoryStream = new MemoryStream(); input.Save(memoryStream, options); memoryStream.Position = 0; using var output = Image.Load <Rgba32>(memoryStream); ImageMetadata meta = output.Metadata; WebpMetadata webpMetaData = meta.GetWebpMetadata(); Assert.Equal(expectedFormat, webpMetaData.FileFormat); }