Code Monkey home page Code Monkey logo

lzw's Introduction

LZW

What is this code?

The Lempel–Ziv–Welch (LZW) is a data compression algorithm. I did my own version of the LZW compressor and decompressor. I used 12-bit fixed with codes.

Input Data

There are three examples of my code running:

  • file1.txt <-> file1.z
  • file2.txt <-> file2.z
  • file3.txt <-> file3.z

Compressor

How to execute the program

If you use g++ to execute your program, you should go to the folder where is the compressor.cpp file. Then, you should write the line g++ compressor.cpp –o compressor -std=c++11. Then, you should write compressor name_of_file_you_want_to_compress. For instance, compressor /LZWInputData/file1.txt. If you use a program like Eclipe, Notepad, … you should add the name of the file to compress as a parameter in the running options. In order to compress a file named file1.txt you should execute the program with the full filename path as an argument.

The LzwStream class

There are :

  1. Private attributes:
  • a dictionary (map)
  • a position (integer - indicates the position in the file)
  • an OldCode (char)
  1. Public attributes:
  • a constructor
  • a method compressedToStream, which does the compression
  • a method initializeDictionary, which creates the dictionary at the beginning of the program

Decompressor

How to execute the program

If you use g++ to execute your program, you should just like you did before with the compressor but instead of writting compressor, you should write decompressor.

The LzwStream class

There are :

  1. Private attributes:
  • a dictionary (map)
  • a position (integer - the position in the file to decompress, that is to say the number of codes we have already read)
  • an OldByte (unsigned char - it memorizes the last byte we read in the file)
  1. Public attributes:
  • A constructor which uses the ifstream constructor
  • readCode : read the next code in the file to decompress
  • DecompressToStream: do the decompression, using the readCode method
  • initializeDictionary: initialize (or reinitialize) the dictionary when needed

To-do list

  • the code is written for a 12-bit fixed with codes. I would like to improve it and make it possible to use with any number of bits.

lzw's People

Contributors

cga83 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.