/src/zlib-ng/deflate_huff.c
Line | Count | Source |
1 | | /* deflate_huff.c -- compress data using huffman encoding only strategy |
2 | | * |
3 | | * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler |
4 | | * For conditions of distribution and use, see copyright notice in zlib.h |
5 | | */ |
6 | | |
7 | | #include "zbuild.h" |
8 | | #include "deflate.h" |
9 | | #include "deflate_p.h" |
10 | | #include "functable.h" |
11 | | |
12 | | /* =========================================================================== |
13 | | * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. |
14 | | * (It will be regenerated if this run of deflate switches away from Huffman.) |
15 | | */ |
16 | 0 | Z_INTERNAL block_state deflate_huff(deflate_state *s, int flush) { |
17 | 0 | unsigned char *window = s->window; |
18 | 0 | int bflush = 0; /* set if current block must be flushed */ |
19 | |
|
20 | 0 | for (;;) { |
21 | | /* Make sure that we have a literal to write. */ |
22 | 0 | if (s->lookahead == 0) { |
23 | 0 | PREFIX(fill_window)(s); |
24 | 0 | if (s->lookahead == 0) { |
25 | 0 | if (flush == Z_NO_FLUSH) |
26 | 0 | return need_more; |
27 | 0 | break; /* flush the current block */ |
28 | 0 | } |
29 | 0 | } |
30 | | |
31 | | /* Output a literal byte */ |
32 | 0 | bflush = zng_tr_tally_lit(s, window[s->strstart]); |
33 | 0 | s->lookahead--; |
34 | 0 | s->strstart++; |
35 | 0 | if (bflush) |
36 | 0 | FLUSH_BLOCK(s, window, 0); |
37 | 0 | } |
38 | 0 | s->insert = 0; |
39 | 0 | if (flush == Z_FINISH) { |
40 | 0 | FLUSH_BLOCK(s, window, 1); |
41 | 0 | return finish_done; |
42 | 0 | } |
43 | 0 | if (s->sym_next) |
44 | 0 | FLUSH_BLOCK(s, window, 0); |
45 | 0 | return block_done; |
46 | 0 | } |