1 // SPDX-License-Identifier: Zlib 2 #ifndef DFLTCC_H 3 #define DFLTCC_H 4 5 #include "../zlib_deflate/defutil.h" 6 7 /* 8 * Tuning parameters. 9 */ 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 14 #define DFLTCC_RIBM 0 15 16 /* 17 * Parameter Block for Query Available Functions. 18 */ 19 struct dfltcc_qaf_param { 20 char fns[16]; 21 char reserved1[8]; 22 char fmts[2]; 23 char reserved2[6]; 24 }; 25 26 static_assert(sizeof(struct dfltcc_qaf_param) == 32); 27 28 #define DFLTCC_FMT0 0 29 30 /* 31 * Parameter Block for Generate Dynamic-Huffman Table, Compress and Expand. 32 */ 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 71 Length */ 72 uint8_t reserved464[6]; 73 uint8_t cdht[288]; 74 uint8_t reserved[32]; 75 uint8_t csb[1152]; 76 }; 77 78 static_assert(sizeof(struct dfltcc_param_v0) == 1536); 79 80 #define CVT_CRC32 0 81 #define CVT_ADLER32 1 82 #define HTT_FIXED 0 83 #define HTT_DYNAMIC 1 84 85 /* 86 * Extension of inflate_state and deflate_state for DFLTCC. 87 */ 88 struct dfltcc_state { 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 */ 96 }; 97 98 /* Resides right after inflate_state or deflate_state */ 99 #define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((state) + 1)) 100 101 /* External functions */ 102 int dfltcc_can_deflate(z_streamp strm); 103 int dfltcc_deflate(z_streamp strm, 104 int flush, 105 block_state *result); 106 void dfltcc_reset(z_streamp strm, uInt size); 107 108 #define DEFLATE_RESET_HOOK(strm) \ 109 dfltcc_reset((strm), sizeof(deflate_state)) 110 111 #define DEFLATE_HOOK dfltcc_deflate 112 113 #define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm))) 114 115 #endif /* DFLTCC_H */ 116