Exemplo n.º 1
0
        public void Encode(Stream input, Stream output)
        {
            if (input.Length > 0xFFFFFF)
            {
                throw new InvalidOperationException("Data to compress is too long.");
            }

            var compressionHeader = new[] { (byte)(0x20 + _bitDepth), (byte)input.Length, (byte)((input.Length >> 8) & 0xFF), (byte)((input.Length >> 16) & 0xFF) };

            output.Write(compressionHeader, 0, 4);

            _encoder.Encode(input, output);
        }
Exemplo n.º 2
0
        public void Encode(Stream input, Stream output, IHuffmanTreeBuilder treeBuilder)
        {
            if (input.Length > 0x1FFFFFFF)
            {
                throw new InvalidOperationException("Data to compress is too long.");
            }

            var huffmanMode       = _bitDepth == 4 ? 2 : 3;
            var compressionHeader = new[] {
                (byte)((byte)(input.Length << 3) | huffmanMode),
                (byte)(input.Length >> 5),
                (byte)(input.Length >> 13),
                (byte)(input.Length >> 21)
            };

            output.Write(compressionHeader, 0, 4);

            _encoder.Encode(input, output, treeBuilder);
        }