Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For lossless compression, the only way you can know how many times you can gain by recompressing a file is by trying. It's going to depend on the compression algorithm and the file you're compressing.</p> <p>Two files can never compress to the same output, so you can't go down to one byte. How could one byte represent all the files you could decompress to?</p> <p>The reason that the second compression sometimes works is that a compression algorithm can't do omniscient perfect compression. There's a trade-off between the work it has to do and the time it takes to do it. Your file is being changed from all data to a combination of data about your data and the data itself.</p> <p><strong>Example</strong></p> <p>Take run-length encoding (probably the simplest useful compression) as an example.</p> <p>04 04 04 04 43 43 43 43 51 52 <strong><em>11 bytes</em></strong></p> <p>That series of bytes could be compressed as:</p> <p>[4] 04 [4] 43 [-2] 51 52 <strong><em>7 bytes (I'm putting meta data in brackets)</em></strong></p> <p>Where the positive number in brackets is a repeat count and the negative number in brackets is a command to emit the next -n characters as they are found.</p> <p>In this case we could try one more compression:</p> <p>[3] 04 [-4] 43 fe 51 52 <strong><em>7 bytes (fe is your -2 seen as two's complement data)</em></strong></p> <p>We gained nothing, and we'll start growing on the next iteration:</p> <p>[-7] 03 04 fc 43 fe 51 52 <strong><em>8 bytes</em></strong></p> <p>We'll grow by one byte per iteration for a while, but it will actually get worse. One byte can only hold negative numbers to -128. We'll start growing by two bytes when the file surpasses 128 bytes in length. The growth will get still worse as the file gets bigger.</p> <p>There's a headwind blowing against the compression program--the meta data. And also, for <em>real</em> compressors, the header tacked on to the beginning of the file. That means that eventually the file will start growing with each additional compression.</p> <hr> <p>RLE is a starting point. If you want to learn more, look at <a href="http://en.wikipedia.org/wiki/LZ77_and_LZ78" rel="noreferrer">LZ77</a> (which looks back into the file to find patterns) and <a href="http://en.wikipedia.org/wiki/LZ77_and_LZ78" rel="noreferrer">LZ78</a> (which builds a dictionary). Compressors like zip often try multiple algorithms and use the best one.</p> <p>Here are some cases I can think of where multiple compression has worked.</p> <ol> <li>I worked at an Amiga magazine that shipped with a disk. Naturally, we packed the disk to the gills. One of the tools we used let you pack an executable so that when it was run, it decompressed and ran itself. Because the decompression algorithm had to be in every executable, it had to be small and simple. We often got extra gains by compressing twice. The decompression was done in RAM. Since reading a floppy was slow, we often got a speed increase as well!</li> <li>Microsoft supported RLE compression on bmp files. Also, many word processors did RLE encoding. RLE files are almost always significantly compressible by a better compressor.</li> <li>A lot of the games I worked on used a small, fast LZ77 decompressor. If you compress a large rectangle of pixels (especially if it has a lot of background color, or if it's an animation), you can very often compress twice with good results. (The reason? You only have so many bits to specify the lookback distance and the length, So a single large repeated pattern is encoded in several pieces, and those pieces are highly compressible.)</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload