/// <summary>
        /// Reads the specified scanline.
        /// </summary>
        /// <param name="scanline">The scanline.</param>
        /// <param name="pixels">The pixels, where the colors should be stored in RGBA format.</param>
        /// <param name="header">The header, which contains information about the png file, like
        /// the width of the image and the height.</param>
        public void ReadScanline(byte[] scanline, byte[] pixels, PngHeader header)
        {
            int offset = 0;

            byte[] newScanline = PngColorReader.ToArrayByBitsLength(scanline, header.BitDepth);

            if (_useAlpha)
            {
                for (int x = 0; x < header.Width / 2; x++)
                {
                    offset = (_row * header.Width + x) * 4;

                    pixels[offset + 0] = newScanline[x * 2];
                    pixels[offset + 1] = newScanline[x * 2];
                    pixels[offset + 2] = newScanline[x * 2];
                    pixels[offset + 3] = newScanline[x * 2 + 1];
                }
            }
            else
            {
                for (int x = 0; x < header.Width; x++)
                {
                    offset = (_row * header.Width + x) * 4;

                    pixels[offset + 0] = newScanline[x];
                    pixels[offset + 1] = newScanline[x];
                    pixels[offset + 2] = newScanline[x];
                    pixels[offset + 3] = (byte)255;
                }
            }

            _row++;
        }
Exemple #2
0
        /// <summary>
        /// Reads the specified scanline.
        /// </summary>
        /// <param name="scanline">The scanline.</param>
        /// <param name="pixels">The pixels, where the colors should be stored in RGBA format.</param>
        /// <param name="header">The header, which contains information about the png file, like
        /// the width of the image and the height.</param>
        public void ReadScanline(byte[] scanline, byte[] pixels, PngHeader header)
        {
            int offset = 0;

            byte[] newScanline = PngColorReader.ToArrayByBitsLength(scanline, header.BitDepth);

            if (_useAlpha)
            {
                for (int x = 0; x < newScanline.Length; x += 4)
                {
                    offset = (_row * header.Width + (x >> 2)) * 4;

                    pixels[offset + 0] = newScanline[x + 2];
                    pixels[offset + 1] = newScanline[x + 1];
                    pixels[offset + 2] = newScanline[x + 0];
                    pixels[offset + 3] = newScanline[x + 3];
                }
            }
            else
            {
                if (header.BitDepth == 8)
                {
                    for (int x = 0; x < newScanline.Length / 3; x++)
                    {
                        offset = (_row * header.Width + x) * 4;

                        pixels[offset + 0] = newScanline[x * 3 + 2];
                        pixels[offset + 1] = newScanline[x * 3 + 1];
                        pixels[offset + 2] = newScanline[x * 3 + 0];
                        pixels[offset + 3] = (byte)255;
                    }
                }
                else
                {
                    for (int x = 0; x < newScanline.Length / 6; x++)
                    {
                        offset = (_row * header.Width + x) * 4;

                        pixels[offset + 0] = newScanline[(x * 6 + 4)];
                        pixels[offset + 1] = newScanline[(x * 6 + 2)];
                        pixels[offset + 2] = newScanline[(x * 6 + 0)];
                        pixels[offset + 3] = (byte)255;
                    }
                }
            }

            _row++;
        }
        /// <summary>
        /// Reads the specified scanline.
        /// </summary>
        /// <param name="scanline">The scanline.</param>
        /// <param name="pixels">The pixels, where the colors should be stored in RGBA format.</param>
        /// <param name="header">The header, which contains information about the png file, like
        /// the width of the image and the height.</param>
        public void ReadScanline(byte[] scanline, byte[] pixels, PngHeader header)
        {
            byte[] newScanline = PngColorReader.ToArrayByBitsLength(scanline, header.BitDepth);

            int offset = 0, index = 0;

            if (_paletteAlpha != null && _paletteAlpha.Length > 0)
            {
                // If the alpha palette is not null and does one or
                // more entries, this means, that the image contains and alpha
                // channel and we should try to read it.
                for (int i = 0; i < header.Width; i++)
                {
                    index = newScanline[i];

                    offset = (_row * header.Width + i) * 4;

                    pixels[offset + 0] = _palette[index * 3 + 2];
                    pixels[offset + 1] = _palette[index * 3 + 1];
                    pixels[offset + 2] = _palette[index * 3 + 0];
                    pixels[offset + 3] = _paletteAlpha.Length > index ? _paletteAlpha[index] : (byte)255;
                }
            }
            else
            {
                for (int i = 0; i < header.Width; i++)
                {
                    index = newScanline[i];

                    offset = (_row * header.Width + i) * 4;

                    pixels[offset + 0] = _palette[index * 3 + 2];
                    pixels[offset + 1] = _palette[index * 3 + 1];
                    pixels[offset + 2] = _palette[index * 3 + 0];
                    pixels[offset + 3] = (byte)255;
                }
            }

            _row++;
        }