Lines Matching full:stream
26 /* associate a stream with a block of data and reset the stream */
27 static void init_stream(struct bitstream *stream, unsigned char *data, in init_stream() argument
30 stream->error = NO_ERROR; in init_stream()
31 stream->memcpy = inflate_memcpy; in init_stream()
32 stream->decoded = 0; in init_stream()
33 stream->data = data; in init_stream()
34 stream->bit = 0; /* The first bit of the stream is the lsb of the in init_stream()
39 stream->codes.bits = 8; in init_stream()
40 stream->codes.num_symbols = 19; in init_stream()
41 stream->codes.lengths = stream->code_lengths; in init_stream()
42 stream->codes.symbols = stream->code_symbols; in init_stream()
43 stream->codes.count = stream->code_count; in init_stream()
44 stream->codes.first = stream->code_first; in init_stream()
45 stream->codes.pos = stream->code_pos; in init_stream()
47 stream->lengths.bits = 16; in init_stream()
48 stream->lengths.num_symbols = 288; in init_stream()
49 stream->lengths.lengths = stream->length_lengths; in init_stream()
50 stream->lengths.symbols = stream->length_symbols; in init_stream()
51 stream->lengths.count = stream->length_count; in init_stream()
52 stream->lengths.first = stream->length_first; in init_stream()
53 stream->lengths.pos = stream->length_pos; in init_stream()
55 stream->distance.bits = 16; in init_stream()
56 stream->distance.num_symbols = 32; in init_stream()
57 stream->distance.lengths = stream->distance_lengths; in init_stream()
58 stream->distance.symbols = stream->distance_symbols; in init_stream()
59 stream->distance.count = stream->distance_count; in init_stream()
60 stream->distance.first = stream->distance_first; in init_stream()
61 stream->distance.pos = stream->distance_pos; in init_stream()
65 /* pull 'bits' bits out of the stream. The last bit pulled it returned as the
68 inline unsigned long pull_bits(struct bitstream *stream, in pull_bits() argument
76 ret += ((*(stream->data) >> stream->bit) & 1) << i; in pull_bits()
80 if (stream->bit++ == 7) { in pull_bits()
81 stream->bit = 0; in pull_bits()
82 stream->data++; in pull_bits()
88 inline int pull_bit(struct bitstream *stream) in pull_bit() argument
90 int ret = ((*(stream->data) >> stream->bit) & 1); in pull_bit()
91 if (stream->bit++ == 7) { in pull_bit()
92 stream->bit = 0; in pull_bit()
93 stream->data++; in pull_bit()
99 static void discard_bits(struct bitstream *stream) in discard_bits() argument
101 if (stream->bit != 0) { in discard_bits()
102 stream->bit = 0; in discard_bits()
103 stream->data++; in discard_bits()
108 static void decompress_none(struct bitstream *stream, unsigned char *dest) in decompress_none() argument
112 discard_bits(stream); in decompress_none()
113 length = *(stream->data++); in decompress_none()
114 length += *(stream->data++) << 8; in decompress_none()
115 pull_bits(stream, 16); /* throw away the inverse of the size */ in decompress_none()
117 stream->decoded += length; in decompress_none()
118 stream->memcpy(dest, stream->data, length); in decompress_none()
119 stream->data += length; in decompress_none()
122 /* Read in a symbol from the stream (section 3.2.2) */
123 static int read_symbol(struct bitstream *stream, struct huffman_set *set) in read_symbol() argument
129 code = (code << 1) + pull_bit(stream); in read_symbol()
132 stream->error = CODE_NOT_FOUND; in read_symbol()
139 /* decompress a stream of data encoded with the passed length and distance
141 static void decompress_huffman(struct bitstream *stream, unsigned char *dest) in decompress_huffman() argument
143 struct huffman_set *lengths = &(stream->lengths); in decompress_huffman()
144 struct huffman_set *distance = &(stream->distance); in decompress_huffman()
149 if ((symbol = read_symbol(stream, lengths)) < 0) return; in decompress_huffman()
152 stream->decoded++; in decompress_huffman()
159 length = pull_bits(stream, (symbol - 261) >> 2); in decompress_huffman()
166 if ((symbol = read_symbol(stream, distance)) < 0) in decompress_huffman()
170 dist = pull_bits(stream, (symbol - 2) >> 1); in decompress_huffman()
174 stream->decoded += length; in decompress_huffman()
214 static void decompress_dynamic(struct bitstream *stream, unsigned char *dest) in decompress_dynamic() argument
226 struct huffman_set *codes = &(stream->codes); in decompress_dynamic()
227 struct huffman_set *lengths = &(stream->lengths); in decompress_dynamic()
228 struct huffman_set *distance = &(stream->distance); in decompress_dynamic()
230 int hlit = pull_bits(stream, 5) + 257; in decompress_dynamic()
231 int hdist = pull_bits(stream, 5) + 1; in decompress_dynamic()
232 int hclen = pull_bits(stream, 4) + 4; in decompress_dynamic()
244 length = pull_bits(stream, 3); in decompress_dynamic()
255 if ((symbol = read_symbol(stream, codes)) < 0) return; in decompress_dynamic()
265 length = 3 + pull_bits(stream, 2); in decompress_dynamic()
277 curr_code += 3 + pull_bits(stream, 3); in decompress_dynamic()
280 curr_code += 11 + pull_bits(stream, 7); in decompress_dynamic()
290 if ((symbol = read_symbol(stream, codes)) < 0) return; in decompress_dynamic()
299 length = 3 + pull_bits(stream, 2); in decompress_dynamic()
306 curr_code += 3 + pull_bits(stream, 3); in decompress_dynamic()
309 curr_code += 11 + pull_bits(stream, 7); in decompress_dynamic()
315 decompress_huffman(stream, dest); in decompress_dynamic()
320 static void decompress_fixed(struct bitstream *stream, unsigned char *dest) in decompress_fixed() argument
323 struct huffman_set *lengths = &(stream->lengths); in decompress_fixed()
324 struct huffman_set *distance = &(stream->distance); in decompress_fixed()
346 decompress_huffman(stream, dest); in decompress_fixed()
356 struct bitstream stream; in decompress_block() local
358 init_stream(&stream, source, inflate_memcpy); in decompress_block()
360 bfinal = pull_bit(&stream); in decompress_block()
361 btype = pull_bits(&stream, 2); in decompress_block()
362 if (btype == NO_COMP) decompress_none(&stream, dest + stream.decoded); in decompress_block()
364 decompress_dynamic(&stream, dest + stream.decoded); in decompress_block()
365 else if (btype == FIXED_COMP) decompress_fixed(&stream, dest + stream.decoded); in decompress_block()
366 else stream.error = COMP_UNKNOWN; in decompress_block()
367 } while (!bfinal && !stream.error); in decompress_block()
371 putLabeledWord("stream.error = ",stream.error); in decompress_block()
372 putLabeledWord("stream.decoded = ",stream.decoded); in decompress_block()
376 return stream.error ? -stream.error : stream.decoded; in decompress_block()