Exemplo n.º 1
0
        public void YCbCrToRGBTest()
        {
            const int maxVariance = 1;

            byte[][][] raster = GetRaster();
            for (short y = 0; y < height; y++)
            {
                for (short x = 0; x < width; x++)
                {
                    // Convert values via slower method.
                    byte r1 = raster[yIndex][x][y];
                    byte g1 = raster[cbIndex][x][y];
                    byte b1 = raster[crIndex][x][y];
                    YCbCr.toRGBSlow(ref r1, ref g1, ref b1);

                    // Convert values via experimental faster method.
                    byte r2 = raster[yIndex][x][y];
                    byte g2 = raster[cbIndex][x][y];
                    byte b2 = raster[crIndex][x][y];
                    YCbCr.toRGB(ref r2, ref g2, ref b2);

                    Assert.IsTrue(Math.Abs(r1 - r2) <= maxVariance);
                    Assert.IsTrue(Math.Abs(r1 - r2) <= maxVariance);
                    Assert.IsTrue(Math.Abs(r1 - r2) <= maxVariance);
                }
            }
        }
Exemplo n.º 2
0
        public void YCbCrToRGBPerformanceTest()
        {
            byte[][][] raster     = GetRaster();
            const int  runs       = 20;
            const int  iterations = 100;
            var        slowPerf   = new PerformanceMonitor("TheoreticallySlower", runs);
            var        fastPerf   = new PerformanceMonitor("TheoreticallyFaster", runs);

            for (int run = 0; run < runs; run++)
            {
                slowPerf.Start();
                for (int i = 0; i < iterations; i++)
                {
                    for (short y = 0; y < height; y++)
                    {
                        for (short x = 0; x < width; x++)
                        {
                            byte r1 = raster[yIndex][x][y];
                            byte g1 = raster[cbIndex][x][y];
                            byte b1 = raster[crIndex][x][y];
                            YCbCr.toRGBSlow(ref r1, ref g1, ref b1);
                        }
                    }
                }
                slowPerf.Stop();

                fastPerf.Start();
                for (int i = 0; i < iterations; i++)
                {
                    for (short y = 0; y < height; y++)
                    {
                        for (short x = 0; x < width; x++)
                        {
                            byte r1 = raster[yIndex][x][y];
                            byte g1 = raster[cbIndex][x][y];
                            byte b1 = raster[crIndex][x][y];
                            YCbCr.toRGB(ref r1, ref g1, ref b1);
                        }
                    }
                }
                fastPerf.Stop();
            }
            Assert.IsTrue(fastPerf.AverageCompletionTimeInMs < slowPerf.AverageCompletionTimeInMs,
                          "The fast conversion method took {0:0.00} ms, while the slow method took {0:0.00} ms", fastPerf.AverageCompletionTimeInMs, slowPerf.AverageCompletionTimeInMs);
        }
Exemplo n.º 3
0
        private void GetUpsampledRgba(byte[][][] raster, byte[] frame)
        {
            // Convert the three-layer raster image to RGBA format.
            int pos = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int posBlue  = pos++;
                    int posGreen = pos++;
                    int posRed   = pos++;
                    frame[posRed]   = raster[yIndex][x][y];
                    frame[posGreen] = raster[cbIndex][x][y];
                    frame[posBlue]  = raster[crIndex][x][y];
                    YCbCr.toRGB(ref frame[posRed], ref frame[posGreen], ref frame[posBlue]);
                    frame[pos++] = alphaValue;
                }
            }
        }