📄 zinflate_8cpp-source.html
字号:
00441 }00442 m_literalDecoder.<a class="code" href="class_huffman_decoder.html#_huffman_decodera2">Initialize</a>(codeLengths, hlit+257);00443 <span class="keywordflow">if</span> (hdist == 0 && codeLengths[hlit+257] == 0)00444 {00445 <span class="keywordflow">if</span> (hlit != 0) <span class="comment">// a single zero distance code length means all literals</span>00446 <span class="keywordflow">throw</span> BadBlockErr();00447 }00448 <span class="keywordflow">else</span>00449 m_distanceDecoder.<a class="code" href="class_huffman_decoder.html#_huffman_decodera2">Initialize</a>(codeLengths+hlit+257, hdist+1);00450 m_nextDecode = LITERAL;00451 }00452 <span class="keywordflow">catch</span> (HuffmanDecoder::Err &)00453 {00454 <span class="keywordflow">throw</span> BadBlockErr();00455 }00456 <span class="keywordflow">break</span>;00457 }00458 <span class="keywordflow">default</span>:00459 <span class="keywordflow">throw</span> BadBlockErr(); <span class="comment">// reserved block type</span>00460 }00461 m_state = DECODING_BODY;00462 }00463 00464 <span class="keywordtype">bool</span> Inflator::DecodeBody()00465 {00466 <span class="keywordtype">bool</span> blockEnd = <span class="keyword">false</span>;00467 <span class="keywordflow">switch</span> (m_blockType)00468 {00469 <span class="keywordflow">case</span> 0: <span class="comment">// stored</span>00470 assert(m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera2">BitsBuffered</a>() == 0);00471 <span class="keywordflow">while</span> (!m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera16">IsEmpty</a>() && !blockEnd)00472 {00473 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size;00474 <span class="keyword">const</span> byte *block = m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera20">Spy</a>(size);00475 size = STDMIN(size, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)m_storedLen);00476 OutputString(block, size);00477 m_inQueue.<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz7_11">Skip</a>(size);00478 m_storedLen -= size;00479 <span class="keywordflow">if</span> (m_storedLen == 0)00480 blockEnd = <span class="keyword">true</span>;00481 }00482 <span class="keywordflow">break</span>;00483 <span class="keywordflow">case</span> 1: <span class="comment">// fixed codes</span>00484 <span class="keywordflow">case</span> 2: <span class="comment">// dynamic codes</span>00485 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> lengthStarts[] = {00486 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,00487 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};00488 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> lengthExtraBits[] = {00489 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,00490 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};00491 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> distanceStarts[] = {00492 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,00493 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,00494 8193, 12289, 16385, 24577};00495 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> distanceExtraBits[] = {00496 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,00497 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,00498 12, 12, 13, 13};00499 00500 <span class="keywordflow">switch</span> (m_nextDecode)00501 {00502 <span class="keywordflow">while</span> (<span class="keyword">true</span>)00503 {00504 <span class="keywordflow">case</span> LITERAL:00505 <span class="keywordflow">if</span> (!m_literalDecoder.<a class="code" href="class_huffman_decoder.html#_huffman_decodera3">Decode</a>(m_reader, m_literal))00506 {00507 m_nextDecode = LITERAL;00508 <span class="keywordflow">break</span>;00509 }00510 <span class="keywordflow">if</span> (m_literal < 256)00511 OutputByte((byte)m_literal);00512 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (m_literal == 256) <span class="comment">// end of block</span>00513 {00514 blockEnd = <span class="keyword">true</span>;00515 <span class="keywordflow">break</span>;00516 }00517 <span class="keywordflow">else</span>00518 {00519 <span class="keywordflow">if</span> (m_literal > 285)00520 <span class="keywordflow">throw</span> BadBlockErr();00521 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bits;00522 <span class="keywordflow">case</span> LENGTH_BITS:00523 bits = lengthExtraBits[m_literal-257];00524 <span class="keywordflow">if</span> (!m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera4">FillBuffer</a>(bits))00525 {00526 m_nextDecode = LENGTH_BITS;00527 <span class="keywordflow">break</span>;00528 }00529 m_literal = m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera7">GetBits</a>(bits) + lengthStarts[m_literal-257];00530 <span class="keywordflow">case</span> DISTANCE:00531 <span class="keywordflow">if</span> (!m_distanceDecoder.<a class="code" href="class_huffman_decoder.html#_huffman_decodera3">Decode</a>(m_reader, m_distance))00532 {00533 m_nextDecode = DISTANCE;00534 <span class="keywordflow">break</span>;00535 }00536 <span class="keywordflow">case</span> DISTANCE_BITS:00537 bits = distanceExtraBits[m_distance];00538 <span class="keywordflow">if</span> (!m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera4">FillBuffer</a>(bits))00539 {00540 m_nextDecode = DISTANCE_BITS;00541 <span class="keywordflow">break</span>;00542 }00543 m_distance = m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera7">GetBits</a>(bits) + distanceStarts[m_distance];00544 OutputPast(m_literal, m_distance);00545 }00546 }00547 }00548 }00549 <span class="keywordflow">if</span> (blockEnd)00550 {00551 <span class="keywordflow">if</span> (m_eof)00552 {00553 FlushOutput();00554 m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera6">SkipBits</a>(m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera2">BitsBuffered</a>()%8);00555 <span class="keywordflow">if</span> (m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera2">BitsBuffered</a>())00556 {00557 <span class="comment">// undo too much lookahead</span>00558 SecBlockWithHint<byte, 4> buffer(m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera2">BitsBuffered</a>() / 8);00559 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i<buffer.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>(); i++)00560 buffer[i] = (byte)m_reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera7">GetBits</a>(8);00561 m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera18">Unget</a>(buffer, buffer.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>());00562 }00563 m_state = POST_STREAM;00564 }00565 <span class="keywordflow">else</span>00566 m_state = WAIT_HEADER;00567 }00568 <span class="keywordflow">return</span> blockEnd;00569 }00570 00571 <span class="keywordtype">void</span> Inflator::FlushOutput()00572 {00573 <span class="keywordflow">if</span> (m_state != PRE_STREAM)00574 {00575 assert(m_current >= m_lastFlush);00576 ProcessDecompressedData(m_window + m_lastFlush, m_current - m_lastFlush);00577 m_lastFlush = m_current;00578 }00579 }00580 00581 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:29 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -