JPEG

JPEG

Compression

Image

$ T

$ Starting compression...

R, G, B Channel Splitting

$ S

$ Compressing [#         ] 10%

Color Space Transformation (YCbCr)

$ T

$ Compressing [##        ] 20%

Chroma Subsampling

$ E

$ Compressing [###       ] 30%

Block Splitting

$ S

$ Compressing [####      ] 40%

D
C
T
C
O
E
F
I
D
C
T
C
O
E
F
T

Discrete Cosine Transform

$

$ Compressing [#####     ] 50%

/
/
Q
N
T
Z
M
T
R
X

Quantization

$ P

$ Compressing [######    ] 60%

Entropy Encoding

35, 12, -12, 0, -5, 0, -1, 0, 0, 9, 0, 4, 0, 0, 0, 0 ...

$ O

$ Compressing [#######   ] 70%

Run-Length Encoding

{ [(0, 6), 35],
  [(0, 4), 12],
  [(0, 4),-12],
  [(1, 3), -5],
  [(1, 1), -1],
  [(2, 4),  9],
  [(2, 2),  4],
  [(0, 0)]      }

$ J

$ Compressing [########  ] 80%

Huffman Encoding

0 1 0 1
0010110100101010001001...

$ C

$ Compressing [######### ] 90%

JPEG

struct Jpeg {
	soi	  byte[2]; # start of image
	app0  App0;    # app specific metadata
	dqt   Dqt[];   # quantization tables
	dht   Dht[];   # huffman tables
	sof0  Sof0;    # start of frame
	sos   byte[2]; # start of scan
	data  byte[];  # compressed data
	eoi   byte[2]; # end of image
}

$ s

$ Compressing [##########] 100% - COMPLETE

Decompression

     00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Decoded text
0000 FF DB FF E0 00 10 4A 46 49 46 00 01 01 01 00 48 ......JFIF.....H
0010 00 48 00 00 FF DB 00 43 00 06 04 05 06 05 04 06 .H.....C........
0020 06 05 06 07 07 06 08 0A 10 0A 0A 09 09 0A 14 0E ................
0030 0F 0C 10 17 14 18 18 17 14 16 16 1A 1D 25 1F 1A .............%..
0040 1B 23 1C 16 16 20 2C 20 23 26 27 29 2A 29 19 1F .#... , #&')*)..
     . . .

$

$ Starting decompression...

JPEG Data

0 1 0 1
0010110100101010001001...

$ E

$ Decompressing [#         ] 10%

Huffman Decoding

{ [(0, 6), 35],
  [(0, 4), 12],
  [(0, 4), 12],
  [(1, 3), -5],
  [(1, 1), -1],
  [(2, 4),  9],
  [(2, 2),  4],
  [(0, 0)]      }

$ D

$ Decompressing [##        ] 20%

Run-Length Decoding

35, 12, -12, 0, -5, 0, -1, 0, 0, 9, 0, 4, 0, 0, 0, 0 ...

$ U

$ Decompressing [###       ] 30%

Entropy Decoding

$ A

$ Decompressing [####      ] 40%

Q
N
T
Z
M
T
R
X

Dequantization

$ M

$ Decompressing [#####     ] 50%

I
D
C
T
C
O
E
F
T
I
D
C
T
C
O
E
F

Inverse Discrete Cosine Transform

$

$ Decompressing [######    ] 60%

Block Merging

$ M

$ Decompressing [#######   ] 70%

Upsampling

$ D

$ Decompressing [########  ] 80%

Color Space Transformation (RGB)

$ T

$ Decompressing [######### ] 90%

R, G, B Channel Joining

$ J

$ Decompressing [##########] 100% - COMPLETE

Discrete Cosine Transform

Frequency Decomposition

X0

C0

X1

C1

X7

C7

Frequency Component

Xk

=

c 0
c 1
c 2
c 3
c 4
c 5
c 6
c 7

x 0
x 1
x 2
x 3
x 4
x 5
x 6
x 7

$ T

Cosine Wave Sampling

16

11π

16

13π

16

15π

16

π

16

16

16

16

$ S

DCT Coefficients

DCT Coefficients - Matrix-Vector Product

X 0
X 1
X 2
X 3
X 4
X 5
X 6
X 7

=

s 0
s 1
s 2
s 3
s 4
s 5
s 6
s 7
f 0
f 1
f 2
f 3
f 4
f 5
f 6
f 7
x 0
x 1
x 2
x 3
x 4
x 5
x 6
x 7

$ T

DCT-2D - Matrix Multiplication

=

s 0
s 1
s 2
s 3
s 4
s 5
s 6
s 7
f 0
f 1
f 2
f 3
f 4
f 5
f 6
f 7
f 0
f 1
f 2
f 3
f 4
f 5
f 6
f 7
s 0
s 1
s 2
s 3
s 4
s 5
s 6
s 7

Observations

Compression-Decompression

Multiple Compression Rounds

Chroma vs Luma Subsampling

Chroma Subsampling
Luma Subsampling

Different Subsampling

No Chroma Subsampling
4:2:2 Chroma Subsampling
4:2:0 Chroma Subsampling
4:1:1 Chroma Subsampling

Different Downsampling

No Chroma Downsampling
Average Chroma Downsampling

Lossy Compression

Discrete Cosine Transform
Quantization
Dequantization
Inverse DCT

Different Quantization Tables

90 Factor Quantization
3
2
2
3
5
8
10
12
2
2
3
4
5
12
12
11
3
3
3
5
8
11
14
11
3
3
4
6
10
17
16
12
4
4
7
11
14
22
21
15
5
7
11
13
16
12
23
18
10
13
16
17
21
24
24
21
14
18
19
20
22
20
20
20
50 Factor Quantization
16
11
10
16
24
40
51
61
12
12
14
19
26
58
60
55
14
13
16
24
40
57
69
56
14
17
22
29
51
87
80
62
18
22
37
56
68
99
99
77
24
35
55
64
81
99
99
92
49
64
78
87
99
99
99
99
72
92
95
98
99
99
99
99
10 Factor Quantization
17
18
24
47
99
99
99
99
18
21
26
66
99
99
99
99
24
26
56
99
99
99
99
99
47
66
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99
99