コード例 #1
0
        public void Start()
        {
            buffer0 = reader.Readbyte();
            buffer1 = reader.Readbyte();

            c = BinaryOperation.Bit32ShiftL((buffer0 ^ 0xff), 16);
            Readbyte();
            c        = BinaryOperation.Bit32ShiftL(c, 7);
            counter -= 7;
            a        = 0x80000000l;
        }
コード例 #2
0
        public long DecodeIAID(long codeLen, ArithmeticDecoderStats stats)
        {
            previous = 1;
            for (long i = 0; i < codeLen; i++)
            {
                int bit = DecodeBit(previous, stats);
                previous = BinaryOperation.Bit32ShiftL(previous, 1) | bit;
            }

            return(previous - (1 << (int)codeLen));
        }
コード例 #3
0
        public long Get24Bits()
        {
            while (bufferLength < 24)
            {
                buffer        = ((BinaryOperation.Bit32ShiftL(buffer, 8)) | (reader.Readbyte() & 0xff));
                bufferLength += 8;
                noOfbytesRead++;
            }

            return((BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 24))) & 0xffffff);
        }
コード例 #4
0
        public int Get2DCode()
        {
            int tuple0, tuple1;

            if (bufferLength == 0)
            {
                buffer = (reader.Readbyte() & 0xff);

                bufferLength = 8;

                noOfbytesRead++;

                int lookup = (int)((BinaryOperation.Bit32ShiftR(buffer, 1)) & 0x7f);

                tuple0 = twoDimensionalTable1[lookup, 0];
                tuple1 = twoDimensionalTable1[lookup, 1];
            }
            else if (bufferLength == 8)
            {
                int lookup = (int)((BinaryOperation.Bit32ShiftR(buffer, 1)) & 0x7f);
                tuple0 = twoDimensionalTable1[lookup, 0];
                tuple1 = twoDimensionalTable1[lookup, 1];
            }
            else
            {
                int lookup = (int)((BinaryOperation.Bit32ShiftL(buffer, (int)(7 - bufferLength))) & 0x7f);

                tuple0 = twoDimensionalTable1[lookup, 0];
                tuple1 = twoDimensionalTable1[lookup, 1];
                if (tuple0 < 0 || tuple0 > (int)bufferLength)
                {
                    int right = (reader.Readbyte() & 0xff);

                    long left = (BinaryOperation.Bit32ShiftL(buffer, 8));

                    buffer        = left | right;
                    bufferLength += 8;
                    noOfbytesRead++;

                    int look = (int)(BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 7)) & 0x7f);

                    tuple0 = twoDimensionalTable1[look, 0];
                    tuple1 = twoDimensionalTable1[look, 1];
                }
            }
            if (tuple0 < 0)
            {
                return(0);
            }
            bufferLength -= tuple0;

            return(tuple1);
        }
コード例 #5
0
        private int DecodeIntBit(ArithmeticDecoderStats stats)
        {
            int bit = DecodeBit(previous, stats);

            if (previous < 0x100)
            {
                previous = BinaryOperation.Bit32ShiftL(previous, 1) | bit;
            }
            else
            {
                previous = (((BinaryOperation.Bit32ShiftL(previous, 1)) | bit) & 0x1ff) | 0x100;
            }
            return(bit);
        }
コード例 #6
0
 private void Readbyte()
 {
     if (buffer0 == 0xff)
     {
         if (buffer1 > 0x8f)
         {
             counter = 8;
         }
         else
         {
             buffer0 = buffer1;
             buffer1 = reader.Readbyte();
             c       = c + 0xfe00 - (BinaryOperation.Bit32ShiftL(buffer0, 9));
             counter = 7;
         }
     }
     else
     {
         buffer0 = buffer1;
         buffer1 = reader.Readbyte();
         c       = c + 0xff00 - (BinaryOperation.Bit32ShiftL(buffer0, 8));
         counter = 8;
     }
 }
コード例 #7
0
        public int DecodeBit(long context, ArithmeticDecoderStats stats)
        {
            int iCX   = BinaryOperation.Bit8Shift(stats.GetContextCodingTableValue((int)context), 1, BinaryOperation.RIGHT_SHIFT);
            int mpsCX = stats.GetContextCodingTableValue((int)context) & 1;
            int qe    = qeTable[iCX];

            a -= qe;

            int bit;

            if (c < a)
            {
                if ((a & 0x80000000) != 0)
                {
                    bit = mpsCX;
                }
                else
                {
                    if (a < qe)
                    {
                        bit = 1 - mpsCX;
                        if (switchTable[iCX] != 0)
                        {
                            stats.SetContextCodingTableValue((int)context, (nlpsTable[iCX] << 1) | (1 - mpsCX));
                        }
                        else
                        {
                            stats.SetContextCodingTableValue((int)context, (nlpsTable[iCX] << 1) | mpsCX);
                        }
                    }
                    else
                    {
                        bit = mpsCX;
                        stats.SetContextCodingTableValue((int)context, (nmpsTable[iCX] << 1) | mpsCX);
                    }
                    do
                    {
                        if (counter == 0)
                        {
                            Readbyte();
                        }

                        a = BinaryOperation.Bit32ShiftL(a, 1);
                        c = BinaryOperation.Bit32ShiftL(c, 1);

                        counter--;
                    } while ((a & 0x80000000) == 0);
                }
            }
            else
            {
                c -= a;

                if (a < qe)
                {
                    bit = mpsCX;
                    stats.SetContextCodingTableValue((int)context, (nmpsTable[iCX] << 1) | mpsCX);
                }
                else
                {
                    bit = 1 - mpsCX;
                    if (switchTable[iCX] != 0)
                    {
                        stats.SetContextCodingTableValue((int)context, (nlpsTable[iCX] << 1) | (1 - mpsCX));
                    }
                    else
                    {
                        stats.SetContextCodingTableValue((int)context, (nlpsTable[iCX] << 1) | mpsCX);
                    }
                }
                a = qe;

                do
                {
                    if (counter == 0)
                    {
                        Readbyte();
                    }

                    a = BinaryOperation.Bit32ShiftL(a, 1);
                    c = BinaryOperation.Bit32ShiftL(c, 1);

                    counter--;
                } while ((a & 0x80000000) == 0);
            }
            return(bit);
        }
コード例 #8
0
        public DecodeIntResult DecodeInt(ArithmeticDecoderStats stats)
        {
            long value;

            previous = 1;
            int s = DecodeIntBit(stats);

            if (DecodeIntBit(stats) != 0)
            {
                if (DecodeIntBit(stats) != 0)
                {
                    if (DecodeIntBit(stats) != 0)
                    {
                        if (DecodeIntBit(stats) != 0)
                        {
                            if (DecodeIntBit(stats) != 0)
                            {
                                value = 0;
                                for (int i = 0; i < 32; i++)
                                {
                                    value = BinaryOperation.Bit32ShiftL(value, 1) | DecodeIntBit(stats);
                                }
                                value += 4436;
                            }
                            else
                            {
                                value = 0;
                                for (int i = 0; i < 12; i++)
                                {
                                    value = BinaryOperation.Bit32ShiftL(value, 1) | DecodeIntBit(stats);
                                }
                                value += 340;
                            }
                        }
                        else
                        {
                            value = 0;
                            for (int i = 0; i < 8; i++)
                            {
                                value = BinaryOperation.Bit32ShiftL(value, 1) | DecodeIntBit(stats);
                            }
                            value += 84;
                        }
                    }
                    else
                    {
                        value = 0;
                        for (int i = 0; i < 6; i++)
                        {
                            value = BinaryOperation.Bit32ShiftL(value, 1) | DecodeIntBit(stats);
                        }
                        value += 20;
                    }
                }
                else
                {
                    value  = DecodeIntBit(stats);
                    value  = BinaryOperation.Bit32ShiftL(value, 1) | DecodeIntBit(stats);
                    value  = BinaryOperation.Bit32ShiftL(value, 1) | DecodeIntBit(stats);
                    value  = BinaryOperation.Bit32ShiftL(value, 1) | DecodeIntBit(stats);
                    value += 4;
                }
            }
            else
            {
                value = DecodeIntBit(stats);
                value = BinaryOperation.Bit32ShiftL(value, 1) | DecodeIntBit(stats);
            }

            int decodedInt;

            if (s != 0)
            {
                if (value == 0)
                {
                    return(new DecodeIntResult((int)value, false));
                }
                decodedInt = (int)-value;
            }
            else
            {
                decodedInt = (int)value;
            }

            return(new DecodeIntResult(decodedInt, true));
        }
コード例 #9
0
        public int GetBlackCode()
        {
            int  tuple0, tuple1;
            long code;

            if (bufferLength == 0)
            {
                buffer       = (reader.Readbyte() & 0xff);
                bufferLength = 8;
                noOfbytesRead++;
            }
            while (true)
            {
                if (bufferLength >= 6 && ((BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 6))) & 0x3f) == 0)
                {
                    if (bufferLength <= 13)
                    {
                        code = BinaryOperation.Bit32ShiftL(buffer, (int)(13 - bufferLength));
                    }
                    else
                    {
                        code = BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 13));
                    }
                    tuple0 = blackTable1[(int)(code & 0x7f), 0];
                    tuple1 = blackTable1[(int)(code & 0x7f), 1];
                }
                else if (bufferLength >= 4 && ((buffer >> ((int)bufferLength - 4)) & 0x0f) == 0)
                {
                    if (bufferLength <= 12)
                    {
                        code = BinaryOperation.Bit32ShiftL(buffer, (int)(12 - bufferLength));
                    }
                    else
                    {
                        code = BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 12));
                    }

                    int lookup = (int)((code & 0xff) - 64);
                    if (lookup >= 0)
                    {
                        tuple0 = blackTable2[lookup, 0];
                        tuple1 = blackTable2[lookup, 1];
                    }
                    else
                    {
                        tuple0 = blackTable1[blackTable1.Length + lookup, 0];
                        tuple1 = blackTable1[blackTable1.Length + lookup, 1];
                    }
                }
                else
                {
                    if (bufferLength <= 6)
                    {
                        code = BinaryOperation.Bit32ShiftL(buffer, (int)(6 - bufferLength));
                    }
                    else
                    {
                        code = BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 6));
                    }

                    int lookup = (int)(code & 0x3f);
                    if (lookup >= 0)
                    {
                        tuple0 = blackTable3[lookup, 0];
                        tuple1 = blackTable3[lookup, 1];
                    }
                    else
                    {
                        tuple0 = blackTable2[blackTable2.Length + lookup, 0];
                        tuple1 = blackTable2[blackTable2.Length + lookup, 1];
                    }
                }
                if (tuple0 > 0 && tuple0 <= (int)bufferLength)
                {
                    bufferLength -= tuple0;
                    return(tuple1);
                }
                if (bufferLength >= 13)
                {
                    break;
                }
                buffer        = ((BinaryOperation.Bit32ShiftL(buffer, 8)) | (reader.Readbyte() & 0xff));
                bufferLength += 8;
                noOfbytesRead++;
            }

            bufferLength--;
            return(1);
        }
コード例 #10
0
        public int GetWhiteCode()
        {
            int  tuple0, tuple1;
            long code;

            if (bufferLength == 0)
            {
                buffer       = (reader.Readbyte() & 0xff);
                bufferLength = 8;
                noOfbytesRead++;
            }
            while (true)
            {
                if (bufferLength >= 7 && ((BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 7))) & 0x7f) == 0)
                {
                    if (bufferLength <= 12)
                    {
                        code = BinaryOperation.Bit32ShiftL(buffer, (int)(12 - bufferLength));
                    }
                    else
                    {
                        code = BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 12));
                    }

                    tuple0 = whiteTable1[(int)(code & 0x1f), 0];
                    tuple1 = whiteTable1[(int)(code & 0x1f), 1];
                }
                else
                {
                    if (bufferLength <= 9)
                    {
                        code = BinaryOperation.Bit32ShiftL(buffer, (int)(9 - bufferLength));
                    }
                    else
                    {
                        code = BinaryOperation.Bit32ShiftR(buffer, (int)(bufferLength - 9));
                    }

                    int lookup = (int)(code & 0x1ff);
                    if (lookup >= 0)
                    {
                        tuple0 = whiteTable2[lookup, 0];
                        tuple1 = whiteTable2[lookup, 1];
                    }
                    else
                    {
                        tuple0 = whiteTable2[whiteTable2.Length + lookup, 0];
                        tuple1 = whiteTable2[whiteTable2.Length + lookup, 1];
                    }
                }
                if (tuple0 > 0 && tuple0 <= (int)bufferLength)
                {
                    bufferLength -= tuple0;
                    return(tuple1);
                }
                if (bufferLength >= 12)
                {
                    break;
                }
                buffer        = ((BinaryOperation.Bit32ShiftL(buffer, 8)) | reader.Readbyte() & 0xff);
                bufferLength += 8;
                noOfbytesRead++;
            }

            bufferLength--;

            return(1);
        }