Example #1
0
        public JArithmeticDecoderStats Copy()
        {
            JArithmeticDecoderStats stats;

            stats = new JArithmeticDecoderStats(m_contextSize);
            Array.Copy(m_cxTab, stats.m_cxTab, m_contextSize);
            return(stats);
        }
Example #2
0
        // Decode eight bits.
        public int DecodeByte(uint context, JArithmeticDecoderStats stats)
        {
            int b;
            int i;

            b = 0;
            for (i = 0; i < 8; ++i)
            {
                b = (b << 1) | DecodeBit(context, stats);
            }
            return(b);
        }
Example #3
0
        public uint DecodeIAID(uint codeLen, JArithmeticDecoderStats stats)
        {
            uint i;
            int  bit;

            m_prev = 1;
            for (i = 0; i < codeLen; ++i)
            {
                bit    = DecodeBit(m_prev, stats);
                m_prev = (m_prev << 1) | (uint)bit;
            }
            return((uint)(m_prev - (1 << (int)codeLen)));
        }
Example #4
0
        private int decodeIntBit(JArithmeticDecoderStats stats)
        {
            int bit;

            bit = DecodeBit(m_prev, stats);

            if (m_prev < 0x100)
            {
                m_prev = (m_prev << 1) | (uint)bit;
            }
            else
            {
                m_prev = (((m_prev << 1) | (uint)bit) & 0x1ff) | 0x100;
            }

            return(bit);
        }
Example #5
0
        // Decode one bit.
        public int DecodeBit(uint context, JArithmeticDecoderStats stats)
        {
            int  bit;
            uint qe;
            int  iCX, mpsCX;

            iCX   = stats[context] >> 1;
            mpsCX = stats[context] & 1;
            qe    = qeTab[iCX];
            m_a  -= qe;
            if (m_c < m_a)
            {
                if ((m_a & 0x80000000) != 0)
                {
                    bit = mpsCX;
                }
                else
                {
                    // MPS_EXCHANGE
                    if (m_a < qe)
                    {
                        bit = 1 - mpsCX;
                        if (switchTab[iCX] != 0)
                        {
                            stats[context] = (byte)((nlpsTab[iCX] << 1) | (1 - mpsCX));
                        }
                        else
                        {
                            stats[context] = (byte)((nlpsTab[iCX] << 1) | mpsCX);
                        }
                    }
                    else
                    {
                        bit            = mpsCX;
                        stats[context] = (byte)((nmpsTab[iCX] << 1) | mpsCX);
                    }
                    // RENORMD
                    do
                    {
                        if (m_ct == 0)
                        {
                            byteIn();
                        }
                        m_a <<= 1;
                        m_c <<= 1;
                        --m_ct;
                    } while ((m_a & 0x80000000) == 0);
                }
            }
            else
            {
                m_c -= m_a;
                // LPS_EXCHANGE
                if (m_a < qe)
                {
                    bit            = mpsCX;
                    stats[context] = (byte)((nmpsTab[iCX] << 1) | mpsCX);
                }
                else
                {
                    bit = 1 - mpsCX;
                    if (switchTab[iCX] != 0)
                    {
                        stats[context] = (byte)((nlpsTab[iCX] << 1) | (1 - mpsCX));
                    }
                    else
                    {
                        stats[context] = (byte)((nlpsTab[iCX] << 1) | mpsCX);
                    }
                }
                m_a = qe;
                // RENORMD
                do
                {
                    if (m_ct == 0)
                    {
                        byteIn();
                    }
                    m_a <<= 1;
                    m_c <<= 1;
                    --m_ct;
                } while ((m_a & 0x80000000) == 0);
            }
            return(bit);
        }
Example #6
0
        // Returns false for OOB, otherwise sets *<x> and returns true.
        public bool DecodeInt(ref int x, JArithmeticDecoderStats stats)
        {
            int  s;
            uint v;
            int  i;

            m_prev = 1;
            s      = decodeIntBit(stats);
            if (decodeIntBit(stats) != 0)
            {
                if (decodeIntBit(stats) != 0)
                {
                    if (decodeIntBit(stats) != 0)
                    {
                        if (decodeIntBit(stats) != 0)
                        {
                            if (decodeIntBit(stats) != 0)
                            {
                                v = 0;
                                for (i = 0; i < 32; ++i)
                                {
                                    v = (v << 1) | (uint)decodeIntBit(stats);
                                }
                                v += 4436;
                            }
                            else
                            {
                                v = 0;
                                for (i = 0; i < 12; ++i)
                                {
                                    v = (v << 1) | (uint)decodeIntBit(stats);
                                }
                                v += 340;
                            }
                        }
                        else
                        {
                            v = 0;
                            for (i = 0; i < 8; ++i)
                            {
                                v = (v << 1) | (uint)decodeIntBit(stats);
                            }
                            v += 84;
                        }
                    }
                    else
                    {
                        v = 0;
                        for (i = 0; i < 6; ++i)
                        {
                            v = (v << 1) | (uint)decodeIntBit(stats);
                        }
                        v += 20;
                    }
                }
                else
                {
                    v  = (uint)decodeIntBit(stats);
                    v  = (v << 1) | (uint)decodeIntBit(stats);
                    v  = (v << 1) | (uint)decodeIntBit(stats);
                    v  = (v << 1) | (uint)decodeIntBit(stats);
                    v += 4;
                }
            }
            else
            {
                v = (uint)decodeIntBit(stats);
                v = (v << 1) | (uint)decodeIntBit(stats);
            }

            if (s != 0)
            {
                if (v == 0)
                {
                    return(false);
                }
                x = -(int)v;
            }
            else
            {
                x = (int)v;
            }
            return(true);
        }
Example #7
0
 public void CopyFrom(JArithmeticDecoderStats stats)
 {
     Array.Copy(stats.m_cxTab, m_cxTab, m_contextSize);
 }
Example #8
0
 public void SetRefinementRegionStats(JArithmeticDecoderStats stats)
 {
     m_refinementRegionStats = stats;
 }
Example #9
0
 public void SetGenericRegionStats(JArithmeticDecoderStats stats)
 {
     m_genericRegionStats = stats;
 }