public void DCTComparisonTest() { const int maxVariance = 2; var source = new float[8][]; var destAan = new float[8][]; var destNvidia = new float[8][]; for (int i = 0; i < 8; i++) { source[i] = new float[] { 100, 110, 120, 130, 140, 150, 160, 170 }; destAan[i] = new float[8]; destNvidia[i] = new float[8]; } var dct = new DCT(20); dct.DoDCT_AAN(source, destAan); dct.DoDCT_NVidia(source, destNvidia); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { float diff = Math.Abs(destAan[i][j] - destNvidia[i][j]); float ratio = destAan[i][j] / destNvidia[i][j]; Debug.WriteLine("aan={0}, nvidia={1}, diff={2}, ratio={3}", destAan[i][j], destNvidia[i][j], diff, ratio); Assert.IsTrue(diff <= maxVariance); } } }
public void DCTPerformanceTest() { const int runs = 5; const int iterations = 100000; var aanPerf = new PerformanceMonitor("AAN", runs); var nvidiaPerf = new PerformanceMonitor("NVidia", runs); var source = new float[8][]; var destAan = new float[8][]; var destNvidia = new float[8][]; for (int i = 0; i < 8; i++) { source[i] = new float[] { 100, 110, 120, 130, 140, 150, 160, 170 }; destAan[i] = new float[8]; destNvidia[i] = new float[8]; } var dct = new DCT(20); for (int run = 0; run < runs; run++) { aanPerf.Start(); for (int i = 0; i < iterations; i++) { dct.DoDCT_AAN(source, destAan); } aanPerf.Stop(); nvidiaPerf.Start(); for (int i = 0; i < iterations; i++) { dct.DoDCT_NVidia(source, destNvidia); } nvidiaPerf.Stop(); } // We don't really care at this point -- they're very close. // Assert.IsTrue(nvidiaPerf.AverageCompletionTimeInMs > aanPerf.AverageCompletionTimeInMs); }
internal void CompressTo(Stream outStream) { int comp; var lastDCvalue = new int[input.Image.ComponentCount]; var buffer = new HuffmanBuffer(outStream); // This initial setting of MinBlockWidth and MinBlockHeight is done to // ensure they start with values larger than will actually be the case. int minBlockWidth = ((width % 8 != 0) ? (int)(Math.Floor(width / 8.0) + 1) * 8 : width); int minBlockHeight = ((height % 8 != 0) ? (int)(Math.Floor(height / 8.0) + 1) * 8 : height); for (comp = 0; comp < input.Image.ComponentCount; comp++) { minBlockWidth = Math.Min(minBlockWidth, input.BlockWidth[comp]); minBlockHeight = Math.Min(minBlockHeight, input.BlockHeight[comp]); } for (int r = 0; r < minBlockHeight; r++) { for (int c = 0; c < minBlockWidth; c++) { int xpos = c * 8; int ypos = r * 8; for (comp = 0; comp < input.Image.ComponentCount; comp++) { byte[][] inputArray = input.Image.Raster[comp]; for (int i = 0; i < input.VSampFactor[comp]; i++) { for (int j = 0; j < input.VSampFactor[comp]; j++) { int xblockoffset = j * 8; int yblockoffset = i * 8; for (int a = 0; a < 8; a++) { // set Y value. check bounds int y = ypos + yblockoffset + a; if (y >= height) { break; } for (int b = 0; b < 8; b++) { int x = xpos + xblockoffset + b; if (x >= width) { break; } dctArray1[a][b] = inputArray[x][y]; } } dct.DoDCT_AAN(dctArray1, dctArray2); dct.QuantizeBlock(dctArray2, FrameDefaults.QtableNumber[comp], dctArray3); huf.HuffmanBlockEncoder(buffer, dctArray3, lastDCvalue[comp], FrameDefaults.DCtableNumber[comp], FrameDefaults.ACtableNumber[comp]); lastDCvalue[comp] = dctArray3[0]; } } } } } buffer.FlushBuffer(); }