コード例 #1
0
ファイル: igzip.c プロジェクト: 01org/isa-l
static int isal_deflate_int_stateless(struct isal_zstream *stream, uint8_t * next_in,
				      const uint32_t avail_in)
{
	uint32_t crc32 = 0;
	uint32_t repeated_char_length;

#ifndef DEFLATE
	if (write_gzip_header_stateless(stream))
		return STATELESS_OVERFLOW;
#endif

	if (avail_in >= 8
	    && (*(uint64_t *) stream->next_in == 0
		|| *(uint64_t *) stream->next_in == ~(uint64_t) 0))
		repeated_char_length =
		    detect_repeated_char_length(stream->next_in, stream->avail_in);
	else
		repeated_char_length = 0;

	if (stream->avail_in == repeated_char_length) {
		if (write_constant_compressed_stateless(stream,
							stream->next_in[0],
							repeated_char_length, 1) != COMP_OK)
			return STATELESS_OVERFLOW;

#ifndef DEFLATE
		crc32 = crc32_gzip(0x0, next_in, avail_in);
#endif

		/* write_trailer_stateless is required because if flushes out the last of the output */
		if (write_trailer_stateless(stream, avail_in, crc32) != COMP_OK)
			return STATELESS_OVERFLOW;
		return COMP_OK;

	} else if (repeated_char_length >= MIN_REPEAT_LEN) {
		if (write_constant_compressed_stateless
		    (stream, stream->next_in[0], repeated_char_length, 0) != COMP_OK)
			return STATELESS_OVERFLOW;
	}

	if (write_deflate_header_unaligned_stateless(stream) != COMP_OK)
		return STATELESS_OVERFLOW;
	if (stream->avail_out < 8)
		return STATELESS_OVERFLOW;

	isal_deflate_body_stateless(stream);

	if (!stream->internal_state.has_eob)
		return STATELESS_OVERFLOW;

#ifndef DEFLATE
	crc32 = crc32_gzip(0x0, next_in, avail_in);
#endif

	if (write_trailer_stateless(stream, avail_in, crc32) != COMP_OK)
		return STATELESS_OVERFLOW;

	return COMP_OK;
}
コード例 #2
0
ファイル: igzip.c プロジェクト: ceph/isa-l
static int isal_deflate_int_stateless(struct isal_zstream *stream)
{
	uint32_t repeat_length;
	struct isal_zstate *state = &stream->internal_state;

	if (stream->gzip_flag == IGZIP_GZIP)
		if (write_gzip_header_stateless(stream))
			return STATELESS_OVERFLOW;

	if (stream->avail_in >= 8
	    && (*(uint64_t *) stream->next_in == 0
		|| *(uint64_t *) stream->next_in == ~(uint64_t) 0)) {
		repeat_length = detect_repeated_char_length(stream->next_in, stream->avail_in);

		if (stream->avail_in == repeat_length || repeat_length >= MIN_REPEAT_LEN)
			write_constant_compressed_stateless(stream, repeat_length);
	}

	if (stream->level == 0) {
		if (state->state == ZSTATE_NEW_HDR || state->state == ZSTATE_HDR) {
			write_deflate_header_unaligned_stateless(stream);
			if (state->state == ZSTATE_NEW_HDR || state->state == ZSTATE_HDR)
				return STATELESS_OVERFLOW;

			reset_match_history(stream);
		}

		state->file_start = stream->next_in - stream->total_in;
		isal_deflate_pass(stream);

	} else if (stream->level == 1) {
		if (stream->level_buf == NULL || stream->level_buf_size < ISAL_DEF_LVL1_MIN) {
			/* Default to internal buffer if invalid size is supplied */
			stream->level_buf = state->buffer;
			stream->level_buf_size = sizeof(state->buffer);
		}

		if (state->state == ZSTATE_NEW_HDR || state->state == ZSTATE_HDR)
			reset_match_history(stream);

		state->count = 0;
		state->file_start = stream->next_in - stream->total_in;
		isal_deflate_icf_pass(stream);

	} else
		return ISAL_INVALID_LEVEL;

	if (state->state == ZSTATE_END
	    || (state->state == ZSTATE_NEW_HDR && stream->flush == FULL_FLUSH))
		return COMP_OK;
	else
		return STATELESS_OVERFLOW;
}
コード例 #3
0
ファイル: igzip.c プロジェクト: ceph/isa-l
static void create_icf_block_hdr(struct isal_zstream *stream)
{
	struct isal_zstate *state = &stream->internal_state;
	struct level_2_buf *level_buf = (struct level_2_buf *)stream->level_buf;
	struct BitBuf2 *write_buf = &state->bitbuf;
	struct BitBuf2 write_buf_tmp;
	uint32_t out_size = stream->avail_out;
	uint8_t *end_out = stream->next_out + out_size;
	/* Write EOB in icf_buf */
	state->hist.ll_hist[256] = 1;
	level_buf->icf_buf_next->lit_len = 0x100;
	level_buf->icf_buf_next->lit_dist = NULL_DIST_SYM;
	level_buf->icf_buf_next->dist_extra = 0;
	level_buf->icf_buf_next++;

	state->has_eob_hdr = stream->end_of_stream && !stream->avail_in;
	if (end_out - stream->next_out >= ISAL_DEF_MAX_HDR_SIZE) {
		/* Determine whether this is the final block */

		if (stream->gzip_flag == IGZIP_GZIP)
			write_gzip_header_stateless(stream);

		set_buf(write_buf, stream->next_out, stream->avail_out);

		create_hufftables_icf(write_buf, &level_buf->encode_tables, &state->hist,
				      state->has_eob_hdr);
		state->state = ZSTATE_FLUSH_ICF_BUFFER;
		stream->next_out = buffer_ptr(write_buf);
		stream->total_out += buffer_used(write_buf);
		stream->avail_out -= buffer_used(write_buf);
	} else {
		/* Start writing into temporary buffer */
		write_buf_tmp.m_bits = write_buf->m_bits;
		write_buf_tmp.m_bit_count = write_buf->m_bit_count;

		write_buf->m_bits = 0;
		write_buf->m_bit_count = 0;

		set_buf(&write_buf_tmp, level_buf->deflate_hdr, ISAL_DEF_MAX_HDR_SIZE);

		create_hufftables_icf(&write_buf_tmp, &level_buf->encode_tables,
				      &state->hist, state->has_eob_hdr);

		level_buf->deflate_hdr_count = buffer_used(&write_buf_tmp);
		level_buf->deflate_hdr_extra_bits = write_buf_tmp.m_bit_count;
		flush(&write_buf_tmp);

		state->state = ZSTATE_HDR;
	}
}