コード例 #1
0
        public byte[] Compress()
        {
            _builder.Append(HALC.RedundancyMagicSignature);

            var literalBuffer = new ByteArrayBuilder();

            while (HasMoreBytes())
            {
                var repeatCount = GetRepeatCount();

                // try RLE first
                if (repeatCount > HALC.RLECommandLength)
                {
                    if (literalBuffer.Length > 0)
                    {
                        UseLiteral(literalBuffer.GetBytes());
                        literalBuffer = new ByteArrayBuilder();
                    }
                    UseRLE(repeatCount);
                }
                else
                {
                    var previousOccurance = GetPreviousOccurance();
                    if (previousOccurance.BestMatchLength > HALC.ShortPointerCommandLength &&
                        previousOccurance.BestMatchOffset <= HALC.MaxShortPointerOffset &&
                        previousOccurance.BestMatchLength <= HALC.MaxShortPointerLength)
                    {
                        if (literalBuffer.Length > 0)
                        {
                            UseLiteral(literalBuffer.GetBytes());
                            literalBuffer = new ByteArrayBuilder();
                        }
                        UseShortPointer(previousOccurance);
                    }
                    else if (previousOccurance.BestMatchLength > HALC.LongPointerCommandLength)
                    {
                        if (literalBuffer.Length > 0)
                        {
                            UseLiteral(literalBuffer.GetBytes());
                            literalBuffer = new ByteArrayBuilder();
                        }
                        UseLongPointer(previousOccurance);
                    }
                    else
                    {
                        literalBuffer.Append(_uncompressed[_compressionPointer]);
                        _compressionPointer++;
                    }
                }
            }

            if (literalBuffer.Length > 0)
            {
                UseLiteral(literalBuffer.GetBytes());
            }

            return(_builder.GetBytes());
        }
コード例 #2
0
 public RedundancyDecompressor(byte[] compressed)
 {
     _compressed = compressed;
     _builder    = new ByteArrayBuilder();
 }
コード例 #3
0
 public RedundancyCompressor(byte[] uncompressed)
 {
     _uncompressed = uncompressed;
     _builder      = new ByteArrayBuilder();
 }
コード例 #4
0
 public ProbabilityCompressor(byte[] data)
 {
     _data    = data;
     _builder = new ByteArrayBuilder();
 }