コード例 #1
0
        public static void Decompress(Span <Byte> compressed, Span <Byte> decompressed)
        {
            unsafe
            {
                fixed(Byte *cPtr = &compressed.GetPinnableReference())
                fixed(Byte * dPtr = &decompressed.GetPinnableReference())
                {
                    DecompressorContext context = DecompressorContext.PrepareDecompression(cPtr, checked ((UInt32)compressed.Length), checked ((UInt32)decompressed.Length));

                    context.Decompress(dPtr);
                }
            }
        }
コード例 #2
0
        public static DecompressorContext PrepareDecompression(Byte *data, UInt32 compressedSize, UInt32 decompressedSize)
        {
            UInt32 *data32 = (UInt32 *)data;

            UInt32 magic = *data32++;

            if (magic != 0x1234)
            {
                throw new NotSupportedException("if (magic != 0x1234)");
            }

            UInt32 blkCnt   = *data32++;
            UInt32 blkSz    = *data32++;
            UInt32 headerSz = *data32++;

            if (headerSz != 16 + 12 * blkCnt)
            {
                throw new NotSupportedException("if (header_sz != 16 + 12 * blk_cnt)");
            }

            var info = new DecompressorContext();

            info.SetInput(data, compressedSize);
            info.SetBlocks(blkCnt, blkSz);

            UInt32 outputSize = 0;

            for (Int32 i = 0; i < blkCnt; ++i)
            {
                UInt32 decSz  = *data32++;
                UInt32 cmpSz  = *data32++;
                UInt32 offset = *data32++;

                outputSize += decSz;
                info.SetDataChunk(i, decSz, cmpSz, offset);
            }

            if (decompressedSize != outputSize)
            {
                throw new NotSupportedException("if (uncompressedSize != output_size)");
            }

            info.SetOutput(outputSize);

            return(info);
        }