Lines Matching refs:stream

25 static void init_stream(struct bitstream *stream, unsigned char *data,  in init_stream()  argument
28 stream->error = NO_ERROR; in init_stream()
29 stream->memcpy = inflate_memcpy; in init_stream()
30 stream->decoded = 0; in init_stream()
31 stream->data = data; in init_stream()
32 stream->bit = 0; /* The first bit of the stream is the lsb of the in init_stream()
37 stream->codes.bits = 8; in init_stream()
38 stream->codes.num_symbols = 19; in init_stream()
39 stream->codes.lengths = stream->code_lengths; in init_stream()
40 stream->codes.symbols = stream->code_symbols; in init_stream()
41 stream->codes.count = stream->code_count; in init_stream()
42 stream->codes.first = stream->code_first; in init_stream()
43 stream->codes.pos = stream->code_pos; in init_stream()
45 stream->lengths.bits = 16; in init_stream()
46 stream->lengths.num_symbols = 288; in init_stream()
47 stream->lengths.lengths = stream->length_lengths; in init_stream()
48 stream->lengths.symbols = stream->length_symbols; in init_stream()
49 stream->lengths.count = stream->length_count; in init_stream()
50 stream->lengths.first = stream->length_first; in init_stream()
51 stream->lengths.pos = stream->length_pos; in init_stream()
53 stream->distance.bits = 16; in init_stream()
54 stream->distance.num_symbols = 32; in init_stream()
55 stream->distance.lengths = stream->distance_lengths; in init_stream()
56 stream->distance.symbols = stream->distance_symbols; in init_stream()
57 stream->distance.count = stream->distance_count; in init_stream()
58 stream->distance.first = stream->distance_first; in init_stream()
59 stream->distance.pos = stream->distance_pos; in init_stream()
66 static inline unsigned long pull_bits(struct bitstream *stream, in pull_bits() argument
74 ret += ((*(stream->data) >> stream->bit) & 1) << i; in pull_bits()
78 if (stream->bit++ == 7) { in pull_bits()
79 stream->bit = 0; in pull_bits()
80 stream->data++; in pull_bits()
86 static inline int pull_bit(struct bitstream *stream) in pull_bit() argument
88 int ret = ((*(stream->data) >> stream->bit) & 1); in pull_bit()
89 if (stream->bit++ == 7) { in pull_bit()
90 stream->bit = 0; in pull_bit()
91 stream->data++; in pull_bit()
97 static void discard_bits(struct bitstream *stream) in discard_bits() argument
99 if (stream->bit != 0) { in discard_bits()
100 stream->bit = 0; in discard_bits()
101 stream->data++; in discard_bits()
106 static void decompress_none(struct bitstream *stream, unsigned char *dest) in decompress_none() argument
110 discard_bits(stream); in decompress_none()
111 length = *(stream->data++); in decompress_none()
112 length += *(stream->data++) << 8; in decompress_none()
113 pull_bits(stream, 16); /* throw away the inverse of the size */ in decompress_none()
115 stream->decoded += length; in decompress_none()
116 stream->memcpy(dest, stream->data, length); in decompress_none()
117 stream->data += length; in decompress_none()
121 static int read_symbol(struct bitstream *stream, struct huffman_set *set) in read_symbol() argument
127 code = (code << 1) + pull_bit(stream); in read_symbol()
130 stream->error = CODE_NOT_FOUND; in read_symbol()
139 static void decompress_huffman(struct bitstream *stream, unsigned char *dest) in decompress_huffman() argument
141 struct huffman_set *lengths = &(stream->lengths); in decompress_huffman()
142 struct huffman_set *distance = &(stream->distance); in decompress_huffman()
147 if ((symbol = read_symbol(stream, lengths)) < 0) return; in decompress_huffman()
150 stream->decoded++; in decompress_huffman()
157 length = pull_bits(stream, (symbol - 261) >> 2); in decompress_huffman()
164 if ((symbol = read_symbol(stream, distance)) < 0) in decompress_huffman()
168 dist = pull_bits(stream, (symbol - 2) >> 1); in decompress_huffman()
172 stream->decoded += length; in decompress_huffman()
212 static void decompress_dynamic(struct bitstream *stream, unsigned char *dest) in decompress_dynamic() argument
224 struct huffman_set *codes = &(stream->codes); in decompress_dynamic()
225 struct huffman_set *lengths = &(stream->lengths); in decompress_dynamic()
226 struct huffman_set *distance = &(stream->distance); in decompress_dynamic()
228 int hlit = pull_bits(stream, 5) + 257; in decompress_dynamic()
229 int hdist = pull_bits(stream, 5) + 1; in decompress_dynamic()
230 int hclen = pull_bits(stream, 4) + 4; in decompress_dynamic()
242 length = pull_bits(stream, 3); in decompress_dynamic()
253 if ((symbol = read_symbol(stream, codes)) < 0) return; in decompress_dynamic()
263 length = 3 + pull_bits(stream, 2); in decompress_dynamic()
275 curr_code += 3 + pull_bits(stream, 3); in decompress_dynamic()
278 curr_code += 11 + pull_bits(stream, 7); in decompress_dynamic()
288 if ((symbol = read_symbol(stream, codes)) < 0) return; in decompress_dynamic()
297 length = 3 + pull_bits(stream, 2); in decompress_dynamic()
304 curr_code += 3 + pull_bits(stream, 3); in decompress_dynamic()
307 curr_code += 11 + pull_bits(stream, 7); in decompress_dynamic()
313 decompress_huffman(stream, dest); in decompress_dynamic()
318 static void decompress_fixed(struct bitstream *stream, unsigned char *dest) in decompress_fixed() argument
321 struct huffman_set *lengths = &(stream->lengths); in decompress_fixed()
322 struct huffman_set *distance = &(stream->distance); in decompress_fixed()
344 decompress_huffman(stream, dest); in decompress_fixed()
354 struct bitstream stream; in decompress_block() local
356 init_stream(&stream, source, inflate_memcpy); in decompress_block()
358 bfinal = pull_bit(&stream); in decompress_block()
359 btype = pull_bits(&stream, 2); in decompress_block()
360 if (btype == NO_COMP) decompress_none(&stream, dest + stream.decoded); in decompress_block()
362 decompress_dynamic(&stream, dest + stream.decoded); in decompress_block()
363 else if (btype == FIXED_COMP) decompress_fixed(&stream, dest + stream.decoded); in decompress_block()
364 else stream.error = COMP_UNKNOWN; in decompress_block()
365 } while (!bfinal && !stream.error); in decompress_block()
369 putLabeledWord("stream.error = ",stream.error); in decompress_block()
370 putLabeledWord("stream.decoded = ",stream.decoded); in decompress_block()
374 return stream.error ? -stream.error : stream.decoded; in decompress_block()