Hjg.Pngcs.PngWriter.encodeRowFromInt C# (CSharp) Method

encodeRowFromInt() protected method

protected encodeRowFromInt ( int row ) : void
row int
return void
        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]);
                    }
                }

            }
        }