nothing is gone.
only the air between.
compression as a box, twice
two boxes, input, processing, output. what goes into the first must come out of the second.
why anything compresses at all
the usual way of writing things down wastes room. that room is the first kind of air.
a second kind of air: some letters come far more often
a fixed code pays the same bits for the e and for the z. that difference is air too.
fewer bits for what surprises less
a stretch seen before: cheaper to name than to spell again (contextual)
a frequent letter: less surprise, so a shorter code (alphabetic)
random characters: full surprise every time, nothing to save
bits go to surprise. the rest is redundancy, and it can go.
trick one: point back
say it once. then say where it was.
trick one: what it looks like in the file
a pointer is three bytes here: a marker, how far back, how long. 49 bytes become 41.
trick one on a picture: run length
the bigger the areas, the more it saves.
trick one: run length, the bad case
every method makes some files bigger. yours too.
trick two: the frequent letter gets the short code
both halves are known: codes of different length, the frequent one short. now the recipe.
trick two: count first
the same code for every letter: the a pays as much as the d.
trick two: build the tree
always join the two rarest. that is the whole algorithm.
trick two: read the codes off the tree
23 bits instead of 33. nothing lost.
trick two: why it reads itself
no code is the start of another. the prefix trap from
code systems, avoided by construction.
try it: squeeze your own text
and that is a zip
every zip you ever opened did these two tricks. nothing else.
why the random bytes could not shrink
no method shrinks everything. counting says so.
how much redundancy a picture has
one colourpng · 569 bytes
the parrotpng · 93 107 bytes
random noisepng · 197 172 bytes
all three are 196 608 bytes raw. lossless packing takes the parrot to half; the noise it cannot touch.
what png does before it packs
predict each point from its neighbour, keep only the surprise. then deflate.
the parrot, honestly
lossless gets you to half. lossy gets you to a twentieth, and it is not the same picture.
what the eye and the ear do not notice
lossy means: a model of the senses decides what may go. not a worse packer, a different bargain.
a one-way street
lossless: unpack, and you hold the original
lossy: unpack, and you hold something that looks like it
from the 2 kb parrot, the 93 kb never come back.
must exactly this file arrive? then lossy is out.
must a presentable picture arrive? then it is your strongest lever.
the task decides, not the tool. and ask before you spend an hour optimising.
which method
which settings
written into the specification, next to preamble and character code
packed data does not explain itself.
today
1 zip three files of your own and explain the three ratios
2 bring the parrot under 2 kb, and write down what you gave up
3 put method and settings into your specification
two kilobytes.
still a parrot.