public void PostProcess <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            string imageFile = provider.SourceFileOrDescription;

            using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile))
                using (var pp = new JpegImagePostProcessor(Configuration.Default, decoder))
                    using (var image = new Image <Rgba32>(decoder.ImageWidth, decoder.ImageHeight))
                    {
                        pp.PostProcess(image.Frames.RootFrame);

                        image.DebugSave(provider);

                        ImagingTestCaseUtility testUtil = provider.Utility;
                        testUtil.TestGroupName = nameof(JpegDecoderTests);
                        testUtil.TestName      = JpegDecoderTests.DecodeBaselineJpegOutputName;

                        using (Image <TPixel> referenceImage =
                                   provider.GetReferenceOutputImage <TPixel>(appendPixelTypeToFileName: false))
                        {
                            ImageSimilarityReport report = ImageComparer.Exact.CompareImagesOrFrames(referenceImage, image);

                            this.Output.WriteLine($"*** {imageFile} ***");
                            this.Output.WriteLine($"Difference: {report.DifferencePercentageString}");

                            // ReSharper disable once PossibleInvalidOperationException
                            Assert.True(report.TotalNormalizedDifference.Value < 0.005f);
                        }
                    }
        }
        public void ColorSpace_IsDeducedCorrectly(string imageFile, object expectedColorSpaceValue)
        {
            var expectedColorSpace = (JpegColorSpace)expectedColorSpaceValue;

            using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile))
            {
                Assert.Equal(expectedColorSpace, decoder.ColorSpace);
            }
        }
Beispiel #3
0
            public void LLM_IDCT_IsEquivalentTo_AccurateImplementation(int seed, int range)
            {
                float[] sourceArray = JpegFixture.Create8x8RoundedRandomFloatData(-range, range, seed);

                var source = Block8x8F.Load(sourceArray);

                Block8x8F expected = ReferenceImplementations.AccurateDCT.TransformIDCT(ref source);

                Block8x8F actual = ReferenceImplementations.LLM_FloatingPoint_DCT.TransformIDCT(ref source);

                this.CompareBlocks(expected, actual, 0.1f);
            }
Beispiel #4
0
            public void LLM_ForwardThenInverse(int seed, int startAt)
            {
                int[]   data     = JpegFixture.Create8x8RandomIntData(-1000, 1000, seed);
                float[] original = data.ConvertAllToFloat();
                float[] src      = data.ConvertAllToFloat();
                float[] dest     = new float[64];
                float[] temp     = new float[64];

                ReferenceImplementations.LLM_FloatingPoint_DCT.fDCT2D_llm(src, dest, temp, true);
                ReferenceImplementations.LLM_FloatingPoint_DCT.iDCT2D_llm(dest, src, temp);

                this.CompareBlocks(original, src, 0.1f);
            }
Beispiel #5
0
            public void ForwardThenInverse(int seed)
            {
                float[] data = JpegFixture.Create8x8RandomFloatData(-1000, 1000, seed);

                var b0 = default(Block8x8F);

                b0.LoadFrom(data);

                Block8x8F b1 = ReferenceImplementations.AccurateDCT.TransformFDCT(ref b0);
                Block8x8F b2 = ReferenceImplementations.AccurateDCT.TransformIDCT(ref b1);

                this.CompareBlocks(b0, b2, 1e-4f);
            }
Beispiel #6
0
            public void GT_IDCT_IsEquivalentTo_AccurateImplementation(int seed, int range)
            {
                int[]   intData  = JpegFixture.Create8x8RandomIntData(-range, range, seed);
                float[] floatSrc = intData.ConvertAllToFloat();

                ReferenceImplementations.AccurateDCT.TransformIDCTInplace(intData);

                float[] dest = new float[64];

                ReferenceImplementations.GT_FloatingPoint_DCT.iDCT8x8GT(floatSrc, dest);

                this.CompareBlocks(intData.ConvertAllToFloat(), dest, 1f);
            }
Beispiel #7
0
            public void LLM_FDCT_IsEquivalentTo_AccurateImplementation(int seed)
            {
                float[] floatData = JpegFixture.Create8x8RandomFloatData(-1000, 1000);

                Block8x8F source = default;

                source.LoadFrom(floatData);

                Block8x8F expected = ReferenceImplementations.AccurateDCT.TransformFDCT(ref source);
                Block8x8F actual   = ReferenceImplementations.LLM_FloatingPoint_DCT.TransformFDCT_UpscaleBy8(ref source);

                actual /= 8;

                this.CompareBlocks(expected, actual, 1f);
            }
Beispiel #8
0
            public void LLM_TransformIDCT_CompareToAccurate(int seed)
            {
                float[] sourceArray = JpegFixture.Create8x8RoundedRandomFloatData(-1000, 1000, seed);

                var source = Block8x8F.Load(sourceArray);

                Block8x8F expected = ReferenceImplementations.AccurateDCT.TransformIDCT(ref source);

                var temp   = default(Block8x8F);
                var actual = default(Block8x8F);

                FastFloatingPointDCT.TransformIDCT(ref source, ref actual, ref temp);

                this.CompareBlocks(expected, actual, 1f);
            }
        public void PrintComponentData(string imageFile)
        {
            var sb = new StringBuilder();

            using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile))
            {
                sb.AppendLine(imageFile);
                sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}");
                JpegComponent c0 = decoder.Components[0];
                JpegComponent c1 = decoder.Components[1];

                sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}");
                sb.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}");
            }
            this.Output.WriteLine(sb.ToString());
        }
Beispiel #10
0
        public void ComponentScalingIsCorrect_1ChannelJpeg()
        {
            using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(TestImages.Jpeg.Baseline.Jpeg400))
            {
                Assert.Equal(1, decoder.ComponentCount);
                Assert.Equal(1, decoder.Components.Length);

                Size expectedSizeInBlocks = decoder.ImageSizeInPixels.DivideRoundUp(8);

                Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU);

                var           uniform1 = new Size(1, 1);
                JpegComponent c0       = decoder.Components[0];
                VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1);
            }
        }
        public void DoProcessorStep <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            string imageFile = provider.SourceFileOrDescription;

            using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile))
                using (var pp = new JpegImagePostProcessor(Configuration.Default, decoder))
                    using (var imageFrame = new ImageFrame <Rgba32>(Configuration.Default, decoder.ImageWidth, decoder.ImageHeight))
                    {
                        pp.DoPostProcessorStep(imageFrame);

                        JpegComponentPostProcessor[] cp = pp.ComponentProcessors;

                        SaveBuffer(cp[0], provider);
                        SaveBuffer(cp[1], provider);
                        SaveBuffer(cp[2], provider);
                    }
        }
Beispiel #12
0
            public void FDCT8x4_RightPart(int seed)
            {
                Span <float> src      = JpegFixture.Create8x8RoundedRandomFloatData(-200, 200, seed);
                var          srcBlock = new Block8x8F();

                srcBlock.LoadFrom(src);

                var destBlock = new Block8x8F();

                float[] expectedDest = new float[64];

                ReferenceImplementations.LLM_FloatingPoint_DCT.fDCT2D8x4_32f(src.Slice(4), expectedDest.AsSpan(4));
                FastFloatingPointDCT.FDCT8x4_RightPart(ref srcBlock, ref destBlock);

                float[] actualDest = new float[64];
                destBlock.CopyTo(actualDest);

                Assert.Equal(actualDest, expectedDest, new ApproximateFloatComparer(1f));
            }
Beispiel #13
0
            public void TransformFDCT(int seed)
            {
                Span <float> src      = JpegFixture.Create8x8RoundedRandomFloatData(-200, 200, seed);
                var          srcBlock = new Block8x8F();

                srcBlock.LoadFrom(src);

                var destBlock = new Block8x8F();

                float[] expectedDest = new float[64];
                float[] temp1        = new float[64];
                var     temp2        = new Block8x8F();

                ReferenceImplementations.LLM_FloatingPoint_DCT.fDCT2D_llm(src, expectedDest, temp1, downscaleBy8: true);
                FastFloatingPointDCT.TransformFDCT(ref srcBlock, ref destBlock, ref temp2, false);

                float[] actualDest = new float[64];
                destBlock.CopyTo(actualDest);

                Assert.Equal(actualDest, expectedDest, new ApproximateFloatComparer(1f));
            }
Beispiel #14
0
            public void ForwardThenInverse(int seed, int startAt)
            {
                Span <int> original = JpegFixture.Create8x8RandomIntData(-200, 200, seed);

                Span <int> block = original.AddScalarToAllValues(128);

                ReferenceImplementations.StandardIntegerDCT.Subtract128_TransformFDCT_Upscale8_Inplace(block);

                for (int i = 0; i < 64; i++)
                {
                    block[i] /= 8;
                }

                ReferenceImplementations.StandardIntegerDCT.TransformIDCTInplace(block);

                for (int i = startAt; i < 64; i++)
                {
                    float expected = original[i];
                    float actual   = (float)block[i];

                    Assert.Equal(expected, actual, new ApproximateFloatComparer(3f));
                }
            }
Beispiel #15
0
        public void ComponentScalingIsCorrect_MultiChannelJpeg(
            string imageFile,
            int componentCount,
            object expectedLumaFactors,
            object expectedChromaFactors)
        {
            var fLuma   = (Size)expectedLumaFactors;
            var fChroma = (Size)expectedChromaFactors;

            using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile))
            {
                Assert.Equal(componentCount, decoder.ComponentCount);
                Assert.Equal(componentCount, decoder.Components.Length);

                JpegComponent c0 = decoder.Components[0];
                JpegComponent c1 = decoder.Components[1];
                JpegComponent c2 = decoder.Components[2];

                var uniform1 = new Size(1, 1);

                Size expectedLumaSizeInBlocks = decoder.ImageSizeInMCU.MultiplyBy(fLuma);

                Size divisor = fLuma.DivideBy(fChroma);

                Size expectedChromaSizeInBlocks = expectedLumaSizeInBlocks.DivideRoundUp(divisor);

                VerifyJpeg.VerifyComponent(c0, expectedLumaSizeInBlocks, fLuma, uniform1);
                VerifyJpeg.VerifyComponent(c1, expectedChromaSizeInBlocks, fChroma, divisor);
                VerifyJpeg.VerifyComponent(c2, expectedChromaSizeInBlocks, fChroma, divisor);

                if (componentCount == 4)
                {
                    JpegComponent c3 = decoder.Components[2];
                    VerifyJpeg.VerifyComponent(c3, expectedLumaSizeInBlocks, fLuma, uniform1);
                }
            }
        }
Beispiel #16
0
            public void iDCT2D8x4_RightPart()
            {
                float[] sourceArray       = JpegFixture.Create8x8FloatData();
                float[] expectedDestArray = new float[64];

                ReferenceImplementations.LLM_FloatingPoint_DCT.iDCT2D8x4_32f(sourceArray.AsSpan(4), expectedDestArray.AsSpan(4));

                var source = new Block8x8F();

                source.LoadFrom(sourceArray);

                var dest = new Block8x8F();

                FastFloatingPointDCT.IDCT8x4_RightPart(ref source, ref dest);

                float[] actualDestArray = new float[64];
                dest.CopyTo(actualDestArray);

                this.Print8x8Data(expectedDestArray);
                this.Output.WriteLine("**************");
                this.Print8x8Data(actualDestArray);

                Assert.Equal(expectedDestArray, actualDestArray);
            }