Ejemplo n.º 1
0
        public static huffmanobject drkDecompress(huffmanobject mysource)
        {
            byte[]     source      = mysource.buffer;
            byte[]     retval      = new byte[0];
            byte       current     = 0;
            int        val         = 0;
            BinaryNode currentNode = m_Tree;

            for (int i = 0; i < source.Length; i++)
            {
                mysource.out_size = i;
                current           = source[i];

                for (int n = 7; n >= 0; n--)
                {
                    int x = (current >> n) % 2;

                    if (x == 0)
                    {
                        currentNode = currentNode.Right;
                    }
                    else
                    {
                        currentNode = currentNode.Left;
                    }

                    if (currentNode.IsLeaf)
                    {
                        val         = currentNode.Value;
                        currentNode = m_Tree;

                        if (val == 256)
                        {
                            mysource.output = retval;
                            return(mysource);
                        }


                        byte[] temp = new byte[retval.Length + 1];
                        //retval.CopyTo(temp, 0);
                        //temp[0] = retval;
                        for (int j = 0; j < retval.Length; j++)
                        {
                            temp[j] = retval[j];
                        }
                        temp[temp.Length - 1] = (byte)val;
                        retval = new byte[temp.Length];
                        //temp.CopyTo(retval, 0);
                        //retval[0] = temp;
                        for (int j = 0; j < temp.Length; j++)
                        {
                            retval[j] = temp[j];
                        }
                        temp = null;
                    }
                }
            }
            mysource.output = retval;
            return(mysource);
        }
Ejemplo n.º 2
0
        public static huffmanobject drkDecompress(huffmanobject mysource)
        {
            byte[] source = mysource.buffer;
            byte[] retval = new byte[0];
            byte current = 0;
            int val = 0;
            BinaryNode currentNode = m_Tree;

            for(int i = 0; i < source.Length; i++)
            {
                mysource.out_size = i;
                current = source[i];

                for(int n = 7; n >= 0; n--)
                {
                    int x = (current >> n) % 2;

                    if(x == 0)
                            currentNode = currentNode.Right;
                    else
                            currentNode = currentNode.Left;

                    if(currentNode.IsLeaf)
                    {
                        val = currentNode.Value;
                        currentNode = m_Tree;

                        if(val == 256){
                                                mysource.output = retval;
                                                return mysource;
                                            }

                        byte[] temp = new byte[retval.Length + 1];
                        //retval.CopyTo(temp, 0);
                        //temp[0] = retval;
                        for (int j = 0; j < retval.Length; j++)
                            temp[j] = retval[j];
                        temp[temp.Length - 1] = (byte)val;
                        retval = new byte[temp.Length];
                        //temp.CopyTo(retval, 0);
                        //retval[0] = temp;
                        for (int j = 0; j < temp.Length; j++)
                            retval[j] = temp[j];
                        temp = null;
                    }
                }
            }
                    mysource.output = retval;
            return mysource;
        }