Example #1
0
        public static int[] Pack(ImageInfo imgInfo, int[] src, int[] dst, bool scale)
        {
            if (imgInfo is null)
            {
                throw new ArgumentNullException(nameof(imgInfo));
            }

            if (src is null)
            {
                throw new ArgumentNullException(nameof(src));
            }

            var len0 = imgInfo.SamplesPerRowPacked;

            if (dst is 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);
        }
Example #2
0
        private 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
                var j = 1;
                if (ImgInfo.BitDepth <= 8)
                {
                    foreach (var x in row)
                    { // optimized
                        rowb[j++] = (byte)x;
                    }
                }
                else
                {     // 16 bitspc
                    foreach (var 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]);
                    }
                }
            }
        }