Ejemplo n.º 1
0
        private unsafe HRESULT CodeSpec(byte *memStream, uint size)
        {
            switch (mDecoderStatus)
            {
            case kStatus.Finished:
                return(HRESULT.S_OK);

            case kStatus.Error:
                return(HRESULT.S_FALSE);

            case kStatus.NeedInit:
                //_inStream.Init();
                if (!PPMD.Ppmd7z_RangeDec_Init(mRangeDecoder))
                {
                    mDecoderStatus = kStatus.Error;
                    return(HRESULT.S_FALSE);
                }
                mDecoderStatus = kStatus.Normal;
                PPMD.Ppmd7_Init(mState, mSettingOrder);
                break;
            }

            /* if (mLength.HasValue) */
            {
                var rem = mLength - mPosition;
                if (size > rem)
                {
                    size = (uint)rem;
                }
            }

            uint i;
            int  sym = 0;

            for (i = 0; i != size; i++)
            {
                sym = PPMD.Ppmd7_DecodeSymbol(mState, mRangeDecoder);
                if (mExceededInput || sym < 0)
                {
                    break;
                }
                memStream[i] = (byte)sym;
            }

            mPosition += i;

            if (mExceededInput)
            {
                mDecoderStatus = kStatus.Error;
                return(HRESULT.E_FAIL);
            }

            if (sym < 0)
            {
                mDecoderStatus = (sym < -1) ? kStatus.Error : kStatus.Finished;
            }

            return(HRESULT.S_OK);
        }
Ejemplo n.º 2
0
 protected override void Dispose(bool isDisposing)
 {
     if (isDisposing)
     {
         mInput?.Dispose();
         PPMD.Ppmd7_Free(mState, mAlloc);
     }
 }
Ejemplo n.º 3
0
        public PpmdDecoderStream(Stream input, byte[] settings, long length)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (settings == default(byte[]))
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (settings.Length != 5)
            {
                throw new InvalidDataException();
            }

            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            mInput  = input;
            mLength = length;

            mSettingOrder = settings[0];
            if (mSettingOrder < PPMD.PPMD7_MIN_ORDER || mSettingOrder > PPMD.PPMD7_MAX_ORDER)
            {
                throw new InvalidDataException();
            }

            mSettingMemory = (uint)settings[1] | ((uint)settings[2] << 8) | ((uint)settings[3] << 16) | ((uint)settings[4] << 24);
            if (mSettingMemory < PPMD.PPMD7_MIN_MEM_SIZE || mSettingMemory > PPMD.PPMD7_MAX_MEM_SIZE)
            {
                throw new InvalidDataException();
            }

            mRangeDecoder = new PPMD.CPpmd7z_RangeDec();
            PPMD.Ppmd7z_RangeDec_CreateVTable(mRangeDecoder);
            mRangeDecoder.Stream = new PPMD.IByteIn {
                Read = x => checked ((byte)ReadByte())
            };

            PPMD.Ppmd7_Construct(mState);
            if (!PPMD.Ppmd7_Alloc(mState, mSettingMemory, mAlloc))
            {
                throw new OutOfMemoryException();
            }
        }