Imc14 05 Dictionary Codes
Imc14 05 Dictionary Codes
Techniques
2/31
Static vs. Adaptive Dictionary
3/31
Basic Idea of Dictionary Coding
4/31
Motivating Example
5/31
Static Dictionary
6/31
Digram Coding
The dictionary is composed of
All letters from the alphabet
As many digrams (pairs of letters) as possible
7/31
Simple Digram Coding Example
8/31
Problem: Which Digrams to Use?
Source 1: LaTex documents Source 2: C programs
9/31
Adaptive Dictionary Technique
10/31
LZ77 (1/2)
General approach
Dictionary is a portion of the previously encoded sequence
Use a sliding window for compression
Mechanism
Find the maximum length match for the string pointed to by
the search pointer in the search buffer, and encode it
Rationale
If patterns tend to repeat locally, we should be able to get
more efficient representation
11/31
LZ77 (2/2)
Sliding window is composed of a search buffer and a look-
ahead buffer (note: window size W = S + LA)
Match pointer Search pointer
a _ _ a b r a _ a d a b r a r r a r r a _
12/31
Possible Cases for Triples
13/31
LZ77 Encoding Example
Sequence |cadabrar|rarrad|
cabracadabrarrarrad |cadabrar|rarrad|
W = 13, S = 7 |cadabrar|rarrad|
|cabraca|dabrar|rarrad send <3, 3, C(r)>
no match for d Could we do better?
send <0, 0, C(d)> send <3, 5, C(d)> instead
|abracad|abrarr|arrad
|abracad|abrarr|arrad
|abracad|abrarr|arrad
|abracad|abrarr|arrad
send <7, 4, C(r)>
14/31
LZ77 Decoding Example
15/31
LZ77 Variants
16/31
Problems with LZ77
17/31
LZ78
18/31
LZ78 Example
Input: wabbabwabbabwabbabwabbabwoobwoobwoo
Dictionaries: final dictionary
Index Entry
19/31
Remarks on LZ78
Observation
If we keep on encoding, the dictionary will keep on growing
Possible solutions
Stop growing the dictionary
Effectively switch to a static dictionary
Prune it
Based on usage statistics
Reset it
Start all over again
The best solution depends on the knowledge of the
source
20/31
LZ78 Variants: LZW
Invented by Terry Welch in 1984
Idea
Instead of <i, c>, encode i only
Algorithm
Initial dictionary contains all alphabet letters, p = null
while (!done)
read next symbol into a
if (p*a) is in the dictionary // Note: ‘*’ stands for concatenation
p = p*a
else
send out index of p
add p*a to the dictionary
p = a
end
21/31
Example: LZW Encoding
Input: wabbabwabbabwabbabwabbabwoobwoobwoo
Dictionaries:
initial dictionary (source alphabet) final dictionary
Index Entry
1 b
2 a
3 b
4 o
5 w
Output: 5 2 3 3 2 1 6 8 10 12 9 11 7 16 5 4 4 11 21 23 4
22/31
Problems with LZW Decoding
23/31
Example: Special Case in Decoding
Index Entry
1 a
2 b
24/31
Application: Compress
25/31
Application: GIF Images
26/31
GIF Performance
27/31
Application: PNG Images
28/31
PNG – Deflate
30/31
PNG: Performance
31/31