📄 zinflate_8cpp-source.html
字号:
00143 }00144 00145 <span class="keywordtype">void</span> HuffmanDecoder::FillCacheEntry(LookupEntry &entry, code_t normalizedCode)<span class="keyword"> const</span>00146 <span class="keyword"></span>{00147 normalizedCode &= m_normalizedCacheMask;00148 <span class="keyword">const</span> CodeInfo &codeInfo = *(std::upper_bound(m_codeToValue.begin(), m_codeToValue.end(), normalizedCode, CodeLessThan())-1);00149 <span class="keywordflow">if</span> (codeInfo.len <= m_cacheBits)00150 {00151 entry.type = 1;00152 entry.value = codeInfo.value;00153 entry.len = codeInfo.len;00154 }00155 <span class="keywordflow">else</span>00156 {00157 entry.begin = &codeInfo;00158 <span class="keyword">const</span> CodeInfo *last = & *(std::upper_bound(m_codeToValue.begin(), m_codeToValue.end(), normalizedCode + ~m_normalizedCacheMask, CodeLessThan())-1);00159 <span class="keywordflow">if</span> (codeInfo.len == last->len)00160 {00161 entry.type = 2;00162 entry.len = codeInfo.len;00163 }00164 <span class="keywordflow">else</span>00165 {00166 entry.type = 3;00167 entry.end = last+1;00168 }00169 }00170 }00171 00172 <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> HuffmanDecoder::Decode(code_t code, <span class="comment">/* out */</span> value_t &value)<span class="keyword"> const</span>00173 <span class="keyword"></span>{00174 assert(m_codeToValue.size() > 0);00175 LookupEntry &entry = m_cache[code & m_cacheMask];00176 00177 code_t normalizedCode;00178 <span class="keywordflow">if</span> (entry.type != 1)00179 normalizedCode = BitReverse(code);00180 00181 <span class="keywordflow">if</span> (entry.type == 0)00182 FillCacheEntry(entry, normalizedCode);00183 00184 <span class="keywordflow">if</span> (entry.type == 1)00185 {00186 value = entry.value;00187 <span class="keywordflow">return</span> entry.len;00188 }00189 <span class="keywordflow">else</span>00190 {00191 <span class="keyword">const</span> CodeInfo &codeInfo = (entry.type == 2)00192 ? entry.begin[(normalizedCode << m_cacheBits) >> (MAX_CODE_BITS - (entry.len - m_cacheBits))]00193 : *(std::upper_bound(entry.begin, entry.end, normalizedCode, CodeLessThan())-1);00194 value = codeInfo.value;00195 <span class="keywordflow">return</span> codeInfo.len;00196 }00197 }00198 00199 <span class="keywordtype">bool</span> HuffmanDecoder::Decode(<a class="code" href="class_low_first_bit_reader.html">LowFirstBitReader</a> &reader, value_t &value)<span class="keyword"> const</span>00200 <span class="keyword"></span>{00201 reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera4">FillBuffer</a>(m_maxCodeBits);00202 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> codeBits = Decode(reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera3">PeekBuffer</a>(), value);00203 <span class="keywordflow">if</span> (codeBits > reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera2">BitsBuffered</a>())00204 <span class="keywordflow">return</span> <span class="keyword">false</span>;00205 reader.<a class="code" href="class_low_first_bit_reader.html#_low_first_bit_readera6">SkipBits</a>(codeBits);00206 <span class="keywordflow">return</span> <span class="keyword">true</span>;00207 }00208 00209 <span class="comment">// *************************************************************</span>00210 <a name="l00211"></a><a class="code" href="class_inflator.html#_inflatora0">00211</a> <a class="code" href="class_inflator.html#_inflatora0">Inflator::Inflator</a>(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> repeat, <span class="keywordtype">int</span> propagation)00212 : AutoSignaling<<a class="code" href="class_filter.html">Filter</a>>(attachment, propagation)00213 , m_state(PRE_STREAM), m_repeat(repeat)00214 , m_decodersInitializedWithFixedCodes(false), m_reader(m_inQueue)00215 {00216 }00217 00218 <span class="keywordtype">void</span> Inflator::IsolatedInitialize(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &parameters)00219 {00220 m_state = PRE_STREAM;00221 parameters.<a class="code" href="class_name_value_pairs.html#_x_t_r___d_ha39">GetValue</a>(<span class="stringliteral">"Repeat"</span>, m_repeat);00222 m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera17">Clear</a>();00223 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>());00224 }00225 00226 <span class="keyword">inline</span> <span class="keywordtype">void</span> Inflator::OutputByte(byte b)00227 {00228 m_window[m_current++] = b;00229 <span class="keywordflow">if</span> (m_current == m_window.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>())00230 {00231 ProcessDecompressedData(m_window + m_lastFlush, m_window.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>() - m_lastFlush);00232 m_lastFlush = 0;00233 m_current = 0;00234 }00235 <span class="keywordflow">if</span> (m_maxDistance < m_window.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>())00236 m_maxDistance++;00237 }00238 00239 <span class="keywordtype">void</span> Inflator::OutputString(<span class="keyword">const</span> byte *string, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00240 {00241 <span class="keywordflow">while</span> (length--)00242 OutputByte(*string++);00243 }00244 00245 <span class="keywordtype">void</span> Inflator::OutputPast(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> distance)00246 {00247 <span class="keywordflow">if</span> (distance > m_maxDistance)00248 <span class="keywordflow">throw</span> BadBlockErr();00249 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> start;00250 <span class="keywordflow">if</span> (m_current > distance)00251 start = m_current - distance;00252 <span class="keywordflow">else</span>00253 start = m_current + m_window.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>() - distance;00254 00255 <span class="keywordflow">if</span> (start + length > m_window.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>())00256 {00257 <span class="keywordflow">for</span> (; start < m_window.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>(); start++, length--)00258 OutputByte(m_window[start]);00259 start = 0;00260 }00261 00262 <span class="keywordflow">if</span> (start + length > m_current || m_current + length >= m_window.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>())00263 {00264 <span class="keywordflow">while</span> (length--)00265 OutputByte(m_window[start++]);00266 }00267 <span class="keywordflow">else</span>00268 {00269 memcpy(m_window + m_current, m_window + start, length);00270 m_current += length;00271 m_maxDistance = STDMIN((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)m_window.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>(), m_maxDistance + length);00272 }00273 }00274 <a name="l00275"></a><a class="code" href="class_inflator.html#_zlib_decompressora3">00275</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_inflator.html#_zlib_decompressora3">Inflator::Put2</a>(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, <span class="keywordtype">int</span> messageEnd, <span class="keywordtype">bool</span> blocking)00276 {00277 <span class="keywordflow">if</span> (!blocking)00278 <span class="keywordflow">throw</span> BlockingInputOnly(<span class="stringliteral">"Inflator"</span>);00279 00280 <a class="code" href="class_lazy_putter.html">LazyPutter</a> lp(m_inQueue, inString, length);00281 ProcessInput(messageEnd != 0);00282 00283 <span class="keywordflow">if</span> (messageEnd)00284 <span class="keywordflow">if</span> (!(m_state == PRE_STREAM || m_state == AFTER_END))00285 <span class="keywordflow">throw</span> UnexpectedEndErr();00286 00287 Output(0, NULL, 0, messageEnd, blocking);00288 <span class="keywordflow">return</span> 0;00289 }00290 00291 <span class="keywordtype">bool</span> Inflator::IsolatedFlush(<span class="keywordtype">bool</span> hardFlush, <span class="keywordtype">bool</span> blocking)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -