Exemple #1
0
        private unsafe void LoadDistTree()
        {
            int n, m, p, code;

            AcedUtils.Fill(0, _pBitLen, AcedConsts.DistCount);
            LoadCharDistLengths(GetNBits(6) + 1);
            AcedUtils.Fill(0, _pDistTree, AcedConsts.DistTreeSize);
            _pNextCode[1]  = 0;
            _pNextCode[2]  = n = _pBitCount[1] << 1;
            _pNextCode[3]  = n = (n + _pBitCount[2]) << 1;
            _pNextCode[4]  = n = (n + _pBitCount[3]) << 1;
            _pNextCode[5]  = n = (n + _pBitCount[4]) << 1;
            _pNextCode[6]  = n = (n + _pBitCount[5]) << 1;
            _pNextCode[7]  = n = (n + _pBitCount[6]) << 1;
            _pNextCode[8]  = n = (n + _pBitCount[7]) << 1;
            _pNextCode[9]  = n = (n + _pBitCount[8]) << 1;
            _pNextCode[10] = n = (n + _pBitCount[9]) << 1;
            _pNextCode[11] = n = (n + _pBitCount[10]) << 1;
            _pNextCode[12] = n = (n + _pBitCount[11]) << 1;
            _pNextCode[13] = n = (n + _pBitCount[12]) << 1;
            _pNextCode[14] = n = (n + _pBitCount[13]) << 1;
            int treeLen = 2;

            for (int i = 0; i < AcedConsts.DistCount; i++)
            {
                n = _pBitLen[i];
                if (n == 0)
                {
                    continue;
                }
                m             = _pNextCode[n];
                code          = (int)AcedUtils.ReverseBits((uint)m, n);
                _pNextCode[n] = m + 1;
                p             = 1;
                while (true)
                {
                    p     += code & 1;
                    code >>= 1;
                    n--;
                    if (n != 0)
                    {
                        m = p;
                        p = _pDistTree[p];
                        if (p == 0)
                        {
                            p             = treeLen + 1;
                            treeLen       = p + 1;
                            _pDistTree[m] = p;
                        }
                    }
                    else
                    {
                        _pDistTree[p] = -i;
                        break;
                    }
                }
            }
        }
Exemple #2
0
        private unsafe void LoadChLenTree()
        {
            int n, m, p, i, code;

            AcedUtils.Fill(0, _pBitCount, AcedConsts.MaxChLenBits + 1);
            for (i = 0; i < AcedConsts.ChLenCount; i++)
            {
                n           = GetNBits(3);
                _pBitLen[i] = n;
                _pBitCount[n]++;
            }
            AcedUtils.Fill(0, _pChLenTree, AcedConsts.ChLenTreeSize);
            _pNextCode[1] = 0;
            _pNextCode[2] = n = _pBitCount[1] << 1;
            _pNextCode[3] = n = (n + _pBitCount[2]) << 1;
            _pNextCode[4] = n = (n + _pBitCount[3]) << 1;
            _pNextCode[5] = n = (n + _pBitCount[4]) << 1;
            _pNextCode[6] = n = (n + _pBitCount[5]) << 1;
            _pNextCode[7] = n = (n + _pBitCount[6]) << 1;
            int treeLen = 2;

            for (i = 0; i < AcedConsts.ChLenCount; i++)
            {
                n = _pBitLen[i];
                if (n == 0)
                {
                    continue;
                }
                m             = _pNextCode[n];
                code          = (int)AcedUtils.ReverseBits((uint)m, n);
                _pNextCode[n] = m + 1;
                p             = 1;
                while (true)
                {
                    p     += code & 1;
                    code >>= 1;
                    n--;
                    if (n != 0)
                    {
                        m = p;
                        p = _pChLenTree[p];
                        if (p == 0)
                        {
                            p              = treeLen + 1;
                            treeLen        = p + 1;
                            _pChLenTree[m] = p;
                        }
                    }
                    else
                    {
                        _pChLenTree[p] = -i;
                        break;
                    }
                }
            }
        }
Exemple #3
0
        private unsafe void LoadCharDistLengths(int count)
        {
            int  c, lastLen = 0;
            int *p = _pBitLen;

            AcedUtils.Fill(0, _pBitCount, AcedConsts.MaxBits + 1);
            while (count > 0)
            {
                c = GetCode(_pChLenTree);
                if (c < 15)
                {
                    *p = c;
                    _pBitCount[c]++;
                    p++;
                    lastLen = c;
                    count--;
                }
                else
                {
                    if (c < 17)
                    {
                        if (c == 15)
                        {
                            c = 2;
                        }
                        else
                        {
                            c = GetBit() + 3;
                        }
                    }
                    else if (c == 17)
                    {
                        c = GetNBits(2) + 5;
                    }
                    else if (c == 18)
                    {
                        c = GetNBits(3) + 9;
                    }
                    else
                    {
                        c = GetNBits(7) + 17;
                    }
                    count -= c;
                    _pBitCount[lastLen] += c;
                    do
                    {
                        c--;
                        *p = lastLen;
                        p++;
                    } while (c != 0);
                }
            }
        }