Lines Matching +full:data +full:- +full:bits

1 // SPDX-License-Identifier: GPL-2.0+
2 /*-------------------------------------------------------------------------
8 *-----------------------------------------------------------------------*/
19 n--; in cramfs_memset()
20 for (;n > 0; n--) s[n] = c; in cramfs_memset()
24 /* associate a stream with a block of data and reset the 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()
63 /* pull 'bits' bits out of the stream. The last bit pulled it returned as the
67 const unsigned int bits) in pull_bits() argument
73 for (i = 0; i < bits; i++) { in pull_bits()
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()
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()
96 /* discard bits up to the next whole byte */
99 if (stream->bit != 0) { in discard_bits()
100 stream->bit = 0; in discard_bits()
101 stream->data++; in discard_bits()
105 /* No decompression, the data is all literals (section 3.2.4) */
111 length = *(stream->data++); in decompress_none()
112 length += *(stream->data++) << 8; 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()
123 int bits = 0; in read_symbol() local
125 while (!(set->count[bits] && code < set->first[bits] + in read_symbol()
126 set->count[bits])) { in read_symbol()
128 if (++bits > set->bits) { in read_symbol()
129 /* error decoding (corrupted data?) */ in read_symbol()
130 stream->error = CODE_NOT_FOUND; in read_symbol()
131 return -1; in read_symbol()
134 return set->symbols[set->pos[bits] + code - set->first[bits]]; in read_symbol()
137 /* decompress a stream of data encoded with the passed length and distance
141 struct huffman_set *lengths = &(stream->lengths); in decompress_huffman()
142 struct huffman_set *distance = &(stream->distance); in decompress_huffman()
150 stream->decoded++; in decompress_huffman()
154 if (symbol < 265) length = symbol - 254; in decompress_huffman()
157 length = pull_bits(stream, (symbol - 261) >> 2); in decompress_huffman()
158 length += (4 << ((symbol - 261) >> 2)) + 3; in decompress_huffman()
159 length += ((symbol - 1) % 4) << in decompress_huffman()
160 ((symbol - 261) >> 2); in decompress_huffman()
168 dist = pull_bits(stream, (symbol - 2) >> 1); in decompress_huffman()
169 dist += (2 << ((symbol - 2) >> 1)) + 1; in decompress_huffman()
170 dist += (symbol % 2) << ((symbol - 2) >> 1); in decompress_huffman()
172 stream->decoded += length; in decompress_huffman()
174 *dest = dest[-dist]; in decompress_huffman()
178 } while (symbol != 256); /* 256 is the end of the data block */ in decompress_huffman()
187 set->pos[0] = 0; in fill_code_tables()
188 for (i = 1; i < set->bits; i++) { in fill_code_tables()
189 code = (code + set->count[i - 1]) << 1; in fill_code_tables()
190 set->first[i] = code; in fill_code_tables()
191 set->pos[i] = set->pos[i - 1] + set->count[i - 1]; in fill_code_tables()
195 for (i = 0; i < set->num_symbols; i++) { in fill_code_tables()
196 if ((length = set->lengths[i])) in fill_code_tables()
197 set->symbols[set->pos[length]++] = i; in fill_code_tables()
201 for (i = 1; i < set->bits; i++) set->pos[i] -= set->count[i]; in fill_code_tables()
206 cramfs_memset(set->lengths, 0, set->num_symbols); in init_code_tables()
207 cramfs_memset(set->count, 0, set->bits); in init_code_tables()
208 cramfs_memset(set->first, 0, set->bits); in init_code_tables()
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()
243 codes->lengths[huffman_order[i]] = length; in decompress_dynamic()
244 if (length) codes->count[length]++; in decompress_dynamic()
258 lengths->lengths[curr_code] = last_code = symbol; in decompress_dynamic()
259 lengths->count[symbol]++; in decompress_dynamic()
261 } else if (symbol == 16) { /* repeat the last symbol 3 - 6 in decompress_dynamic()
264 for (;length; length--, curr_code++) in decompress_dynamic()
266 lengths->lengths[curr_code] = in decompress_dynamic()
268 lengths->count[last_code]++; in decompress_dynamic()
270 distance->lengths[curr_code - hlit] = in decompress_dynamic()
272 distance->count[last_code]++; in decompress_dynamic()
286 curr_code -= hlit; in decompress_dynamic()
293 distance->lengths[curr_code] = last_code = symbol; in decompress_dynamic()
294 distance->count[symbol]++; in decompress_dynamic()
298 for (;length; length--, curr_code++) { in decompress_dynamic()
299 distance->lengths[curr_code] = in decompress_dynamic()
301 distance->count[last_code]++; in decompress_dynamic()
321 struct huffman_set *lengths = &(stream->lengths); in decompress_fixed()
322 struct huffman_set *distance = &(stream->distance); in decompress_fixed()
324 cramfs_memset(lengths->count, 0, 16); in decompress_fixed()
325 cramfs_memset(lengths->first, 0, 16); in decompress_fixed()
326 cramfs_memset(lengths->lengths, 8, 144); in decompress_fixed()
327 cramfs_memset(lengths->lengths + 144, 9, 112); in decompress_fixed()
328 cramfs_memset(lengths->lengths + 256, 7, 24); in decompress_fixed()
329 cramfs_memset(lengths->lengths + 280, 8, 8); in decompress_fixed()
330 lengths->count[7] = 24; in decompress_fixed()
331 lengths->count[8] = 152; in decompress_fixed()
332 lengths->count[9] = 112; in decompress_fixed()
334 cramfs_memset(distance->count, 0, 16); in decompress_fixed()
335 cramfs_memset(distance->first, 0, 16); in decompress_fixed()
336 cramfs_memset(distance->lengths, 5, 32); in decompress_fixed()
337 distance->count[5] = 32; in decompress_fixed()
349 * (non-compliant, but I don't see where this would happen). section 3.2.3 */
374 return stream.error ? -stream.error : stream.decoded; in decompress_block()