Beispiel #1
0
def main():
    txtin = getText()
    huffman = Huffman(txtin)
    huffman.setFrequency()
    huffman.setTree()
    huffman.setCodes()
    huffman.encode()
    store(huffman.result, huffman.frequency, huffman.probability,
          huffman.codes)
Beispiel #2
0
 def ejecutarHM(self, texto=""):
     codificador = hm.Huffman()
     resultado = codificador.codificar(texto)
     return resultado
Beispiel #3
0
from Huffman import *
import time
import os
import sys


def cls():
    """
    Clears screen depending on operating system
    :return: None
    """
    os.system('cls' if os.name == 'nt' else 'clear')


HH = Huffman()


def menu() -> None:
    """
    A menu system giving user the options
    :return:
    """
    options = input(
        f"Enter an option to begin:\n\n{1}. create codes\n{2}. encode a file\n{3}. decode a file\n\n{0}. to exit\n"
    )
    try:
        options = int(options)
    except:
        pass
        #logging.info("Not an integer")
    if (options == 1) or (options == 2) or (options == 4):
Beispiel #4
0
    o = binascii.b2a_hex(gzip.compress(i))
    print(len(i))
    print(len(o))
    outfile.write(o)
    outfile.close()
    infile.close()

def a2b_fast(open_file):
    infile = open_file[0]
    outfile = open_file[1]
    i = infile.read()
    o = gzip.decompress(binascii.a2b_hex(i))
    outfile.write(o)
    outfile.close()
    infile.close()

def open_file(source_path,target_path):
    infile = open(source_path,"rb")
    outfile = open(target_path,"wb")
    return [infile,outfile]  
    
if __name__=="__main__":
    source_path = r'C:\Users\wiwang\Desktop\File\UDM-pic\test_case_1.png'
    target_path = r'C:\Users\wiwang\Desktop\est_case_1.txt'
    h = Huffman.Huffman()
    h.compress(source_path,target_path)
    #b2a_fast(open_file(source_path,target_path))
    
    #source_path = r'C:\Users\wiwang\Desktop\python-3.8.0.txt'
    #target_path = r'C:\Users\wiwang\Desktop\python-3.8.0.exe'
    #a2b_fast(open_file(source_path,target_path))
Beispiel #5
0
 def setUp(self):
     self.huffman = Huffman()
     self.phrase = 'The quick brown fox jumped over the lazy dog. Filler text to create a bigger shift in the character probabilities.'
     self.huffman.build(self.phrase)
Beispiel #6
0
        bit allocations, quantized mantissas, and overall scale factor.
        """
        #Passes decoding logic to the Decode function defined in the codec module
        return codec.Decode(scaleFactor, bitAlloc, mantissa,
                            overallScaleFactor, codingParams, LRMS)


#-----------------------------------------------------------------------------

# Testing the full PAC coder
if __name__ == "__main__":

    import time
    from pcmfile import *  # to get access to WAV file handling
    '''==============Huffman coder init====================='''
    huffman = Huffman()
    '''====================================================='''

    test = [True, False, False, False, False]

    coded_filename = "../coded/coded.wak"

    if test[0]:
        input_filename = "../inputs/castanets.wav"
        output_filename = "../outputs/castanets.wav"

    if test[1]:
        input_filename = "../inputs/trumpet.wav"
        output_filename = "../outputs/trumpet.wav"

    if test[2]:
Beispiel #7
0
import Huffman

if __name__ == "__main__":
    huf = Huffman.Huffman()
    huf.compress(filename="test.txt", save_as="ana", debug=True)
    huf.decompress(filename="ana", save_as="test2", debug=True)
Beispiel #8
0
from Arguments import *
from Huffman import *
from ComprimirYDescomprimir import *
import Constant as p

decode, archivo_frecuencia, archivo_entrada, archivo_salida = Arguments(
).getArgs()
"""Creamos un Huffman que lee el archivo de frecuencias y procesa los datos ingresados, 
almacena dos diccionarios de codificiación y decodificacion """
huff = Huffman(archivo_frecuencia.name)
huff.procesarHuffman()

#Dependiendo de lo ingresado en teclado, llamará a la funcion codificar o decodificar
if not decode:
    codificar(archivo_entrada.name, archivo_salida.name,
              huff.getDicCodificar())
else:
    decodificar(archivo_entrada.name, archivo_salida.name,
                huff.getDicDecodificar())