public void RunDumpJpegCoeffsTool() { if (!TestEnvironment.IsWindows) { return; } string inputFile = TestFile.GetInputFileFullPath(TestImages.Jpeg.Progressive.Progress); string outputDir = TestEnvironment.CreateOutputDirectory(nameof(SpectralJpegTests)); string outputFile = Path.Combine(outputDir, "progress.dctdump"); LibJpegTools.RunDumpJpegCoeffsTool(inputFile, outputFile); Assert.True(File.Exists(outputFile)); }
private void VerifySpectralCorrectnessImpl <TPixel>( TestImageProvider <TPixel> provider, LibJpegTools.SpectralData imageSharpData) where TPixel : unmanaged, IPixel <TPixel> { LibJpegTools.SpectralData libJpegData = LibJpegTools.ExtractSpectralData(provider.SourceFileOrDescription); bool equality = libJpegData.Equals(imageSharpData); this.Output.WriteLine("Spectral data equality: " + equality); int componentCount = imageSharpData.ComponentCount; if (libJpegData.ComponentCount != componentCount) { throw new Exception("libJpegData.ComponentCount != componentCount"); } double averageDifference = 0; double totalDifference = 0; double tolerance = 0; this.Output.WriteLine("*** Differences ***"); for (int i = 0; i < componentCount; i++) { LibJpegTools.ComponentData libJpegComponent = libJpegData.Components[i]; LibJpegTools.ComponentData imageSharpComponent = imageSharpData.Components[i]; (double total, double average)diff = LibJpegTools.CalculateDifference(libJpegComponent, imageSharpComponent); this.Output.WriteLine($"Component{i}: {diff}"); averageDifference += diff.average; totalDifference += diff.total; tolerance += libJpegComponent.SpectralBlocks.GetSingleSpan().Length; } averageDifference /= componentCount; tolerance /= 64; // fair enough? this.Output.WriteLine($"AVERAGE: {averageDifference}"); this.Output.WriteLine($"TOTAL: {totalDifference}"); this.Output.WriteLine($"TOLERANCE = totalNumOfBlocks / 64 = {tolerance}"); Assert.True(totalDifference < tolerance); }
public void ExtractSpectralData <TPixel>(TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { if (!TestEnvironment.IsWindows) { return; } string testImage = provider.SourceFileOrDescription; LibJpegTools.SpectralData data = LibJpegTools.ExtractSpectralData(testImage); Assert.True(data.ComponentCount == 3); Assert.True(data.Components.Length == 3); VerifyJpeg.SaveSpectralImage(provider, data); // I knew this one well: if (testImage == TestImages.Jpeg.Progressive.Progress) { VerifyJpeg.VerifyComponentSizes3(data.Components, 43, 61, 22, 31, 22, 31); } }