Beispiel #1
0
        public static unsafe DecompressionHandle DecompressReinit(DecompressionHandle state, DecompressionParameters parameters)
        {
            parameters.Initialize();
            byte *pBytes = (byte *)&parameters;

            return(lzham_decompress_reinit(state, pBytes));
        }
Beispiel #2
0
 public LzhamStream(Stream stream, DecompressionParameters mode, bool leaveOpen)
 {
     if (stream == null)
         throw new ArgumentNullException(nameof(stream));
     if (!stream.CanRead)
         throw new ArgumentException("The base stream is not readable", nameof(stream));
     _stream = stream;
     _leaveOpen = leaveOpen;
     _buffer = new byte[DefaultBufferSize];
     _decompressionHandle = LzhamInterop.DecompressInit(mode);
     if (_decompressionHandle.IsInvalid)
     {
         throw new ApplicationException("Could not initialize Decompression stream with specified parameters");
     }
     ReadInput();
 }
Beispiel #3
0
        public static unsafe DecompressStatus Decompress(DecompressionHandle state, byte[] inBuf, ref int inBufSize, int inBufOffset, byte[] outBuf, ref int outBufSize, int outBufOffset, bool noMoreInputBytesFlag)
        {
            if (inBufOffset + inBufSize > inBuf.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(inBuf), "Offset + Size is larger than the length of the array.");
            }
            if (outBufOffset + outBufSize > outBuf.Length)
                throw new ArgumentOutOfRangeException(nameof(outBuf), "Offset + Size is larger than the length of the array.");

            fixed(byte *inBytes = inBuf, outBytes = outBuf)
            {
                IntPtr           inSize  = new IntPtr(inBufSize);
                IntPtr           outSize = new IntPtr(outBufSize);
                DecompressStatus result  = (DecompressStatus)lzham_decompress(state, inBytes + inBufOffset, ref inSize, outBytes + outBufOffset, ref outSize, noMoreInputBytesFlag ? 1 : 0);

                inBufSize  = inSize.ToInt32();
                outBufSize = outSize.ToInt32();
                return(result);
            }
        }
Beispiel #4
0
 // Decompresses an arbitrarily sized block of compressed data, writing as much available decompressed data as possible to the output buffer. 
 // This method is implemented as a coroutine so it may be called as many times as needed. However, for best perf. try not to call it with tiny buffers.
 // pState - Pointer to public decompression state, originally created by lzham_decompress_init.
 // pIn_buf, pIn_buf_size - Pointer to input data buffer, and pointer to a size_t containing the number of bytes available in this buffer. 
 //                         On return, *pIn_buf_size will be set to the number of bytes read from the buffer.
 // pOut_buf, pOut_buf_size - Pointer to the output data buffer, and a pointer to a size_t containing the max number of bytes that can be written to this buffer.
 //                         On return, *pOut_buf_size will be set to the number of bytes written to this buffer.
 // no_more_input_bytes_flag - Set to true to indicate that no more input bytes are available to compress (EOF). Once you call this function with this param set to true, it must stay set to true in all future calls.
 // Notes:
 // In unbuffered mode, the output buffer MUST be large enough to hold the entire decompressed stream. Otherwise, you'll receive the
 //  LZHAM_DECOMP_STATUS_FAILED_DEST_BUF_TOO_SMALL error (which is currently unrecoverable during unbuffered decompression).
 // In buffered mode, if the output buffer's size is 0 bytes, the caller is indicating that no more output bytes are expected from the
 //  decompressor. In this case, if the decompressor actually has more bytes you'll receive the LZHAM_DECOMP_STATUS_HAS_MORE_OUTPUT
 //  error (which is recoverable in the buffered case - just call lzham_decompress() again with a non-zero size output buffer).
 private static extern unsafe int lzham_decompress(DecompressionHandle state, byte* inBuf, ref IntPtr inBufSize, byte* outBuf,
     ref IntPtr outBufSize, int noMoreInputBytesFlag);
Beispiel #5
0
 private static extern unsafe DecompressionHandle lzham_decompress_reinit(DecompressionHandle state, byte* parameters);
Beispiel #6
0
 public static unsafe DecompressStatus Decompress(DecompressionHandle state, byte[] inBuf, ref int inBufSize, int inBufOffset, byte[] outBuf, ref int outBufSize, int outBufOffset, bool noMoreInputBytesFlag)
 {
     if (inBufOffset + inBufSize > inBuf.Length)
     {
         throw new ArgumentException("Offset plus count is larger than the length of array", nameof(inBuf));
     }
     if (outBufOffset + outBufSize > outBuf.Length)
     {
         throw new ArgumentException("Offset plus count is larger than the length of array", nameof(outBuf));
     }
     fixed (byte* inBytes = inBuf)
     fixed (byte* outBytes = outBuf)
     {
         IntPtr inSize = new IntPtr(inBufSize);
         IntPtr outSize = new IntPtr(outBufSize);
         DecompressStatus result = (DecompressStatus)lzham_decompress(state, inBytes+inBufOffset, ref inSize, outBytes+outBufOffset, ref outSize, noMoreInputBytesFlag ? 1 : 0);
         inBufSize = inSize.ToInt32();
         outBufSize = outSize.ToInt32();
         return result;
     }
 }
Beispiel #7
0
        public static unsafe DecompressionHandle DecompressReinit(DecompressionHandle state, DecompressionParameters parameters)
        {
            DecompressionParametersInternal p;
            p.m_struct_size = (uint)sizeof(DecompressionParametersInternal);
            p.m_decompress_flags = parameters.Flags;
            p.m_dict_size_log2 = parameters.DictionarySize;
            p.m_table_max_update_interval = parameters.MaxUpdateInterval;
            p.m_table_update_interval_slow_rate = parameters.UpdateIntervalSlowRate;
            p.m_table_update_rate = parameters.UpdateRate;
            if (parameters.SeedBytes != null)
            {
                p.m_num_seed_bytes = (uint) parameters.SeedBytes.Length;
            }

            p.m_struct_size = (uint)sizeof(DecompressionParametersInternal);
            fixed (byte* seedBytes = parameters.SeedBytes)
            {
                p.m_pSeed_bytes = seedBytes;
                byte* pBytes = (byte*)&p;
                return lzham_decompress_reinit(state, pBytes);
            }
        }