コード例 #1
0
        /**
         * Public constructor
         * @param bitOutputStream The BZip2BitOutputStream to write to
         * @param mtfBlock The MTF block data
         * @param mtfLength The actual length of the MTF block
         * @param mtfAlphabetSize The size of the MTF block's alphabet
         * @param mtfSymbolFrequencies The frequencies the MTF block's symbols
         */
        public BZip2HuffmanStageEncoder(BZip2BitOutputStream bitOutputStream, ushort[] mtfBlock, int mtfLength, int mtfAlphabetSize, int[] mtfSymbolFrequencies)
        {
            this.bitOutputStream = bitOutputStream;
            this.mtfBlock = mtfBlock;
            this.mtfSymbolFrequencies = mtfSymbolFrequencies;
            this.mtfAlphabetSize = mtfAlphabetSize;
            this.mtfLength = mtfLength;

            var totalTables = selectTableCount(mtfLength);

            this.huffmanCodeLengths = new int[totalTables, mtfAlphabetSize];
            this.huffmanMergedCodeSymbols = new int[totalTables, mtfAlphabetSize];
            this.selectors = new byte[(mtfLength + HUFFMAN_GROUP_RUN_LENGTH - 1) / HUFFMAN_GROUP_RUN_LENGTH];
        }
コード例 #2
0
        /// <summary>Public constructor</summary>
        /// <param name="outputStream">The output stream to write to</param>
        /// <param name="blockSizeMultiplier">The BZip2 block size as a multiple of 100,000 bytes (minimum 1, maximum 9)</param>
        /// <param name="isOwner">True if the underlying stream will be closed with the current Stream</param>
        /// <exception>On any I/O error writing to the output stream</exception>
        /// <remarks>Larger block sizes require more memory for both compression and decompression,
        /// but give better compression ratios. 9 will usually be the best value to use</remarks>
        public BZip2OutputStream(Stream outputStream, bool isOwner = true, int blockSizeMultiplier = 9)
        {
            if (outputStream == null)
                throw new ArgumentException("Null output stream");

            if ((blockSizeMultiplier < 1) || (blockSizeMultiplier > 9))
                throw new ArgumentException("Invalid BZip2 block size" + blockSizeMultiplier);

            this.streamBlockSize = blockSizeMultiplier * 100000;
            this.outputStream = outputStream;
            this.bitOutputStream = new BZip2BitOutputStream(this.outputStream);
            this.isOwner = isOwner;

            this.bitOutputStream.WriteBits(16, STREAM_START_MARKER_1);
            this.bitOutputStream.WriteBits(8, STREAM_START_MARKER_2);
            this.bitOutputStream.WriteBits(8, (uint)('0' + blockSizeMultiplier));

            this.InitialiseNextBlock();
        }