Example #1
0
File: main.py Project: zbanach/koda
def test_encoding_and_decoding():
    print "1. TEST KODOWANIA I DEKODOWANIA\n"
    source = [
        1, 2, 3, 0, 0, 4, 5, 0, 2, 6, 0, 7, 8, 0, 1, 0, 2, 2, 3, 9, 0, 0, 1, 2
    ]
    print "   Ciąg wejściowy:   ", source

    print "\n   1.1. Kodowanie pośrednie (ze słownikiem)"
    codec = ExpGolombCodec()
    encoded = codec.encode(source)
    print "        Dane zakodowane:  ", encoded
    print "        - Statystyki"
    print "        -- Stopień kompresji: %.2f" % codec.statistics.compression_ratio
    print "        -- Entropia źródła:   %.2f" % codec.statistics.entropy
    print "        -- Średnia dł. słowa: %.2f" % codec.statistics.mean_code_word_length
    decoded = codec.decode(encoded)
    print "        Dane zdekodowane: ", decoded

    print "\n    1.2. Kodowane bezpośrednie (bez słownika)"
    codec = ExpGolombCodec(direct=True)
    encoded = codec.encode(source)
    print "        Dane zakodowane:  ", encoded
    print "        - Statystyki"
    print "        -- Stopień kompresji: %.2f" % codec.statistics.compression_ratio
    print "        -- Entropia źródła:   %.2f" % codec.statistics.entropy
    print "        -- Średnia dł. słowa: %.2f" % codec.statistics.mean_code_word_length
    decoded = codec.decode(encoded)
    print "        Dane zdekodowane: ", decoded

    print "\n=======================================================================\n"
Example #2
0
File: main.py Project: zbanach/koda
def encode_and_print_stats(source, indent):
    codec = ExpGolombCodec(direct=True)
    codec.encode(source)
    stat = codec.statistics

    tab = ' ' * indent
    print "%sEntropia źródła:                %5.2f" % (tab, stat.entropy)
    print "%sRozmiar danych źródłowych [KB]: %5.1f" % (tab, stat.source_size /
                                                       1024. / 8)
    print
    print "%s+-- Kodowanie bezpośrednie ----------+" % tab
    print "%s| Rozmiar po kompresji [KB]:    %5.1f |" % (
        tab, stat.compressed_size / 1024. / 8)
    print "%s| Stopień kompresji:            %5.2f |" % (
        tab, stat.compression_ratio)
    print "%s| Długość słowa kodowego:       %5.2f |" % (
        tab, stat.mean_code_word_length)
    print "%s+------------------------------------+" % tab

    codec = ExpGolombCodec(direct=False)
    codec.encode(source)
    stat = codec.statistics
    print "%s+-- Kodowanie pośrednie -------------+" % tab
    print "%s| Rozmiar po kompresji [KB]:    %5.1f |" % (
        tab, stat.compressed_size / 1024. / 8)
    print "%s| Stopień kompresji:            %5.2f |" % (
        tab, stat.compression_ratio)
    print "%s| Długość słowa kodowego:       %5.2f |" % (
        tab, stat.mean_code_word_length)
    print "%s+------------------------------------+" % tab
    print
Example #3
0
File: main.py Project: zbanach/koda
def test_encoding_and_decoding():
    print "1. TEST KODOWANIA I DEKODOWANIA\n"
    source = [1, 2, 3, 0, 0, 4, 5, 0, 2, 6, 0, 7, 8, 0, 1, 0, 2, 2, 3, 9, 0, 0, 1, 2]
    print "   Ciąg wejściowy:   ", source

    print "\n   1.1. Kodowanie pośrednie (ze słownikiem)"
    codec = ExpGolombCodec()
    encoded = codec.encode(source)
    print "        Dane zakodowane:  ", encoded
    print "        - Statystyki"
    print "        -- Stopień kompresji: %.2f" % codec.statistics.compression_ratio
    print "        -- Entropia źródła:   %.2f" % codec.statistics.entropy
    print "        -- Średnia dł. słowa: %.2f" % codec.statistics.mean_code_word_length
    decoded = codec.decode(encoded)
    print "        Dane zdekodowane: ", decoded


    print "\n    1.2. Kodowane bezpośrednie (bez słownika)"
    codec = ExpGolombCodec(direct=True)
    encoded = codec.encode(source)
    print "        Dane zakodowane:  ", encoded
    print "        - Statystyki"
    print "        -- Stopień kompresji: %.2f" % codec.statistics.compression_ratio
    print "        -- Entropia źródła:   %.2f" % codec.statistics.entropy
    print "        -- Średnia dł. słowa: %.2f" % codec.statistics.mean_code_word_length
    decoded = codec.decode(encoded)
    print "        Dane zdekodowane: ", decoded

    print "\n=======================================================================\n"
Example #4
0
File: main.py Project: zbanach/koda
def encode_and_print_stats(source, indent):
    codec = ExpGolombCodec(direct=True)
    codec.encode(source)
    stat = codec.statistics

    tab = ' ' * indent
    print "%sEntropia źródła:                %5.2f" % (tab, stat.entropy)
    print "%sRozmiar danych źródłowych [KB]: %5.1f" % (tab, stat.source_size/1024./8)
    print
    print "%s+-- Kodowanie bezpośrednie ----------+" % tab
    print "%s| Rozmiar po kompresji [KB]:    %5.1f |" % (tab, stat.compressed_size/1024./8)
    print "%s| Stopień kompresji:            %5.2f |" % (tab, stat.compression_ratio)
    print "%s| Długość słowa kodowego:       %5.2f |" % (tab, stat.mean_code_word_length)
    print "%s+------------------------------------+" % tab

    codec = ExpGolombCodec(direct=False)
    codec.encode(source)
    stat = codec.statistics
    print "%s+-- Kodowanie pośrednie -------------+" % tab
    print "%s| Rozmiar po kompresji [KB]:    %5.1f |" % (tab, stat.compressed_size/1024./8)
    print "%s| Stopień kompresji:            %5.2f |" % (tab, stat.compression_ratio)
    print "%s| Długość słowa kodowego:       %5.2f |" % (tab, stat.mean_code_word_length)
    print "%s+------------------------------------+" % tab
    print