Ejemplo n.º 1
0
        /// <summary>
        /// Run the Inverse DCT method on all of the block data
        /// </summary>
        public void IdctData()
        {
            foreach (float[][][] t in scanData)
            {
                for (int v = 0; v < factorV; v++)
                {
                    for (int h = 0; h < factorH; h++)
                    {
                        float[] toDecode = t[h][v];
                        ZigZag.UnZigZag(toDecode, unZZ);
                        byte[][] decoded = scanDecodedBufferPool.GetNext();
                        switch (JpegConstants.SelectedIdct)
                        {
                        case IdctImplementation.Naive:
                            dct.DoIDCT_Naive(unZZ, decoded);
                            break;

                        case IdctImplementation.AAN:
                            dct.DoIDCT_AAN(unZZ, quantizationTable, decoded);
                            break;

                        case IdctImplementation.NVidia:
                            dct.DoIDCT_NVidia(unZZ, decoded);
                            break;
                        }
                        scanDecoded.Add(decoded);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void IDCTPerformanceTest()
        {
            var source = new float[]
            {
                560, -196, -150, -80, 0, 0, 0, 0,
                -210, -60, -35, 0, 0, 0, 0, 0,
                -140, -32, -40, 0, 0, 0, 0, 0,
                -70, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0
            };

            const int iterations = 100000;
            const int runs       = 5;
            var       naivePerf  = new PerformanceMonitor("Naive", runs);
            var       nvidiaPerf = new PerformanceMonitor("NVidia", runs);
            var       dct        = new DCT(20);

            var naive  = new byte[8][];
            var nvidia = new byte[8][];

            for (int i = 0; i < 8; i++)
            {
                naive[i]  = new byte[8];
                nvidia[i] = new byte[8];
            }

            for (int run = 0; run < runs; run++)
            {
                naivePerf.Start();
                for (int i = 0; i < iterations; i++)
                {
                    dct.DoIDCT_Naive(source, naive);
                }
                naivePerf.Stop();

                nvidiaPerf.Start();
                for (int i = 0; i < iterations; i++)
                {
                    dct.DoIDCT_NVidia(source, nvidia);
                }
                nvidiaPerf.Stop();
            }

            Assert.IsTrue(nvidiaPerf.AverageCompletionTimeInMs < naivePerf.AverageCompletionTimeInMs,
                          "The NVidia IDCT took {0:0.00} ms, while the naive IDCT took {1:0.00}", nvidiaPerf.AverageCompletionTimeInMs, naivePerf.AverageCompletionTimeInMs);
        }
Ejemplo n.º 3
0
        public void IDCTComparisonTest()
        {
            const int maxVariance = 1;
            var       source      = new float[]
            {
                560, -196, -150, -80, 0, 0, 0, 0,
                -210, -60, -35, 0, 0, 0, 0, 0,
                -140, -32, -40, 0, 0, 0, 0, 0,
                -70, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0
            };

            var dct = new DCT(20);

            var naive  = new byte[8][];
            var nvidia = new byte[8][];

            for (int i = 0; i < 8; i++)
            {
                naive[i]  = new byte[8];
                nvidia[i] = new byte[8];
            }

            dct.DoIDCT_Naive(source, naive);
            dct.DoIDCT_NVidia(source, nvidia);

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    int diff = Math.Abs(naive[i][j] - nvidia[i][j]);
                    // Debug.WriteLine("diff={0}", diff);
                    Assert.IsTrue(diff <= maxVariance);
                }
            }
        }