internal void CompressTo(Stream outStream) { int i = 0, j = 0, r = 0, c = 0, a = 0, b = 0; int comp, xpos, ypos, xblockoffset, yblockoffset; byte[,] inputArray = null; float[,] dctArray1 = new float[8, 8]; float[,] dctArray2 = new float[8, 8]; int[] dctArray3 = new int[8 * 8]; int[] lastDCvalue = new int[_input.Image.ComponentCount]; int Width = 0, Height = 0; int MinBlockWidth, MinBlockHeight; // This initial setting of MinBlockWidth and MinBlockHeight is done to // ensure they start with values larger than will actually be the case. MinBlockWidth = ((_width % 8 != 0) ? (int)(Math.Floor((double)_width / 8.0) + 1) * 8 : _width); MinBlockHeight = ((_height % 8 != 0) ? (int)(Math.Floor((double)_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]); } xpos = 0; for (r = 0; r < MinBlockHeight; r++) { // Keep track of progress _progress.EncodeProgress = (double)r / MinBlockHeight; if (EncodeProgressChanged != null) { EncodeProgressChanged(this, _progress); } for (c = 0; c < MinBlockWidth; c++) { xpos = c * 8; ypos = r * 8; for (comp = 0; comp < _input.Image.ComponentCount; comp++) { Width = _input.BlockWidth[comp]; Height = _input.BlockHeight[comp]; inputArray = _input.Image.Raster[comp]; for (i = 0; i < _input.VsampFactor[comp]; i++) { for (j = 0; j < _input.HsampFactor[comp]; j++) { xblockoffset = j * 8; yblockoffset = i * 8; for (a = 0; a < 8; a++) { // set Y value. check bounds int y = ypos + yblockoffset + a; if (y >= _height) { break; } for (b = 0; b < 8; b++) { int x = xpos + xblockoffset + b; if (x >= _width) { break; } dctArray1[a, b] = inputArray[x, y]; } } dctArray2 = _dct.FastFDCT(dctArray1); dctArray3 = _dct.QuantizeBlock(dctArray2, JpegEncoder.QtableNumber[comp]); _huf.HuffmanBlockEncoder(outStream, dctArray3, lastDCvalue[comp], JpegEncoder.DCtableNumber[comp], JpegEncoder.ACtableNumber[comp]); lastDCvalue[comp] = dctArray3[0]; } } } } } _huf.FlushBuffer(outStream); }
internal void CompressTo(Stream outStream) { int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; byte[,] array = null; float[,] array2 = new float[8, 8]; float[,] array3 = new float[8, 8]; int[] array4 = new int[64]; int[] array5 = new int[_input.Image.ComponentCount]; int num7 = (_width % 8 != 0) ? ((int)(Math.Floor((double)_width / 8.0) + 1.0) * 8) : _width; int num8 = (_height % 8 != 0) ? ((int)(Math.Floor((double)_height / 8.0) + 1.0) * 8) : _height; for (int i = 0; i < _input.Image.ComponentCount; i++) { num7 = Math.Min(num7, _input.BlockWidth[i]); num8 = Math.Min(num8, _input.BlockHeight[i]); } int num9 = 0; for (num3 = 0; num3 < num8; num3++) { _progress.EncodeProgress = (double)num3 / (double)num8; if (this.EncodeProgressChanged != null) { this.EncodeProgressChanged(this, _progress); } for (num4 = 0; num4 < num7; num4++) { num9 = num4 * 8; int num10 = num3 * 8; for (int i = 0; i < _input.Image.ComponentCount; i++) { array = _input.Image.Raster[i]; for (num = 0; num < _input.VsampFactor[i]; num++) { for (num2 = 0; num2 < _input.HsampFactor[i]; num2++) { int num11 = num2 * 8; int num12 = num * 8; for (num5 = 0; num5 < 8; num5++) { int num13 = num10 + num12 + num5; if (num13 >= _height) { break; } for (num6 = 0; num6 < 8; num6++) { int num14 = num9 + num11 + num6; if (num14 >= _width) { break; } array2[num5, num6] = (int)array[num14, num13]; } } array3 = _dct.FastFDCT(array2); array4 = _dct.QuantizeBlock(array3, QtableNumber[i]); _huf.HuffmanBlockEncoder(outStream, array4, array5[i], DCtableNumber[i], ACtableNumber[i]); array5[i] = array4[0]; } } } } } _huf.FlushBuffer(outStream); }