MCPcopy Create free account
hub / github.com/TheRealMJP/DeferredTexturing / tdefl_flush_block

Function tdefl_flush_block

SampleFramework12/v1.00/TinyEXR.cpp:3143–3271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3141}
3142
3143static int tdefl_flush_block(tdefl_compressor *d, int flush) {
3144 mz_uint saved_bit_buf, saved_bits_in;
3145 mz_uint8 *pSaved_output_buf;
3146 mz_bool comp_block_succeeded = MZ_FALSE;
3147 int n, use_raw_block =
3148 ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) &&
3149 (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
3150 mz_uint8 *pOutput_buf_start =
3151 ((d->m_pPut_buf_func == NULL) &&
3152 ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE))
3153 ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs)
3154 : d->m_output_buf;
3155
3156 d->m_pOutput_buf = pOutput_buf_start;
3157 d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
3158
3159 MZ_ASSERT(!d->m_output_flush_remaining);
3160 d->m_output_flush_ofs = 0;
3161 d->m_output_flush_remaining = 0;
3162
3163 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
3164 d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
3165
3166 if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index)) {
3167 TDEFL_PUT_BITS(0x78, 8);
3168 TDEFL_PUT_BITS(0x01, 8);
3169 }
3170
3171 TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);
3172
3173 pSaved_output_buf = d->m_pOutput_buf;
3174 saved_bit_buf = d->m_bit_buffer;
3175 saved_bits_in = d->m_bits_in;
3176
3177 if (!use_raw_block)
3178 comp_block_succeeded =
3179 tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) ||
3180 (d->m_total_lz_bytes < 48));
3181
3182 // If the block gets expanded, forget the current contents of the output
3183 // buffer and send a raw block instead.
3184 if (((use_raw_block) ||
3185 ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >=
3186 d->m_total_lz_bytes))) &&
3187 ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size)) {
3188 mz_uint i;
3189 d->m_pOutput_buf = pSaved_output_buf;
3190 d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
3191 TDEFL_PUT_BITS(0, 2);
3192 if (d->m_bits_in) {
3193 TDEFL_PUT_BITS(0, 8 - d->m_bits_in);
3194 }
3195 for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF) {
3196 TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16);
3197 }
3198 for (i = 0; i < d->m_total_lz_bytes; ++i) {
3199 TDEFL_PUT_BITS(
3200 d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK],

Callers 3

tdefl_compress_fastFunction · 0.85
tdefl_compress_normalFunction · 0.85
tdefl_compressFunction · 0.85

Calls 1

tdefl_compress_blockFunction · 0.85

Tested by

no test coverage detected