protected void encodeRowFromInt(int[] row) { if (row.Length == ImgInfo.SamplesPerRowPacked && !needsPack) { // some duplication of code - because this case is typical and it works faster this way int j = 1; if (ImgInfo.BitDepth <= 8) foreach (int x in row) // optimized rowb[j++] = (byte)x; else // 16 bitspc foreach (int x in row) { // optimized rowb[j++] = (byte)(x >> 8); rowb[j++] = (byte)x; } } else { // perhaps we need to pack? if (row.Length >= ImgInfo.SamplesPerRow && needsPack) ImageLine.packInplaceInt(ImgInfo, row, row, false); // row is packed in place! if (ImgInfo.BitDepth <= 8) for (int i = 0, j = 1; i < ImgInfo.SamplesPerRowPacked; i++) rowb[j++] = (byte)row[i]; else // 16 bitspc for (int i = 0, j = 1; i < ImgInfo.SamplesPerRowPacked; i++) { rowb[j++] = (byte)(row[i] >> 8); rowb[j++] = (byte)row[i]; } } }
public static int[] Pack(ImageInfo imgInfo, int[] src, int[] dst, bool scale) { int len0 = imgInfo.SamplesPerRowPacked; if (dst == null || dst.Length < len0) { dst = new int[len0]; } if (imgInfo.Packed) { ImageLine.packInplaceInt(imgInfo, src, dst, scale); } else { Array.Copy(src, 0, dst, 0, len0); } return(dst); }
public void encodeRowFromInt(int[] row) { if (row.Length == ImgInfo.SamplesPerRowPacked && !needsPack) { int num = 1; if (ImgInfo.BitDepth <= 8) { foreach (int num2 in row) { rowb[num++] = (byte)num2; } return; } foreach (int num3 in row) { rowb[num++] = (byte)(num3 >> 8); rowb[num++] = (byte)num3; } return; } if (row.Length >= ImgInfo.SamplesPerRow && needsPack) { ImageLine.packInplaceInt(ImgInfo, row, row, scaled: false); } if (ImgInfo.BitDepth <= 8) { int j = 0; int num4 = 1; for (; j < ImgInfo.SamplesPerRowPacked; j++) { rowb[num4++] = (byte)row[j]; } return; } int k = 0; int num5 = 1; for (; k < ImgInfo.SamplesPerRowPacked; k++) { rowb[num5++] = (byte)(row[k] >> 8); rowb[num5++] = (byte)row[k]; } }