コード例 #1
0
def compress(inp, bitout):
    initfreqs = [1] * 5
    # initfreqs = [1] * 257
    freqs = huffmancoding.FrequencyTable(initfreqs)
    enc = huffmancoding.HuffmanEncoder(bitout)
    enc.codetree = freqs.build_code_tree(
    )  # Don't need to make canonical code because we don't transmit the code tree
    # exit()
    count = 0  # Number of bytes read from the input file
    while True:
        # Read and encode one byte
        symbol = inp.read(1)
        if len(symbol) == 0:
            break
        symbol = symbol[0] if python3 else ord(symbol)
        enc.write(symbol)
        count += 1

        # Update the frequency table and possibly the code tree
        freqs.increment(symbol)
        if (count < 262144 and is_power_of_2(count)
            ) or count % 262144 == 0:  # Update code tree
            enc.codetree = freqs.build_code_tree()
        if count % 262144 == 0:  # Reset frequency table
            freqs = huffmancoding.FrequencyTable(initfreqs)
    enc.write(256)  # EOF
コード例 #2
0
ファイル: sz.py プロジェクト: szcompressor/SZ_HLS
def compress(code_tree, quant_code, bit_out):
    enc = huffmancoding.HuffmanEncoder(bit_out)
    enc.codetree = code_tree

    for q_c in quant_code:
        enc.write(q_c)

    enc.write(1024)  # EOF
コード例 #3
0
def compress(code, inp, bitout):
	enc = huffmancoding.HuffmanEncoder(bitout)
	enc.codetree = code
	while True:
		b = inp.read(1)
		if len(b) == 0:
			break
		enc.write(b[0] if python3 else ord(b))
	enc.write(256)  # EOF
コード例 #4
0
def compress(code, inp, bitout, files_count):
    enc = huffmancoding.HuffmanEncoder(bitout)
    enc.codetree = code
    for i in range(0, files_count):
        while True:
            b = inp[i].read(1)
            if len(b) == 0:
                break
            enc.write(b[0])
        enc.write(256)  # EOF