public ITablePart GetTablePart(IRectangle rectangle) { var excelReferenceToCell = internalTable .GetSortedCellsInRange(new ExcelCellIndex(rectangle.UpperLeft.CellReference), new ExcelCellIndex(rectangle.LowerRight.CellReference)) .Select(cell => new ExcelCell(cell)) .ToDictionary(cell => cell.CellPosition.CellReference); var subTableSize = rectangle.Size; var subTable = JaggedArrayHelper.CreateJaggedArray <ICell[][]>(subTableSize.Height, subTableSize.Width); for (var x = rectangle.UpperLeft.ColumnIndex; x <= rectangle.LowerRight.ColumnIndex; ++x) { for (var y = rectangle.UpperLeft.RowIndex; y <= rectangle.LowerRight.RowIndex; ++y) { if (!excelReferenceToCell.TryGetValue(new CellPosition(y, x).CellReference, out var cell)) { cell = new ExcelCell(internalTable.InsertCell(new ExcelCellIndex(y, x))); } subTable[y - rectangle.UpperLeft.RowIndex][x - rectangle.UpperLeft.ColumnIndex] = cell; } } return(new ExcelTablePart(subTable)); }
public FakeTable(int width, int height) { this.width = width; this.height = height; cells = JaggedArrayHelper.CreateJaggedArray <ICell[][]>(height, width); mergedCells = new List <IRectangle>(); }
public ITablePart GetTablePart(IRectangle rectangle) { if (OutOfBounds(rectangle.UpperLeft) || OutOfBounds(rectangle.LowerRight)) { return(null); } var subTableSize = rectangle.Size; var subTable = JaggedArrayHelper.CreateJaggedArray <ICell[][]>(subTableSize.Height, subTableSize.Width); for (var y = 0; y < subTableSize.Height; ++y) { for (var x = 0; x < subTableSize.Width; ++x) { var sourceCell = cells[rectangle.UpperLeft.RowIndex + y - 1][rectangle.UpperLeft.ColumnIndex + x - 1]; subTable[y][x] = sourceCell ?? new FakeCell(new CellPosition(y + 1, x + 1)); } } return(new FakeTablePart(subTable)); }
/// <summary> /// Initialisation of the Huffman codes for Luminance and Chrominance. /// This code results in the same tables created in the IJG Jpeg-6a /// library. /// </summary> private void initHuf() { DC_matrix0 = JaggedArrayHelper.Create2DJaggedArray <int>(12, 2); // new int[12, 2]; DC_matrix1 = JaggedArrayHelper.Create2DJaggedArray <int>(12, 2); // new int[12, 2]; AC_matrix0 = JaggedArrayHelper.Create2DJaggedArray <int>(255, 2); // new int[255, 2]; AC_matrix1 = JaggedArrayHelper.Create2DJaggedArray <int>(255, 2); // new int[255, 2]; DC_matrix = new int[2][][]; AC_matrix = new int[2][][]; int p, l, i, lastp, si, code; int[] huffsize = new int[257]; int[] huffcode = new int[257]; short[] bitsDCchrominance = JpegHuffmanTable.StdDCChrominance.Lengths; short[] bitsACchrominance = JpegHuffmanTable.StdAcChrominance.Lengths; short[] bitsDCluminance = JpegHuffmanTable.StdDCLuminance.Lengths; short[] bitsACluminance = JpegHuffmanTable.StdAcLuminance.Lengths; short[] valDCchrominance = JpegHuffmanTable.StdDCChrominance.Values; short[] valACchrominance = JpegHuffmanTable.StdAcChrominance.Values; short[] valDCluminance = JpegHuffmanTable.StdDCLuminance.Values; short[] valACluminance = JpegHuffmanTable.StdAcLuminance.Values; /* * init of the DC values for the chrominance * [,0] is the code [,1] is the number of bit */ p = 0; for (l = 0; l < 16; l++) { for (i = 1; i <= bitsDCchrominance[l]; i++) { huffsize[p++] = l + 1; } } huffsize[p] = 0; lastp = p; code = 0; si = huffsize[0]; p = 0; while (huffsize[p] != 0) { while (huffsize[p] == si) { huffcode[p++] = code; code++; } code <<= 1; si++; } for (p = 0; p < lastp; p++) { DC_matrix1[valDCchrominance[p]][0] = huffcode[p]; DC_matrix1[valDCchrominance[p]][1] = huffsize[p]; } /* * Init of the AC hufmann code for the chrominance * matrix [,,0] is the code & matrix[,,1] is the number of bit needed */ p = 0; for (l = 0; l < 16; l++) { for (i = 1; i <= bitsACchrominance[l]; i++) { huffsize[p++] = l + 1; } } huffsize[p] = 0; lastp = p; code = 0; si = huffsize[0]; p = 0; while (huffsize[p] != 0) { while (huffsize[p] == si) { huffcode[p++] = code; code++; } code <<= 1; si++; } for (p = 0; p < lastp; p++) { AC_matrix1[valACchrominance[p]][0] = huffcode[p]; AC_matrix1[valACchrominance[p]][1] = huffsize[p]; } /* * init of the DC values for the luminance * [,0] is the code [,1] is the number of bit */ p = 0; for (l = 0; l < 16; l++) { for (i = 1; i <= bitsDCluminance[l]; i++) { huffsize[p++] = l + 1; } } huffsize[p] = 0; lastp = p; code = 0; si = huffsize[0]; p = 0; while (huffsize[p] != 0) { while (huffsize[p] == si) { huffcode[p++] = code; code++; } code <<= 1; si++; } for (p = 0; p < lastp; p++) { DC_matrix0[valDCluminance[p]][0] = huffcode[p]; DC_matrix0[valDCluminance[p]][1] = huffsize[p]; } /* * Init of the AC hufmann code for luminance * matrix [,,0] is the code & matrix[,,1] is the number of bit */ p = 0; for (l = 0; l < 16; l++) { for (i = 1; i <= bitsACluminance[l]; i++) { huffsize[p++] = l + 1; } } huffsize[p] = 0; lastp = p; code = 0; si = huffsize[0]; p = 0; while (huffsize[p] != 0) { while (huffsize[p] == si) { huffcode[p++] = code; code++; } code <<= 1; si++; } for (int q = 0; q < lastp; q++) { AC_matrix0[valACluminance[q]][0] = huffcode[q]; AC_matrix0[valACluminance[q]][1] = huffsize[q]; } DC_matrix[0] = DC_matrix0; DC_matrix[1] = DC_matrix1; AC_matrix[0] = AC_matrix0; AC_matrix[1] = AC_matrix1; }