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); } } }
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); }