Ejemplo n.º 1
0
        public void RGBToYCbCrPerformanceTest()
        {
            byte[]    rgba       = GetRgba(1);
            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 (int p = 0; p < rgba.Length; p++)
                    {
                        byte b = rgba[p++];
                        byte g = rgba[p++];
                        byte r = rgba[p++];
                        YCbCr.fromRGBSlow(ref r, ref g, ref b);
                    }
                }
                slowPerf.Stop();

                fastPerf.Start();
                for (int i = 0; i < iterations; i++)
                {
                    for (int p = 0; p < rgba.Length; p++)
                    {
                        byte b = rgba[p++];
                        byte g = rgba[p++];
                        byte r = rgba[p++];
                        YCbCr.fromRGB(ref r, ref g, ref b);
                    }
                }
                fastPerf.Stop();
            }
#if !DEBUG
            // This is only true when running with the optimized JIT.
            Assert.IsTrue(fastPerf.AverageCompletionTimeInMs < slowPerf.AverageCompletionTimeInMs,
                          "The fast conversion method took {0:0.00} ms, while the slow took {1:0.00}", fastPerf.AverageCompletionTimeInMs, slowPerf.AverageCompletionTimeInMs);
#endif
        }
Ejemplo n.º 2
0
        public void RGBToYCbCrTest()
        {
            const int maxVariance = 1;

            byte[] rgba = GetRgba(1);
            for (int i = 0; i < rgba.Length; i++)
            {
                byte b2 = rgba[i];
                byte b1 = rgba[i++];
                byte g2 = rgba[i];
                byte g1 = rgba[i++];
                byte r2 = rgba[i];
                byte r1 = rgba[i++];
                YCbCr.fromRGBSlow(ref r1, ref g1, ref b1);
                YCbCr.fromRGB(ref r2, ref g2, ref b2);
                Assert.IsTrue(Math.Abs(r1 - r2) <= maxVariance);
                Assert.IsTrue(Math.Abs(g1 - g2) <= maxVariance);
                Assert.IsTrue(Math.Abs(b1 - b2) <= maxVariance);
            }
        }