How do compression software work?

This is a discussion on How do compression software work? within the Tech Board forums, part of the Community Boards category; How do they cram the data into a smaller file without loosing any bytes ? ...or do they loose some ...

  1. #1
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321

    Question How do compression software work?

    How do they cram the data into a smaller file without loosing any bytes ? ...or do they loose some bytes?
    Last edited by abh!shek; 05-13-2008 at 12:57 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,461
    How do they cram the data into a smaller file without loosing any bytes ? ...or do they loose some bytes?
    It depends on the algorithm: some are lossless, others are lossy.

    As a simple example: suppose you wanted to compress a string of ten 'a's. You could express this as a pair: the number 10, and the character 'a'. This is lossless, since given this pair, you can re-construct the string of ten 'a's.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Thanks, and sorry for starting this thread without googling properly.

  4. #4

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Some are lossy, when the information lost is of low value. Like in a picture. If 3 pixels are very close to the same red value e.g. (0,0,128 0,1,129 0,0,127) there really is very little information that the human eye would percieve in the difference, so to improve compression the algorithm may treat them as being the same value, like 0,0,128. You lost information, but its not noticeable, so the decompressed image woudl look almost exactly like the original.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    A general approach is to split the data into subsets (like bytes or pixels), sort according to frequency and then encode the more frequent subsets with shorter codes while the less frequent subsets gets longer codes. Check out huffman tables.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Software Developer Opportunity in Delaware
    By Jdorazio in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 04-28-2009, 10:58 AM
  2. Replies: 3
    Last Post: 11-17-2008, 11:36 AM
  3. torrents are destroying the world
    By Trennto in forum A Brief History of Cprogramming.com
    Replies: 141
    Last Post: 07-15-2008, 01:48 PM
  4. Writing a .gif animator software
    By rEtard in forum Windows Programming
    Replies: 5
    Last Post: 09-21-2005, 12:23 PM
  5. Is Linux More Secure Than Windows?
    By xErath in forum A Brief History of Cprogramming.com
    Replies: 69
    Last Post: 06-29-2005, 07:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21