Sie sind auf Seite 1von 26

CS3242 Hypermedia Information Processing

Programming Assignment I: Simple Hierarchical JPEG Encoder/Decoder


Name:

Wu Yinghui Freddie

Matric No.:

986933H13

I. Introduction
This project is to develop a program that implements a simple hierarchical JPEG
encoder/decoder for greyscale images.

JPEG still picture compression standard is one of the most popularly used formats for
digital images storage and interchange. The JPEG (Joint Photographic Experts Group)
format was established in 1986 and adopted as standard by ISO/CCITT in 1991.

The power of JPEG compression lies in its efficiency in data compression and its
flexibility in handling different kinds of picture data. With the lossy mode compression,
which is most commonly used, JPEG can achieve a compression ratio from 1:10 to 1:50.

Hierarchical JPEG is one of the operation modes defined by the JPEG standard. Despite
the slightly lower compression ratio, hierarchical operation mode offers decoders the
flexibility to choose an appropriate position in the trade-off for image quality and system
capability.
II. System Design
The whole system was designed with the hierarchical JPEG operational flowchart in
mind. However, for the ease of implementation, I decided to simplify the actual
compressed file format as well as part of the internal data flows. (I call the simplified

JPEG file format vJPG. Thus, the system is called GIF2vJPG.) The brief system
block diagram is presented in Figure 1.
Image
Container

JPEG
Encoder/Decoder

Image
Container

Image
Reader

Huffman
Encoder/Decoder

Image
Writer

Figure 1

Brief block diagram of GIF2vJPG system.

By implementing image reader/writer and image container separately, the system can be
modified to access any image format as long as the corresponding reader/writer is
provided.

The JPEG encoder and decoder are designed to be stream-based black boxes, which is
because of the idea that JPEG encoders functionality is basically to convert an image
into a bit stream, and JPEG decoders is to convert a bit stream back into an image. With
the stream-based black box implementation of JPEG encoder/decoder, the system can
simply redirect output from JPEG encoder into a file stream during encoding stage, and
redirect a file stream into JPEG decoder during decoding stage. This convention greatly
simplifies the interface between the I/O components and the core encoder/decoder. A
more detailed block diagram of the JPEG and Huffman encoder is presented in Figure 2,
and diagram of JPEG and Huffman decoder is presented in Figure 3.

Image
blocks
Low-pass
Down-sampling

Low-pass
Down-sampling

+
-

Up-sampling
Interpolation

DCT

Up-sampling
Interpolation
Level shift
DCT

DCT
IDCT

Quantize
r

IDCT
Level shift
Quantizer

Quantizer

Dequantizer

Dequantizer

Zigzag
scan

Zigzag
scan

Generate
Huffman
coding table

Generate
Huffman
coding tree

Zigzag
scan

Compute
statistics for
symbol usage

Convert to
intermediate
symbols

Symbol
translation
Encoded bit stream

Figure 2

Sample block diagram of 3-level hierarchical JPEG and


Huffman encoder.

III. System Implementation


The GIF2vJPG system is implemented purely in the JAVA programming langauage, in
favour of JAVAs portability, its rich data structure library and its flexible object-oriented
programming style.

For the ease of black box implementation, I defined a few interfaces and abstract classes
to specify the external views of different blocks in the system:
-

ImageIOContainer: Abstract class used as define image I/O wrappers.

Encoded bit stream


Symbol
translation

Recover
Huffman
coding table

Convert from
intermediate symbols
back to coefficients

Zigzag
scan

Zigzag
scan

Dequantizer

Dequantizer

IDCT

IDCT
Up-sampling
Interpolation

Zigzag
scan

Dequantizer

IDCT
Level shift
Up-sampling
Interpolation

Image
blocks

Figure 3

Sample block diagram of 3-level hierarchical JPEG and


Huffman decoder.

GreymapFilter: Interface used to define filters for images (greymaps in this


project).

JPEGCodec: Interface defining common data structures and constants used by


both JPEG encoder and decoder.

HuffmanCodec: Abstract class defining common data structures, methods and


constants used by both Huffman encoder and decoder.

In addition, to provide the bit stream black box view of JPEG encoder/decoder,
JPEGEncode and JPEGDecode classes, both of which implement JPEGCodec,
interface, are extended from ByteArrayInputStream and

ByteArrayOutputStream classes, respectively. Thus, images are transformed from


pixel blocks to bit streams via the decoder and then directed to file output stream;
compressed images are read from file input stream and then directed to encoder to be
transformed back to pixel blocks. This architecture gave great advantage in coding and
debugging stages of the system.

Furthermore, in order to read in greyscale GIF images as input, a subclass of


ImageConsumer, PixelGrabber, was created to grab pixels from the
ImageProducer implementation provided by JAVAs API library. However, as the
output of the system, only vJPG (defined in Table 1, as compression output) and rawbit
PGM (as decompression output) files are use.
Table 1
vJPG1.0

vJPG file format

Magic tag for vJPG file format

CR
Lines of comments

Comment lines start with # and end at CR

Width

Width of original image (in plain ASCII decimal)

Space
Height

Height of original image (in plain ASCII decimal)

CR
Quantization scalar

Quantization scalar used (in plain ASCII decimal)

Space
Level of hierarchies

Level of hierarchies used (in plain ASCII decimal)

CR
DC Huffman table length

2 bytes (in binary, hi-byte first)

DC Huffman table

In plain bytes

DC code length

2 bytes (in binary, hi-byte first)

DC codes

In plain bytes (padded to byte with 0s)

0xFFFF

DC-AC separator

AC Huffman table length

2 bytes (in binary, hi-byte first)

AC Huffman table

In plain bytes

AC code length

2 bytes (in binary, hi-byte first)

AC codes

In plain bytes (padded to byte with 0s)

0xFFFE

End of file tag

IV. Evaluation
The following are the compression ratios obtained using the implemented GIF2vJPG
system on some sample images (for original image, please refer to Appendix 1) :

Image

Mandrill

Peppers

Board

Glasses

Girl

Lenna

vJPG compression

Rawbit
PGM size

GIF (256
colors)
size

58,558

36,511

15,878

16,775

17,133

17,193

2502348bit

62.35%

27.11%

28.65%

29.26%

29.36%

68,858

57,411

6,134

6,799

7,480

8,108

2752508bit

83.38%

8.91%

9.87%

10.86%

11.77%

288,664

90,331

10,681

12,490

13,669

14,404

6184678bit

31.29%

3.70%

4.33%

4.74%

4.99%

55,334

46,160

9,621

10,771

11,295

11,486

2881928bit

83.42%

17.39%

19.47%

20.41%

20.76%

393,254

283,675

29,290

32,289

34,688

36,408

7685128bit

72.14%

7.45%

8.21%

8.82%

9.26%

262,182

241,375

21,354

23,449

26,184

27,469

5125128bit

92.06%

8.14%

8.94%

9.99%

10.48%

Level 1

Level 2

Level 3

Level 4

From the table above, we can see that vJPGs compression ratios varies from 1:3.5 to
1:27. Also, we can observe that the more levels of hierarchies used, the lower the
compression ratio, which can be understood as a trade-off between flexibility and
compression efficiency. Furthermore, the more complex the original image is (such as
gmandrill.pgm), the lower the compression ratio. This can be explained by the fact
that heavily textured images give more significant high frequency DCT coefficients than
simple, plain images.

For more visualization of the compressed images, please refer to the Appendix I.

V. Conclusion
I implemented a pair of simplified hierarchical JPEG encoder and decoder, GIF2vJPG.
The system can perform multiple levels of hierarchical JPEG encoding/decoding with
variable quantization scalars.

I also conducted a performance test with three greyscale images of different complexities.
The compression ratios obtained showed that both the level of hierarchies used and the
level of texture the images contain affect the efficiency of JPEG compression. However,
lossy JPEG compression can provide much better compression performance than GIF in
general, due to the fact that lossy JPEG throws away some information from images.

VI. References
[1]

Wallace, G. K., et al. The JPEG Still Picture Compression Standard. IEEE
Transactioins on Consumer Electronics, December 1991.

[2]

International Telecommunication Union (ITU). Information Technology Digital


Compression And Coding of Continuous-tone Still Images Requirements And
Guidelines. CCITT Recommendation T.81, 1993.

[3]

ISO/IEC JTC 1/SC 29/WG 1. FCD 14495, Lossless and near-lossless coding of
continuous tone still image (JPEG-LS) (public draft). ISO/IEC JTC1/SC29 WG1
(JPEG/JBIG), 1997.

VII.

Appendix I: Visualization examples

gmandrill.gif

gmandrill_11-1.jpgv

gpeppers.gif

gpeppers_11-1.jpgv

board.gif

board_11-1.jpgv

glasses.pgm

glasses_11-1.jpgv

girl.pgm

girl_11-1.jpgv

lenna.pgm

lenna_11-1.jpgv

Quantization scalar

= 0.5

Quantization scalar

= 1.0

Compression level

=1

Compression level

=1

Decompression level = 1

Decompression level = 1

10

(shown above)

Quantization scalar

= 2.0

Quantization scalar

= 4.0

Compression level

=1

Compression level

=1

Decompression level = 1

Decompression level = 1

Quantization scalar

=1

Compression level

=4

Quantization scalar

=1

Decompression level = 1

Compression level

=4

Decompression level = 2

Quantization scalar

=1

Compression level

=4

Decompression level = 3

Quantization scalar

=1

Compression level

=4

Decompression level = 4

11

VIII.

Appendix II: Partial source code (attached in separate sheets)

Source code list includes the listing of following source files:


1) FDCT/IDCT:
DCT.java
2) Up-/down-sampling:
GreymapFilter.java, AvgDownSample.java,
RepeatUpSample.java
3) Entropy encoding/decoding:
JPEGCodec.java, JPEGEncode.java, JPEGDecode.java,
HuffmanCodec.java, HuffmanEncode.java, HuffmanDecode.java

12

B

>?
>?


# <


8
=

Mar 2 2001 03:28

DCT.java

 8

'
0
; 

0 ; 
:
 
#

0 :

 
# 

?
3 >*
 ?
>B
 
8  
?

> 0 
B
?  
>* 


<


"



B



0


<

<

>0
?

'B

-
(
(

2
(

5


6(
(


-,


-


=






K
K
K
K


K

"

K
K



K
K
LK



-


K

(


"

>?
>?

2
-

-6


=


"








"






'8

5


" N
 

7
 "


 )

" 



 




K

"

K
K


=





=
K



 I
G
F
E
D

)*


H

%


%
I

 I
G
F
E
>D




,2

Page 1

,
%
+
$

#
"


)*



DCT.java








 







K
K

"


K
K

K

K
K
K


K
K


K

"

K
K



LK

1


 I
G
 F
 I
E

G  D
F J
E "
 
D
J 
8

? 
>
8

?
 ,> 



 :
 

 " 
:  =

"

=8






=
(



O
?

,>

  ,>
=



=

?

2

5


62
2

&8

$
"

:;


&



7
2
6




5


,


" 9





-


>?




6

#

)

2
6

5




"






2

"


5


6

<

5,


5

'

* >B

8 
H 
B
 I
:
G
F ;
E

D #
J 
:
* 
8
, ?
 >*
?
* >B



: 

;'
'

8
%
H

;'

;


>0

8
0

?

=A@ 8
= ;
,

"  @

>? 
B
>? 


=A@
 =
=
: 
"
 :




>?
>?
 
0
 
= 
"
 9

)
0


>
?

>0




"



>
?

>0
=

=8

=

"


"

<


0


<

<





(

-

2
6

5
,















?'


(


-


2
6




5

,

"

@
;'




'

8
%
B H
8  I
%
H G
F
 I E
G D
F J
E
D *
J
8
,
B 
8
, *


B )*
:

)* 
: =

"
>?


=
:




>?
>?




"

)





-
2

>

>0

8 =

0 H
8 
%
H G
F
 I E
G D
F J
E

D
J
8
,
0 
8

,


0 )*
:

8
, )* 
 : =


0 = 


"
I

?

>
?

>0




"

'

'


(

=

6

5


,(


(


(


0

9
;





0

0

#



8


8


*
'

'

;'

>?

'

;'
9

?
=

;'
9

=A@

>



B

>?
>?


#


B

>?
>?


# <





'




8

%
0 H
G
F
8  I
E
%
H G
D
F
J
 IE
G D
B
F J
8
E

,

D
J
8
B
,
0  =8


8

,
, )* 

 : =


0 )*

8
: 0 = 

0
)* 
 : =

 
= =
'

>
#


>B

H 

 I 
G "
F
IE 
D
J ?
>*
* ?
>B
8
, 


* 
'


)*
: 0
%

=


9
;

* ?

;'
9

=





'

"





-
(

;'

B

0
  
: =

<

(

>?

"




0
 9


"

)



=

>?

"
"



>?



0







"



H
 I

G
 F
 E
=
 D
# J

B

0 8
,

C


8
:;

-

8
%



(

>

<

  

. 3



'

'

>

?

>*




"


>*
'

#

?

 =

;'




'

;'

<

# 

'


;
=

#

H

=8

>

%


H

-
2

8
%

,>

H

=
:

8
; 

'

 (

 9

(


;

'

O 


;'


;'




=

K
K

"

G






!


4


 





/ 0 56

 

 

#0


1


>?


K

>D




 I
G
F
E
>D

>?


H

"










0
"






=A@

:;

'

# 
;'
' 8 
 %
H 3
8  I ;

%
H G
F 
 IE =
:
G D
F J 
E

?
D
J
>
8
 , ?
 >

8 

,
  

 
: "

 
: =

B

>?
>?


#




8


O
# 


3

;'




@



*

"



:



!


,






8
; 
;

'

; 

=


"

H

 I
 G
F
E

" >D
 
=
=

 =
"

C

-;  

  "




 ;

0  :

; " 
' 
;
B
:0
: >? 

:
 >? 
 
"
  
=


"
0  0
  

"  "



  


  
 " 


8  8
?  ?
%
%
H
H
'
'


2
2


%



&

?
H

>D
%


&

3%



>D

M8



=A@ 8
= ;
,

"  @

>? 
B
>?
 

=A@
 =
=
: 
"
 :

 


>?
>?
 
0

# 
 
"
 9

)
0


8

"
&

G

 I
G
F
E
D 

G

DCT.java

Page 2

H

;


Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg

I
%



2








*

B




0
)
#


AvgDownSample.java

"















C

 

 













'





-
(

5



,



-



(

2

5


,
+

Page 1



*



"

#
"


;7

)*





GreymapFilter.java


!




























 

 





*
 





&

(

-
2

"




5


,



 9
 

*



)

"
"

)



0





(

-
2

*


&
*









&
"

&

"
=




&









&8

$




'




&
:




"




 






&


  

. 3



*


&
:

"

"


*


 =



/ 0 56






#0


1








@







&
8





*




!


3




C


'

'

'

'


:

'

'

:B


B




:B


B




:B


B




:B


B




M






:


@ #

:


"





&





=




<

*


&


0



  ;M
 7
 

 
0



C

 

C 
=

# 



8


F


*





B
%

@
:B


B

    
    
    


3

C

0

*


&
*

;
*

0

'

;7


8



 =

'

' @

C


;

"









<

5





(

-

2
6

5
,
















(


-


C









 <
0

0
 9

<

%






"


#

&



&




2
6




5



"

" 9







8

0
 9

2

"


!




C #
 
 

&



"


#

 

C /
3


#

:













;
:;

&




"

'

B *
' @ 8
' #

B 
#8 #

 J

C
*
J
8
,
B 
8
,
 *
@

,
B 
@
, *
 

B :

8
 
0 : = 

 
 
/
* 


&



 


:


C :;

!



  

3
.



"





&8

$





4





-

*


&











!





Mar 2 2001 03:28

/ 0 56


*

 










#0


1







:;

:;

&




;


)*





# @ 


'

#






;
#

)*


!



;


"

+
$



,
%

'
,




<




AvgDownSample.java

Page 1


"

&

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg



"

"

"

#
"


!






#

JPEGCodec.java


*

)*

















"



Mar 2 2001 03:28




'


&



-
(

"

2




5







 9
 





'




"


"



Page 1

"



&
%
$

&8

$

"

"



 


  

. 3



 

 

$
$


%

%

;

&

&%

 @
9

- @
9

( @

- @

< @ < @ < @


(
(

< @

< @
(

< @
(

< @
(

< @
2

@ ( @ @
,9 9 9

( @

 @

( @

- @

( @

< @

< @


(




N

 @
9

< @

( @
9

@  @ @  @  @
,9 9 9 9 9

 @

- @

 @

< @ < @ < @ < @ < @ < @




< @

< @

@ @  @ @ ( @
9 9 9 9

< @ < @ < @ < @ < @ < @ < @



(

< @
2

,
"




N





@
9,

"

 >?

@ @ @  @ @ - @
9 9 9 9 9
9

5


,





-
(

< @
'


< @
'

5

< @
'


,

< @
'


< @
'

< @
'






,
9


*

"

#
"


)*


RepeatUpSample.java





















&

2
6




5

"










,


" 9


8
;

8
;

# @ 


C :;

:;

 
 
/
* 

!





#





B



#




3

C













8


!


!

#



:


 
3 
C /




 
3
* C

& 

#





:




8 :;

:;

C


&


#







#





#





' @ 8
' #

B 
#8 #

 J

C
*
J
8
,
B 
8
,
 *
@

,
B 
@
, *
 

B :

 
: =

;

'
B

#

*
' @


'

8
;
*
@

:B


B









B


;

;

B B B
  
@ @ @
'

* * *
@ @ @
'

:B :B :B
  
  
B B B
  
  
  
  
  
3 3 3
C C C
  

;

B







M






@

:


'

*
"

&

:B


B





*



3

&


<











0 <




(

-
2

5
,





(

-

2
6

5
,
















(


-


2
6




5

,

'




"






0
 9




#

"


C 

 

C =
 



0

C # =



0




<



8
M;




F


&
:

%



@

'

;7




0
 9


"

&


-



&8

$

7
(






'

&



*


"




 







  

. 3

 

 


!


"






4


/ 0 56




#0


1

;
*

&

















8
8


:;
:; 
# #
 
 

/ !
 

 
 
 
 
 
 
 

# #
 
 

C #
 
 







 *
 





 


 K
 


;
8

;
#


B









)*


'


!

-
(

2
6




5

,

- @

@
6
2 @

 @

- @

 @

( @

 @
@

 @
@

 
 
0

,
9

5 @

@
6
2 @

- @

( @

 @

@
,

@


( @


"





5 @



 @

2 @


'



H
H




H

<


"

I
H

< @
'


1

 
)* )*
 

 
<8 = =

2

8


%

8
,

< @ < @ < @ < @ < @ < @ < @ < @




, ,
,
,
,
@ @ @  @ @ ( @ @ 2 @
,9 9 ,9 9 ,9 9 ,9 9

 

)*
N
 

H
 
 =


70

 E
 
 


9



B
 







" ) 

B *

 >?
>?
 
 
#
) 


*

 
 =

@
9

5 @

 @




2 @
9

N




&

2 @
9

(


*

2 @
9




)
2 @

>?

 @
9




 @
9

< @
2

@  @  @
9 9
9

< @


2

< @

-

< @
(

 @
9

< @ < @ < @ < @ < @



  


C

2 @

 H

 


< @ < @ < @ < @


 

 N

 7
"

" 
 )


 
 

 
= =





8

&

:;

" 

"

!




/ 0 56


 



"




#0


1




- @

"


$





"
&





*


H
 I
G
F
E
D 



- @


8

< @


< @

< @

"

< @

< @




< @

< @ < @
-

- @

,
$

2 @

%

K

"
#

2 @

9,

%
&

(
2

"

'

K


< @
'




< @
'




< @
'



JPEGCodec.java

Page 1



&K
%
$

2




Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg







<




< @
(

< @
(

< @
(

< @
(

 @

 @

9


@
9
< @ 5

 @

Mar 2 2001 03:28

9
< @
< @ 2 < @
,
,
@
 @
@
9
9
9
< @
@
'

Page 2

2

62

- @

( @

2 @

 @
 @


JPEGCodec.java

 @
@

 @
(
@

@
(

,
5 @

@
6

5 @


- @

9


< @
'

(

-


2

6

5 @

56

6
( @

9


,
6
9

,(

< @
'
(

9




< @
'
(



(



6
@
6
@
,
6
(
9



< @
'

(?

<8

2

<
'

6(

>

B B
 
 
 
 
) )
 
* *
 
E
FD
% H
 
 
# #
 
 

 
= =

 @

-

H


5
(

-,


-

-

< @
(

< @
(

< @
(

< @
(

< @
(

< @
(

< @
(

< @
(

< @
(

< @
(

< @
(

< @
(

 @

( @

- @

5 @

"

<

(

8 ?
,>

,>

 @




@
,
9

< @

< @



0





.0

,>

< @
'




?


< @
'

( @

"
=


%

-6

"



&
%
$

'




"

 E
D

5 @




,2


< @
'

- @

- @
(

 @


< @
'

2 @

@
2

 @
2

2 @





6(

 @

( @


@

- @


56

C


5


5 @
(

 @


< @
'

,
5

5

2 @

 @

5 @

- @
2

 @

( @


-,

- @
2

#
5 @



@
5,

( @



% 
H 
 I D I
E E
D D
 
 
)* )*
 

 
 = =

6

2 @

5 @





 @
@

=

8


62

 @

2

( @

,(

- @

2 @


 @
@

2 @
5

6
6

@
(
(

6

 @

 @
(

( @

-

 
)* )*
 

 
= =

!0


'

- @


=




(


5




 
)* )*
 

"  
= =




5 @

- @

 @
@

- @

< @
'

#
=



 @

,

2 @


@


< @
'

N N
0
0


B B B B
3 3 3 3
" " " "
 
C

 
)* )*
 

 
= =

@


 @

2 @


< @
'

D


( @

"
=


I

8
,






#

E
I

D


5 @

,
6

@
2


5,

- @

5 @

5


,

 @
2

2 @

5,

@
-,

 
)* )*
 

  
 = =

@
6

 @
@

 @
@

FD
I

JK

6

( @

 @

- @
2

,(

2 @


( @

D
I

2

 @

- @

2 @

 @
-


D
)* 


=

( @
-

62

(

5 @
2

 @
@

- @

" D
3
I


)*

-



2 @
-

 @



D


(
5

-6

( @

@


- @
(

F
I



8 8 8
  

8
 ,



 
)* )*
 

< @
 
<8 = =

5 @


 !
)*
D

JK


)*

# 


 
 =

( @

"

8 (8



8

(8

=

,2







!0

%
H
I I
 
 

< @
2



( @
'

2
@



@


E%

( @

6(

 @
'

5



&

9
< @
2 < @
,
 @
( @
9
9
< @



8





< @

( @

9
< @
2 < @
,
 @
 @
9
9
< @
 @
'

 @

 @

< @

( @

( @

< @

< @

 @

< @

< @




< @

"



( @
9

< @ 5

 @

 @

< @

< @

 @

 @

< @ 5







@

< @

( @

< @

< @ 5

 @


)0

< @

=


< @

 @

< @

 @

 @

7
( @

< @

< @

#



( @

< @

< @

=

<

< @


 @

 @

< @

< @

 @




< @

< @



"

( @

< @

< @


JPEGCodec.java

< @

< @


 @

< @

< @

@

@ ,

9

70
<
< @

 ,
 E
 
@ ,
 
, 9

9

<
 9
< @ 5

 

@ ,

 )
, 9

9


*
<

< @

6
" 
B
 
 @ ,
)   , 9

9
)
* >? 
<
< @ 2
>? *

,
 

@ ,
B )*

N , 9
  9

N
<
 
 =
K
B

,
'
'
 
(
- -


@

@
@

@
@

9
@
@
@

@
-

-

9
< @
< @ 2 < @
,
,
@
@
@
@
9
9
9
@
< @
@

'
-

2

9
< @
2 < @
,
@
 @
9
9
< @
-

@
'
-6

< @

< @

 @

 @

< @

< @

9
< @
2 < @
,
 @
 @
9
9
< @
-

 @
'
-

5

< @

< @
6

( @

( @

9
< @
2 < @
,
 @
( @
9
9
< @
-

 @
'


,2

- @

- @
9

9
< @

< @
6

9
< @
2 < @
,
( @
- @
9
9
< @
-

( @
'

9
< @
2 < @
,
- @
2 @
9
9
< @
-

- @
'

@ 6
6

9
< @
2 < @
,
2 @
@
9 6
9
< @
-

9
< @
2 < @
,
@
6 5 @
9
9
< @


2

@
2



@
9

9
< @
< @
2 < @ 2
,
@
@
@
,
9
9
9
< @
< @
,

6
@

(

< @

< @

9
< @
2 < @
,
5 @
@
9 ,
9
< @

@ ,
,

@
@

< @

< @

5 @
'

'

5 @
9

5 @

< @

< @ 5

@ ,

< @

< @

< @

@
@

< @ 5

5 @

5 @

< @

< @

2 @

2 @
'

6
9

@
9

< @

2 @

< @

< @

@ ,

< @

,
9

< @ 5

@ 6
6

< @

@
@

< @

< @

5 @

< @

< @ 5

- @

- @

5 @

2 @

2 @

@ 6

< @ 5

6
< @

< @ 5

( @

( @

 @

 @

2 @
9

< @

@
9

< @

< @

< @

< @


@ ,
,

< @

< @


5 @

5 @

< @

< @

2 @

< @

- @

< @

< @

- @

< @ 5

 @

 @

< @

< @

 @

 @

< @

< @

( @

< @ 5

< @

< @

( @

< @

< @ 5

 @

< @

< @

< @

 @

< @ 5

 @

< @

< @

 @

9
< @

< @ 5

< @

9
@

< @

< @

@
9

< @

< @


@ 6
6

@
,

< @

< @


2 @

2 @

< @

< @


- @

- @

< @

< @


( @

( @

2 @

< @

< @


 @

 @

< @

< @


 @

< @

< @

< @

 @

< @

< @

 @

< @


9
@

< @

< @

@

JPEGCodec.java

Page 3

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg

@
'

@
-

'
2

JPEGEncode.java

:;

:;








Mar 2 2001 03:28

"






)





:


K
K

N


K
K
K

K

K

#
K


K
K




K

"

"

K
K


K



LK







N



K

"


 )
 :
;

 
= #
= 
 :




 





 #
 

#

"


=


0 ?
,>

?
 ,>
 7

>?




)
>?

;

* 

7A@
"













 
" "
 
 
 
" "
 
 
 
 
*

#

 

%
F


.




3%

=


;

 
" "
 
C C
 

 
 
 
) )
 
* *
" "

8

&

M
8

=

 9



-



(
(

2
(

5


6(
(

Page 1
#

"


!









*
"

5

-6




'





 


:







5


62




&8

$
"


&

(

-
2


6

"




5


,



8 




0
 


 
 
 
 
 
 
  


*

@




%
$

&%

"


%
$



" 9

-

8
,

8
,







"



0

O

#

2




5
,





(

:%


#


;




,>

2

"





)

)


<



0



"

<

<

-



(

2

5



5,

N




5



 ,


5

-
(

2
5

56

=

@





#

:;






"

"

%



"


)

5
,













-


2

8
:;




6

5


#

<



-



(

%

I

0

8
M;







 <

?
>



 
 
" "
 
C C
 

 
 
 
) )
 
* *
" "


I


8
:;


"

C


8
,




)0






0

 8
0 

O
 



= 
 
 
" "
 
 
 
 
K
K


K
K

0

K


K
8

K

"



K
K

 



0
K
K
K
K
K
K
K
K

5

,













(

'

LK

<


'



)*

(

<

#




0
 9

"



8  =
:;

 " "
 B &
" F% 
  $

:


 #
 " 
9 0  &

"
*

<

C








@


.0

)



)0

B

3%






<




K
'



"





K N


%




"

8 


*




5






  9 
0 0




   = 
:  
=


<



N  
  0 0


   : 
) * =
: 

"

8
'



;


9

=
:





-

8
?

=
M

#
N









)*


"


 9


,>

 @



N






'

C





"




C


8 :

FD


0

0
 9

(

&%

)* 
C 
0
 " 
:   
  
  
  
0 0 0
"

8
>



"



&



"





*
:







"








'

"


0
O

,


 ?  
 ; 


) N ) 0

 

* B * 
" 3 " 
" 

N

@
:
C





# 




3
"
:



=

0




8 # 





3


;
#


:



; 
 , N
 J
7
  "
"
" 
 

)
 :
8
:



  


*  *


 
& 



 


 

 
8 
 #  ; #
   ; 
;
O

<





 K


0




N

'

2


)*


@

'

-
2

8
;

(




J

8



@

0

M


N




<

)0

"

"







 
 )
 

:N *
"

9 

#
 C




!


)*

9
;

#


)*

:





 -8








 


  

. 3

:N


2



 

 





*

#

-;

;

;




;


'

)


0


?'



/ 0 56



;E
:H



=

;

#0


1


%





2



,2





;

>
#8 ?

 ?
I

 
H

>H

" ?
>


"
N
 

N
J N


N
>
8 7
"


 )
 
 
: 



'

;'

;





8





"


 8 

 
N


 
 #

  )* =

)







 

"

"

,







C




"

)*






*








&
%
$

*

;





*



>N

+
"




%

'

)


#

JPEGEncode.java

&%

-
(

N


'

;'


0

"

%

"

&



'





:N

%
&

K

"

"





"

&K
%
$



"


"

>



-,
(




?




>
?

JPEGEncode.java

Page 2




?1 I

H
>H

 @
 ;

: 


 N "

 

 


 
> 
? 
>
0
B 


 :



)
 #

* 
:
 

# 0

 
C 



:
 


 


8
) ;

;
*
" ?
 ;

N

B
3
"

'
2
-

M8

"

&%
%
$

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg





-


2

6

5


,(


(


(




JPEGEncode.java

"








C




=





Mar 2 2001 03:28


:




 @





:

"

%















:














=

;
:;

:


;
:;















 

 
K 

0 






:


;
 :;









=
=
























<




"




 & K

 %
 $
#

#
 

 
=




: 

=
 "


9


 ;


;

E


=

"

:




0 
K
 





C


=





0






=


"


=




"

=





 





"




3

E




#


=


=




8

"




" # @




= 
=

!0 0
 B
3
 "
 
:
0
 B
 
# 
 
"
 3
= :
=


"



 

)

 *

" B


% 

 


<


C

2

5


-6

'8

,2


2

'8

;'


2



(

-

2
2

5


62
2


,



'



(

-
2

5


6
6

5,

!0
'




)*



=


)*



=

#


JPEGEncode.java

0

 <



)






#

=

'

*



)*



"



8

)*


0



 9

<

;
,

,
,

,
,

B
,




,
B

*


)*



"



;)


B

 
)*
 :
)* 


 


 





 
 "



 
  9


 
0 0

:
: :
; ;
 
)* )*
: :



,
B

 
0 0

 : :
: :

; ;
) *  
)* )*
?> : :

)*
9

)*
,

8

)*


0



<8

 9

<

 
= 
 )0
B 


* 

 0


" 

 


0
 * "


 

 0
 :
 =
 


,



;#

"
:

;



 #

 :
 :


 
*
 D
= 
= 
!0 
" #
 
 
 
 
" ) *

;


"
8

:;







;
8 8
;  ;
 
) * "
: :
 
 
 
 

B
,

B
,

 ;

 

)*
 :
:

 

 
 


)*
:
:






6
8
;



)



2
5

5

56


5


,





-

(
,

2

5


,

*
'B



*








;

)0




=
=
@

 ,






=A@

0
=  DC
0) 

 @
 ,

0 =A@
>
)0
 
)* 

C 
0
 :

 *

= "
0 *
DC

 


>?

 
)* *


)0

;"



 &
 %
$


 






 :
 
 

>?

,
,

=
;





=

 
0 0

 :
: :

; ;
) *  
)* )*
?> : :

)*
<8
9


:

,


#
>?




)*

@
;
6



 ; "
 
 
&

#  %
 $


 






 :
 
 

0



;


@
-;




C




:


;
D

3

#

)*






M;

3
:


 =
N
!0
 "
B 
3
"
 
:
"
B

%
# 
 
=
3 =
:
!0 8

;


;
'

)

;#


*

'
'B
-
(
5
5

0
#

;

@ =

#

;



"

!0 %

 
=
 =

!0
0
 C



 
"

=
= 
=
 =
"
!0
 "


 

"

%
"

=
% =

 !0


"

C


=
=

;
;

:
 
8

;#

  "
  ;
 
) #

:
 :


 
*
 D
= 
= 
!0 
" #
 
 
  8
;
 

" ) *
)*
:
>? >?

  

)* )* 


!0

;

N

B
3
"



Page 3

-
(

=
K

 

=
'

"


*
"


8

:;

8 %
;





"


=

"

 )

;#
*


:



@


)

@
"

@

"







=


=


 =
=

 

C
0
 
 :
 

  "
0
 

" = 
=
 
 

"





=
@

8
;

=

"


"




@
"




#


0
B

 3







"

=





"




3






=







0




=


8

;
0








;

JPEGEncode.java

Page 4





Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg

;

*


)8


DC


 >?







0
>


=

)0




0




0
<

<


8 ;
?
 >
)
 :
 

 
: 

"


=
<









 @








*

&

9
;



=

0
2
,

5






(

-
2

5
,





(

-

2
6

5
,
















(


-


2
6




5

,










(

-


2

6

5


,(


(


(


(

(

-
(

2

6(

5
(

-,

C

 :
 

 
K 
C




 



C





=
=



#



 

"
"

%

& 

%  
$
 



*
 
&
K
 


0 "
 
 
  9


&

 :

) 
J

 
)* )*
:
=

 

* 
 
 




 
 "



 
  9


0
"

)0

;)

?'
'


=8



:;





#8









'

#





;'






)*

"


-


-





=

N



0

JPEGEncode.java

=
=


;
,

=A@

0
O


N



:
8 =
0 ; 


"


0
O
. @

3
E
'
-
2




"




'



"


'

5


-6

,2



7
8




"




0




<
8


<

N
7
"

)
'

"


 




"



7

D




=

#

)
:

 

  

 = 

 = 


 

  "
"
" 

  
: 

=



:


=

 ;

"






7A@
"


0
.
7
"

D


)B



Mar 2 2001 03:28

=A@

)*

)
:

7A@
"



"

8
6

7A@
"


=


=A@

7A@
"


;
8

7A@
"


)B


N
7
"

)

)*

@




N
7
"

)


I

"
@

8
;



$



-
2

2

5

62
2

"


(


%

"
&%

<

N
7
'




<


,

Page 5



;








;#

8


;#

:;




 
  "
  ;
 
) #

:
 :


 
*
 D
= 
= 
!0 
" #

 
 
 
" ) *

JPEGEncode.java




)




0


8
:;

; ;
 
) * "
: :
 
 
 
 




; ;
 
) * "
: :
 
 
 
 

8






"





-
(

2

5






-
(

2

5


,

*


&



= 
"

 






<




0

 
 0

 

<


8
















&


 

"
#


E

)*



=
0

 ;
 

)*
 :
:

 

 
 

"

 9




-
(

N
'

N


@


%


8

&

"



 #

 :
 :


 
*
 D
= 
= 
!0 
" #

 
 
 
" ) *

=

;

"

2



 
 

N 

#
C
0
O #
' 


 
=
 ;


)
 
K *




 





'

6

)*















*

C





8




"

  
" ) 

"

>?

>?
>?










 # #
=  

&
;


,



,
=

=A@

=
#

 :

"





"




-


2

5


6

,(



 
=
 =


N 
 
:
N
 =
 
8



-
(

2



N


*



















N

"


. @
(











"



'

)
:

7A@
"


"

'

;
"



=

#

(

#

0
O
N
 

 N

0
O

 0




;








7A@
"

8

;
=

"



 





9




"
:








"



=
=
 

=A@

=


"
7A@
"


;

"
8

=



 

E%

=A@

K
7A@
"


=

=

) 


* 

=

!
'

7A@
"


;




N


8

"

=



D


)
7

@





I
3

=

7A@
"

:

%

)B


B

=

7
"

)




=

)*

#


8
:;

5



! 






 
 J


)B
J
8
)* ,

8
, )B


)* 
:

 
: =


&

:;








N
7
"

)
8




I
E

N
7
"

)


E


8

8 
:; 
 
# /
 


:

7
=

>?

N
7
"

)
>


#

C

@
:;

N
7
"

)
>
?


N
7
"

)
>



=


8
?

N
7
"

)
>
?





"

"
:







N
 7
N "
7  
" )
 
) '

' )B










8


8


=





=




"



'

5


6(

-,

"
'





-



(

JPEGEncode.java

Page 6


%

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg

I
E


N






M8

"

&
%
$




=
=

)0

0

8
:;

JPEGDecode.java


"
8


E
8
  B

"
  @


0 
O


8
?
>


)*
C

K
K
8

,


K
K

K
K


)0


Mar 2 2001 03:28

K
=
K

K
K

0


 
 
" "
 
 
 
 
K
K

0
K
K
K

'
(

-
(

LK
<

2

5


6(

Page 1

-,



"







-




-

-
(

2
-6

5

,2

K
K
K
K
K
K
K
K
K

K
K
LK


"
#
"

"

&K
%
$

*










)*
















*

 ?
 ,>


)  ,>
 7
"
*
"  
 )





&8

$


&

"


(

-
2


6

"

5


,


8 
 


0
 


 
 
 
 
 
 
  


,



-



(

2

&



-

8
,

 

)*
 :
) 


*
:
0
= 

9


  
 N 


<
<

B
,



? I

H
>H




N


5,





-
(

56

8
>


  N
 
) >
 7
"
*
"  
)

)



* 



 
:

"








N
'8
'


=
<

8

8


'


5


8 ?
:,

;E

2

* ;
"

=
<

? I

H
>H

0 N
 
 N
 >
 7
N "
8 
: )







)

"

N
?

N

?
>





>

:,



'



(

-

2

"

"


0
0

O



;



#


# @


#



:

8
:;









#

"




"



9


)

<

5
,





(

-

2
6

5

%

#



/



















8
M;

#









 <

C











#


0
 9

:;

#


'

:
8 

8 :;

C
 @




;'

8



# E

 B

!
 J

 

  8




 
 
 
#
 


# :


 =

)

;
#


"





#

# @ 




C 
:

8 8
 
 

# #
 
 

C #

 8


0



: 
* 

" 



 





*


&






 *

 &
"

<

8
:;

 
 
" "
 
C C
 

 
 
 
) )
 
* *
" "


;




8
:;






B
6

 



8  =
:;

 " "
 B &
" F% 
  $

:


 #
 " 
9 0  &

"
*

<




;

E
'




9


#

8


J
E

B


 
:





E


B
 
 
 
 
# #
 




;
#






2

3%

O
*


" 9

78



* ) 

)

*




"


(

"





&

%

FD

"

%

"

"





@


&

-8

;E

5






B


)

@ >

8






K

0




N
8

*
>



N


)


"




'

'


?













8

0


8 
 
N

 
#
 )*

)


8


  

. 3




"



/ 0 56


"   ; 
 
 &  
&

% * 
% $  
$
 




'
 


#0


1


:

;'

"

"




F0
*








 

"



"

#



:,






;
8




2

>









#










-
(

"

 @









#8 )
 

*
"


;

" 
# 8

;
:  ,:
:
N


 

N 
J

)  
  

*
8
)
 

 *
 #  "
8 : 


 =

"








  
 " 
:

:
 
  
 =
= 
)

 !0 
*  
"
   
=











'
'
5

62
2

"


?


0



#



!

K

"



&
%
$



*



"

+
$

K
*

%

N


#



"


 9


 &
 
 
" "
 
 
 
 


:,

)




N

K
K

8


 ;



'

"

>



"

)





8










"

E%

?1 I

H
>H

8
:;

?

>

:,

JPEGDecode.java

"

;





"

%
&




=


"



:,



:


#





 
 
= 
=
 
 




#


>?
>?











7A@
"



%




 
 
" "
 
 
 
" "
 
 
 
 


K

K
0

"


K

#

0




"

?!
&


0



#


8
:;

:;



0

?1 I

H
>H


.




3%

 
 
" "
 
C C
 

 
 
 
) )
 
* *
" "





M
8

:;

;

=


JPEGDecode.java

Page 2

=

*




Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg

,
















'


(


-


2
6




5

,










(

-


2

6

5


,(


(


(










JPEGDecode.java


"


&
%
$
=



#



#

*






9
;






*


 


J

&





 
 "
 


N

B
3
"

:
B

# 


3
:

;





 9


-

-
-

2
-

5


-6





;

)*
:


#



8
; 
8
? ) * ; 
> >

 
"
)* )* :

C C

 

: : 
 

 

  
=
  =
  !0
"
) * " 

"


=
=

!0
C





=
=

!0
"



"




>?

=
=

 
)* )*

;
:

!0

:;





:
B

,
;









:

)

:


*
"

 I
= 

"
I
&

$




&


:;

%

)*
:




!0
"


;

!0
)*
:




#

0





8
; 

" ? ) *
 > >
=
=  
 )* )*
"
C C

  

 : :
  

 

 
"
 

 

 ) * "




=

8
;

M;

,2


2




2

-

2
2

5


62
2


,








=
=

!0
"


"



=

!0

@
3%
 
.



)



 I
= 

"
I
&

$




&


:;



:

)

"

!0
"



)*
:

:


%




:
B

,




M;

-
(

2

5



5,


5





-
(

2

5

56

8


%





:;




0



#





0
"

JPEGDecode.java




=
;
;

FD

:,
9

;#







=


 :,



<

5






"











 

 
K 

0 






9
8




-



(

'8

2

5



,


'









8
?

 ;"
 
 
&
)*
%
$
C


 






 :
 
 

,>
?

,>
7
"

)



0


<





,
B

B
,


6

D
>

J
!

D
>


;"



)* &
%
 $
0
=

 






 :
 
 


  
)* )*

:
0
 

 

 
 0 0
#



0



0


<

,
,

J
J
?
D

E

D

>

?
E

D

>


FD

D

>

8  
 )* )*
:
  
0
 

 
 0 0



?
!

I


D

D

>

 
)* )*
: :
 
 
 
0 0


0



0


<

)

  ;:

)*





 )*

 
"
E 
 
  9


0 ;

"

-
2

5
,





(

-

2
6

5
,
















(


-


2
6




5

,










(

-


'

)0
C

"




0

#
 

" :
=
 



0


8

M;


=
=

2

6

5


,(


C

#

>
=

#8






=  ?>
 
 ) *
:
)* 

=


* >?
 

)*

 
"
E 
 
  9


?'
*


0

=


 


0


'

 ;)



0

;'


#


F0



'




=


)*
0

=D
F

#


D3


I


)*
J


B
%



"

;

*


-;
6

)0

*
B


)*
:





)*




"


 9





)0

,
B

>?




,
B

;

)*

?
I

,
,
,

J
?F

=
,

=

:
8

.
M




8
,

3
:

#

8

)*
:


#




)*


#



"


 9


<

(




,
6

>?

#


0 
* 
" 
" 



 ; 
)


 
 N # 
*


:  "
N :
#  :
9
" 
=


 
 = 

:


 =
 
<


3
:

;

)*


?

? I
#8

 
H
>H


?

>

"
"



N
 N

N
J N
>
 7
"
8 
: )










)*



=

#

N

>
'

 ;

 


N

;'



)*



=

"

)




<

?
>

#

?1 I

H
>H

FD



 

 

C






= 
 

 

 


 @








9
*

 & 





K


:;

 # @
 

" 
C
 :
= 


 *


& 
 C

 :
 
 


E


 
 
= 
 


 
 



=




;
#





C




" 

'




0







=
'




:






)
'

=







=

;

#


 # @

" 

 C
:
=

 

*


&

C

 
:
C 
  

E
#
 



 
=

 
 0

 

I


 #

=
'

(

!0

8
:;

 
$
M

:;

;
#



#

 &





=




)
'

;

)*
:


#



8
; 
8
? ) * ;
> >

 
"
)* )* :

C C

 

: : 
 

 

  
=
  =
  !0
"
) * "

"






 
)*
;




'




B

;


"
:

@
3%
 
.

)

 K

M




"


8
:;


)*






@







=



B

"
:

>?

'
;#

(
-

'

;

N

B
3
"


*




B
@

?
;

)*
:


#



8
; 
? ) *
> >
 
)* )*
C C
 

: :
 

 
 
 
 
) * "

Page 3

Mar 2 2001 03:28

 @





:

"






"


8

" # @




= 
=

!0 0
 B
3
 "
 
:
0
 B
 
# 
 
"
 3
= :
=


"



 

)

 *

" B




 



"

# @


 3




#





JPEGDecode.java

Page 4

;
#

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg



<

)0
'
(


(


(


(

(

-
(

) 
J

8
,

8
:;


 





)8

?

 >
: )



0



=

2

<

6(

5
(

-,


-


-


-




"
#
"







HuffmanCodec.java












"



"

  

3

&






'




-
(

2


6

"

5









Page 5

;













=











@




)








 =







;
:;

3
0

 


 
 
 0
= 


*


&
:


E




C


:


"

 0

 



"




 9

<

-
(

&


<



*


2

5





K  8
  ?

N


 
7
 # "
C
'

)
# >


?


N

7
N
 ; "



) )
0  >

O
  *
'

 =

 C
" 






 =
N
=
 


"
N
 
=  >?


 >?

 



  =



"
:

'





8
?

N
7
"

)
>
?



"

 
)




>?
>?




# #
 






5



,





;

;




:

2


N








"

'

5





;

,
=

 ;







,








(

"
:











"






"



=






=

=


"

-
(

2

5



=

,

@
@

'

-

2

6

5

,






7A@
"

)
:
7
"

D








8




"
%
$



5


6

,(

"




'8
2

<

-

&%



0




N
'
(

!0



)B

'



<





;'
'

@

-


2



:

:K

#



6



!0

" :

 
)
F 
:


 

 . 
 

" 



 =
=
"
 !0 

)
0


0


 ;:
*  
:
 .

# 
 



9 
=
=
!0



0


)



)



 =




5


,(





B  @

0

)*


0
.
7
; "


 D
=
= 



 
 
:
=




<




O
. @


.


<


=

#

!0

0
"

=



N
7
"

)

)
:

6




'



B

=

7
"

)




 
 

#
 

7A@
"


=
#

"

=A@




=A@

7A@
"





)B

7A@
"


8
;


.

 @


8




0
"

 
@

;

N
7
"

)

)*




"


N
7
"

)

=

<




O
N 




0 N
O 


8

 0 ;


"


*







8

0
"

@

'



=

N

N



"

,













)

!0 
 .
 
" 

 

 
 = 9
 =
!0

=A@

N





,

 

5


)
:

7A@
"


N 
=
 =

 



 :
 =
 






7 @
A
"


#
:

N

2

7A@
"





B



@



-
(

=

"

;



N






*

 @



0 

 )

0
 *
* 

 
:
:

:K
 .

# 
 



9 
=
=
;
!0

0
"



'
 (
 

K
 @

0


;'
'


=
" 



<




 9


-
(



K
K
LK

!0




" 9


%

=



=


0


"

=


K





K




*

)B

)* 
:

 
: =




. 
8
 )
 
0

 * "



=
= 

!0  

)*
:

E%

 

)* ,
8




;
;

@ "


)


.



;



0

"









)B

J


)

 J



)*
K






K
K




:;




.


B
:,

D
K








E




B
,


! 








8 


/
 










;



:

.


,


K

2

)*

N
7
"

)
>


#



-
(

:;

'

N
;
 7
N "
7  
" )
 
) '

' )B

;



*


* 
#
  

"
0





 


B
 

 


0

 )
  

*



=




!0

,
8

)



:
7
*



"

*







!0




"

"



)
9

&8

$
"



>?

"




#0



"



 





 

 

!0

!0






 =
=




"  




"

/ 0 56

#0


1





 
0
 0

* 











!0


;



)



"

<
@

"


=
@

<
0







!0


)




Mar 2 2001 03:28

;

;



)



!

JPEGDecode.java

)*


.


<




*




,
+
$

%




.

10

Page 1

@


*
 

9
K
; B


0 
" 
  )


 *



0
0
" 
: 
=


(


(

9



<



HuffmanCodec.java


"

&

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg






,
,
;



*


"

#
"


HuffmanEncode.java

"












 =
!0





'



2
6

Page 2




0
"



8
K

HuffmanCodec.java

;
,



.

0
"
 

K


0
"




=




"





'

!0




"

<

!0
"




<

(



0



"

2

6(






-

!0
=

<

5
(

-,


-

<

5





,









#


)





*



#

!0



"

=
=




=



>?

D

)*
"


0
 9

= 
=
0

D





,


=



#0



*


@

J
B





!0









N



;
6


0 #

: 

=





?
> ) 

) *

 


= C
=

#0 
:
=

)
8




:;

;

;
,

:;

0 #
D 



 

C B



 :
B 
 
#
 C

@
:,






N


)

*

 


 










-
2

5
,





(

-

2
6

5
,




;
;





N

:
8




 N ;:
 #





C

;
,

:;
0

D








 =
=
"
#0
:


=
= 

! 0 



 
C  
 
 

8
;


N
@ 
:, :
 

 

 
 


N 






 
=


8
;














(


-


2
6




5

,













>?


)*
"

0





)

<

'










>
)

:;





?




:

<




(

>
) 
 )

*


=
B



:


;


0
 9

<


:

;
?



8 9











>?



.


)


'


D



;'

D




:

)


 

!0
"



=





0
"



!0




" 9


"


"


-
(






"

0





"




&



 


  

3

*








!0

"


 

 

8

&8

$

"

"


-

"

)


:


!

!0



"




!0


/ 0 56


 

#0


1


=

)






:;
8

;




8



:














@


*

Mar 2 2001 03:28

)

*






*



D


)




*







!



)*





11

Page 1




8

(

-


2

6

5


,(


(


(


(

(

-
(

HuffmanEncode.java

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg

%

#0

;

&

8
;

"


=



=
=




HuffmanEncode.java

:;

!0
C








Mar 2 2001 03:28


8
  ;
.
0
 "



 

= 
=
'
!0


0
"
,

8
;



 
:







0




<





=
=

;


<




)



?

;'
'





!0

:
 
) )





 =
 =

 !0



 
"

 >?
= 
=

!0






"

 
 
  9



=



;

.






=
=
!0
:



!0



=







 .




:

.

;



:;






) #8
 

*
>
 



 )

 
C
J 8



0


8 
 ,
) 

?
  >
 
)
>?
 
: 

 
=


C


 @


:

)




=
=
!0



"
)

>?



0


<




'



(


-
2

5



,





-
(

2

5



,



'

 
" "
@
,

;
,

)



*





:
=

2

6

Page 2
8
:;


=

HuffmanEncode.java


9

D







8





)

*


=
=

D

8
)

*

"

)
F


0







 #



8
,




:

)


;




:;

N





J

;
9

*

#  ;
8  
;' = # 
'
  :
: " :


 
 

  )


 
*
 ) 




* 
) : 

=
* 



0 
&
 %
$

 @
; 
0
)


:
*

;
 "


 
:
 
:
:

 


 
0





 

6(

-,


-


-

(
-

-
-

2

;
?

%
H




-6




:

 I



&
%
$




)



D


 
0 
)





:
=

12


0

J

:;

8 :





 
 0
 )
: 

=
<

=












0



<

<





<

-
(

2

5


6

,(



(



(

-
2

5


6(


-,





) 



 


8

 9






:






,


=



0



)
:

"








-
(

*

K
K
K
K


K

K

K

K
K
K



0


<

K
K
K
K

K
K
K
LK

<

>

'



) 

* 

 "
 
 
 
" "
 
 
 
 

"

@



K


:


>

K
K
K
K
K
K
K
K
K
K
K
K
K
K

LK



"

*


*



 

*
?>
" 
* 
E 




 
= "
0
  
 


  9
K

)


,




;

?
>


8

,
8

:;

N





J

*

)





;
8

)



0



#



"

)

8 ;'
? '
 

:;

*

'
?

8
)

*

"

)
F

  

 
>? : 


 =

8
,




:


#  ;
8  )
;' = 
'
  *
: "

;

  
  # 
  :

:
  >

 ) 



* 
) :

=
* 

8





0



=
<

<


)

2
-


-6

= 9
,





;'


'

#8





:;
 


)
8




 ,

)  
  

?
*  J >

 C  
)

 
8
0  , 
 

* 
 



 :


 =
  : 
 
G 
  
  =



 @
:

.






=
=
!0
C


:









)

*




;
,
 
. 
:

 


 

 
= 
= 
! 0 

:;



N



  
:

 

 #
 C
=

!0


8





=



;

.






=
=
!0
:




 ;

8
:;



=



;

.






=
=
!0
:


>
)

8
:;

;
?





 


 ?>
) 

 
" :

 
 
 
 

 
 =
=
# !0



 
 "
0


 .




 
=
= 
=
!0 =
!0



"

 
 
  9


'8

<

8






"

?

5



 @

#



*

;


8

>

M











"

M8

;






0



,

)



<

5






>

2

5


*

"

=

8
 8
0 ;

:

K



9 0 

) 





8
;


8

"

)




:;




8

8



C

'




*


 8
 ;:
*

 0

)
 
* 
#
 

*

;'


8 0
; 

?

)


*


0
 "

>
 #
) 
:



= 
= 
*
#0

:
 )


 *

 
 


 9

 


<



:

  



D




)



=


0

<

)




:;

=




8


)*
C

<

-

;


)




"

 

 
 
: :
 
) )

 

 
= =
= =
!0 !0
 
9
 
" " 


J



 )





@




D



@

'

=
=

@
,

 

>?
 



" 
 
 @
  9

"

'
(




8 8
;
 
) )

 
;






HuffmanEncode.java

Page 3




 @




.






=
=
!0
:

)




=
=
!0



"


,

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg




.


 ==

,2


2


2


2


2

(

-
2

2

62

5
2
6


6


6

'
6




6

-
(

2
6

5


5,


5


5


5


5


5

(
5

-
5

2
56


5

5


,


,




,

-
(

2
,

5







!0


*

"

#
"




)*

*




@

HuffmanDecode.java


!













 



 =
=




!0


&

7
-
(

2


5

!0
"

!0




" 9







=



"



"


"

0









)

2

Page 4

#










HuffmanEncode.java



:

"
# 


3
:

?


# 


3
;

:



*
D
0













)*


*  
"

  
 9


)*

'
-

5

J
C





8
,

8
,

:
7

"
>?


)*



3


8

 
 

;
 :

 


J #
"



8 
,
 
 

 :
 =
: 



D




?
6


>


?  
 >
 

 

: " ) *



=
 =



8
; 
6'



D

)*

 ;




0

8

>


'

D

;
8

;'





'

:;

;'


D




:

=

>?




;





8



"


"

"
%

=
=

0



,2


2





2


2


2

(

-
2

2

62

5
2
6


6



!0




"

<

<

6

*

 
)

 =
=
#0
 :


 )


 


 
=
=

! 0 "

 



"



5
,





9


>?


)



=
=

D

)


*











8

8 
 
N
 



)*


:






*
C

5
,
















(


-


2
6




5

,




"





8
0




"

"











-


N


H

<
@

;

N


"


'
2


<




8

;
8




 I

(







@
:,

N



6

,'



=

 
 

" 
B #
% 



0

= D 
F 
 
F0

B 
 
 
 "
 B

 

: #
# 
" 
 

"
<
<

8
;

"



%  *
" 

 
B
 
&

%
$ "
 

&
B
  %
$

 
)
 
N
* 


)

FD

;E







*
>

 H 
"

 
"  
&

%
$


 

B
0 


 

 )
 
*
:

 =



=


N



#

'

0
 9
2

C




9


)

#
















:
*




#

C







"


"

-



*
;





8

:;



)*
:







(

:;

=





)


)

)


"






,



;

"







:

;


K 

"





 )

0


"

8 

;



;


 
= )



8
;

<


:;

0
 9

-
(

)

 =
 ) !0


* 


=  "
=

! 0  



N  
)

)
 


 *


  =
 =
 #
  #0

)*




"



8

&8

$





'




/ 0 56



 



-



!0

>?


  

. 3

 

 




"



!0


"

"  

#0


1




=

















"



Mar 2 2001 03:28







;



)



)




13

Page 1

?





,
;

$
>




)

%

.


+
$



@
5


,(


(


(



HuffmanDecode.java

%
%

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg

:
&





"

&



14

Page 3

=
=

HuffmanDecode.java

;
6
0

)

*

)






Mar 2 2001 03:28






K
:;
#


:

=






78

 
 )
:


)

0



2

5







 

;

)

;
,
D

 8
6
J
 ?


)*






"










=


8






0



 



"



 "
E


=

;


:,

2

5



,













-

(

2

)

 

!0 =

5

,




-



(

2

HuffmanDecode.java
:;





8
K

* 



K
K
K
K
K
K
K
K
K
K
K
K
K

K
K
LK



8  

) 

* 

 "
 
 
 
" "
 
 
 
 


 
 0
"

 
"
 9

)
0

<



)


<


K
K






K
K


K

K

K
K
K
K


K
"
K
K



K
K
LK




#




)
C

=
 #0
) :
 
 0
8  
, 
 = 
= )


#0 
 :
 =
: 



)


)



!

?

* >

0 )





)






0



=

 9


=

D

=
0





<

:
G

"



)

*


=
8 =
 0
D






,



-
(

2

6(

5
(

-,


-


-


-


-


-

(
-

-
-

2
-6





"

0



=
=

0



!0




"






0




5

,2


2


2


2

(

-
2

2

62

5
2


6





-

(
6

2

5


5,


5

5


6(

<


-,


-

<
8

'
5


5


5





)*

(

8
;

;'

-
5

2
56


5


:;





8 

=
=

D




B 

 


 
 : 

# 
 =
0


,

)



8





N














,




)

0


# 8
;
 6

@
 :,
  



# 
 


B 


 

-
,


#
 
 N 




)  


* # 
 


 
 N
 

2
,



(
,






:




"






@
:,

5

0




)




) #8
 

*
>
 



 )

 
C
J 8



0


8 
 ,
) 

?
  >
 
)
>?
 
: 

 
=


;
@

:,

:
'

;



)



8
?



 

)* 
=
 =
 !0
=




) "

 

>?
 
=
= 
!0 

 



" "
 
 
  9



:

2




(

 
 )





-


(

* :




>?



;



)




@

:;
(

8


8
:,

,(



;






" 
 
 :
) 


 



 
)
: 
*


#
C

C


* #








)

*
:


8

;
 '
;
'

 :

* 

D

 
)


:
B
 


 

)

 *



= 
=

!0

7
" 
"
#
 
 
  9










 





>

 =
 =
@

?

:;







)
8

:;

"


8 ;





'




C

;'


8
:;

 
 )
=
= 
#
!0 

!



"

 

6

;
:;

5


;
;

;
B 






 


 
 



  "




#0



<

*

;


>?
 
 


0
:

) 
)

)




 9


8
;

#








0

8



6



0




 
 
 




8
"


0


0




 
8 #
"
  

0
0

 

 :

 =

: 


=


#





-
(


<

)
:

 9





;
J

 ,

'
,

8

8





"



;



 

:




'

;'












>

)
=

:








)*

'


'

8 
 
 
:

 
: =

D




;'



7
3

=







  

"



Page 2

(

-



#8






"
J





*  

;
'

D




;

;'

D




<





<

=

)*






"



=



 8
 ;

 N


 @
 :,
 

?
B 
 


> 
 
)

 

=

>?

;
8

:;
"








)

;


HuffmanDecode.java

;

N

:,

D



8

Mar 2 2001 03:28

Printed by wuyinghu from sun450.comp.nus.edu.sg




5


8
;
6
@
:,












Das könnte Ihnen auch gefallen