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

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

            var len1 = imgInfo.SamplesPerRow;
            var len0 = imgInfo.SamplesPerRowPacked;

            if (dst is null || dst.Length < len1)
            {
                dst = new byte[len1];
            }

            if (imgInfo.Packed)
            {
                ImageLine.UnpackInplaceByte(imgInfo, src, dst, scale);
            }
            else
            {
                Array.Copy(src, 0, dst, 0, len0);
            }

            return(dst);
        }
Example #2
0
        private void DecodeLastReadRowToByte(byte[] buffer, int bytesRead)
        {            // see http://www.libpng.org/pub/png/spec/1.2/PNG-DataRep.html
            if (ImgInfo.BitDepth <= 8)
            {
                Array.Copy(rowb, 1, buffer, 0, bytesRead);
            }
            else
            { // 16 bitspc
                for (int i = 0, j = 1; j < bytesRead; i++, j += 2)
                {
                    buffer[i] = rowb[j]; // 16 bits in 1 byte: this discards the LSB!!!
                }
            }

            if (ImgInfo.Packed && unpackedMode)
            {
                ImageLine.UnpackInplaceByte(ImgInfo, buffer, buffer, false);
            }
        }