예제 #1
0
            public override void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)
            {
                this.frame = frame;

                var spectralComponents = new LibJpegTools.ComponentData[frame.ComponentCount];

                for (int i = 0; i < spectralComponents.Length; i++)
                {
                    JpegComponent component = frame.Components[i];
                    spectralComponents[i] = new LibJpegTools.ComponentData(component.WidthInBlocks, component.HeightInBlocks, component.Index);
                }

                this.spectralData = new LibJpegTools.SpectralData(spectralComponents);
            }
예제 #2
0
        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);
        }