2023-12-27 12:06:17 +08:00
|
|
|
/* deflate_huff.c -- compress data using huffman encoding only strategy
|
|
|
|
*
|
2024-09-12 21:05:24 +08:00
|
|
|
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
2023-12-27 12:06:17 +08:00
|
|
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "zbuild.h"
|
|
|
|
#include "deflate.h"
|
|
|
|
#include "deflate_p.h"
|
|
|
|
#include "functable.h"
|
|
|
|
|
|
|
|
/* ===========================================================================
|
|
|
|
* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
|
|
|
|
* (It will be regenerated if this run of deflate switches away from Huffman.)
|
|
|
|
*/
|
|
|
|
Z_INTERNAL block_state deflate_huff(deflate_state *s, int flush) {
|
|
|
|
int bflush = 0; /* set if current block must be flushed */
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* Make sure that we have a literal to write. */
|
|
|
|
if (s->lookahead == 0) {
|
|
|
|
PREFIX(fill_window)(s);
|
|
|
|
if (s->lookahead == 0) {
|
|
|
|
if (flush == Z_NO_FLUSH)
|
|
|
|
return need_more;
|
|
|
|
break; /* flush the current block */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output a literal byte */
|
|
|
|
bflush = zng_tr_tally_lit(s, s->window[s->strstart]);
|
|
|
|
s->lookahead--;
|
|
|
|
s->strstart++;
|
|
|
|
if (bflush)
|
|
|
|
FLUSH_BLOCK(s, 0);
|
|
|
|
}
|
|
|
|
s->insert = 0;
|
|
|
|
if (flush == Z_FINISH) {
|
|
|
|
FLUSH_BLOCK(s, 1);
|
|
|
|
return finish_done;
|
|
|
|
}
|
|
|
|
if (s->sym_next)
|
|
|
|
FLUSH_BLOCK(s, 0);
|
|
|
|
return block_done;
|
|
|
|
}
|