=========================================================================== * 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)
| 1681 | * deflate switches away from Z_RLE.) |
| 1682 | */ |
| 1683 | local block_state deflate_rle(s, flush) |
| 1684 | deflate_state *s; |
| 1685 | int flush; |
| 1686 | { |
| 1687 | int bflush; /* set if current block must be flushed */ |
| 1688 | uInt run; /* length of run */ |
| 1689 | uInt max; /* maximum length of run */ |
| 1690 | uInt prev; /* byte at distance one to match */ |
| 1691 | Bytef *scan; /* scan for end of run */ |
| 1692 | |
| 1693 | for (;;) { |
| 1694 | /* Make sure that we always have enough lookahead, except |
| 1695 | * at the end of the input file. We need MAX_MATCH bytes |
| 1696 | * for the longest encodable run. |
| 1697 | */ |
| 1698 | if (s->lookahead < MAX_MATCH) { |
| 1699 | fill_window(s); |
| 1700 | if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) { |
| 1701 | return need_more; |
| 1702 | } |
| 1703 | if (s->lookahead == 0) break; /* flush the current block */ |
| 1704 | } |
| 1705 | |
| 1706 | /* See how many times the previous byte repeats */ |
| 1707 | run = 0; |
| 1708 | if (s->strstart > 0) { /* if there is a previous byte, that is */ |
| 1709 | max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH; |
| 1710 | scan = s->window + s->strstart - 1; |
| 1711 | prev = *scan++; |
| 1712 | do { |
| 1713 | if (*scan++ != prev) |
| 1714 | break; |
| 1715 | } while (++run < max); |
| 1716 | } |
| 1717 | |
| 1718 | /* Emit match if have run of MIN_MATCH or longer, else emit literal */ |
| 1719 | if (run >= MIN_MATCH) { |
| 1720 | check_match(s, s->strstart, s->strstart - 1, run); |
| 1721 | _tr_tally_dist(s, 1, run - MIN_MATCH, bflush); |
| 1722 | s->lookahead -= run; |
| 1723 | s->strstart += run; |
| 1724 | } else { |
| 1725 | /* No match, output a literal byte */ |
| 1726 | Tracevv((stderr,"%c", s->window[s->strstart])); |
| 1727 | _tr_tally_lit (s, s->window[s->strstart], bflush); |
| 1728 | s->lookahead--; |
| 1729 | s->strstart++; |
| 1730 | } |
| 1731 | if (bflush) FLUSH_BLOCK(s, 0); |
| 1732 | } |
| 1733 | FLUSH_BLOCK(s, flush == Z_FINISH); |
| 1734 | return flush == Z_FINISH ? finish_done : block_done; |
| 1735 | } |
| 1736 | #endif |
nothing calls this directly
no test coverage detected