MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / deflate_rle

Function deflate_rle

extlibs/minizip/src/deflate.c:2226–2306  ·  view source on GitHub ↗

=========================================================================== * For Z_RLE, simply look for runs of bytes, generate matches only of distance * one. Do not maintain a hash table. (It will be regenerated if this run of * deflate switches away from Z_RLE.) */

(s, flush)

Source from the content-addressed store, hash-verified

2224 * deflate switches away from Z_RLE.)
2225 */
2226local block_state deflate_rle(s, flush)
2227deflate_state* s;
2228
2229int flush;
2230{
2231 int bflush; /* set if current block must be flushed */
2232 uInt prev; /* byte at distance one to match */
2233 Bytef *scan, *strend; /* scan goes up to strend for length of run */
2234
2235 for (;;)
2236 {
2237 /* Make sure that we always have enough lookahead, except
2238 * at the end of the input file. We need MAX_MATCH bytes
2239 * for the longest run, plus one for the unrolled loop.
2240 */
2241 if (s->lookahead <= MAX_MATCH)
2242 {
2243 fill_window(s);
2244 if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH)
2245 {
2246 return need_more;
2247 }
2248 if (s->lookahead == 0) break; /* flush the current block */
2249 }
2250
2251 /* See how many times the previous byte repeats */
2252 s->match_length = 0;
2253 if (s->lookahead >= MIN_MATCH && s->strstart > 0)
2254 {
2255 scan = s->window + s->strstart - 1;
2256 prev = *scan;
2257 if (prev == *++scan && prev == *++scan && prev == *++scan)
2258 {
2259 strend = s->window + s->strstart + MAX_MATCH;
2260 do
2261 {
2262 }
2263 while (prev == *++scan && prev == *++scan &&
2264 prev == *++scan && prev == *++scan &&
2265 prev == *++scan && prev == *++scan &&
2266 prev == *++scan && prev == *++scan &&
2267 scan < strend);
2268 s->match_length = MAX_MATCH - (uInt)(strend - scan);
2269 if (s->match_length > s->lookahead)
2270 s->match_length = s->lookahead;
2271 }
2272 Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
2273 }
2274
2275 /* Emit match if have run of MIN_MATCH or longer, else emit literal */
2276 if (s->match_length >= MIN_MATCH)
2277 {
2278 check_match(s, s->strstart, s->strstart - 1, s->match_length);
2279
2280 _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
2281
2282 s->lookahead -= s->match_length;
2283 s->strstart += s->match_length;

Callers 1

deflateFunction · 0.85

Calls 2

fill_windowFunction · 0.85
check_matchFunction · 0.70

Tested by

no test coverage detected