You are on page 1of 21

1.

JPEG

Joint Photographic Experts GroupJPEG 1986


JPEG
Joint Photographic Experts Group 1994
ISO/IEC 10918-1 | ITU-T Rec. T.81 "Information Technology Digital
compression and coding of continuous-tone still images" JPEG
Baseline Sequential
DCT-based Coding Progressive
DCT-based Coding
Lossless Coding
Hierarchical
Coding JPEG
Baseline Sequential DCT-based Coding JPEG
Baseline Sequential
DCT-based Coding JPEG

1.1

RGB

YCbCr

Y = 0.299 R + 0.587G + 0.114B

Cb = 0.168R 0.331G + 0.499B L


C = 0.5R 0.419G 0.081B
r

(1)

RGB JPEG YCbCr


luminance
YCbCr Y
chrominanceYCbCr Cb Cr

SoC Design Lab., 2004

1.2

JPEG
YCbCr

4:4:44:2:24:2:0 JPEG
Block Coding
88 JPEG
88 2-D Discrete Cosine
Transform2-D DCT

QuantizationQ

JPEG DC Differential Pulse Code


ModulationDPCM DC AC Zig-Zag
AC Run-Length CodingRLC
Huffman Coding JPEG
JPEG
JPEG
Variable Length
DecodingVLDIQIDCT
YCbCrRGB

pixel with Y, Cr and Cb value

4:4:4

4:2:2

pixel with only Y value


pixel with only Cr and Cb value

4:1:1

4:2:0

SoC Design Lab., 2004

8
8

f(i,j)

F(u,v)
DCT

Fq(u,v)
Quantization

8x8

Header

Coding
Tables

Quantization
Table

Tables

01001011101

DC
DPCM

Data

Entropy
Coding
RLC
AC

zig zag
scan

JPEG

01001011101
Quantization
Table
Header

Coding
Tables

Tables
Data

F(u,v)
Entropy Fq(u,v)
Inverse
IDCT
Decoder
Quantization

f(i,j)

8x8

JPEG
SoC Design Lab., 2004

2-D Discrete Cosine Transform2-D DCT

1.3

Transpose
Memory
(Y)

1 D DCT
Unit

1 D DCT
Unit

Z=YAT

Y=AX

Forward Discrete Cosine TransformFDCT


Inverse Discrete Cosine
TransformIDCT
88 JPEG
JPEG 128

128

X k1 ,k2

N 1 N 1
(2n + 1)k1 cos (2n2 + 1)k 2
2
= c(k1 )c(k 2 ) xn1,n2 cos 1
2N
2N
N
n1 =0 n2 =0

n1 , n2 , k1 , k 2 = 0,1,L, N 1
where c(0) =
xn1 ,n2 =

2
N

c ( k )c ( k
1

) X k1,k2 cos

(3)

(2n1 + 1)k1 cos (2n2 + 1)k 2


2N

n1 , n2 , k1 , k 2 = 0,1,L, N 1
where c(0) =

(2)

and c(n) = 1 for n 0

N 1 N 1

k1 =0 k 2 =0

2N

1
and c(n) = 1 for n 0
2

Row-Column Decomposition

Z=AXAT X
SoC Design Lab., 2004


8 point
1-D DCT
N 1

(2u + 1)v

u =0

2N

F (v) = c(v) f (u ) cos


u, v = 0,1,L, N 1
N 1

(2u + 1)v

v =0

2N

f (u ) = c(v) F (v) cos


where c(0) =

1
and c(v) =
N

2
N

(4)

for v 0

Chens Algorithm 8 point 1-D DCT


Chens Algorithm 16 26
Chens Algorithm

-C4

X0

X1

+
x
x

C4

x
x

-C2
C2

Y0

C4

Y4

Y2

-C4
C6

X2

X3

Y6

C6

X4

x
C7
C3

-C4

X5

X6

+
x
x

C4

x
C3
C7

C4

X7

+
x

x+y

x-y

C4

C1

+
x
x
x

Y1

Y5

C5
-C5

Y3

-C1

Y7

cx

Chens Algorithm[1]

SoC Design Lab., 2004

1.4

JPEG

16

11

10

16

24

40

51

61

17

18

24

47

99

99

99

99

12

12

14

19

26

58

60

55

18

21

26

66

99

99

99

99

14

13

16

24

40

67

69

56

24

26

56

99

99

99

99

99

14

17

22

29

51

87

80

62

47

66

99

99

99

99

99

99

18

22

37

56

68

109

103

77

99

99

99

99

99

99

99

99

24

35

55

64

81

104

113

92

99

99

99

99

99

99

99

99

49

64

78

87

103

121

120

101

99

99

99

99

99

99

99

99

99

99

99

99

99

99

99

99

99

72

92

95

98

112

100

103

1.5

Differential Pulse Code ModulationDPCM


DC AC

DC 88 JPEG
88 DC 88
DC DC
DC

SoC Design Lab., 2004

DCi 1

DCi

blocki 1

sample

blocki

DCi

Difference
Previous sample

DCi DCi 1

DC i 1

1.6

Zig-Zag Run-Length CodingRLC


DC AC

88 63 AC
Zig-Zag
Zig-Zag 88

Zig-Zag AC

Zig-Zag
Zig-Zag
Row ScanColumn Scan

SoC Design Lab., 2004

DC

30

-3

-1

-2

-2

-1

-1

(R,L) => (0,-3)(0,-2)(0,-1)(0,-2)(0,-1)(2,-1)(EOB)


Zig-Zag

R,L= 0 ,
DC AC -3-3 0
0,-3-3 -2-2 0
0,-2(0,-1) 0,-2
0,-1 0 AC -12,-1
-1 88 0 EOB
-1 0

1.7

Huffman CodingHuffman Table

JPEG DC AC
DC
DC

DC AC

SoC Design Lab., 2004

Size Length Codeword


0
2
0
1
3
10
2
3
11
3
3
100
4
3
101
5
3
110
6
4
1110
7
5
11110
8
6
111110
9
7
1111110
10
8
11111110
111111110
11
9
(a) DC

Size Length Codeword


0
2
0
1
2
1
2
2
10
3
3
110
4
4
1110
5
5
11110
6
6
111110
7
7
1111110
8
8
11111110
9
9
111111110
10
10
1111111110
11
11 11111111110
(b) DC

SoC Design Lab., 2004

Category

AC Coefficient Range

-1,1

-3,-2,2,3

-7,,-4,4,,7

-15,,-8,8,,15

-31,,-16,16,,31

-63,,-32,32,,63

-127,,-64,64,,127

-255,,-128,128,,255

-511,,-256,256,,511

10

-1023,,-512,512,,1023

11

-2047,,-1024,1024,,2047
AC

1.8

Baseline Sequential DCT-based


Coding
Baseline Sequential

DCT-based Coding
88 888=512(bits)
88 98(bits)

SoC Design Lab., 2004

10

140
144
152
168
162
147
136
148

144 147
152 140
155 136
145 156
148 156
167 140
156 123
155 136

140
147
167
160
148
155
167
155

140 155 179


140 148 167
163 162 152
152 155 136
140 136 147
155 140 136
162 144 140
152 147 147

61
4
-1
0
0
0
0
0

-3
-4
-2
0
0
0
0
0

2
2
0
1
0
-1
0
0

0 2 0 0 -1
0 0 0 0 0
0 -1 0 -1 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

3
5
7
9
11
13
15
17

5
7
9
11
13
15
17
19

7
9
11
13
15
17
19
21

9
11
13
15
17
19
21
23

11
13
15
17
19
21
23
25

13
15
17
19
21
23
25
27

15
17
19
21
23
25
27
29

179
179
172
160
162
162
147
136

-128

12
16
24
40
34
19
3
20

16
24
27
17
20
39
28
27

19
12
8
28
28
12
-5
8

12
19
39
32
20
27
39
27

11
12
35
24
12
27
34
24

27
20
34
27
8
12
16
19

51
39
24
8
19
8
12
19

47
51
44
32
34
34
19
8

FDCT

185
20
-10
-8
-3
3
8
0

-17
-34
-23
-5
9
-2
0
-7

14
26
-1
14
7
-18
-2
-2

-8
-9
6
-14
1
8
3
1

23
-10
-18
-8
-11
8
-1
1

-9
10
3
-2
17
-3
-7
4

-13
13
-20
-3
18
0
-1
-6

-18
6
0
8
15
-6
-1
0

(6)(61),(0,2)(-3),
(0,3)(4),(0,1)(-1),
(110)(111101)(01)(00)(100)
(0,3)(-4),(0,2)(2), Huffman (100)(00)(0)(100)(001)(01)
(1,2)(2),(0,2)(-2),
(10)(11011)(10)(01)(01)(01)
(0,2)(-2),(5,2)(2),
(01)(11111110111)(10)(111010)
Run-length
(3,1)(1),(6,1)(-1),
(1)(1111011)(0)(11100)(0)
(2,1)(-1),(4,1)((111011)(0)(11111010)(0)(1010)
1),
(7,1)(-1),(0,0)
17

19
21
23
25
27
29
31

Zig-Zag

total 98 bits
Q Table

1.9

JPEG

JPEG

Start_of_image

Frame

Tables, etc. header

scan

End_of_image

......

scan

Tables, etc. header segment Restart segment Restart

block

block

block

......

......

block

JPEG

SoC Design Lab., 2004

11

2.

2.1

Final_project --------- sw.bat


|
|---- sw -------- bmp.cpp *.bmp
|---- jpeg.cpp JPEG
|---- jpeg.h jpeg.cpp
|---- main.cpp JPEG Codec
|---- marker.h JPEG
|---- picture.cpp
|---- stream.cpp bitstream
|---- stream.h stream.cpp
|---- type.h

2.2

JPEG

ARM
Integrator/AP
JPEG

Hardware/Software Co-design
JPEG
JPEG
JPEG
JPEG
JPEG
JPEG: Still Image Data Compression Standard
[2]
SoC Design Lab., 2004

12


JPEG
JPEG JPEG

JPEG
z

4 Component

Interleave and non-interleave scans


JPEG

Component
RedGreenBlue

JPEG YCbCr 1
Y 2 Cb 4
JPEG 3
JPEG 88
8

1Y
88
Non-interleave order 3
1 88 2
88 3 88 88
Interleave
orderY1Cb1Cr1 MCUMinimum
Coded Unit
SoC Design Lab., 2004

13

8
8

Cb

Cr

MCU
MCU

Non-interleave orderMCU
MCU MCU 3
88 4:4:4 4 Y CbCr 88
4:1:1 MCU 88

JPEG 4:4:4 YCbCr 4:1:1 4 Y


CbCr DCT-based
88 DCT
QuantizeEntropy coding
JPEG
Arithmetic coding
JPEG
3
3 SSSS 2SSSS 2
Category2 011 3
011SSSS
3 01111
1 32
0110001101
SoC Design Lab., 2004

14

SSSS

Value

-1,1

-3,-2,2,3

-7,,-4,4,,7

-15,,-8,8,,15

-31,,-16,16,,31

Category
0
1
2
3
4

Code Word
00
010
011
100
101

2.3

JPEG bmp.cpppicture.cppjpeg.cpp

stream.cpp
bmp.cpp*.bmp
picture.cpp 88
88
88
jpeg.cpp
88 picture.cpp
stream.cppbit-stream
bit
byte 0 1 16
SoC Design Lab., 2004

15

1 16 0 JPEG

Encoder
Bmp.cpp

Picture.cpp

Jpeg.cpp

Stream.cpp

Bmp.cpp

Picture.cpp

Jpeg.cpp

Decoder
JPEG

type.h ByteWordDWord
picture.cpp

bmp.cpp *.bmp
RGB JPEG
YCbCr YCbCr
RGB

stream.cpp
9

BufferBufferLengthbyte Buffer
1 bit Buffer BufferLength
Buffer bit

ByteStuffing ByteStuffing true 0xFF


0x00 0xFF byte

Name[32]

bool Open (const char* name, const char* attr) fopen()

SoC Design Lab., 2004

16

bool Close() fclose()

bool IsEndOfStream() feof()

bool PutStream(DWord code, Byte length) Buffer


code bit-streamlength
code falsePutStream(0x19,5)
11001 5 bit

bool GetStream(DWord* code, Byte length) Buffer


length
code falseGetStream(&strm, 5)
5 strm void Align(bool flag) flag
true BufferLength 8 Buffer 1 8
flag false 0 Buffer

picture.cpp
9

Pixel
32 4

32-bits

Cb

Cr

8-bits
Pixel

WidthHeight Pixel

MCU88 88
Type 88 Y Cb

SoC Design Lab., 2004

17

address
0

10 11 12 13 14 15

16 17 18 19

MCU

bool IsEmpty()Pixel 0NULL


IsEmpty() false Pixel 0NULL
true

void Create(Word w, Word h)


Pixel

void Release() Pixel 0NULL

bool _get_min_code_unit(int address) Pixel


MCU 8
8 address 88 0
address 1 88
Block_Address Block_Address
88 0

SoC Design Lab., 2004

18

0 , 0

8 , 0

16 , 0

24 , 0

3
MCU

address

8
8

Cb

8
8
8

Cr

bool _get_min_code_unit(int address)


9

bool _put_min_code_unit(int address)


MCU Pixel

jpeg.cpp
9

HuffmanDC DC[3] CodeWord


CodeLengthCodeWord CodeLength
CodeWord
SSSS15 SSSS 4
DC.CodeWord[4] 0x0005DC.CodeLength[4]
3 101 000015
1010000

HuffmanAC AC[3] CodeWord CodeLength


RRRR 0
SSSS

void ChenFDCT(int (*block)[8]) Chens Algorithm

Chens Algorithm 1

void ChenIDCT(int (*block)[8]) Chens Algorithm

SoC Design Lab., 2004

19

1
9

void _initial_dc_table(Byte identifier, Byte


(*dc_length)[17], Byte (*dc_value)[12]) DC
DCjpeg.h 34 identifier
DC

void _initial_ac_table(Byte identifier, Byte


(*ac_length)[17], Byte (*ac_value)[162])

void _encoding_block_value(Byte identifier, int


(*block)[8])VLC

void _decoding_block_value(Byte identifier, int


(*block)[8])VLC

2.4

HW/SW Co-design JPEG

JPEG CodecHW/SW Co-design


HW/SW Partition
ARM JPEG

Profiling JPEG Profiling


2-D DCT/IDCT2-D
DCT/IDCT AMBA Slave
JPEG

JPEG

sw.bat JPEG
ARM sw.axf
CodeWarrior C++
bmp test1.bmp test2.bmp test3.bmp
SoC Design Lab., 2004

20

test4.bmp sw
C++

[1] W. Chen, CH Smith, and S. Fralic, "A fast computational algorithm for the
discrete cosine transform," IEEE Trans. Commun., vol. COM-25, pp. 1004-1009,
Sept 1977.
[2] JPEG: Still Image Data Compression Standard by William B. Pennebaker and
Joan L. Mitchell, Kluwer Academic Publishers, ISBN: 0442012721

SoC Design Lab., 2004

21

You might also like