Example #1
0
        internal int DecodeBlock(Stream source, byte[] buffer, int offset, int count)
        {
            if (minimumContext == PpmContext.Zero)
            {
                return(0);
            }

            int total = 0;

            while (total < count)
            {
                if (numberStatistics != 0)
                {
                    DecodeSymbol1(minimumContext);
                }
                else
                {
                    DecodeBinarySymbol(minimumContext);
                }

                Coder.RangeRemoveSubrange();

                while (foundState == PpmState.Zero)
                {
                    Coder.RangeDecoderNormalize(source);
                    do
                    {
                        orderFall++;
                        minimumContext = minimumContext.Suffix;
                        if (minimumContext == PpmContext.Zero)
                        {
                            goto StopDecoding;
                        }
                    } while (minimumContext.NumberStatistics == numberMasked);
                    DecodeSymbol2(minimumContext);
                    Coder.RangeRemoveSubrange();
                }

                buffer[offset] = foundState.Symbol;
                offset++;
                total++;

                if (orderFall == 0 && (Pointer)foundState.Successor >= Allocator.BaseUnit)
                {
                    maximumContext = foundState.Successor;
                }
                else
                {
                    UpdateModel(minimumContext);
                    if (escapeCount == 0)
                    {
                        ClearMask();
                    }
                }

                minimumContext   = maximumContext;
                numberStatistics = minimumContext.NumberStatistics;
                Coder.RangeDecoderNormalize(source);
            }

StopDecoding:
            return(total);
        }