Example #1
0
        internal void EncodeBlock(Stream target, Stream source, bool final)
        {
            while (true)
            {
                _minimumContext   = _maximumContext;
                _numberStatistics = _minimumContext.NumberStatistics;

                int c = source.ReadByte();
                if (c < 0 && !final)
                {
                    return;
                }

                if (_numberStatistics != 0)
                {
                    EncodeSymbol1(c, _minimumContext);
                    _coder.RangeEncodeSymbol();
                }
                else
                {
                    EncodeBinarySymbol(c, _minimumContext);
                    _coder.RangeShiftEncodeSymbol(TOTAL_BIT_COUNT);
                }

                while (_foundState == PpmState.ZERO)
                {
                    _coder.RangeEncoderNormalize(target);
                    do
                    {
                        _orderFall++;
                        _minimumContext = _minimumContext.Suffix;
                        if (_minimumContext == PpmContext.ZERO)
                        {
                            goto StopEncoding;
                        }
                    }while (_minimumContext.NumberStatistics == _numberMasked);
                    EncodeSymbol2(c, _minimumContext);
                    _coder.RangeEncodeSymbol();
                }

                if (_orderFall == 0 && (Pointer)_foundState.Successor >= _allocator._baseUnit)
                {
                    _maximumContext = _foundState.Successor;
                }
                else
                {
                    UpdateModel(_minimumContext);
                    if (_escapeCount == 0)
                    {
                        ClearMask();
                    }
                }

                _coder.RangeEncoderNormalize(target);
            }

StopEncoding:
            _coder.RangeEncoderFlush(target);
        }
        internal void EncodeBlock(Stream target, Stream source, bool final)
        {
            while (true)
            {
                minimumContext   = maximumContext;
                numberStatistics = minimumContext.NumberStatistics;

                int c = source.ReadByte();
                if (c < 0 && !final)
                {
                    return;
                }

                if (numberStatistics != 0)
                {
                    EncodeSymbol1(c, minimumContext);
                    Coder.RangeEncodeSymbol();
                }
                else
                {
                    EncodeBinarySymbol(c, minimumContext);
                    Coder.RangeShiftEncodeSymbol(TotalBitCount);
                }

                while (foundState == PpmState.Zero)
                {
                    Coder.RangeEncoderNormalize(target);
                    do
                    {
                        orderFall++;
                        minimumContext = minimumContext.Suffix;
                        if (minimumContext == PpmContext.Zero)
                        {
                            goto StopEncoding;
                        }
                    }while (minimumContext.NumberStatistics == numberMasked);
                    EncodeSymbol2(c, minimumContext);
                    Coder.RangeEncodeSymbol();
                }

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

                Coder.RangeEncoderNormalize(target);
            }

StopEncoding:
            Coder.RangeEncoderFlush(target);
        }