Пример #1
0
        /// <summary>
        /// This will take a visit from a byte.  This will create new code entries as
        /// necessary.
        /// </summary>
        /// <param name="data">The byte to get a visit from.</param>
        public void Visit(byte data)
        {
            buffer.WriteByte(data);
            byte[] curBuffer = buffer.ToArray();

            LzwNode previous = null;
            LzwNode current  = this.Root;

            bool createNewCode = false;

            for (int i = 0; i < curBuffer.Length && current != null; i++)
            {
                previous = current;
                current  = current.GetNode(curBuffer[i]);
                if (current == null)
                {
                    createNewCode = true;
                    current       = new LzwNode();
                    previous.SetNode(curBuffer[i], current);
                }
            }

            if (createNewCode)
            {
                long code = nextCode++;
                current.Code = code;
                this.Add(code, curBuffer);

                buffer = new MemoryStream();
                buffer.WriteByte(data);
                resetCodeSize();
            }
        }
Пример #2
0
        public LzwNode GetNode(byte[] data)
        {
            LzwNode current = this;

            for (int i = 0; i < data.Length && current != null; i++)
            {
                current = current.GetNode(data[i]);
            }
            return(current);
        }
Пример #3
0
        /// <summary>
        /// This is the used for the LZWDecode filter.  This represents the dictionary mappings
        /// between codes and their values.
        /// </summary>
        /// <remarks>
        public LzwDictionary(int size) : base(size)
        {
            Root = new LzwNode();

            for (long i = 0; i < 256; i++)
            {
                LzwNode node = new LzwNode();
                node.Code = i;
                this.Root.SetNode((byte)i, node);
                this.Add(i, new byte[] { (byte)i });
            }
        }
Пример #4
0
 public void SetNode(byte b, LzwNode node)
 {
     subNodes.Add(b, node);
 }