Thread: How do compression software work?

  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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,195
    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.

  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, 12:36 PM
  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