public PNGImage(System.IO.Stream inputStream)
        {
            validatePNG(inputStream);

            List <Chunk> chunks = new List <Chunk>();

            processPNG(chunks, inputStream);

            for (int i = 0; i < chunks.Count; i++)
            {
                Chunk chunk = chunks[i];
                if (chunk.type[0] == 'I' &&
                    chunk.type[1] == 'H' &&
                    chunk.type[2] == 'D' &&
                    chunk.type[3] == 'R')
                {
                    this.w         = toIntValue(chunk.GetData(), 0); // Width
                    this.h         = toIntValue(chunk.GetData(), 4); // Height
                    this.bitDepth  = chunk.GetData()[8];             // Bit Depth
                    this.colorType = chunk.GetData()[9];             // Color Type

                    // Console.WriteLine(
                    //         "Bit Depth == " + chunk.GetData()[ 8 ] );
                    // Console.WriteLine(
                    //         "Color Type == " + chunk.GetData()[ 9 ] );
                    // Console.WriteLine( chunk.GetData()[ 10 ] );
                    // Console.WriteLine( chunk.GetData()[ 11 ] );
                    // Console.WriteLine( chunk.GetData()[ 12 ] );
                }
                else if (chunk.type[0] == 'I' &&
                         chunk.type[1] == 'D' &&
                         chunk.type[2] == 'A' &&
                         chunk.type[3] == 'T')
                {
                    data = appendIdatChunk(data, chunk.GetData());
                }
                else if (chunk.type[0] == 'P' &&
                         chunk.type[1] == 'L' &&
                         chunk.type[2] == 'T' &&
                         chunk.type[3] == 'E')
                {
                    rgb = chunk.GetData();
                    if (rgb.Length % 3 != 0)
                    {
                        throw new Exception("Incorrect palette length.");
                    }
                }
            }

            inflated = getDecompressedData();

            if (colorType == 0)
            {
                // Grayscale Image
                if (bitDepth == 16)
                {
                    image = getImageColorType0BitDepth16();
                }
                else if (bitDepth == 8)
                {
                    image = getImageColorType0BitDepth8();
                }
                else if (bitDepth == 4)
                {
                    image = getImageColorType0BitDepth4();
                }
                else if (bitDepth == 2)
                {
                    image = getImageColorType0BitDepth2();
                }
                else if (bitDepth == 1)
                {
                    image = getImageColorType0BitDepth1();
                }
                else
                {
                    throw new Exception("Image with unsupported bit depth == " + bitDepth);
                }
            }
            else if (colorType == 6)
            {
                image = getImageColorType6BitDepth8();
            }
            else
            {
                // Color Image
                if (rgb == null)
                {
                    // Trucolor Image
                    if (bitDepth == 16)
                    {
                        image = getImageColorType2BitDepth16();
                    }
                    else
                    {
                        image = getImageColorType2BitDepth8();
                    }
                }
                else
                {
                    // Indexed Image
                    if (bitDepth == 8)
                    {
                        image = getImageColorType3BitDepth8();
                    }
                    else if (bitDepth == 4)
                    {
                        image = getImageColorType3BitDepth4();
                    }
                    else if (bitDepth == 2)
                    {
                        image = getImageColorType3BitDepth2();
                    }
                    else if (bitDepth == 1)
                    {
                        image = getImageColorType3BitDepth1();
                    }
                    else
                    {
                        throw new Exception("Image with unsupported bit depth == " + bitDepth);
                    }
                }
            }

            deflated = deflateReconstructedData();
        }