140 likes | 236 Views
Learn about the JPEG image compression algorithm with details on encoding principles, decoding challenges, code words, data words, Huffman tables, quantization, and MCU structures. Discover the steps involved in encoding and decoding JPEG images.
E N D
YUV RGB DCT ZZ Q VLC + in - 68 -23 -4 -3 11110 68 70 7 0 0 0 8 -23 -28 17 3 101 -20 -23 -2 Non-overlapping 8x8 blocks 0 0 8 8 sym code -4 17 20 -11 101 -23 -20 -2 0 0 0 8 8 4 -3 3 -11 -12 0 -4 0 0 -1 100 8 8 4 4 -2 101 11100 -3 -28 -30 +2 110 0 -4 0 0 2 0 0 9 70 -20 0 0 -3 11100 0 0 0 -3 +1 11101 0 0 7 8 -20 -30 20 0 +7 11110 110 17 2 20 0 7 8 4 0 20 20 -10 110 20 2 17 9 8 4 3 0 0 -10 -10 0 0 0 -3 0 3 0 0 110 20 20 2 0 0 0 3 offset 100 -10 -11 -1 - 100 -10 -1 -11 IDCT ZZ IQ VLD + 100 -12 -10 -1 out JPEG Joint Photographic Expert Group jvm
Coding principle: frequent data words have shorter code words than infrequent data words Decoding (throughput) problem: “hidden” code word boundaries -> algorithm comprises a feedback loop Clock cycle Data word bitstream Code book 0 1 2 3 4 5 6 1100111100110 1100111100110 1100111100110 1100111100110 1100111100110 1100111100110 1100111100110 - 10 00 11 01 00 10 Code word Data word probability 0 10 110 111 00 01 10 11 50% 25% 12.5% 12.5% Average length 1.75 bits 2 bits 1/2+2/4+3/8+3/8 jvm
Multiple components, interleaving and minimum coded unit A1 A2 B1 B2 C1 C2 An Bn Cn non-interleaved MCU = 1 data unit = 8x8 pixels A1 A2 B1 B2 C1 C2 … An … Bn … Cn scan1 scan2 scan3 MCU interleaved MCU=3 data units A1 B1 C1 A2 B2 C2 … An Cn Bn scan1 jvm
Multiple components with different dimensions A1 A2 B1 B2 C1 C2 An Bn/2 Cn/2 MCU interleaved MCU=4 data units A1 A2 B1 C1 A3 A4 B2 C2 … An-1 An Cn/2 Bn/2 scan1 jvm
X : number of horizontal samples in image Y : number of vertical samples in image xi : number of horizontal samples in component Ci yi : number of vertical samples in component Ci C4 xi = ceil(X*Hi/Hmax) yi = ceil(Y*Vi/Vmax) C3 C2 C1 Example: X=Y=512 Hmax=4 Vmax=2 C1 H1=4 V1=1 x1=512 y1=256 C2 H2=2 V2=2 x2=256 y2=512 C3 H3=1 V3=1 x3=128 y3=256 jvm
SOI APP < ...> DQT <quantisation table 1> DQT <quantisation table 2> SOF <image info, size …> DHT <huffmann table 1> DHT <huffmann table 2> DHT <huffmann table 3> DHT <huffmann table 4> SOS <encoded data> jvm
SOI Frame EOI Quant. Tables Frame header Scan1 Scan2 … Scann SOF DQT Huffmann tables Scan header ECS DHT SOS MCU1 MCU2 ... MCUn jvm
Frame header structure • Parameter size in bits • Marker (FFC0…FFCF) 16 • frame header length 16 • sample precision 8 • number of lines 16 • number of samples/line 16 • number of components in frame 8 • for each frame component • component identifier 8 • horizontal sampling factor 4 • vertical sampling factor 4 • quantization table destination selector 8 jvm
Scan header structure • Parameter size in bits • Marker (FFDA) 16 • scan header length 16 • number of components in scan 8 • for each component • component selector 8 • DC entropy coding table selector 4 • AC entropy coding table selector 4 • start of spectral selection or predictor selection 8 • end of spectral selection 8 • successive approximation bit stream position high 4 • successive approximation bit stream position low 4 jvm
DHT marker segment structure • Parameter size in bits • Marker (FFC4) 16 • Huffman table definition length 16 • for each Huffman table • table class 4 • Huffman table identifier 4 • number of Huffman codes of length i (Li) • for i = 1..16 8 • value associated with each Huffman code • for i = 1..16; j = 1..Li 8 jvm
Table for luminance DC difference (p. 509) 0 00 1 010 2 011 3 100 4 101 5 110 6 1110 7 11110 8 111110 9 1111110 10 11111110 11 111111110 jvm
FF C4 0 1F 0 0 1 5 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 A B 5 words of length 3 Length = 31 B values 1 words of length 2 Class AC|DC 0 words of length 1 jvm
DQT marker segment structure • Parameter size in bits • Marker (FFDE) 16 • Quantization table definition length 16 • for each Quantization table • Quantization table element precision 4 • Quantization table identifier 4 • Quantization table element (0..63) 8 or 16 jvm
Structure of the Guerrier code jpeg.c jpeg.h utils.c parse.c get_bits ( ) get_next_MK ( ) load_quant_tables ( ) init_MCU ( ) process_MCU ( ) fast_idct.c idct_1d ( ) IDCT ( ) color.c tree_vld.c load_huff_tables ( ) get_symbol ( ) huffman.c unpack _block ( ) spy.c unpack.c jvm