1 // SPDX-License-Identifier: Zlib
5 #include "../zlib_deflate/defutil.h"
10 #define DFLTCC_LEVEL_MASK 0x2 /* DFLTCC compression for level 1 only */
11 #define DFLTCC_BLOCK_SIZE 1048576
12 #define DFLTCC_FIRST_FHT_BLOCK_SIZE 4096
13 #define DFLTCC_DHT_MIN_SAMPLE_SIZE 4096
17 * Parameter Block for Query Available Functions.
19 struct dfltcc_qaf_param {
26 static_assert(sizeof(struct dfltcc_qaf_param) == 32);
31 * Parameter Block for Generate Dynamic-Huffman Table, Compress and Expand.
33 struct dfltcc_param_v0 {
34 uint16_t pbvn; /* Parameter-Block-Version Number */
35 uint8_t mvn; /* Model-Version Number */
36 uint8_t ribm; /* Reserved for IBM use */
37 unsigned reserved32 : 31;
38 unsigned cf : 1; /* Continuation Flag */
39 uint8_t reserved64[8];
40 unsigned nt : 1; /* New Task */
41 unsigned reserved129 : 1;
42 unsigned cvt : 1; /* Check Value Type */
43 unsigned reserved131 : 1;
44 unsigned htt : 1; /* Huffman-Table Type */
45 unsigned bcf : 1; /* Block-Continuation Flag */
46 unsigned bcc : 1; /* Block Closing Control */
47 unsigned bhf : 1; /* Block Header Final */
48 unsigned reserved136 : 1;
49 unsigned reserved137 : 1;
50 unsigned dhtgc : 1; /* DHT Generation Control */
51 unsigned reserved139 : 5;
52 unsigned reserved144 : 5;
53 unsigned sbb : 3; /* Sub-Byte Boundary */
54 uint8_t oesc; /* Operation-Ending-Supplemental Code */
55 unsigned reserved160 : 12;
56 unsigned ifs : 4; /* Incomplete-Function Status */
57 uint16_t ifl; /* Incomplete-Function Length */
58 uint8_t reserved192[8];
59 uint8_t reserved256[8];
60 uint8_t reserved320[4];
61 uint16_t hl; /* History Length */
62 unsigned reserved368 : 1;
63 uint16_t ho : 15; /* History Offset */
64 uint32_t cv; /* Check Value */
65 unsigned eobs : 15; /* End-of-block Symbol */
66 unsigned reserved431: 1;
67 uint8_t eobl : 4; /* End-of-block Length */
68 unsigned reserved436 : 12;
69 unsigned reserved448 : 4;
70 uint16_t cdhtl : 12; /* Compressed-Dynamic-Huffman Table
72 uint8_t reserved464[6];
78 static_assert(sizeof(struct dfltcc_param_v0) == 1536);
86 * Extension of inflate_state and deflate_state for DFLTCC.
89 struct dfltcc_param_v0 param; /* Parameter block */
90 struct dfltcc_qaf_param af; /* Available functions */
91 uLong level_mask; /* Levels on which to use DFLTCC */
92 uLong block_size; /* New block each X bytes */
93 uLong block_threshold; /* New block after total_in > X */
94 uLong dht_threshold; /* New block only if avail_in >= X */
95 char msg[64]; /* Buffer for strm->msg */
98 /* Resides right after inflate_state or deflate_state */
99 #define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((state) + 1))
101 /* External functions */
102 int dfltcc_can_deflate(z_streamp strm);
103 int dfltcc_deflate(z_streamp strm,
105 block_state *result);
106 void dfltcc_reset(z_streamp strm, uInt size);
108 #define DEFLATE_RESET_HOOK(strm) \
109 dfltcc_reset((strm), sizeof(deflate_state))
111 #define DEFLATE_HOOK dfltcc_deflate
113 #define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm)))
115 #endif /* DFLTCC_H */