private void ReadLZWImage(BinaryReader aReader, GIFImageBlock res)
        {
            byte initialCodeSize = aReader.ReadByte();
            var  bitReader       = new BitStreamReader(aReader);
            var  output          = new List <byte>();
            var  dict            = new Dict(initialCodeSize);
            long startPos        = aReader.BaseStream.Position;

            while (!bitReader.EndOfData)
            {
                int code = (int)bitReader.ReadBits(dict.bits);
                if (bitReader.EndOfData)
                {
                    break;
                }
                if (code == dict.ClearCode)
                {
                    dict.Clear();
                }
                else if (code == dict.EODCode)
                {
                    break;
                }
                else
                {
                    int pre = dict.Expand(code, output);
                    if (pre != -1 && dict.lastCode != -1)
                    {
                        dict.AddPair(dict.lastCode, (byte)pre);
                    }
                    dict.lastCode = code;
                }
            }
            if (!bitReader.EndOfData)
            {
                byte tmp = 1;
                while (tmp != 0 && aReader.BaseStream.Position < aReader.BaseStream.Length)
                {
                    tmp = aReader.ReadByte();
                }
            }
            res.packedSize = (int)(aReader.BaseStream.Position - startPos);
            res.data       = output;
            GIFLoader.Log("Image Data:" + output.Count + " (packed: " + res.packedSize + ")");
            GIFLoader.Log("X: " + res.xPos + "  Y: " + res.yPos);
            GIFLoader.Log("W: " + res.width + "  H: " + res.height);
            GIFLoader.Log("Winterlaced: " + res.IsInterlaced);
            GIFLoader.Log("---");
        }