// Benchmark, enable manually! // [Theory] // [InlineData(1, 75, JpegSubsample.Ratio420)] // [InlineData(30, 75, JpegSubsample.Ratio420)] // [InlineData(30, 75, JpegSubsample.Ratio444)] // [InlineData(30, 100, JpegSubsample.Ratio444)] public void EncodeJpeg(int executionCount, int quality, JpegSubsample subsample) { string[] testFiles = TestImages.Bmp.All .Concat(new[] { TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk }) .ToArray(); Image <Rgba32>[] testImages = testFiles.Select( tf => TestImageProvider <Rgba32> .File(tf, pixelTypeOverride: PixelTypes.Rgba32).GetImage()) .ToArray(); using (MemoryStream ms = new MemoryStream()) { this.Measure(executionCount, () => { foreach (Image <Rgba32> img in testImages) { JpegEncoder options = new JpegEncoder { Quality = quality, Subsample = subsample }; img.Save(ms, options); ms.Seek(0, SeekOrigin.Begin); } }, // ReSharper disable once ExplicitCallerInfoArgument $@"Encode {testFiles.Length} images" ); } }
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 EncodeJpeg(int executionCount, int quality, JpegColorType colorType) { // do not run this on CI even by accident if (TestEnvironment.RunsOnCI) { return; } string[] testFiles = TestImages.Bmp.Benchmark .Concat(new[] { TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk }).ToArray(); Image <Rgba32>[] testImages = testFiles.Select( tf => TestImageProvider <Rgba32> .File(tf, pixelTypeOverride: PixelTypes.Rgba32).GetImage()).ToArray(); using (var ms = new MemoryStream()) { this.Measure( executionCount, () => { foreach (Image <Rgba32> img in testImages) { var options = new JpegEncoder { Quality = quality, ColorType = colorType }; img.Save(ms, options); ms.Seek(0, SeekOrigin.Begin); } }, #pragma warning disable SA1515 // Single-line comment should be preceded by blank line // ReSharper disable once ExplicitCallerInfoArgument $@"Encode {testFiles.Length} images"); #pragma warning restore SA1515 // Single-line comment should be preceded by blank line } foreach (Image <Rgba32> image in testImages) { image.Dispose(); } }