Exemplo n.º 1
0
        public void IDCTInto()
        {
            float[] sourceArray       = Create8x8FloatData();
            float[] expectedDestArray = new float[64];
            float[] tempArray         = new float[64];

            ReferenceImplementations.iDCT2D_llm(sourceArray, expectedDestArray, tempArray);

            //ReferenceImplementations.iDCT8x8_llm_sse(sourceArray, expectedDestArray, tempArray);

            Block8x8F source = new Block8x8F();

            source.LoadFrom(sourceArray);

            Block8x8F dest       = new Block8x8F();
            Block8x8F tempBuffer = new Block8x8F();

            source.TransformIDCTInto(ref dest, ref tempBuffer);

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

            Print8x8Data(expectedDestArray);
            Output.WriteLine("**************");
            Print8x8Data(actualDestArray);
            Assert.Equal(expectedDestArray, actualDestArray, new ApproximateFloatComparer());
            Assert.Equal(expectedDestArray, actualDestArray, new ApproximateFloatComparer());
        }
Exemplo n.º 2
0
        public void TransformIDCT(int seed)
        {
            var sourceArray = Create8x8RandomFloatData(-200, 200, seed);

            float[] expectedDestArray = new float[64];
            float[] tempArray         = new float[64];

            ReferenceImplementations.iDCT2D_llm(sourceArray, expectedDestArray, tempArray);

            // ReferenceImplementations.iDCT8x8_llm_sse(sourceArray, expectedDestArray, tempArray);
            Block8x8F source = new Block8x8F();

            source.LoadFrom(sourceArray);

            Block8x8F dest       = new Block8x8F();
            Block8x8F tempBuffer = new Block8x8F();

            DCT.TransformIDCT(ref source, ref dest, ref tempBuffer);

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

            this.Print8x8Data(expectedDestArray);
            this.Output.WriteLine("**************");
            this.Print8x8Data(actualDestArray);
            Assert.Equal(expectedDestArray, actualDestArray, new ApproximateFloatComparer(1f));
            Assert.Equal(expectedDestArray, actualDestArray, new ApproximateFloatComparer(1f));
        }
            public void CopyTo(int horizontalFactor, int verticalFactor)
            {
                Block8x8F block = CreateRandomFloatBlock(0, 100);

                var start = new Point(50, 50);

                using (Buffer2D <float> buffer = Configuration.Default.MemoryAllocator.Allocate2D <float>(100, 100, AllocationOptions.Clean))
                {
                    BufferArea <float> area = buffer.GetArea(start.X, start.Y, 8 * horizontalFactor, 8 * verticalFactor);
                    block.CopyTo(area, horizontalFactor, verticalFactor);

                    for (int y = 0; y < 8 * verticalFactor; y++)
                    {
                        for (int x = 0; x < 8 * horizontalFactor; x++)
                        {
                            int yy = y / verticalFactor;
                            int xx = x / horizontalFactor;

                            float expected = block[xx, yy];
                            float actual   = area[x, y];

                            Assert.Equal(expected, actual);
                        }
                    }

                    VerifyAllZeroOutsideSubArea(buffer, start.X, start.Y, horizontalFactor, verticalFactor);
                }
            }
Exemplo n.º 4
0
            public void iDCT2D8x4_RightPart()
            {
                float[] sourceArray       = Create8x8FloatData();
                var     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);

                var actualDestArray = new float[64];

                dest.CopyTo(actualDestArray);

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

                Assert.Equal(expectedDestArray, actualDestArray);
            }
Exemplo n.º 5
0
            public static Block8x8F TransformFDCT_UpscaleBy8(ref Block8x8F source)
            {
                float[] s = new float[64];
                source.CopyTo(s);
                float[] d    = new float[64];
                float[] temp = new float[64];

                fDCT2D_llm(s, d, temp);
                Block8x8F result = default;

                result.LoadFrom(d);
                return(result);
            }
Exemplo n.º 6
0
            public static Block8x8F TransformIDCT(ref Block8x8F source)
            {
                var s = new float[64];

                source.CopyTo(s);
                var d    = new float[64];
                var temp = new float[64];

                iDCT2D_llm(s, d, temp);
                Block8x8F result = default;

                result.LoadFrom(d);
                return(result);
            }
            //[Fact]
            public void Unscaled()
            {
                Block8x8F block = CreateRandomFloatBlock(0, 100);

                using (var buffer = Configuration.Default.MemoryManager.Allocate2D <float>(20, 20))
                {
                    BufferArea <float> area = buffer.GetArea(5, 10, 8, 8);
                    block.CopyTo(area);

                    Assert.Equal(block[0, 0], buffer[5, 10]);
                    Assert.Equal(block[1, 0], buffer[6, 10]);
                    Assert.Equal(block[0, 1], buffer[5, 11]);
                    Assert.Equal(block[0, 7], buffer[5, 17]);
                    Assert.Equal(block[63], buffer[12, 17]);

                    VerifyAllZeroOutsideSubArea(buffer, 5, 10);
                }
            }
Exemplo n.º 8
0
        public void TransposeInto()
        {
            float[] expected = Create8x8FloatData();
            ReferenceImplementations.Transpose8x8(expected);

            var source = new Block8x8F();

            source.LoadFrom(Create8x8FloatData());

            var dest = new Block8x8F();

            source.TransposeInto(ref dest);

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

            Assert.Equal(expected, actual);
        }
Exemplo n.º 9
0
        public void Load_Store_FloatArray()
        {
            float[] data   = new float[Block8x8F.ScalarCount];
            float[] mirror = new float[Block8x8F.ScalarCount];

            for (int i = 0; i < Block8x8F.ScalarCount; i++)
            {
                data[i] = i;
            }
            Measure(Times, () =>
            {
                Block8x8F b = new Block8x8F();
                b.LoadFrom(data);
                b.CopyTo(mirror);
            });

            Assert.Equal(data, mirror);
            //PrintLinearData((MutableSpan<float>)mirror);
        }
Exemplo n.º 10
0
            public void FDCT8x4_RightPart(int seed)
            {
                Span <float> src      = 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));
            }
Exemplo n.º 11
0
        public void FDCT8x4_RightPart(int seed)
        {
            var src      = Create8x8RandomFloatData(-200, 200, seed);
            var srcBlock = new Block8x8F();

            srcBlock.LoadFrom(src);

            var destBlock = new Block8x8F();

            var expectedDest = new MutableSpan <float>(64);

            ReferenceImplementations.fDCT2D8x4_32f(src.Slice(4), expectedDest.Slice(4));
            DCT.FDCT8x4_RightPart(ref srcBlock, ref destBlock);

            var actualDest = new MutableSpan <float>(64);

            destBlock.CopyTo(actualDest);

            Assert.Equal(actualDest.Data, expectedDest.Data, new ApproximateFloatComparer(1f));
        }
Exemplo n.º 12
0
            public void TransformFDCT(int seed)
            {
                Span <float> src      = 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));
            }
Exemplo n.º 13
0
        public void TransformByteConvetibleColorValuesInto()
        {
            Block8x8F block = new Block8x8F();
            var       input = Create8x8ColorCropTestData();

            block.LoadFrom(input);
            this.Output.WriteLine("Input:");
            this.PrintLinearData(input);

            Block8x8F dest = new Block8x8F();

            block.TransformByteConvetibleColorValuesInto(ref dest);

            float[] array = new float[64];
            dest.CopyTo(array);
            this.Output.WriteLine("Result:");
            this.PrintLinearData(array);
            foreach (float val in array)
            {
                Assert.InRange(val, 0, 255);
            }
        }
Exemplo n.º 14
0
        public void NormalizeColors()
        {
            var block = default(Block8x8F);

            float[] input = Create8x8ColorCropTestData();
            block.LoadFrom(input);
            this.Output.WriteLine("Input:");
            this.PrintLinearData(input);

            Block8x8F dest = block;

            dest.NormalizeColorsInplace(255);

            float[] array = new float[64];
            dest.CopyTo(array);
            this.Output.WriteLine("Result:");
            this.PrintLinearData(array);
            foreach (float val in array)
            {
                Assert.InRange(val, 0, 255);
            }
        }
Exemplo n.º 15
0
        public void TransformFDCT(int seed)
        {
            var src      = Create8x8RandomFloatData(-200, 200, seed);
            var srcBlock = new Block8x8F();

            srcBlock.LoadFrom(src);

            var destBlock = new Block8x8F();

            var expectedDest = new MutableSpan <float>(64);
            var temp1        = new MutableSpan <float>(64);
            var temp2        = new Block8x8F();

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

            var actualDest = new MutableSpan <float>(64);

            destBlock.CopyTo(actualDest);

            Assert.Equal(actualDest.Data, expectedDest.Data, new ApproximateFloatComparer(1f));
        }
Exemplo n.º 16
0
        public void Load_Store_IntArray()
        {
            int[] data   = new int[Block8x8F.ScalarCount];
            int[] mirror = new int[Block8x8F.ScalarCount];

            for (int i = 0; i < Block8x8F.ScalarCount; i++)
            {
                data[i] = i;
            }

            this.Measure(
                Times,
                () =>
            {
                Block8x8F v = new Block8x8F();
                v.LoadFrom(data);
                v.CopyTo(mirror);
            });

            Assert.Equal(data, mirror);

            // PrintLinearData((MutableSpan<int>)mirror);
        }
Exemplo n.º 17
0
        public void Load_Store_IntArray()
        {
            var data   = new int[Block8x8F.Size];
            var mirror = new int[Block8x8F.Size];

            for (int i = 0; i < Block8x8F.Size; i++)
            {
                data[i] = i;
            }

            this.Measure(
                Times,
                () =>
            {
                var v = new Block8x8F();
                v.LoadFrom(data);
                v.CopyTo(mirror);
            });

            Assert.Equal(data, mirror);

            // PrintLinearData((Span<int>)mirror);
        }
Exemplo n.º 18
0
        public void Load_Store_FloatArray()
        {
            float[] data   = new float[Block8x8F.Size];
            float[] mirror = new float[Block8x8F.Size];

            for (int i = 0; i < Block8x8F.Size; i++)
            {
                data[i] = i;
            }

            this.Measure(
                Times,
                () =>
            {
                var b = new Block8x8F();
                b.LoadFrom(data);
                b.CopyTo(mirror);
            });

            Assert.Equal(data, mirror);

            // PrintLinearData((Span<float>)mirror);
        }
Exemplo n.º 19
0
        public unsafe void Load_Store_FloatArray_Ptr()
        {
            var data   = new float[Block8x8F.Size];
            var mirror = new float[Block8x8F.Size];

            for (int i = 0; i < Block8x8F.Size; i++)
            {
                data[i] = i;
            }

            this.Measure(
                Times,
                () =>
            {
                var b = new Block8x8F();
                Block8x8F.LoadFrom(&b, data);
                Block8x8F.CopyTo(&b, mirror);
            });

            Assert.Equal(data, mirror);

            // PrintLinearData((Span<float>)mirror);
        }
Exemplo n.º 20
0
        public void iDCT2D8x4_LeftPart()
        {
            float[] sourceArray       = Create8x8FloatData();
            float[] expectedDestArray = new float[64];

            ReferenceImplementations.iDCT2D8x4_32f(sourceArray, expectedDestArray);

            Block8x8F source = new Block8x8F();

            source.LoadFrom(sourceArray);

            Block8x8F dest = new Block8x8F();

            source.IDCT8x4_LeftPart(ref dest);

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

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

            Assert.Equal(expectedDestArray, actualDestArray);
        }
Exemplo n.º 21
0
        public void iDCT2D8x4_RightPart()
        {
            MutableSpan <float> sourceArray       = Create8x8FloatData();
            MutableSpan <float> expectedDestArray = new float[64];

            ReferenceImplementations.iDCT2D8x4_32f(sourceArray.Slice(4), expectedDestArray.Slice(4));

            Block8x8F source = new Block8x8F();

            source.LoadFrom(sourceArray);

            Block8x8F dest = new Block8x8F();

            DCT.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.Data, actualDestArray);
        }